(* spawn handler *)
Notation tvoidptr := (Tpointer Tvoid noattr).
Notation tvoidfun := (Tfunction (Tcons tvoidptr Tnil) tvoidptr AST.cc_default).
Definition f_wrapper : Clight.function :=
{| Clight.fn_return := Tvoid; Clight.fn_callconv := AST.cc_default;
Clight.fn_params := [(1%positive, tvoidfun); (2%positive, tvoidptr)];
Clight.fn_vars := []; Clight.fn_temps := [];
Clight.fn_body := Clight.Scall None (Clight.Etempvar 1%positive tvoidfun) [Clight.Etempvar 2%positive tvoidptr] |}.
Class spawn_wrapper := { lookup_wrapper: exists b_wrapper, Genv.find_funct_ptr (Clight.genv_genv ge) b_wrapper = Some (Ctypes.Internal f_wrapper)}.
Context {SW : spawn_wrapper}.

(* Specifications: *)
Lemma match_cont_prefix: forall k k1 k2, match_cont (Clight_new.strip_skip k1) (strip_skip' k2) ->
match_cont (Clight_new.strip_skip (Clight_new.Kseq k :: k1))
(strip_skip' (CC.Kseq k k2)).
Lemma match_body: forall body f te,
match_cont
(Clight_new.strip_skip
[Clight_new.Kseq body; Clight_new.Kseq (Clight.Sreturn None);
Clight_new.Kcall None f Clight.empty_env te;
Clight_new.Kseq (Clight.Sloop Clight.Sskip Clight.Sskip)])
(strip_skip'
(CC.Kseq body
(Clight.Kcall None f_wrapper Clight.empty_env te (Clight.Kseq (Clight.Sloop Clight.Sskip Clight.Sskip) Clight.Kstop)))).
Lemma match_ext: forall ef v2 t0 tyres te,
match_states
(Clight_new.ExtCall ef [v2] None Clight.empty_env te
[Clight_new.Kseq (Clight.Sloop Clight.Sskip Clight.Sskip) ])
(CC'.CC_core_Callstate (Ctypes.External ef (Ctypes.Tcons t0 Ctypes.Tnil) tyres AST.cc_default) [v2]
(Clight.Kcall None f_wrapper Clight.empty_env te
(Clight.Kseq (Clight.Sloop Clight.Sskip Clight.Sskip) Clight.Kstop))).
Lemma mem_compatible_updThreadC: forall {Sem ThreadPool} (tp : @t _ Sem ThreadPool)
m i c (cnti : containsThread tp i),
mem_compatible tp m -> mem_compatible (updThreadC cnti c) m.