Local Open Scope nat_scope.
Definition control_as_safe {Espec: OracleKind} ge n ctl1 ctl2 :=
forall (ora : OK_ty) (ve : env) (te : temp_env) (m : juicy_mem) (n' : nat),
n' <= n ->
jsafeN (@OK_spec Espec) ge n' ora (State ve te ctl1) m ->
jsafeN (@OK_spec Espec) ge n' ora (State ve te ctl2) m.
Fixpoint prebreak_cont (k: cont) : cont :=
match k with
| Kloop1 s e3 :: k' => k
| Kseq s :: k' => prebreak_cont k'
| Kloop2 s e3 :: k' => k
| Kswitch :: k' => k
| _ =>  nil (* stuck *)
end.

Lemma corestep_preservation_lemma {Espec: OracleKind}:
forall ge ctl1 ctl2 ora ve te m n c l c' m',
filter_seq ctl1 = filter_seq ctl2 ->
(forall k : list cont', control_as_safe ge n (k ++ ctl1) (k ++ ctl2)) ->
control_as_safe ge (S n) ctl1 ctl2 ->
jstep (cl_core_sem ge) (State ve te (c :: l ++ ctl1)) m c' m' ->
jm_bupd ora (jsafeN (@OK_spec Espec) ge n ora c') m' ->
exists c2 : corestate,
exists m2 : juicy_mem,
jstep (cl_core_sem ge) (State ve te (c :: l ++ ctl2)) m c2 m2 /\
jm_bupd ora (jsafeN (@OK_spec Espec) ge n ora c2) m2.