The OCaml manual states:
Local variables of type value must be declared with one of the
CAMLlocal macros. [...] These macros must be used at the beginning
of the function, not in a nested block.
This patch moves several instances of CAMLlocal macros from nested
blocks to the function beginning.