(* Lemma malloc_compat : forall {cs : compspecs} sh t p, complete_legal_cosu_type t = true -> natural_aligned natural_alignment t = true -> malloc_token sh (sizeof t) p = !!field_compatible t [] p && malloc_token sh (sizeof t) p. *)
Ltac lock_props := rewrite ?sepcon_assoc; rewrite <- sepcon_emp at 1; rewrite sepcon_comm; apply sepcon_derives;
[repeat apply andp_right; auto; eapply derives_trans;
try (apply exclusive_weak_exclusive || (apply rec_inv_weak_rec_inv; try apply selflock_rec)); auto |
try timeout 20 cancel].
Ltac join_sub := repeat (eapply sepalg.join_sub_trans;
[eexists; first [eassumption | simple eapply sepalg.join_comm; eassumption]|]); eassumption.
Ltac join_inj := repeat match goal with H1 : sepalg.join ?a ?b ?c, H2 : sepalg.join ?a ?b ?d |- _ =>
pose proof (sepalg.join_eq H1 H2); clear H1 H2; subst; auto end.
Ltac fast_cancel := rewrite ?sepcon_emp, ?emp_sepcon; rewrite ?sepcon_assoc;
repeat match goal with
| |- ?P |-- ?P => apply derives_refl
| |- ?P * _ |-- ?P * _ => apply sepcon_derives; [apply derives_refl|]
| |- _ |-- ?P * _ => rewrite <- !sepcon_assoc, (sepcon_comm _ P), !sepcon_assoc end;
try cancel_frame.
(*Ltac forward_malloc t n := forward_call (sizeof t); [simpl; try computable | Intros n; rewrite malloc_compat by (auto; reflexivity); Intros; rewrite memory_block_data_at_ by auto]. *)

(* Specifications: *)
Lemma semax_fun_id'' id f gv Espec {cs} Delta P Q R Post c :
(var_types Delta) ! id = None ->
(glob_specs Delta) ! id = Some f ->
(glob_types Delta) ! id = Some (type_of_funspec f) ->
snd (local2ptree Q) = Some gv ->
@semax cs Espec Delta
(PROPx P
(LOCALx Q
(SEPx ((func_ptr' f (gv id)) :: R)))) c Post ->
@semax cs Espec Delta (PROPx P (LOCALx Q (SEPx R))) c Post.