let with_open_out_file x f =
match x with
| Some file ->
let oc = open_out_bin file
in (f oc; flush oc; close_out oc)
| None ->
(set_binary_mode_out stdout true; f stdout; flush stdout)