Section Ksafety_Clight.
(* Import DryMachineSource.THE_DRY_MACHINE_SOURCE.DMS.DryConc. Import DryMachineSource.THE_DRY_MACHINE_SOURCE.SCH. Import DryMachineSource.THE_DRY_MACHINE_SOURCE.DMS.DryMachine. *)
(** *Clight setup *)
(** We define state and step to match the type of ksafe (in konig/safety) *)
Parameter machine_event:Type.
Definition new_state: Type:= list machine_event * machine_state * mem.
Definition mk_nstate (st:MachState) m:new_state:= (snd (fst st), snd st, m).
Definition ksafe_new_step (ge : G) (st : MachState) (m : mem) : nat -> Prop :=
ksafe _ _ (new_step ge) new_valid (mk_nstate st m) (fst (fst st)).
(* Lemma init_schedule_all: forall U pmap n g m p t init_mach om, (semantics.initial_core (MachineSemantics U pmap) n g m p t) = Some (init_mach, om) -> forall U'', correct_schedule (U'', snd (fst init_mach), snd init_mach) -> schedPeek U'' = Some 1  \/ schedPeek U'' = None .  Ad_itted. *)
End Ksafety_Clight.
(*The following variables represent a program satisfying some CSL*)
(* Section Clight_safety. Variable CPROOF: CSL_proof. Definition CS :=   CPROOF.(CSL_CS). Definition V :=   CPROOF.(CSL_V). Definition G :=   CPROOF.(CSL_G). Definition ext_link :=   CPROOF.(CSL_ext_link). Definition ext_link_inj :=   CPROOF.(CSL_ext_link_inj). Definition prog :=   CPROOF.(CSL_prog). Definition all_safe :=   CPROOF.(CSL_all_safe). Definition init_mem_not_none :=   CPROOF.(CSL_init_mem_not_none).  Variables (x: block) (block: (Genv.find_symbol (globalenv prog) (prog_main (Ctypes.program_of_program prog)) = Some x)).  Notation init_jmem n:= (initial_jm CPROOF n). Notation init_rmap n:=(Some (juicy_mem.m_phi (init_jmem n) )). Notation init_genv:=(globalenv prog). Notation init_point:=(Vptr (projT1 ((spr CPROOF))) Integers.Int.zero).   Section Csafety_Clight. (** The initial Juicy Machine *)
Definition js_initial n := initial_machine_state CPROOF n.
Definition Juicy_safety:=
safety_initial_state CPROOF.
(*Import JuicyMachineModule.THE_JUICY_MACHINE.SCH.*)
(*this is showing the similarity between JM's initial machine and CoreSemantics initial machine*)
Definition CoreInitial U r := (semantics.initial_core (MachineSemantics U r)).

Lemma initial_equivalence: forall u r n
(g:JuicyMachineModule.THE_JUICY_MACHINE.JSEM.ThreadPool.SEM.G)
b,
genv_genv g = Genv.globalenv (Ctypes.program_of_program prog) ->
b =  projT1 ((spr CPROOF)) ->
r = Some (juicy_mem.m_phi (initial_jm CPROOF  n)) ->
CoreInitial u r 0 g
(juicy_mem.m_dry (initial_jm CPROOF  n)) (Vptr b Integers.Int.zero) nil =
Some (u, nil, initial_machine_state CPROOF n, None).