Require Import VST.veric.Clight_base.
Require Import VST.msl.msl_standard.
Require Import VST.veric.compcert_rmaps.
Require Import VST.veric.Clight_lemmas.
Require Import VST.veric.mpred.
Require Import VST.veric.tycontext.
Require Import VST.veric.expr2.
Require Export VST.veric.environ_lemmas.
Require Import VST.veric.binop_lemmas2.
Require Import VST.veric.binop_lemmas.
Require Import VST.veric.binop_lemmas4.
Require Import VST.veric.binop_lemmas5.
Require Import VST.veric.binop_lemmas6.
Require Import VST.veric.expr_lemmas2.
Require Export VST.veric.expr_lemmas3.
Require Import VST.veric.juicy_mem.
Import Cop.
Import Cop2.
Import Clight_Cop2.

(** Main soundness result for the typechecker **)

Lemma typecheck_both_sound:
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
  forall {CS: compspecs} Delta rho m e ,
             typecheck_environ Delta rho ->
             (denote_tc_assert (typecheck_expr Delta e) rho m ->
             tc_val (typeof e) (eval_expr e rho)) /\
             (forall pt,
             denote_tc_assert (typecheck_lvalue Delta e) rho m ->
             is_pointer_type pt = true ->
             tc_val pt (eval_lvalue e rho)).
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros. induction e; split; intros; try solve[subst; auto]; try contradiction.

* (*Const int*)
simpl in *. destruct t; try contradiction.
(* Goal: tc_val (Tint i0 s a) (@liftx (LiftEnviron val) (Vint i) rho) *)
destruct i0; try contradiction. auto.

* (*Const float*)
destruct f; simpl in *; subst; destruct t; try destruct f; intuition.
* (* Const single *)
destruct f; simpl in *; subst; destruct t; try destruct f; intuition.

* (*Var*)
(* Goal: @eq bool true true *)
eapply typecheck_expr_sound_Evar; eauto.

*eapply typecheck_lvalue_Evar; eauto.

* (*Temp*)
(* Goal: @eq bool true true *)
eapply typecheck_temp_sound; eauto.

* (*deref*)

simpl in H0 |- *.
(* Goal: tc_val t (@eval_expr CS e rho) *)
unfold deref_noload.
(* Goal: tc_val t (@eval_expr CS e rho) *)
destruct (access_mode t) eqn:?H; try inversion H0.
(* Goal: tc_val t (@eval_expr CS e rho) *)
unfold Datatypes.id.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
unfold_lift.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
rewrite !denote_tc_assert_andp in H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
simpl in H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
destruct H0.
(* Goal: tc_val t (@eval_expr CS e rho) *)
unfold_lift in H2.
(* Goal: tc_val t (@eval_expr CS e rho) *)
destruct (eval_expr e rho); inversion H2.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
(* Goal: tc_val t (Vptr b i) *)
destruct t; try reflexivity; try inversion H1.
- destruct i0, s; inversion H4.
- destruct f; inversion H4.

*

simpl in H0 |- *.
(* Goal: tc_val pt (@eval_expr CS e rho) *)
unfold tc_val.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
rewrite !denote_tc_assert_andp in H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
simpl in H0.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
destruct H0 as [[? ?] ?].
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
unfold tc_bool in H2; simpl in H2.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
destruct (is_pointer_type (typeof e)) eqn:?H; [|inversion H2].
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
unfold_lift.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
unfold_lift in H3.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
destruct (eval_expr e rho); inversion H3.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (Vptr b i) *)
unfold is_pointer_type in H1.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (Vptr b i) *)
destruct pt; try reflexivity; try solve [inversion H1].
(* Goal: (if eqb_type (Tpointer pt a) int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null) (Vptr b i) *)
destruct (eqb_type (Tpointer pt a) int_or_ptr_type); inv H1.
(* Goal: is_pointer_or_null (Vptr b i) *)
apply I.

* (*addrof*)
(* Goal: tc_val (typeof e) (@eval_expr CS e rho) *)
intuition.
simpl in *.
(* Goal: tc_val t (@eval_lvalue CS e rho) *)
rewrite denote_tc_assert_andp in H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
destruct H0.
(* Goal: @eq bool true true *)
destruct t; auto.
unfold tc_val, is_pointer_type in H3|-*.
(* Goal: (if eqb_type (Tpointer t a) int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null) (@eval_lvalue CS e rho) *)
destruct (eqb_type (Tpointer t a) int_or_ptr_type) eqn:J.
(* Goal: is_pointer_or_integer (@eval_lvalue CS e rho) *)
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
apply eqb_type_true in J. rewrite J in H3.
(* Goal: is_pointer_or_integer (@eval_lvalue CS e rho) *)
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
contradiction H3.
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
specialize (H2 (Tpointer t a) H0).
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
unfold tc_val in H2.
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
rewrite J in H2.
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
unfold is_pointer_type in H2. rewrite J in H2.
(* Goal: @eq bool true true *)
apply H2; auto.

* (*Unop*)
(* Goal: @eq bool true true *)
eapply typecheck_unop_sound; eauto.
* (*binop*)
repeat rewrite andb_true_iff in *; intuition.
(* Goal: tc_val (typeof (Ebinop b e1 e2 t)) (@eval_expr CS (Ebinop b e1 e2 t) rho) *)
clear H4. clear H2. clear H.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
simpl in H0.
(* Goal: tc_val t (@eval_lvalue CS e rho) *)
repeat rewrite denote_tc_assert_andp in H0.
(* Goal: tc_val (typeof (Ebinop b e1 e2 t)) (@eval_expr CS (Ebinop b e1 e2 t) rho) *)
destruct H0 as [[H0 E1] E2].
(* Goal: tc_val (typeof (Ebinop b e1 e2 t)) (@eval_expr CS (Ebinop b e1 e2 t) rho) *)
apply (typecheck_binop_sound b rho m e1 e2 t H0 (H3 E2) (H1 E1)).

* (* cast *)
(* Goal: tc_val (typeof (Ecast e t)) (@eval_expr CS (Ecast e t) rho) *)
destruct IHe.
(* Goal: @eq bool true true *)
eapply typecheck_cast_sound; eauto.

* (*EField*)
(* Goal: @eq bool true true *)
eapply typecheck_expr_sound_Efield; eauto.
*
(* Goal: @eq bool true true *)
eapply typecheck_lvalue_sound_Efield; eauto.
* (* Esizeof *)
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
simpl in H0.
(* Goal: tc_val t (@eval_lvalue CS e rho) *)
repeat rewrite denote_tc_assert_andp in H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
destruct H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
apply tc_bool_e in H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
apply tc_bool_e in H1.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
rewrite eqb_type_spec in H1.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
subst.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
(* Goal: tc_val size_t (@liftx (LiftEnviron val) (Vptrofs (Ptrofs.repr (@alignof (@cenv_cs CS) t))) rho) *)
reflexivity.
* (* Ealignof *)
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
simpl in H0.
(* Goal: tc_val t (@eval_lvalue CS e rho) *)
repeat rewrite denote_tc_assert_andp in H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
destruct H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
apply tc_bool_e in H0.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
apply tc_bool_e in H1.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
rewrite eqb_type_spec in H1.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
subst.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
(* Goal: tc_val size_t (@liftx (LiftEnviron val) (Vptrofs (Ptrofs.repr (@alignof (@cenv_cs CS) t))) rho) *)
reflexivity.
Qed.

(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
Lemma typecheck_expr_sound : forall {CS: compspecs} Delta rho m e,
 typecheck_environ Delta rho ->
              denote_tc_assert (typecheck_expr Delta e) rho m ->
              tc_val (typeof e) (eval_expr e rho).
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
Proof. intros.
(* Goal: tc_val (typeof e) (@eval_expr CS e rho) *)
assert (TC := typecheck_both_sound Delta rho m e). intuition. Qed.


(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
Lemma typecheck_lvalue_sound : forall {CS: compspecs} Delta rho m e,
  typecheck_environ Delta rho ->
  denote_tc_assert (typecheck_lvalue Delta e) rho m ->
  is_pointer_or_null (eval_lvalue e rho).
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
 edestruct (typecheck_both_sound _ _ m e H).
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
specialize (H2 (Tpointer Tvoid noattr) H0 (eq_refl _)).
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
apply H2.
Qed.

Ltac unfold_cop2_sem_cmp :=
unfold Clight_Cop2.sem_cmp, Clight_Cop2.sem_cmp_pl, Clight_Cop2.sem_cmp_lp, Clight_Cop2.sem_cmp_pp.

Lemma eval_binop_relate:
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
 forall {CS: compspecs} Delta (ge: genv) te ve rho b e1 e2 t m
        (Hcenv: genv_cenv ge = @cenv_cs CS),
    rho = construct_rho (filter_genv ge) ve te ->
    typecheck_environ Delta rho ->
    ((denote_tc_assert (typecheck_expr Delta e1) rho) (m_phi m) ->
      Clight.eval_expr ge ve te (m_dry m) e1 (eval_expr e1 rho)) ->
    ((denote_tc_assert (typecheck_expr Delta e2) rho) (m_phi m) ->
       Clight.eval_expr ge ve te (m_dry m) e2 (eval_expr e2 rho)) ->
    (denote_tc_assert (typecheck_expr Delta (Ebinop b e1 e2 t)) rho) (m_phi m) ->
    Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t)
                     (eval_expr (Ebinop b e1 e2 t) rho).
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (b : binary_operation) (e1 e2 : expr) (t : type) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : forall _ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_expr CS Delta e1) rho) (m_phi m), Clight.eval_expr ge ve te (m_dry m) e1 (@eval_expr CS e1 rho)) (_ : forall _ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_expr CS Delta e2) rho) (m_phi m), Clight.eval_expr ge ve te (m_dry m) e2 (@eval_expr CS e2 rho)) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_expr CS Delta (Ebinop b e1 e2 t)) rho) (m_phi m)), Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (@eval_expr CS (Ebinop b e1 e2 t) rho) *)
intros until 1. intros H H0 H1 H2 H3.
simpl in *. super_unfold_lift.
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
rewrite !denote_tc_assert_andp in H3.
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
destruct H3 as [[H3 TC1] TC2].
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
specialize (H1 TC1).
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
specialize (H2 TC2).
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
apply typecheck_expr_sound in TC1; [| auto].
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
apply typecheck_expr_sound in TC2; [| auto].
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
clear H0 H.
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
clear Delta.
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
eapply eval_binop_relate'; eassumption.
Qed.

Lemma valid_pointer_dry0:
  forall b ofs m, app_pred (valid_pointer (Vptr b ofs)) (m_phi m) ->
           Mem.valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) = true.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
rewrite <- (Z.add_0_r (Ptrofs.unsigned ofs)).
(* Goal: @eq bool true true *)
apply valid_pointer_dry; auto.
Qed.



Definition some_pt_type := Tpointer Tvoid noattr.

Lemma tc_force_Some : forall ov t, tc_val t (force_val ov)
-> exists v, ov = Some v.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
  intros.
(* Goal: @ex val (fun v : val => @eq (option val) ov (@Some val v)) *)
 unfold tc_val in H.
  destruct (eqb_type t int_or_ptr_type);
 destruct ov; destruct t; eauto; simpl in *; try tauto;
(* Goal: @eq bool true true *)
  destruct f; tauto.
Qed.

Lemma typecheck_binop_sound2:
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
 forall {CS: compspecs} (Delta : tycontext) (rho : environ) m (b : binary_operation)
     (e1 e2 : expr) (t : type),
   denote_tc_assert (typecheck_expr Delta e2) rho m ->
   denote_tc_assert (isBinOpResultType b e1 e2 t) rho m ->
   denote_tc_assert (typecheck_expr Delta e1) rho m ->
   tc_val (typeof e2) (eval_expr e2 rho) ->
   tc_val (typeof e1) (eval_expr e1 rho) ->
   tc_val t
     (eval_binop b (typeof e1) (typeof e2) (eval_expr e1 rho) (eval_expr e2 rho)).
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
(* Goal: tc_val t (@eval_binop CS b (typeof e1) (typeof e2) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
pose proof (typecheck_binop_sound).
(* Goal: @eq bool true true *)
simpl in H4. unfold_lift in H4. eapply H4; eauto.
Qed.

Lemma eval_binop_relate_fail :
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
forall {CS: compspecs} (Delta : tycontext) (rho : environ) (b : binary_operation)
  (e1 e2 : expr) (t : type) m,
typecheck_environ  Delta rho ->
forall (ge : genv) te ve,
rho = construct_rho (filter_genv ge) ve te ->
denote_tc_assert (typecheck_expr Delta e2) rho (m_phi m) ->
denote_tc_assert (isBinOpResultType b e1 e2 t) rho (m_phi m) ->
denote_tc_assert (typecheck_expr Delta e1) rho (m_phi m) ->
None =
sem_binary_operation' b  (typeof e1) (typeof e2) (eval_expr e1 rho) (eval_expr e2 rho) ->
Clight.eval_expr ge ve te (m_dry m) e2 (eval_expr e2 rho) ->
Clight.eval_expr ge ve te (m_dry m) e1 (eval_expr e1 rho) ->
Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) Vundef.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) Vundef *)
assert (TC1 := typecheck_expr_sound _ _ _ _ H H1).
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) Vundef *)
assert (TC2 := typecheck_expr_sound _ _ _ _ H H3).
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) Vundef *)
copy H2.
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) Vundef *)
rewrite den_isBinOpR in H7; simpl in H7.
(* Goal: @eq bool true true *)
eapply typecheck_binop_sound2 in H2; eauto.
remember (eval_expr e1 rho); remember (eval_expr e2 rho);
destruct v; destruct v0;
try solve [exfalso; eapply tc_val_Vundef; eauto];
apply tc_force_Some in H2; destruct H2; try congruence.
Qed.

Opaque tc_andp.
(** Equivalence of CompCert eval_expr and our function eval_expr on programs that typecheck **)

Lemma tc_test_eq0:
  forall b i m,
  (denote_tc_test_eq (Vptr b i) (Vint Int.zero)) (m_phi m) ->
  Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) = true.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
destruct H;
apply weak_valid_pointer_dry in H0;
apply H0.
Qed.

Lemma cop2_sem_cast :
    forall t1 t2 v m,
 (classify_cast t1 t2 = classify_cast size_t tbool ->
   denote_tc_test_eq v (Vint Int.zero) (m_phi m) )->
  t1 <> int_or_ptr_type ->
  t2 <> int_or_ptr_type ->
  tc_val t1 v ->
 Cop.sem_cast v t1 t2 (m_dry m) = sem_cast t1 t2 v.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
(* Goal: @eq (option val) (Cop.sem_cast v t1 t2 (m_dry m)) (sem_cast t1 t2 v) *)
 unfold Cop.sem_cast, sem_cast.
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
assert (Cop.classify_cast t1 t2 = classify_cast t1 t2). {
  clear - H0 H1.
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
  apply eqb_type_false in H0.
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
  apply eqb_type_false in H1.
  destruct t1; auto; destruct t2; auto;
(* Goal: @eq bool true true *)
  unfold Cop.classify_cast, classify_cast; auto; rewrite ?H0,?H1; auto.
}
rewrite <- H3 in *.
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match Cop.classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
rewrite H3.
destruct (classify_cast t1 t2);
(* Goal: tc_val size_t (@liftx (LiftEnviron val) (Vptrofs (Ptrofs.repr (@alignof (@cenv_cs CS) t))) rho) *)
destruct v; try reflexivity.
+ destruct t1 as [| [| | |] | | [|] | | | | |], t2 as [| [| | |] | | [|] | | | | |]; inv H3; simpl in H2; try inv H2.
  - revert H2; simple_if_tac; intros H2; inv H2.
  - revert H2; simple_if_tac; intros H2; inv H2.
+ destruct t1 as [| [| | |] | | [|] | | | | |], t2 as [| [| | |] | | [|] | | | | |]; inv H3; simpl in H2; try inv H2.
  - revert H2; simple_if_tac; intros H2; inv H2.
  - revert H2; simple_if_tac; intros H2; inv H2.
+ destruct t1 as [| [| | |] | | [|] | | | | |], t2 as [| [| | |] | | [|] | | | | |]; inv H3; simpl in H2; try inv H2.
  - revert H2; simple_if_tac; intros H2; inv H2.
  - revert H2; simple_if_tac; intros H2; inv H2.
+ destruct t1 as [| [| | |] | | [|] | | | | |], t2 as [| [| | |] | | [|] | | | | |]; inv H3; simpl in H2; try inv H2.
  - revert H2; simple_if_tac; intros H2; inv H2.
  - revert H2; simple_if_tac; intros H2; inv H2.
+ unfold sem_cast_i2bool.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
    simpl.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
  destruct Archi.ptr64 eqn:Hp; auto; simpl.
(* Goal: @eq (option val) (if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (@Some val Vone) *)
  specialize (H H3).
  do 3 red in H;
  rewrite Hp in H; try contradiction;
  (red in H; destruct H as [_ H];
  apply weak_valid_pointer_dry in H;
  unfold Mem.weak_valid_pointer;
  rewrite H; reflexivity).
Qed.

Ltac destruct_eqb_type := 
match goal with H: context [eqb_type ?t1 ?t2] |- _ =>
 let J := fresh "J" in 
  destruct (eqb_type t1 t2) eqn:?J;
 [apply eqb_type_true in J | apply eqb_type_false in J]
end.

Lemma classify_cast_eq:
 forall t1 t2,
  t1 <> int_or_ptr_type ->
  t2 <> int_or_ptr_type ->
  classify_cast t1 t2 = Cop.classify_cast t1 t2.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
destruct t1,t2; try reflexivity;
unfold classify_cast;
try rewrite (proj2 (eqb_type_false _ _) H0);
try rewrite (proj2 (eqb_type_false _ _) H);
(* Goal: tc_val size_t (@liftx (LiftEnviron val) (Vptrofs (Ptrofs.repr (@alignof (@cenv_cs CS) t))) rho) *)
reflexivity.
Qed.

Definition cast_pointer_to_bool t1 t2 :=
 match t1 with (Tpointer _ _ | Tarray _ _ _ | Tfunction _ _ _) => 
           match t2 with Tint IBool _ _ => true | _ => false end
 | _ => false
end.

Lemma sem_cast_e1:
 forall t t1 v1 v m,
   sem_cast t t1 v = Some v1 ->
   cast_pointer_to_bool t t1 = false ->
   tc_val t v ->
   Cop.sem_cast v t t1 m = Some v1.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
destruct (eqb_type t int_or_ptr_type) eqn:J;
 [apply eqb_type_true in J; subst t
 | apply eqb_type_false in J];
(destruct (eqb_type t1 int_or_ptr_type) eqn:J0;
 [apply eqb_type_true in J0; subst t1
 | apply eqb_type_false in J0]).
* unfold sem_cast, sem_cast_pointer in H; simpl in *.
  rewrite N.eqb_refl in *.
  simpl in H.
  inv H.
  destruct v1; auto; inv H1.
*
unfold sem_cast, classify_cast in H.
destruct t1; [auto | | | auto ..].
+
destruct i,s; auto; try solve [destruct v; inv H]; try solve [inv H0];
simpl in H;
simpl;
destruct Archi.ptr64; auto;
(* Goal: @eq bool true true *)
destruct v; inv H1; inv H; auto.
+ rewrite <- H; clear H.
  unfold tc_val in H1.
  rewrite eqb_type_refl in H1.
  simpl in H1.
  simpl in *.
  solve [auto | destruct Archi.ptr64 eqn:?Hp; auto; destruct v; inv H1; auto].
+
destruct f; inv H.
+
clear H0.
unfold int_or_ptr_type at 1 in H.
inv H.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
(* Goal: @eq bool true true *)
destruct v1; inv H1; auto.
*
unfold sem_cast in H.
destruct t; try solve [inv H].
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
{
  simpl in H.
  rewrite N.eqb_refl in H.
  simpl in H1.
  destruct v; try inv H1.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
  simpl.
  destruct Archi.ptr64 eqn:Hp; auto; inv Hp.
}
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
{
unfold classify_cast in H.
unfold int_or_ptr_type at 1 in H.
inv H.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
unfold tc_val in H1.
rewrite <- eqb_type_spec in J.
destruct (eqb_type (Tpointer t a) int_or_ptr_type); [congruence |].
hnf in H1.
(* Goal: @eq bool true true *)
destruct v1; tauto.
}
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
{
unfold classify_cast in H.
unfold int_or_ptr_type at 1 in H.
inv H.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
unfold tc_val in H1.
hnf in H1.
(* Goal: @eq bool true true *)
destruct v1; tauto.
}
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
{
unfold classify_cast in H.
unfold int_or_ptr_type at 1 in H.
inv H.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
unfold tc_val in H1.
hnf in H1.
(* Goal: @eq bool true true *)
destruct v1; tauto.
}
*
revert H.
clear - J J0 H0 H1.
(* Goal: @eq (option val) (Cop.sem_cast v t1 t2 (m_dry m)) (sem_cast t1 t2 v) *)
unfold Cop.sem_cast, sem_cast.
unfold Cop.classify_cast, classify_cast, sem_cast_pointer, 
 sem_cast_l2bool, sem_cast_i2bool.
rewrite ?(proj2 (eqb_type_false _ _) J);
rewrite ?(proj2 (eqb_type_false _ _) J0).
destruct t1   as [ | [ | | | ] [ | ] | | [ | ] | | | | | ]; auto;
destruct t   as [ | [ | | | ] [ | ] | | [ | ] | | | | | ]; auto; try discriminate H0;
 auto;
 destruct Archi.ptr64 eqn:Hp; auto;
 destruct v; auto; try contradiction;
 try solve [simpl in H1; rewrite Hp in H1; inv H1];
 try solve [simpl in H1; revert H1; simple_if_tac; intros []].
 
 simpl in H1; revert H1; simple_if_tac; simpl; rewrite Hp; intros [].
Qed.

Lemma cop2_sem_cast' :
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
    forall {CS: compspecs} t2 e rho m,
 (denote_tc_assert (isCastResultType (typeof e) t2 e) rho) (m_phi m) ->
  tc_val (typeof e) (eval_expr e rho) ->
 Cop.sem_cast (eval_expr e rho) (typeof e) t2 (m_dry m) =
 sem_cast (typeof e) t2 (eval_expr e rho).
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
rewrite isCastR in H.
destruct (typeof e)   as [ | [ | | | ] [ | ] | | [ | ] | | | | | ]; auto;
destruct t2  as [ | [ | | | ] [ | ] | | [ | ] | | | | | ]; auto; 
try contradiction.
all: try solve [ destruct (eval_expr e rho); try contradiction; reflexivity].

all: (*try solve [*)
unfold classify_cast, is_pointer_type in H;
unfold sem_cast, classify_cast;
unfold tc_val, is_pointer_or_null, is_pointer_or_integer in H0;
repeat match type of H with context [eqb_type ?A int_or_ptr_type] =>
  let J := fresh "J" in destruct (eqb_type A int_or_ptr_type) eqn:J; try solve [inv J]
end;
simpl; destruct Archi.ptr64 eqn:Hp; simpl in H;
(* Goal: tc_val size_t (@liftx (LiftEnviron val) (Vptrofs (Ptrofs.repr (@alignof (@cenv_cs CS) t))) rho) *)
destruct (eval_expr e rho) eqn:?; try contradiction; subst; try reflexivity.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
all: simpl.

all: try solve [

rewrite denote_tc_assert_test_eq' in H;
simpl in H;
unfold_lift in H;
unfold denote_tc_test_eq in H;
rewrite Heqv, Hp in H; destruct H;
apply weak_valid_pointer_dry in H1;
unfold Mem.weak_valid_pointer; rewrite H1, Hp; reflexivity].
all: try solve [inv Hp].
all: simpl in H0; rewrite Hp in H0; inv H0.
Qed.

(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
Lemma isBinOpResultType_binop_stable: forall {CS: compspecs} b e1 e2 t rho phi,
  denote_tc_assert (isBinOpResultType b e1 e2 t) rho phi ->
  binop_stable cenv_cs b e1 e2 = true.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
  intros.
  destruct b; auto;
  unfold isBinOpResultType in H;
  unfold binop_stable.
  + destruct (classify_add (typeof e1) (typeof e2));
    rewrite ?denote_tc_assert_andp in H;
    repeat match goal with
    | H: app_pred (_ && _) _ |- _ => destruct H
    end;
    try solve [eapply tc_bool_e; eauto].
(* Goal: @eq bool true true *)
    auto.
  + destruct (classify_sub (typeof e1) (typeof e2));
    rewrite ?denote_tc_assert_andp in H;
    repeat match goal with
    | H: app_pred (_ && _) _ |- _ => destruct H
    end;
    try solve [eapply tc_bool_e; eauto].
(* Goal: @eq bool true true *)
    auto.
Qed.

Lemma eval_unop_relate:
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
 forall {CS: compspecs} Delta (ge: genv) te ve rho u e t m 
 (Hcenv : genv_cenv ge = @cenv_cs CS)
 (H : rho = construct_rho (filter_genv ge) ve te)
 (H0 : typecheck_environ Delta rho)
 (H1 : (denote_tc_assert (typecheck_expr Delta e) rho) (m_phi m) ->
     Clight.eval_expr ge ve te (m_dry m) e (eval_expr e rho))
 (H2 : (denote_tc_assert (typecheck_lvalue Delta e) rho) (m_phi m) ->
     exists (b : block) (ofs : ptrofs),
       Clight.eval_lvalue ge ve te (m_dry m) e b ofs /\
       eval_lvalue e rho = Vptr b ofs)
 (H3 : (denote_tc_assert (typecheck_expr Delta (Eunop u e t)) rho)
       (m_phi m)),
Clight.eval_expr ge ve te (m_dry m) (Eunop u e t)
  (eval_expr (Eunop u e t) rho).
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
simpl in *.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
super_unfold_lift.
rewrite denote_tc_assert_andp in H3; destruct H3.
(* Goal: tc_val (typeof e) (@eval_expr CS e rho) *)
intuition. clear H2.
unfold eval_unop in *. unfold force_val1, force_val.
remember (sem_unary_operation u (typeof e) (eval_expr e rho)).
eapply Clight.eval_Eunop. eapply H5.  rewrite Heqo.

unfold sem_unary_operation. unfold Cop.sem_unary_operation.
(* Goal: @eq bool true true *)
apply typecheck_expr_sound in H4; auto.
destruct u;
  simpl in H3;
  destruct (typeof e) as [ | [ | | | ] [ | ] | [ | ] | [ | ] | | | | | ]; simpl;
  hnf in H4; try contradiction;
  repeat match goal with
       | H: app_pred (denote_tc_assert (tc_andp _ _) _) _ |- _ => 
          rewrite denote_tc_assert_andp in H; destruct H
       | H: app_pred (denote_tc_assert (if ?A then _ else _) _) _ |- _ =>
           first [change A with false in H | change A with true in H]; cbv iota in H
       | H: app_pred (denote_tc_assert (tc_iszero _) _) _ |- _ =>
                   rewrite denote_tc_assert_iszero in H
       | H: app_pred (denote_tc_assert (tc_bool _ _) _) _ |- _ => apply tc_bool_e in H
       end;
  destruct (eval_expr e rho) eqn:?;
  try match type of H4 with context [if ?A then _ else _] => destruct A end;
  try contradiction; try reflexivity;
 unfold Cop.sem_notbool; simpl;
 unfold Cop.bool_val, bool_val;
 apply tc_bool_e in H1; apply negb_true_iff in H1; rewrite H1;
 try reflexivity;
 unfold classify_bool, typeconv, remove_attributes, change_attributes;
 rewrite denote_tc_assert_test_eq' in H3;
 simpl in H3; unfold denote_tc_test_eq in H3; unfold_lift in H3; rewrite Heqv in H3.
*
 destruct Archi.ptr64 eqn:Hp; simpl eval_expr in H3; unfold_lift in H3; destruct H3;
 apply weak_valid_pointer_dry in H6;
(* Goal: tc_val size_t (@liftx (LiftEnviron val) (Vptrofs (Ptrofs.repr (@alignof (@cenv_cs CS) t))) rho) *)
 simpl; unfold Mem.weak_valid_pointer; rewrite H6; reflexivity.
*
 destruct Archi.ptr64 eqn:Hp; simpl eval_expr in H3; unfold_lift in H3; destruct H3;
 apply weak_valid_pointer_dry in H6;
(* Goal: tc_val size_t (@liftx (LiftEnviron val) (Vptrofs (Ptrofs.repr (@alignof (@cenv_cs CS) t))) rho) *)
 simpl; unfold Mem.weak_valid_pointer; rewrite H6; reflexivity.
Qed.

Lemma eqb_type_sym: forall a b, eqb_type a b = eqb_type b a.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
(* Goal: @eq bool (eqb_type a b) (eqb_type b a) *)
destruct (eqb_type a b) eqn:?.
rewrite -> eqb_type_spec in Heqb0. subst; symmetry; apply eqb_type_refl.
(* Goal: @eq bool false (eqb_type b a) *)
apply eqb_type_false in Heqb0.
(* Goal: @eq bool false (eqb_type b a) *)
assert (b<>a) by congruence.
rewrite <- eqb_type_spec in H.
(* Goal: @eq bool true true *)
destruct (eqb_type b a); auto.
Qed.

Lemma Ptrofs_to_int_repr: 
  Archi.ptr64=false -> 
  forall i, Ptrofs.to_int (Ptrofs.repr i) = Int.repr i.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
try solve [inversion H];
unfold Ptrofs.to_int;
apply Int.eqm_samerepr;
change Int.eqm with Ptrofs.eqm;
apply Ptrofs.eqm_sym;
apply Ptrofs.eqm_unsigned_repr.
Qed.

Lemma eval_both_relate:
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
  forall {CS: compspecs} Delta ge te ve rho e m,
           genv_cenv ge = cenv_cs ->
           rho = construct_rho (filter_genv ge) ve te ->
           typecheck_environ Delta rho ->
           (denote_tc_assert (typecheck_expr Delta e) rho (m_phi m) ->
             Clight.eval_expr ge ve te (m_dry m) e  (eval_expr e rho))
           /\
           (denote_tc_assert (typecheck_lvalue Delta e) rho (m_phi m) ->
             exists b, exists ofs,
              Clight.eval_lvalue ge ve te (m_dry m) e b ofs /\
              eval_lvalue e rho = Vptr b ofs).
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros until m; intro Hcenv; intros.
(*generalize dependent ge.*)
 induction e; intros;
(* Goal: tc_val (typeof e) (@eval_expr CS e rho) *)
try solve[intuition; constructor; auto | subst; inv H1]; intuition.

* (* eval_expr Evar*)

assert (TC_Sound:= typecheck_expr_sound).
specialize (TC_Sound Delta rho _ (Evar i t) H0 H1).
simpl in H1, TC_Sound |- *.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
super_unfold_lift.
destruct (access_mode t) eqn:MODE; try solve [inv H1].

unfold get_var_type, eval_var in *.
remember (Map.get (ve_of rho) i); destruct o; try destruct p;
try rewrite eqb_type_eq in *; simpl in *.
destruct (type_eq t t0); simpl in *; [| exfalso; eapply tc_val_Vundef; eauto].
subst t0.
apply Clight.eval_Elvalue with b Ptrofs.zero;
  [ | constructor; simpl; rewrite MODE; auto].
apply eval_Evar_local.
subst rho.
simpl in Heqo. symmetry in Heqo; apply Heqo.
subst rho.
unfold typecheck_environ in *.
destruct H0 as [? [Hve Hge]].
hnf in Hve,Hge.
revert H1; case_eq ((var_types Delta) ! i); intros; try contradiction.
specialize (Hve i t0). destruct Hve as [Hve _].
destruct (Hve H0). simpl in *; congruence.
revert H1; case_eq ((glob_types Delta) ! i); intros; try contradiction.
destruct (Hge _ _ H1) as [b ?].
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl. simpl in H3.
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match Cop.classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
rewrite H3.

repeat( rewrite tc_andp_sound in *; simpl in *; super_unfold_lift).
unfold tc_bool in H2.
destruct (eqb_type t t0); try contradiction.
apply Clight.eval_Elvalue with b Ptrofs.zero; [  | econstructor 2; apply MODE].
(* Goal: @eq bool true true *)
apply Clight.eval_Evar_global; auto.

* (* eval_lvalue Evar *)
 simpl in H1.
 unfold get_var_type in H1.
 subst rho; simpl in *.
 unfold eval_var.
 destruct_var_types i eqn:HH1&HH2; rewrite ?HH1, ?HH2 in *;
  [| destruct_glob_types i eqn:HH3&HH4; rewrite ?HH3, ?HH4 in *; [| inv H1]].
 +
 destruct (eqb_type t t0) eqn:?; [| inv H1].
 apply eqb_type_true in Heqb0; subst t0.
(* Goal: @eq bool true true *)
 exists b; exists Ptrofs.zero; split; auto.
(* Goal: @eq bool true true *)
 constructor; auto.
 +
 destruct (eqb_type t t0) eqn:?; [| inv H1].
 apply eqb_type_true in Heqb0; subst t0.
(* Goal: @eq bool true true *)
 exists b; exists Ptrofs.zero; split; auto.
(* Goal: @eq bool true true *)
 constructor 2; auto.

* (*temp*)
assert (TC:= typecheck_expr_sound).
specialize (TC Delta rho (m_phi m) (Etempvar i t)). simpl in *.
(* Goal: tc_val (typeof e) (@eval_expr CS e rho) *)
intuition.
constructor. unfold eval_id in *. remember (Map.get (te_of rho)  i);
destruct o;  auto. destruct rho; inv H; unfold make_tenv in *.
unfold Map.get in *. auto.
simpl in *.
clear - H3.
destruct t as [ | [ | | | ] [ | ] | [ | ] | [ | ] | | | | | ]; 
(* Goal: is_pointer_or_integer (@eval_lvalue CS e rho) *)
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
  try contradiction H3.
unfold tc_val in H3. 
(* Goal: is_pointer_or_integer (@eval_lvalue CS e rho) *)
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
destruct (eqb_type _ _); contradiction H3.

* (*deref*)
assert (TC:= typecheck_expr_sound).
specialize (TC Delta rho (m_phi m) (Ederef e t)). simpl in *.
(* Goal: tc_val (typeof e) (@eval_expr CS e rho) *)
intuition.
destruct (access_mode t) eqn:?H; try inversion H3.
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
rewrite !denote_tc_assert_andp in H3.
destruct H3 as [[? ?] ?].
simpl in H5.
unfold_lift in H5.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
unfold_lift.
apply tc_bool_e in H6.
specialize (H1 H3).
hnf in H7.
destruct (eval_expr e rho) eqn:?H; try contradiction.
eapply eval_Elvalue.
econstructor. eassumption.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
simpl.
(* Goal: @eq bool true true *)
constructor. auto.
* (*deref*)
assert (TC:= typecheck_lvalue_sound _ _ _ _ H0 H3).
simpl in *.
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
rewrite !denote_tc_assert_andp in H3.
destruct H3 as [[? ?] ?].
specialize (H1 H3).
(* Goal: tc_val t (@eval_binop CS b (typeof e1) (typeof e2) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
apply tc_bool_e in H4. simpl in H4.
hnf in H5.
destruct (eval_expr e rho) eqn:?; try contradiction.
exists b, i. simpl in *. unfold_lift. intuition. constructor.
(* Goal: @eq bool true true *)
auto.
* (*addrof*)

simpl in H3.
(* Goal: Clight.eval_expr ge ve te (m_dry m) (Ebinop b e1 e2 t) (force_val2 (@sem_binary_operation' CS b (typeof e1) (typeof e2)) (@eval_expr CS e1 rho) (@eval_expr CS e2 rho)) *)
rewrite !denote_tc_assert_andp in H3.
destruct H3.
assert (ISPTR := eval_lvalue_ptr rho (m_phi m) e Delta (te_of rho) (ve_of rho) (ge_of rho)).
specialize (H2 H3).
apply tc_bool_e in H4.
(* Goal: @eq bool true true *)
assert (mkEnviron (ge_of rho) (ve_of rho) (te_of rho) = rho). destruct rho; auto.
destruct rho. unfold typecheck_environ in *. intuition.
destruct H2 as [b [? ?]]. destruct H9 as [base [ofs ?]].  simpl in *.
intuition. rewrite H10 in *. constructor. inv H7. auto.

* (*unop*)
(* Goal: @eq bool true true *)
 eapply eval_unop_relate; eauto.
* (*binop*)
(* Goal: @eq bool true true *)
  eapply eval_binop_relate; eauto.
* (*Cast*)
assert (TC := typecheck_expr_sound _ _ _ _ H0 H3).
simpl in *.
rewrite denote_tc_assert_andp in H3.
destruct H3.
assert (TC' := typecheck_expr_sound _ _ _ _ H0 H3).
unfold force_val1, force_val in *; super_unfold_lift; intuition.
eapply Clight.eval_Ecast.
(* Goal: @eq bool true true *)
eapply H5; auto.
destruct (sem_cast (typeof e) t (eval_expr e rho)) eqn:?H;
 [ | contradiction (tc_val_Vundef t)].
pose proof cop2_sem_cast' t e rho m H4 TC'.
(* Goal: @eq bool true true *)
rewrite H6; auto.
* (*Field*)
 assert (TC := typecheck_expr_sound _ _ _ _ H0 H3).
 clear H1; rename H3 into H1.
simpl in H1.
 destruct (access_mode t) eqn:?; try solve [inv H1].
 rewrite denote_tc_assert_andp in H1. destruct H1.
 specialize (H2 H1). destruct H2 as [b [ofs [? ?]]].
 destruct (typeof e) eqn:?; try solve[inv H3];
 destruct (cenv_cs ! i0) as [co |] eqn:Hco; try solve [inv H3].
+
   destruct (field_offset cenv_cs i (co_members co)) eqn:?;
     try contradiction.
  inv H3. simpl in *.
(* Goal: @eq bool true true *)
  eapply Clight.eval_Elvalue; eauto.
(* Goal: @eq bool true true *)
  eapply Clight.eval_Efield_struct; eauto.
(* Goal: @eq bool true true *)
  eapply Clight.eval_Elvalue; auto. eassumption.
  rewrite Heqt0.
(* Goal: @eq bool true true *)
  apply Clight.deref_loc_copy. auto.
  rewrite Hcenv; eassumption.
  rewrite Hcenv; eassumption.
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
  unfold_lift.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
  unfold Datatypes.id; simpl.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
  rewrite Heqt0. rewrite H4. simpl. rewrite Hco. rewrite Heqr.
(* Goal: @eq bool true true *)
   apply Clight.deref_loc_reference. auto.

(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
+ simpl. unfold_lift.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
   rewrite Heqt0. simpl. rewrite Hco.
(* Goal: @eq bool true true *)
  eapply Clight.eval_Elvalue; eauto.
  eapply Clight.eval_Efield_union.
(* Goal: @eq bool true true *)
  eapply Clight.eval_Elvalue; eauto.
  apply Clight.deref_loc_copy.
(* Goal: @eq bool true true *)
  rewrite Heqt0. auto. eauto.
(* Goal: @eq bool true true *)
  rewrite Hcenv; eauto.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
  rewrite H4. simpl.
(* Goal: @eq bool true true *)
  apply Clight.deref_loc_reference; auto.
*
 clear H1.
 assert (TC:= typecheck_lvalue_sound _ _ _ _ H0 H3).
 simpl in *.
 rewrite denote_tc_assert_andp in H3. destruct H3.
 unfold eval_field,offset_val in *; super_unfold_lift.
 specialize (H2 H1).
destruct H2 as [b [ofs H4]].
destruct H4.
rewrite H4 in TC|-*.
 destruct (typeof e) eqn:?; try contradiction;
destruct (cenv_cs ! i0) as [co |] eqn:Hco; try solve [inv H3].
+
destruct (field_offset cenv_cs i (co_members co)) eqn:?; try contradiction.
exists b. exists (Ptrofs.add ofs (Ptrofs.repr z)).
(* Goal: tc_val (typeof e) (@eval_expr CS e rho) *)
intuition.
 eapply Clight.eval_Efield_struct; auto; try eassumption.
(* Goal: is_pointer_or_null (@eval_lvalue CS e rho) *)
eapply Clight.eval_Elvalue in H2. apply H2.
(* Goal: @eq bool true true *)
rewrite Heqt0. apply Clight.deref_loc_copy. simpl; auto.
rewrite Hcenv; eassumption.
rewrite Hcenv; eassumption.
+
(* Goal: @eq bool true true *)
exists b, ofs. simpl. split; auto.
(* Goal: @eq bool true true *)
eapply Clight.eval_Efield_union; eauto.
(* Goal: @eq bool true true *)
eapply Clight.eval_Elvalue; eauto.
rewrite Heqt0. apply Clight.deref_loc_copy.
(* Goal: @eq bool true true *)
auto.
rewrite Hcenv; eassumption.
*
simpl in H1.
repeat rewrite denote_tc_assert_andp in H1.
destruct H1.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
apply tc_bool_e in H1.
apply tc_bool_e in H2.
rewrite eqb_type_spec in H2.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
subst.
unfold eval_expr.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
unfold_lift; simpl.
rewrite <- Hcenv.
apply Clight.eval_Esizeof.
*
simpl in H1.
repeat rewrite denote_tc_assert_andp in H1.
destruct H1.
(* Goal: tc_val (typeof (Ealignof t t0)) (@eval_expr CS (Ealignof t t0) rho) *)
apply tc_bool_e in H1.
apply tc_bool_e in H2.
unfold eval_expr.
(* Goal: @eq (option val) (if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned i) then @Some val Vone else @None val) (if Archi.ptr64 then @None val else @Some val Vone) *)
unfold_lift; simpl.
unfold alignof; rewrite <- Hcenv.
constructor.
Qed.

Lemma eval_expr_relate:
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
  forall {CS: compspecs} Delta ge te ve rho e m,
           genv_cenv ge = cenv_cs ->
           rho = construct_rho (filter_genv ge) ve te ->
           typecheck_environ Delta rho ->
           (denote_tc_assert (typecheck_expr Delta e) rho (m_phi m) ->
             Clight.eval_expr ge ve te (m_dry m) e  (eval_expr e rho)).
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
(* Goal: @eq bool true true *)
edestruct eval_both_relate; eauto.
Qed.

Lemma eval_lvalue_relate:
(* Goal: @eq classify_cast_cases (Cop.classify_cast t1 t2) (classify_cast t1 t2) *)
(* Goal: @eq (option val) match Cop.classify_cast t1 t2 with | cast_case_pointer => match v with | Vundef => @None val | Vint i => if Archi.ptr64 then @None val else @Some val v | Vlong i => if Archi.ptr64 then @Some val v else @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @Some val v end | cast_case_i2i sz2 si2 => match v with | Vundef => @None val | Vint i => @Some val (Vint (cast_int_int sz2 si2 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vfloat f) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vsingle f) | Vptr b i => @None val end | cast_case_f2s => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vsingle (Float.to_single f)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2f => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vfloat (Float.of_single f)) | Vptr b i => @None val end | cast_case_i2f si1 => match v with | Vundef => @None val | Vint i => @Some val (Vfloat (cast_int_float si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2s si1 => match v with | Vundef => @None val | Vint i => @Some val (Vsingle (cast_int_single si1 i)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2i sz2 si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_int si2 f with | Some i => @Some val (Vint (cast_int_int sz2 si2 i)) | None => @None val end | Vptr b i => @None val end | cast_case_l2l => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vlong n) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_i2l si => match v with | Vundef => @None val | Vint n => @Some val (Vlong (cast_int_long si n)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2i sz si => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (cast_int_int sz si (Int.repr (Int64.unsigned n)))) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2f si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vfloat (cast_long_float si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_l2s si1 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @Some val (Vsingle (cast_long_single si1 i)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b i => @None val end | cast_case_f2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => match cast_float_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2l si2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => match cast_single_long si2 f with | Some i => @Some val (Vlong i) | None => @None val end | Vptr b i => @None val end | cast_case_i2bool => match v with | Vundef => @None val | Vint n => @Some val (Vint (if Int.eq n Int.zero then Int.zero else Int.one)) | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_l2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong n => @Some val (Vint (if Int64.eq n Int64.zero then Int.zero else Int.one)) | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if negb Archi.ptr64 then @None val else if Mem.weak_valid_pointer (m_dry m) b (Ptrofs.unsigned ofs) then @Some val Vone else @None val end | cast_case_f2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @Some val (Vint (if Float.cmp Ceq f Float.zero then Int.zero else Int.one)) | Vsingle f => @None val | Vptr b i => @None val end | cast_case_s2bool => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @Some val (Vint (if Float32.cmp Ceq f Float32.zero then Int.zero else Int.one)) | Vptr b i => @None val end | cast_case_struct id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_union id1 id2 => match v with | Vundef => @None val | Vint i => @None val | Vlong i => @None val | Vfloat f => @None val | Vsingle f => @None val | Vptr b ofs => if ident_eq id1 id2 then @Some val v else @None val end | cast_case_void => @Some val v | cast_case_default => @None val end (match classify_cast t1 t2 with | cast_case_pointer => sem_cast_pointer | cast_case_i2i sz2 si2 => sem_cast_i2i sz2 si2 | cast_case_f2f => sem_cast_f2f | cast_case_s2s => sem_cast_s2s | cast_case_f2s => sem_cast_f2s | cast_case_s2f => sem_cast_s2f | cast_case_i2f si1 => sem_cast_i2f si1 | cast_case_i2s si1 => sem_cast_i2s si1 | cast_case_f2i sz2 si2 => sem_cast_f2i sz2 si2 | cast_case_s2i sz2 si2 => sem_cast_s2i sz2 si2 | cast_case_l2l => sem_cast_l2l | cast_case_i2l si => sem_cast_i2l si | cast_case_l2i sz si => sem_cast_l2i sz si | cast_case_l2f si1 => sem_cast_l2f si1 | cast_case_l2s si1 => sem_cast_l2s si1 | cast_case_f2l si2 => sem_cast_f2l si2 | cast_case_s2l si2 => sem_cast_s2l si2 | cast_case_i2bool => sem_cast_i2bool | cast_case_l2bool => sem_cast_l2bool | cast_case_f2bool => sem_cast_f2bool | cast_case_s2bool => sem_cast_s2bool | cast_case_struct id1 id2 => sem_cast_struct id1 id2 | cast_case_union id1 id2 => sem_cast_union id1 id2 | cast_case_void => fun v : val => @Some val v | cast_case_default => fun _ : val => @None val end v) *)
  forall {CS: compspecs} Delta ge te ve rho e m,
           genv_cenv ge = cenv_cs ->
           rho = construct_rho (filter_genv ge) ve te->
           typecheck_environ Delta rho ->
           (denote_tc_assert (typecheck_lvalue Delta e) rho (m_phi m) ->
             exists b, exists ofs,
              Clight.eval_lvalue ge ve te (m_dry m) e b ofs /\
              eval_lvalue e rho = Vptr b ofs).
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
(* Goal: @eq bool true true *)
edestruct eval_both_relate; eauto.
Qed.

(*
Lemma tc_lvalue_nonvol : forall rho Delta e,
(denote_tc_assert (typecheck_lvalue Delta e) rho) ->
type_is_volatile (typeof e) = false.
Proof.
(* Goal: forall (CS : compspecs) (Delta : tycontext) (ge : genv) (te : temp_env) (ve : env) (rho : environ) (e : expr) (m : juicy_mem) (_ : @eq composite_env (genv_cenv ge) (@cenv_cs CS)) (_ : @eq environ rho (construct_rho (filter_genv ge) ve te)) (_ : typecheck_environ Delta rho) (_ : @app_pred rmap ag_rmap (@denote_tc_assert CS (@typecheck_lvalue CS Delta e) rho) (m_phi m)), @ex block (fun b : block => @ex Ptrofs.int (fun ofs : Ptrofs.int => and (Clight.eval_lvalue ge ve te (m_dry m) e b ofs) (@eq val (@eval_lvalue CS e rho) (Vptr b ofs)))) *)
intros.
destruct e; intuition; simpl in *.
unfold get_var_type in *.

destruct ((var_types Delta) ! i); intuition; simpl in *.
repeat( rewrite tc_andp_sound in *; simpl in *; super_unfold_lift).
 super_unfold_lift;
intuition. unfold tc_bool in *. rewrite if_negb in *.
if_tac in H1; simpl in *; super_unfold_lift; intuition.

super_unfold_lift; intuition. unfold tc_bool in *. rewrite if_negb in *.
destruct ((glob_types Delta) ! i). simpl in *.
repeat( rewrite tc_andp_sound in *; simpl in *; super_unfold_lift).
(* Goal: match pt with | Tvoid => fun _ : val => False | Tint sz sg a => is_int sz sg | Tlong s a => is_long | Tfloat (F32 as f) a => is_single | Tfloat (F64 as f) a => is_float | Tpointer t a => if eqb_type pt int_or_ptr_type then is_pointer_or_integer else is_pointer_or_null | Tarray t z a => is_pointer_or_null | Tfunction t t0 c => is_pointer_or_null | Tstruct i a => isptr | Tunion i a => isptr end (@eval_expr CS e rho) *)
 super_unfold_lift.
destruct H. if_tac in H0; auto; inv H0. inv H.


repeat( rewrite tc_andp_sound in *; simpl in *; super_unfold_lift).
super_unfold_lift; intuition. clear - H1. unfold tc_bool in *. rewrite if_negb in *.
(* Goal: tc_val (typeof e) (@eval_expr CS e rho) *)
if_tac in H1; intuition.

repeat( rewrite tc_andp_sound in *; simpl in *; super_unfold_lift).
super_unfold_lift. intuition. unfold tc_bool in *.  rewrite if_negb in *.
(* Goal: @eq bool true true *)
if_tac in H1; auto. inv H1.
Qed.
*)






