Local Open Scope logic.
(*new*) Genv.find_symbol ge id = Some b -> (*new*) Genv.find_funct_ptr ge b = Some (External ef argsig retsig cc) -> semax_func V G ge fs G' -> semax_func V G ge ((id, External ef argsig retsig cc) :: fs) ((id, vacuous_funspec (External ef argsig retsig cc)) :: G').  Lemma int_eq_false_e: forall i j, Int.eq i j = false -> i <> j.   Lemma semax_ifthenelse_PQR' : forall Espec {cs: compspecs} (v: val) Delta P Q R (b: expr) c d Post, bool_type (typeof b) = true -> ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |-- (tc_expr Delta (Eunop Cop.Onotbool b tint))  -> ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |-- local (`(eq v) (eval_expr b)) -> @semax cs Espec Delta (PROPx (typed_true (typeof b) v :: P) (LOCALx Q (SEPx R))) c Post -> @semax cs Espec Delta (PROPx (typed_false (typeof b) v :: P) (LOCALx Q (SEPx R))) d Post -> @semax cs Espec Delta (PROPx P (LOCALx Q (SEPx R))) (Sifthenelse b c d) Post.  Definition logical_and_result v1 t1 v2 t2 := match (strict_bool_val t1 v1) with | Some b1 => if b1 then match (strict_bool_val t2 v2) with | Some b2 => if b2 then  Vint Int.one else Vint Int.zero | None => Vundef end else Vint Int.zero | None => Vundef end.  Definition logical_or_result v1 t1 v2 t2 := match (strict_bool_val t1 v1) with | Some b1 => if b1 then Vint Int.one else match (strict_bool_val t2 v2) with | Some b2 => if b2 then  Vint Int.one else Vint Int.zero | None => Vundef end | None => Vundef end.  (* NOTE: In both logical_or and logical_and, compcert (up to 2.4) has (Etempvar tid tbool) where I conjecture that it should have (Etempvar tid tint). That means our lemmas here are incompatible with compcert, at the moment. *)
Definition logical_and tid e1 e2 :=
(Sifthenelse e1
(Ssequence
(Sset tid (Ecast e2 tbool))
(Sset tid (Ecast (Etempvar tid tint (*tbool*)) tint)))
(Sset tid (Econst_int (Int.repr 0) tint))).
(* Lemma field_at_mapsto__at1: forall Espec Delta P Q sh ty fld e v R c Post, @semax Espec Delta (PROPx P (LOCALx Q (SEPx (`(field_at_ sh ty fld) e :: R)))) c Post -> @semax Espec Delta (PROPx P (LOCALx Q (SEPx (`(field_at sh ty fld) v e :: R)))) c Post.  Lemma later_field_at_mapsto__at1: forall Espec Delta P Q sh ty fld e v R c Post, @semax Espec Delta (PROPx P (LOCALx Q (SEPx (|>`(field_at_ sh ty fld) e :: R)))) c Post -> @semax Espec Delta (PROPx P (LOCALx Q (SEPx (|> `(field_at sh ty fld) v e :: R)))) c Post. *)
(* Lemma forward_setx: forall Espec {cs: compspecs} Delta P Q R id e, (PROPx P (LOCALx (tc_env Delta :: Q) (SEPx R)) |-- (tc_expr Delta e) && (tc_temp_id id (typeof e) Delta e) ) -> @semax cs Espec Delta (PROPx P (LOCALx Q (SEPx R))) (Sset id e) (normal_ret_assert (EX old:val, PROPx P (LOCALx (`eq (eval_id id) (subst id (`old) (eval_expr e)) :: map (subst id (`old)) Q) (SEPx R)))). *)
Definition signof (e: expr) :=
match typeof e with
| Tint _ s _ => s
| Tlong s _ => s
| _ =>  Unsigned
end.
Definition adjust_for_sign (s: signedness) (x: Z) :=
match s with
| Unsigned => x
| Signed => if (zlt x Int.half_modulus) then x else x - Int.modulus
end.
(* Lemma normal_ret_assert_derives': forall ek vl P Q, P |-- Q -> normal_ret_assert P ek vl |-- normal_ret_assert Q ek vl.  Lemma normal_ret_assert_derives'': forall (P: environ->mpred) (Q: ret_assert), (P |-- Q EK_normal None) -> normal_ret_assert P |-- Q. *)
(* Lemma elim_redundant_Delta: forall Espec {cs: compspecs} Delta P Q R c Post, @semax cs Espec Delta (PROPx P (LOCALx Q R)) c Post -> @semax cs Espec Delta (PROPx P (LOCALx (tc_env Delta:: Q) R)) c Post. *)

Lemma semax_for_3g1 :
forall Espec {cs: compspecs} {A} (PQR: A -> environ -> mpred) (v: A -> val) Delta P Q R test body incr Post,
bool_type (typeof test) = true ->
(forall a, ENTAIL Delta, PROPx (P a) (LOCALx (Q a) (SEPx (R a))) |-- (tc_expr Delta (Eunop Cop.Onotbool test tint))) ->
(forall a, ENTAIL Delta, PROPx (P a) (LOCALx (Q a) (SEPx (R a))) |-- local (`(eq (v a)) (eval_expr test))) ->
(forall a, @semax cs Espec Delta (PROPx (typed_true (typeof test) (v a) :: (P a)) (LOCALx (Q a) (SEPx (R a))))
body (loop1_ret_assert (EX a:A, PQR a) Post)) ->
(forall a, @semax cs Espec Delta (PQR a) incr
(normal_ret_assert (EX a:A, PROPx (P a) (LOCALx (Q a) (SEPx (R a)))))) ->
(forall a, ENTAIL Delta, PROPx (typed_false (typeof test) (v a) :: (P a)) (LOCALx (Q a) (SEPx (R a)))
|-- RA_normal Post) ->
@semax cs Espec Delta (EX a:A, PROPx (P a) (LOCALx (Q a) (SEPx (R a))))
(Sloop (Ssequence (Sifthenelse test Sskip Sbreak)  body) incr)
Post.