let annotate_kf_with kf new_gen_opts new_other_opts =
  (* generates annotation for function kf
     on the basis of options given as arguments
     (which may differ from command-line options)
  *)

  let do_annotate_kf kf =
    (* annotate function kf with option selected in StateManager *)
    match kf.fundec with
      | Declaration _ -> ()
      | Definition (f,_) ->
          remove_annotations_kf kf ;
          let vis = new rte_annot_visitor kf
            (* (StateManager.find_current_gen_options kf) *)
          in let _nkf = Visitor.visitFramacFunction vis f in
            assert(_nkf == f)
  in
  let old_gen_opts = StateManager.find_current_gen_options kf
  and old_other_opts = StateManager.find_current_other_options kf
  in
    if
      (* case 1: generating options have changed *)
      Parameter_map.compare old_gen_opts new_gen_opts <> 0
      ||
        (* case 2: no generating option has changed,
           but the user wants to generate the same annotations with const
           folding, warning enabled ... *)

        (Parameter_map.is_one_true ~except:None new_gen_opts &&
           Parameter_map.compare old_other_opts new_other_opts <> 0)
    then begin
      (* options have changed for function kf: there is some work to do *)
      debug "Options have changed: something to do for function %s"
        (Kernel_function.get_name kf) ;
      (* update analysis options for function kf *)
      StateManager.FuncOptionTbl.replace kf (new_gen_opts, new_other_opts) ;
      if Parameter_map.is_one_true ~except:None new_gen_opts then begin
        (* there may be new annotations to add and remove *)
        feedback "annotating function %s" (Kernel_function.get_name kf) ;
        do_annotate_kf kf ;
        (* set status of rte/precond generation (see properties_status.mli) *)
        List.iter
          (fun (opt_name, _opt_get, _, property_set) ->
             property_set kf (Parameter_map.is_true opt_name new_gen_opts))
          Parameter_map.generating_opts
      end else begin
        (* all annotations should be removed *)
        (* and RTE_Generated / Called_Precond_Generated are reset *)
        feedback "unannotating function %s" (Kernel_function.get_name kf) ;
        (* reset status of rte/precond generation *)
        List.iter
          (fun (_opt_name, _opt_get, _, property_set) ->
             property_set kf false)
          Parameter_map.generating_opts;
        remove_annotations_kf kf
      end
    end