Module SortBodyProof := Mergesort.Sort(BodyProofOrder).
Definition Gprog_of_proof (p: semax_body_proof) :=
match p with
| @mk_body _ G _ _ _ _ _ => G
| @mk_external _ _ _ _ _ _ _ _ _ _ => nil
end.
Fixpoint delete_dups' id f (al: funspecs) : funspecs :=
match al with
| (id',f')::al' => if ident_eq id id' then delete_dups' id f al'
else (id,f)::delete_dups' id' f' al'
| nil => (id,f)::nil
end.
Definition delete_dups (al: funspecs) : funspecs :=
match al with
| (id,f)::al' => delete_dups' id f al'
| nil => nil
end.
Definition merge_Gprogs_of (module: list semax_body_proof) :=
delete_dups
(SortFunspec.sort
(List.fold_right (fun m G => Gprog_of_proof m ++ G) (nil: funspecs) module)).

Lemma tycontext_sub_i99:
forall f Vprog1 Vprog2 Gprog1 Gprog2 Annot,
(forall id : positive,
sub_option (make_tycontext_g Vprog1 Gprog1) ! id
(make_tycontext_g Vprog2 Gprog2) ! id) ->
(forall id : positive,
subsumespec (make_tycontext_s Gprog1) ! id (make_tycontext_s Gprog2) ! id) ->
tycontext_sub (func_tycontext f Vprog1 Gprog1 Annot)
(func_tycontext f Vprog2 Gprog2 Annot).