let safe_div a b =
  if b = 0 then None else Some (a / b)

let safe_chain a b c =
  match safe_div a b with
  | None -> None
  | Some q -> safe_div q c

;;

(match safe_chain 100 2 5 with Some x -> x | None -> -1)
+ (match safe_chain 100 0 5 with Some x -> x | None -> -1)
+ (match safe_chain 50 5 0 with Some x -> x | None -> -1)
+ (match safe_chain 1000 10 5 with Some x -> x | None -> -1)
