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. *)

(* Specifications: *)
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.