(* Require Import VST.concurrency.common.core_semantics. Require Import VST.concurrency.common.bounded_maps. Require Import VST.concurrency.common.threadPool. Require Import VST.concurrency.common.permissions. Require Import VST.concurrency.common.HybridMachineSig. Require Import VST.concurrency.common.ClightSemanticsForMachines. Require Import VST.concurrency.common.ClightMachine. Require Import VST.concurrency.common.dry_machine_lemmas. Require Import VST.concurrency.juicy.semax_simlemmas. Require Import VST.concurrency.juicy.semax_to_juicy_machine. Require Import VST.concurrency.juicy.mem_wd2. Require Import VST.veric.Clight_sim. *)
Set Bullet Behavior "Strict Subproofs".
Section GE.
Variable ge: Clight.genv.
Section CTL_OK.
Variable nextb : block.
Definition block_ok (b: block) := Plt b nextb.
Definition val_ok (v: val) : Prop :=
match v with
| Vptr b _ => block_ok b
| _ => True
end.
Definition venv_ok (ve: Clight.env) :=
forall i bt, PTree.get i ve = Some bt -> block_ok (fst bt).
Definition tenv_ok (te: Clight.temp_env) :=
forall i (v: val), PTree.get i te = Some v -> val_ok v.
Definition cont'_ok (k: Clight_new.cont') :=
match k with
| Clight_new.Kcall _ _ ve te => venv_ok ve /\ tenv_ok te
| _ => True
end.
Definition cont_ok (k: Clight_new.cont) := Forall cont'_ok k.
Definition corestate_ok (q: Clight_new.corestate) : Prop :=
match q with
| Clight_new.State ve te k => venv_ok ve /\ tenv_ok te /\ cont_ok k
| Clight_new.ExtCall f vl _ ve te k => Forall val_ok vl /\ venv_ok ve /\ tenv_ok te /\ cont_ok k
end.
End CTL_OK.
Section ALLOC_OK.
Variable nextb: positive.
Variable nextb': positive.
Variable LESS:  (nextb <= nextb')%positive.

Lemma eval_expr_ok:
forall (m : mem) (ve : Clight.env) (te : Clight.temp_env)
(a : Clight.expr) (v : val),
@Smallstep.globals_not_fresh Clight.fundef type (Clight.genv_genv ge) m ->
mem_wd2 m ->
venv_ok (Mem.nextblock m) ve ->
tenv_ok (Mem.nextblock m) te ->
eval_expr ge ve te m a v ->
val_ok (Mem.nextblock m) v
with eval_lvalue_ok:
forall (m : mem) (ve : Clight.env) (te : Clight.temp_env)
(a : Clight.expr) (v : block) ofs,
@Smallstep.globals_not_fresh Clight.fundef type (Clight.genv_genv ge) m ->
mem_wd2 m ->
venv_ok (Mem.nextblock m) ve ->
tenv_ok (Mem.nextblock m) te ->
eval_lvalue ge ve te m a v ofs ->
block_ok (Mem.nextblock m) v.