Section MainTheorem.
(*Assumptions *)
Context (CPROOF : semax_to_juicy_machine.CSL_proof).
Context (program_proof : CSL_prog CPROOF = C_program).
Definition Main_ptr:=Values.Vptr (Ctypes.prog_main C_program) Integers.Ptrofs.zero.
Context (compilation : CC_correct.CompCert_compiler C_program = Some Asm_program).
Context (asm_genv_safe: Asm_core.safe_genv (@x86_context.X86Context.the_ge Asm_program)).
Instance SemTarget : Semantics:= @x86_context.X86Context.X86Sem Asm_program asm_genv_safe.
Existing Instance X86Inj.X86Inj.
Variable init_mem_wd:
forall m,
Genv.init_mem Asm_program = Some m ->
mem_obs_eq.MemoryWD.valid_mem m /\
mem_obs_eq.CoreInjections.ge_wd (Renamings.id_ren m) semantics.the_ge.
(* This should be instantiated: it says initial_Clight_state taken from CPROOF, is an initial state of CompCert. *)
Context (CPROOF_initial:
entry_point (Clight.globalenv C_program)
(erasure_safety.init_mem CPROOF)
(Clight_safety.initial_Clight_state CPROOF)
Main_ptr nil).
(*Safety from CSL to Coarse Asm*)
Definition SemSource p:= (ClightSemanticsForMachines.ClightSem (Clight.globalenv p)).
Definition asm_concursem m:=
(HybridMachineSig.HybridMachineSig.ConcurMachineSemantics
(Sem:=SemTarget)
(ThreadPool:= threadPool.OrdinalPool.OrdinalThreadPool(Sem:=SemTarget))
(HybridMachine:=concurrent_compiler_safety.TargetHybridMachine)
(machineSig:= HybridMachine.DryHybridMachine.DryHybridMachineSig) m).
Definition asm_init_machine:=
machine_semantics.initial_machine (asm_concursem (Genv.init_mem Asm_program)).
Context {SW : Clight_safety.spawn_wrapper CPROOF}.

Lemma CSL2CoarseAsm_safety:
forall U,
exists init_mem_target init_mem_target' init_thread_target,
let res_target := permissions.getCurPerm init_mem_target' in
let res:=(res_target, permissions.empty_map) in
let init_tp_target :=
threadPool.ThreadPool.mkPool
(Sem:=SemTarget)
(resources:=erasure_proof.Parching.DR)
(Krun init_thread_target)
res in
let init_MachState_target := (U, nil, init_tp_target) in
asm_init_machine (Some res) init_mem_target init_tp_target init_mem_target' Main_ptr nil /\
forall n,
HybridMachineSig.HybridMachineSig.HybridCoarseMachine.csafe
(ThreadPool:=threadPool.OrdinalPool.OrdinalThreadPool
(Sem:=SemTarget))
(machineSig:= HybridMachine.DryHybridMachine.DryHybridMachineSig)
init_MachState_target init_mem_target' n.