(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*                 Xavier Leroy, INRIA Paris                           *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)

(** Correctness of instruction selection for 64-bit integer operations *)

Require Import String Coqlib Maps Integers Floats Errors.
Require Archi.
Require Import AST Values Memory Globalenvs Events.
Require Import Cminor Op CminorSel.
Require Import SelectOp SelectOpproof SplitLong SplitLongproof.
Require Import SelectLong.

Local Open Scope cminorsel_scope.
Local Open Scope string_scope.

(** * Correctness of the instruction selection functions for 64-bit operators *)

Section CMCONSTR.

Variable prog: program.
Variable hf: helper_functions.
Hypothesis HELPERS: helper_functions_declared prog hf.
Let ge := Genv.globalenv prog.
Variable sp: val.
Variable e: env.
Variable m: mem.

Definition unary_constructor_sound (cstr: expr -> expr) (sem: val -> val) : Prop :=
  forall le a x,
  eval_expr ge sp e m le a x ->
  exists v, eval_expr ge sp e m le (cstr a) v /\ Val.lessdef (sem x) v.

Definition binary_constructor_sound (cstr: expr -> expr -> expr) (sem: val -> val -> val) : Prop :=
  forall le a x b y,
  eval_expr ge sp e m le a x ->
  eval_expr ge sp e m le b y ->
  exists v, eval_expr ge sp e m le (cstr a b) v /\ Val.lessdef (sem x y) v.

Definition partial_unary_constructor_sound (cstr: expr -> expr) (sem: val -> option val) : Prop :=
  forall le a x y,
  eval_expr ge sp e m le a x ->
  sem x = Some y ->
  exists v, eval_expr ge sp e m le (cstr a) v /\ Val.lessdef y v.

Definition partial_binary_constructor_sound (cstr: expr -> expr -> expr) (sem: val -> val -> option val) : Prop :=
  forall le a x b y z,
  eval_expr ge sp e m le a x ->
  eval_expr ge sp e m le b y ->
  sem x y = Some z ->
  exists v, eval_expr ge sp e m le (cstr a b) v /\ Val.lessdef z v.

Theorem eval_longconst:
  forall le n, eval_expr ge sp e m le (longconst n) (Vlong n).
Proof.
(* Goal: forall (le : letenv) (n : Int64.int), eval_expr ge sp e m le (longconst n) (Vlong n) *)
  unfold longconst; intros; destruct Archi.splitlong.
(* Goal: eval_expr ge sp e m le (SplitLong.longconst n) (Vlong n) *)
(* Goal: eval_expr ge sp e m le (Eop (Olongconst n) Enil) (Vlong n) *)
  apply SplitLongproof.eval_longconst.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
  EvalOp.
Qed.

Lemma is_longconst_sound:
  forall v a n le,
  is_longconst a = Some n -> eval_expr ge sp e m le a v -> v = Vlong n.
Proof with (try discriminate).
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  intros. unfold is_longconst in *. destruct Archi.splitlong.
  eapply SplitLongproof.is_longconst_sound; eauto.
  assert (a = Eop (Olongconst n) Enil).
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
(* Goal: binary_constructor_sound addl Val.addl *)
  { destruct a... destruct o... destruct e0... congruence. }
  subst a. InvEval. auto.
Qed.

Theorem eval_intoflong: unary_constructor_sound intoflong Val.loword.
Proof.
  unfold intoflong; destruct Archi.splitlong. apply SplitLongproof.eval_intoflong.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (is_longconst a) as [n|] eqn:C.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- TrivialExists. simpl. erewrite (is_longconst_sound x) by eauto. auto.
- TrivialExists.
Qed.

Theorem eval_longofintu: unary_constructor_sound longofintu Val.longofintu.
Proof.
  unfold longofintu; destruct Archi.splitlong. apply SplitLongproof.eval_longofintu.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (is_intconst a) as [n|] eqn:C.
- econstructor; split. apply eval_longconst.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exploit is_intconst_sound; eauto. intros; subst x. auto.
- TrivialExists.
Qed.

Theorem eval_longofint: unary_constructor_sound longofint Val.longofint.
Proof.
  unfold longofint; destruct Archi.splitlong. apply SplitLongproof.eval_longofint.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (is_intconst a) as [n|] eqn:C.
- econstructor; split. apply eval_longconst.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exploit is_intconst_sound; eauto. intros; subst x. auto.
- TrivialExists.
Qed.

Theorem eval_notl: unary_constructor_sound notl Val.notl.
Proof.
  unfold notl; destruct Archi.splitlong. apply SplitLongproof.eval_notl.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (notl_match a).
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
- InvEval. econstructor; split. apply eval_longconst. auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
- InvEval. subst. exists v1; split; auto. destruct v1; simpl; auto. rewrite Int64.not_involutive; auto.
- TrivialExists.
Qed.

Theorem eval_andlimm: forall n, unary_constructor_sound (andlimm n) (fun v => Val.andl v (Vlong n)).
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold andlimm; intros; red; intros.
  predSpec Int64.eq Int64.eq_spec n Int64.zero.
  exists (Vlong Int64.zero); split. apply eval_longconst.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  subst. destruct x; simpl; auto. rewrite Int64.and_zero; auto.
  predSpec Int64.eq Int64.eq_spec n Int64.mone.
  exists x; split. assumption.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  subst. destruct x; simpl; auto. rewrite Int64.and_mone; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (addlimm (Int64.repr (Z.opp n2)) (Eop Osubl (Econs t1 (Econs t2 Enil)))) v) (Val.lessdef (Val.subl x (Val.addl v1 (Vlong (Int64.repr n2)))) v)) *)
  destruct (andlimm_match a); InvEval; subst.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- econstructor; split. apply eval_longconst. simpl. rewrite Int64.and_commut; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- TrivialExists. simpl. rewrite Val.andl_assoc. rewrite Int64.and_commut; auto.
- TrivialExists.
Qed.

Theorem eval_andl: binary_constructor_sound andl Val.andl.
Proof.
  unfold andl; destruct Archi.splitlong. apply SplitLongproof.eval_andl.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (andl_match a b).
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
- InvEval. rewrite Val.andl_commut. apply eval_andlimm; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
- InvEval. apply eval_andlimm; auto.
- TrivialExists.
Qed.

Theorem eval_orlimm: forall n, unary_constructor_sound (orlimm n) (fun v => Val.orl v (Vlong n)).
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold orlimm; intros; red; intros.
  predSpec Int64.eq Int64.eq_spec n Int64.zero.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exists x; split; auto. subst. destruct x; simpl; auto. rewrite Int64.or_zero; auto.
  predSpec Int64.eq Int64.eq_spec n Int64.mone.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  econstructor; split. apply eval_longconst. subst. destruct x; simpl; auto. rewrite Int64.or_mone; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (addlimm (Int64.repr (Z.opp n2)) (Eop Osubl (Econs t1 (Econs t2 Enil)))) v) (Val.lessdef (Val.subl x (Val.addl v1 (Vlong (Int64.repr n2)))) v)) *)
  destruct (orlimm_match a); InvEval; subst.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- econstructor; split. apply eval_longconst. simpl. rewrite Int64.or_commut; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- TrivialExists. simpl. rewrite Val.orl_assoc. rewrite Int64.or_commut; auto.
- TrivialExists.
Qed.

Theorem eval_orl: binary_constructor_sound orl Val.orl.
Proof.
  unfold orl; destruct Archi.splitlong. apply SplitLongproof.eval_orl.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  assert (DEFAULT: exists v, eval_expr ge sp e m le (Eop Oorl (a:::b:::Enil)) v /\ Val.lessdef (Val.orl x y) v) by TrivialExists.
  assert (ROR: forall v n1 n2,
    Int.add n1 n2 = Int64.iwordsize' ->
    Val.lessdef (Val.orl (Val.shll v (Vint n1)) (Val.shrlu v (Vint n2)))
                (Val.rorl v (Vint n2))).
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  { intros. destruct v; simpl; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
    destruct (Int.ltu n1 Int64.iwordsize') eqn:N1; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
    destruct (Int.ltu n2 Int64.iwordsize') eqn:N2; auto.
    simpl. rewrite <- Int64.or_ror'; auto. }
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le match orl_match a b with | orl_case1 n1 t2 => orlimm n1 t2 | orl_case2 t1 n2 => orlimm n2 t1 | orl_case3 n1 t1 n2 t2 => if andb (Int.eq (Int.add n1 n2) Int64.iwordsize') (same_expr_pure t1 t2) then Eop (Ororlimm n2) (Econs t1 Enil) else Eop Oorl (Econs a (Econs b Enil)) | orl_case4 n2 t2 n1 t1 => if andb (Int.eq (Int.add n1 n2) Int64.iwordsize') (same_expr_pure t1 t2) then Eop (Ororlimm n2) (Econs t1 Enil) else Eop Oorl (Econs a (Econs b Enil)) | orl_default e1 e2 => Eop Oorl (Econs e1 (Econs e2 Enil)) end v) (Val.lessdef (Val.orl x y) v)) *)
  destruct (orl_match a b).
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
- InvEval. rewrite Val.orl_commut. apply eval_orlimm; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
- InvEval. apply eval_orlimm; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- predSpec Int.eq Int.eq_spec (Int.add n1 n2) Int64.iwordsize'; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct (same_expr_pure t1 t2) eqn:?; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  InvEval. exploit eval_same_expr; eauto. intros [EQ1 EQ2]; subst.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
  exists (Val.rorl v0 (Vint n2)); split. EvalOp. apply ROR; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- predSpec Int.eq Int.eq_spec (Int.add n1 n2) Int64.iwordsize'; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct (same_expr_pure t1 t2) eqn:?; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  InvEval. exploit eval_same_expr; eauto. intros [EQ1 EQ2]; subst.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
  exists (Val.rorl v1 (Vint n2)); split. EvalOp. rewrite Val.orl_commut. apply ROR; auto.
- apply DEFAULT.
Qed.

Theorem eval_xorlimm: forall n, unary_constructor_sound (xorlimm n) (fun v => Val.xorl v (Vlong n)).
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold xorlimm; intros; red; intros.
  predSpec Int64.eq Int64.eq_spec n Int64.zero.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exists x; split; auto. subst. destruct x; simpl; auto. rewrite Int64.xor_zero; auto.
  predSpec Int64.eq Int64.eq_spec n Int64.mone.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  replace (Val.xorl x (Vlong n)) with (Val.notl x). apply eval_notl; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  subst n. destruct x; simpl; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (addlimm (Int64.repr (Z.opp n2)) (Eop Osubl (Econs t1 (Econs t2 Enil)))) v) (Val.lessdef (Val.subl x (Val.addl v1 (Vlong (Int64.repr n2)))) v)) *)
  destruct (xorlimm_match a); InvEval; subst.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- econstructor; split. apply eval_longconst. simpl. rewrite Int64.xor_commut; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- TrivialExists. simpl. rewrite Val.xorl_assoc. rewrite Int64.xor_commut; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- TrivialExists. simpl. destruct v1; simpl; auto. unfold Int64.not.
  rewrite Int64.xor_assoc. apply f_equal. apply f_equal. apply f_equal.
  apply Int64.xor_commut.
- TrivialExists.
Qed.

Theorem eval_xorl: binary_constructor_sound xorl Val.xorl.
Proof.
  unfold xorl; destruct Archi.splitlong. apply SplitLongproof.eval_xorl.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (xorl_match a b).
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
- InvEval. rewrite Val.xorl_commut. apply eval_xorlimm; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
- InvEval. apply eval_xorlimm; auto.
- TrivialExists.
Qed.

Theorem eval_shllimm: forall n, unary_constructor_sound (fun e => shllimm e n) (fun v => Val.shll v (Vint n)).
Proof.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  intros; unfold shllimm. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_shllimm; auto.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (if Int.eq n Int.zero then a else Eop (Oshrxlimm n) (Econs a Enil)) v) (Val.lessdef z v)) *)
  predSpec Int.eq Int.eq_spec n Int.zero.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exists x; split; auto. subst n; destruct x; simpl; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct (Int.ltu Int.zero Int64.iwordsize'); auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  change (Int64.shl' i Int.zero) with (Int64.shl i Int64.zero). rewrite Int64.shl_zero; auto.
(* Goal: @eq (option val) (@eval_operation fundef unit ge sp (Ocmp (Ccomplimm (swap_comparison c) n1)) (@cons val y (@nil val)) m) (@Some val (Val.of_bool vb)) *)
  destruct (Int.ltu n Int64.iwordsize') eqn:LT; simpl.
  assert (DEFAULT: exists v, eval_expr ge sp e m le (Eop (Oshllimm n) (a:::Enil)) v
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
                         /\  Val.lessdef (Val.shll x (Vint n)) v) by TrivialExists.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  destruct (shllimm_match a); InvEval.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- TrivialExists. simpl; rewrite LT; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- destruct (Int.ltu (Int.add n n1) Int64.iwordsize') eqn:LT'; auto.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
  subst. econstructor; split. EvalOp. simpl; eauto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct v1; simpl; auto. rewrite LT'.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct (Int.ltu n1 Int64.iwordsize') eqn:LT1; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  simpl; rewrite LT. rewrite Int.add_commut, Int64.shl'_shl'; auto. rewrite Int.add_commut; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- destruct (shift_is_scale n); auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  TrivialExists. simpl. destruct v1; simpl; auto.
  rewrite LT. rewrite ! Int64.repr_unsigned. rewrite Int64.shl'_one_two_p.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  rewrite ! Int64.shl'_mul_two_p.  rewrite Int64.mul_add_distr_l. auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- destruct (shift_is_scale n); auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  TrivialExists. simpl. destruct x; simpl; auto.
  rewrite LT. rewrite ! Int64.repr_unsigned. rewrite Int64.shl'_one_two_p.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  rewrite ! Int64.shl'_mul_two_p. rewrite Int64.add_zero. auto.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- TrivialExists. constructor; eauto. constructor. EvalOp. simpl; eauto. constructor. auto.
Qed.

Theorem eval_shrluimm: forall n, unary_constructor_sound (fun e => shrluimm e n) (fun v => Val.shrlu v (Vint n)).
Proof.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  intros; unfold shrluimm. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_shrluimm; auto.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (if Int.eq n Int.zero then a else Eop (Oshrxlimm n) (Econs a Enil)) v) (Val.lessdef z v)) *)
  predSpec Int.eq Int.eq_spec n Int.zero.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exists x; split; auto. subst n; destruct x; simpl; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct (Int.ltu Int.zero Int64.iwordsize'); auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  change (Int64.shru' i Int.zero) with (Int64.shru i Int64.zero). rewrite Int64.shru_zero; auto.
(* Goal: @eq (option val) (@eval_operation fundef unit ge sp (Ocmp (Ccomplimm (swap_comparison c) n1)) (@cons val y (@nil val)) m) (@Some val (Val.of_bool vb)) *)
  destruct (Int.ltu n Int64.iwordsize') eqn:LT; simpl.
  assert (DEFAULT: exists v, eval_expr ge sp e m le (Eop (Oshrluimm n) (a:::Enil)) v
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
                         /\  Val.lessdef (Val.shrlu x (Vint n)) v) by TrivialExists.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  destruct (shrluimm_match a); InvEval.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- TrivialExists. simpl; rewrite LT; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- destruct (Int.ltu (Int.add n n1) Int64.iwordsize') eqn:LT'; auto.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
  subst. econstructor; split. EvalOp. simpl; eauto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct v1; simpl; auto. rewrite LT'.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct (Int.ltu n1 Int64.iwordsize') eqn:LT1; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  simpl; rewrite LT. rewrite Int.add_commut, Int64.shru'_shru'; auto. rewrite Int.add_commut; auto.
- apply DEFAULT.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- TrivialExists. constructor; eauto. constructor. EvalOp. simpl; eauto. constructor. auto.
Qed.

Theorem eval_shrlimm: forall n, unary_constructor_sound (fun e => shrlimm e n) (fun v => Val.shrl v (Vint n)).
Proof.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  intros; unfold shrlimm. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_shrlimm; auto.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (if Int.eq n Int.zero then a else Eop (Oshrxlimm n) (Econs a Enil)) v) (Val.lessdef z v)) *)
  predSpec Int.eq Int.eq_spec n Int.zero.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exists x; split; auto. subst n; destruct x; simpl; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct (Int.ltu Int.zero Int64.iwordsize'); auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  change (Int64.shr' i Int.zero) with (Int64.shr i Int64.zero). rewrite Int64.shr_zero; auto.
(* Goal: @eq (option val) (@eval_operation fundef unit ge sp (Ocmp (Ccomplimm (swap_comparison c) n1)) (@cons val y (@nil val)) m) (@Some val (Val.of_bool vb)) *)
  destruct (Int.ltu n Int64.iwordsize') eqn:LT; simpl.
  assert (DEFAULT: exists v, eval_expr ge sp e m le (Eop (Oshrlimm n) (a:::Enil)) v
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
                         /\  Val.lessdef (Val.shrl x (Vint n)) v) by TrivialExists.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  destruct (shrlimm_match a); InvEval.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- TrivialExists. simpl; rewrite LT; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- destruct (Int.ltu (Int.add n n1) Int64.iwordsize') eqn:LT'; auto.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
  subst. econstructor; split. EvalOp. simpl; eauto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct v1; simpl; auto. rewrite LT'.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct (Int.ltu n1 Int64.iwordsize') eqn:LT1; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  simpl; rewrite LT. rewrite Int.add_commut, Int64.shr'_shr'; auto. rewrite Int.add_commut; auto.
- apply DEFAULT.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- TrivialExists. constructor; eauto. constructor. EvalOp. simpl; eauto. constructor. auto.
Qed.

Theorem eval_shll: binary_constructor_sound shll Val.shll.
Proof.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  unfold shll. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_shll; auto.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (is_intconst b) as [n2|] eqn:C.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- exploit is_intconst_sound; eauto. intros EQ; subst y. apply eval_shllimm; auto.
- TrivialExists.
Qed.

Theorem eval_shrlu: binary_constructor_sound shrlu Val.shrlu.
Proof.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  unfold shrlu. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_shrlu; auto.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (is_intconst b) as [n2|] eqn:C.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- exploit is_intconst_sound; eauto. intros EQ; subst y. apply eval_shrluimm; auto.
- TrivialExists.
Qed.

Theorem eval_shrl: binary_constructor_sound shrl Val.shrl.
Proof.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  unfold shrl. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_shrl; auto.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (is_intconst b) as [n2|] eqn:C.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- exploit is_intconst_sound; eauto. intros EQ; subst y. apply eval_shrlimm; auto.
- TrivialExists.
Qed.

Theorem eval_negl: unary_constructor_sound negl Val.negl.
Proof.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  unfold negl. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_negl; auto.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. destruct (is_longconst a) as [n|] eqn:C.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- exploit is_longconst_sound; eauto. intros EQ; subst x.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  econstructor; split. apply eval_longconst. auto.
- TrivialExists.
Qed.

Theorem eval_addlimm: forall n, unary_constructor_sound (addlimm n) (fun v => Val.addl v (Vlong n)).
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold addlimm; intros; red; intros.
  predSpec Int64.eq Int64.eq_spec n Int64.zero.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  subst. exists x; split; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct x; simpl; rewrite ?Int64.add_zero, ?Ptrofs.add_zero; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  destruct (addlimm_match a); InvEval.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- econstructor; split. apply eval_longconst. rewrite Int64.add_commut; auto.
- inv H. simpl in H6. TrivialExists. simpl.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  erewrite eval_offset_addressing_total_64 by eauto. rewrite Int64.repr_signed; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- TrivialExists. simpl. rewrite Int64.repr_signed; auto.
Qed.

Theorem eval_addl: binary_constructor_sound addl Val.addl.
Proof.
(* Goal: binary_constructor_sound addl Val.addl *)
  assert (A: forall x y, Int64.repr (x + y) = Int64.add (Int64.repr x) (Int64.repr y)).
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
(* Goal: binary_constructor_sound addl Val.addl *)
  { intros; apply Int64.eqm_samerepr; auto with ints. }
  assert (B: forall id ofs n, Archi.ptr64 = true ->
             Genv.symbol_address ge id (Ptrofs.add ofs (Ptrofs.repr n)) =
             Val.addl (Genv.symbol_address ge id ofs) (Vlong (Int64.repr n))).
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  { intros. replace (Ptrofs.repr n) with (Ptrofs.of_int64 (Int64.repr n)) by auto with ptrofs.
    apply Genv.shift_symbol_address_64; auto. }
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (if Archi.splitlong then @SplitLong.singleoflong hf a else Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  unfold addl. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  apply SplitLongproof.eval_addl. apply Archi.splitlong_ptr32; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  red; intros; destruct (addl_match a b); InvEval.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- rewrite Val.addl_commut. apply eval_addlimm; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- apply eval_addlimm; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- subst. TrivialExists. simpl. rewrite A, Val.addl_permut_4. auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- subst. TrivialExists. simpl. rewrite A, Val.addl_assoc. decEq; decEq. rewrite Val.addl_permut. auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- subst. TrivialExists. simpl. rewrite A, Val.addl_permut_4. rewrite <- Val.addl_permut. rewrite <- Val.addl_assoc. auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- subst. TrivialExists. simpl. rewrite Val.addl_commut; auto.
- subst. TrivialExists.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- subst. TrivialExists. simpl. rewrite ! Val.addl_assoc. rewrite (Val.addl_commut y). auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- subst. TrivialExists. simpl. rewrite ! Val.addl_assoc. auto.
- TrivialExists. simpl.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  unfold Val.addl. destruct Archi.ptr64, x, y; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  + rewrite Int64.add_zero; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  + rewrite Ptrofs.add_assoc, Ptrofs.add_zero. auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  + rewrite Ptrofs.add_assoc, Ptrofs.add_zero. auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  + rewrite Int64.add_zero; auto.
Qed.

Theorem eval_subl: binary_constructor_sound subl Val.subl.
Proof.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (if Archi.splitlong then @SplitLong.singleoflong hf a else Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  unfold subl. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  apply SplitLongproof.eval_subl. apply Archi.splitlong_ptr32; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  red; intros; destruct (subl_match a b); InvEval.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- rewrite Val.subl_addl_opp. apply eval_addlimm; auto.
- subst. rewrite Val.subl_addl_l. rewrite Val.subl_addl_r.
  rewrite Val.addl_assoc. simpl. rewrite Int64.add_commut. rewrite <- Int64.sub_add_opp.
  replace (Int64.repr (n1 - n2)) with (Int64.sub (Int64.repr n1) (Int64.repr n2)).
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
  apply eval_addlimm; EvalOp.
(* Goal: @eq Int64.int (Int64.neg (Int64.repr n2)) (Int64.repr (Z.opp n2)) *)
  apply Int64.eqm_samerepr; auto with ints.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- subst. rewrite Val.subl_addl_l. apply eval_addlimm; EvalOp.
- subst. rewrite Val.subl_addl_r.
  replace (Int64.repr (-n2)) with (Int64.neg (Int64.repr n2)).
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
  apply eval_addlimm; EvalOp.
(* Goal: @eq Int64.int (Int64.neg (Int64.repr n2)) (Int64.repr (Z.opp n2)) *)
  apply Int64.eqm_samerepr; auto with ints.
- TrivialExists.
Qed.

Theorem eval_mullimm_base: forall n, unary_constructor_sound (mullimm_base n) (fun v => Val.mull v (Vlong n)).
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  intros; unfold mullimm_base. red; intros.
  generalize (Int64.one_bits'_decomp n); intros D.
  destruct (Int64.one_bits' n) as [ | i [ | j [ | ? ? ]]] eqn:B.
- TrivialExists.
- replace (Val.mull x (Vlong n)) with (Val.shll x (Vint i)).
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  apply eval_shllimm; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  simpl in D. rewrite D, Int64.add_zero. destruct x; simpl; auto.
  rewrite (Int64.one_bits'_range n) by (rewrite B; auto with coqlib).
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  rewrite Int64.shl'_mul; auto.
- set (le' := x :: le).
  assert (A0: eval_expr ge sp e m le' (Eletvar O) x) by (constructor; reflexivity).
  exploit (eval_shllimm i). eexact A0. intros (v1 & A1 & B1).
  exploit (eval_shllimm j). eexact A0. intros (v2 & A2 & B2).
  exploit (eval_addl). eexact A1. eexact A2. intros (v3 & A3 & B3).
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exists v3; split. econstructor; eauto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  rewrite D. simpl. rewrite Int64.add_zero. destruct x; auto.
  simpl in *.
  rewrite (Int64.one_bits'_range n) in B1 by (rewrite B; auto with coqlib).
  rewrite (Int64.one_bits'_range n) in B2 by (rewrite B; auto with coqlib).
  inv B1; inv B2. simpl in B3; inv B3.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  rewrite Int64.mul_add_distr_r. rewrite <- ! Int64.shl'_mul. auto.
- TrivialExists.
Qed.

Theorem eval_mullimm: forall n, unary_constructor_sound (mullimm n) (fun v => Val.mull v (Vlong n)).
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold mullimm. intros; red; intros.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (if Archi.splitlong then @SplitLong.singleoflong hf a else Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_mullimm; eauto.
  predSpec Int64.eq Int64.eq_spec n Int64.zero.
  exists (Vlong Int64.zero); split. apply eval_longconst.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct x; simpl; auto. subst n; rewrite Int64.mul_zero; auto.
  predSpec Int64.eq Int64.eq_spec n Int64.one.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exists x; split; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct x; simpl; auto. subst n; rewrite Int64.mul_one; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  destruct (mullimm_match a); InvEval.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- econstructor; split. apply eval_longconst. rewrite Int64.mul_commut; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- exploit (eval_mullimm_base n); eauto. intros (v2 & A2 & B2).
  exploit (eval_addlimm (Int64.mul n (Int64.repr n2))). eexact A2. intros (v3 & A3 & B3).
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  exists v3; split; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  destruct v1; simpl; auto.
  simpl in B2; inv B2. simpl in B3; inv B3. rewrite Int64.mul_add_distr_l.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  rewrite (Int64.mul_commut n). auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- apply eval_mullimm_base; auto.
Qed.

Theorem eval_mull: binary_constructor_sound mull Val.mull.
Proof.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  unfold mull. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_mull; auto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (xorlimm n2 t1) v) (Val.lessdef (Val.xorl x y) v)) *)
  red; intros; destruct (mull_match a b); InvEval.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- rewrite Val.mull_commut. apply eval_mullimm; auto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- apply eval_mullimm; auto.
- TrivialExists.
Qed.

Theorem eval_mullhu:
  forall n, unary_constructor_sound (fun a => mullhu a n) (fun v => Val.mullhu v (Vlong n)).
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold mullhu; intros. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_mullhu; auto.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. TrivialExists. constructor. eauto. constructor. apply eval_longconst. constructor. auto.
Qed.

Theorem eval_mullhs:
  forall n, unary_constructor_sound (fun a => mullhs a n) (fun v => Val.mullhs v (Vlong n)).
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold mullhs; intros. destruct Archi.splitlong eqn:SL. apply SplitLongproof.eval_mullhs; auto.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  red; intros. TrivialExists. constructor. eauto. constructor. apply eval_longconst. constructor. auto.
Qed.

Theorem eval_shrxlimm:
  forall le a n x z,
  eval_expr ge sp e m le a x ->
  Val.shrxl x (Vint n) = Some z ->
  exists v, eval_expr ge sp e m le (shrxlimm a n) v /\ Val.lessdef z v.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold shrxlimm; intros. destruct Archi.splitlong eqn:SL.
+ eapply SplitLongproof.eval_shrxlimm; eauto using Archi.splitlong_ptr32.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (if Int.eq n Int.zero then a else Eop (Oshrxlimm n) (Econs a Enil)) v) (Val.lessdef z v)) *)
+ predSpec Int.eq Int.eq_spec n Int.zero.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
- subst n. destruct x; simpl in H0; inv H0. econstructor; split; eauto.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  change (Int.ltu Int.zero (Int.repr 63)) with true. simpl. rewrite Int64.shrx'_zero; auto.
- TrivialExists.
Qed.

Theorem eval_divls_base: partial_binary_constructor_sound divls_base Val.divls.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold divls_base; red; intros. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_divls_base; eauto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  TrivialExists.
Qed.

Theorem eval_modls_base: partial_binary_constructor_sound modls_base Val.modls.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold modls_base; red; intros. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_modls_base; eauto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  TrivialExists.
Qed.

Theorem eval_divlu_base: partial_binary_constructor_sound divlu_base Val.divlu.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold divlu_base; red; intros. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_divlu_base; eauto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  TrivialExists.
Qed.

Theorem eval_modlu_base: partial_binary_constructor_sound modlu_base Val.modlu.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold modlu_base; red; intros. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_modlu_base; eauto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  TrivialExists.
Qed.

Theorem eval_cmplu:
  forall c le a x b y v,
  eval_expr ge sp e m le a x ->
  eval_expr ge sp e m le b y ->
  Val.cmplu (Mem.valid_pointer m) c x y = Some v ->
  eval_expr ge sp e m le (cmplu c a b) v.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold cmplu; intros. destruct Archi.splitlong eqn:SL.
(* Goal: eval_expr ge sp e m le (SplitLong.cmplu c a b) v *)
(* Goal: eval_expr ge sp e m le match is_longconst a with | Some n1 => match is_longconst b with | Some n2 => Eop (Ointconst (if Int64.cmpu c n1 n2 then Int.one else Int.zero)) Enil | None => Eop (Ocmp (Ccompluimm (swap_comparison c) n1)) (Econs b Enil) end | None => match is_longconst b with | Some n2 => Eop (Ocmp (Ccompluimm c n2)) (Econs a Enil) | None => Eop (Ocmp (Ccomplu c)) (Econs a (Econs b Enil)) end end v *)
  eapply SplitLongproof.eval_cmplu; eauto using Archi.splitlong_ptr32.
(* Goal: eval_expr ge sp e m le match is_longconst a with | Some n1 => match is_longconst b with | Some n2 => Eop (Ointconst (if Int64.cmpu c n1 n2 then Int.one else Int.zero)) Enil | None => Eop (Ocmp (Ccompluimm (swap_comparison c) n1)) (Econs b Enil) end | None => match is_longconst b with | Some n2 => Eop (Ocmp (Ccompluimm c n2)) (Econs a Enil) | None => Eop (Ocmp (Ccomplu c)) (Econs a (Econs b Enil)) end end v *)
  unfold Val.cmplu in H1.
(* Goal: eval_expr ge sp e m le match is_longconst a with | Some n1 => match is_longconst b with | Some n2 => Eop (Ointconst (if Int64.cmpu c n1 n2 then Int.one else Int.zero)) Enil | None => Eop (Ocmp (Ccompluimm (swap_comparison c) n1)) (Econs b Enil) end | None => match is_longconst b with | Some n2 => Eop (Ocmp (Ccompluimm c n2)) (Econs a Enil) | None => Eop (Ocmp (Ccomplu c)) (Econs a (Econs b Enil)) end end v *)
  destruct (Val.cmplu_bool (Mem.valid_pointer m) c x y) as [vb|] eqn:C; simpl in H1; inv H1.
  destruct (is_longconst a) as [n1|] eqn:LC1; destruct (is_longconst b) as [n2|] eqn:LC2;
  try (assert (x = Vlong n1) by (eapply is_longconst_sound; eauto));
  try (assert (y = Vlong n2) by (eapply is_longconst_sound; eauto));
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (addlimm (Int64.repr (Z.opp n2)) (Eop Osubl (Econs t1 (Econs t2 Enil)))) v) (Val.lessdef (Val.subl x (Val.addl v1 (Vlong (Int64.repr n2)))) v)) *)
  subst.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- simpl in C; inv C. EvalOp. destruct (Int64.cmpu c n1 n2); reflexivity.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- EvalOp. simpl. rewrite Val.swap_cmplu_bool. rewrite C; auto.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- EvalOp. simpl; rewrite C; auto.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- EvalOp. simpl; rewrite C; auto.
Qed.

Theorem eval_cmpl:
  forall c le a x b y v,
  eval_expr ge sp e m le a x ->
  eval_expr ge sp e m le b y ->
  Val.cmpl c x y = Some v ->
  eval_expr ge sp e m le (cmpl c a b) v.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold cmpl; intros. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_cmpl; eauto.
(* Goal: eval_expr ge sp e m le match is_longconst a with | Some n1 => match is_longconst b with | Some n2 => Eop (Ointconst (if Int64.cmp c n1 n2 then Int.one else Int.zero)) Enil | None => Eop (Ocmp (Ccomplimm (swap_comparison c) n1)) (Econs b Enil) end | None => match is_longconst b with | Some n2 => Eop (Ocmp (Ccomplimm c n2)) (Econs a Enil) | None => Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil)) end end v *)
  unfold Val.cmpl in H1.
(* Goal: eval_expr ge sp e m le match is_longconst a with | Some n1 => match is_longconst b with | Some n2 => Eop (Ointconst (if Int64.cmp c n1 n2 then Int.one else Int.zero)) Enil | None => Eop (Ocmp (Ccomplimm (swap_comparison c) n1)) (Econs b Enil) end | None => match is_longconst b with | Some n2 => Eop (Ocmp (Ccomplimm c n2)) (Econs a Enil) | None => Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil)) end end v *)
  destruct (Val.cmpl_bool c x y) as [vb|] eqn:C; simpl in H1; inv H1.
  destruct (is_longconst a) as [n1|] eqn:LC1; destruct (is_longconst b) as [n2|] eqn:LC2;
  try (assert (x = Vlong n1) by (eapply is_longconst_sound; eauto));
  try (assert (y = Vlong n2) by (eapply is_longconst_sound; eauto));
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (addlimm (Int64.repr (Z.opp n2)) (Eop Osubl (Econs t1 (Econs t2 Enil)))) v) (Val.lessdef (Val.subl x (Val.addl v1 (Vlong (Int64.repr n2)))) v)) *)
  subst.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- simpl in C; inv C. EvalOp. destruct (Int64.cmp c n1 n2); reflexivity.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- EvalOp. simpl. rewrite Val.swap_cmpl_bool. rewrite C; auto.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- EvalOp. simpl; rewrite C; auto.
(* Goal: eval_expr ge sp e m le (Eop (Ocmp (Ccompl c)) (Econs a (Econs b Enil))) (Val.of_bool vb) *)
- EvalOp. simpl; rewrite C; auto.
Qed.

Theorem eval_longoffloat: partial_unary_constructor_sound longoffloat Val.longoffloat.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold longoffloat; red; intros. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_longoffloat; eauto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  TrivialExists.
Qed.

Theorem eval_floatoflong: partial_unary_constructor_sound floatoflong Val.floatoflong.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold floatoflong; red; intros. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_floatoflong; eauto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  TrivialExists.
Qed.

Theorem eval_longofsingle: partial_unary_constructor_sound longofsingle Val.longofsingle.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold longofsingle; red; intros. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_longofsingle; eauto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  TrivialExists.
Qed.

Theorem eval_singleoflong: partial_unary_constructor_sound singleoflong Val.singleoflong.
Proof.
(* Goal: forall (id : ident) (ofs : Ptrofs.int) (n : Z) (_ : @eq bool Archi.ptr64 true), @eq val (@Genv.symbol_address fundef unit ge id (Ptrofs.add ofs (Ptrofs.repr n))) (Val.addl (@Genv.symbol_address fundef unit ge id ofs) (Vlong (Int64.repr n))) *)
  unfold singleoflong; red; intros. destruct Archi.splitlong eqn:SL.
(* Goal: @eq (option val) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) (@Some val (Vptr b (Ptrofs.add i (Ptrofs.of_int64 i0)))) *)
  eapply SplitLongproof.eval_singleoflong; eauto.
(* Goal: @ex val (fun v : val => Logic.and (eval_expr ge sp e m le (Eop Osingleoflong (Econs a Enil)) v) (Val.lessdef y v)) *)
  TrivialExists.
Qed.

End CMCONSTR.
