(* Definition Vubyte (c: Byte.int) : val := Vint (Int.repr (Byte.unsigned c)).  Lemma Znth_map_Vubyte: forall (i : Z) (l : list byte), 0 <= i < Zlength l -> Znth i (map Vubyte l)  = Vubyte (Znth i l). Locate Znth_map_Vubyte. Hint Rewrite Znth_map_Vubyte using list_solve : norm entailer_rewrite. *)
Local Open Scope nat.
Fixpoint map2 {A B C: Type} (f: A -> B -> C) (al: list A) (bl: list B) : list C :=
match al, bl with
| a::al', b::bl' => f a b :: map2 f al' bl'
| _, _ => nil
end.
Local Open Scope Z.
Definition roundup (a b : Z) := (a + (b-1))/b*b.
(*Definition isbyteZ (i: Z) := (0 <= i < 256)%Z. *)
Definition Shr b x := Int.shru x (Int.repr b).
Fixpoint intlist_to_bytelist (l: list int) : list byte :=
match l with
| nil => nil
| i::r =>
Byte.repr (Int.unsigned (Shr 24 i)) ::
Byte.repr (Int.unsigned (Shr 16 i)) ::
Byte.repr (Int.unsigned (Shr 8 i)) ::
Byte.repr (Int.unsigned i) ::
intlist_to_bytelist r
end.
Definition bytes_to_Int (a b c d : byte) : Int.int :=
Int.or (Int.or (Int.or
(Int.shl (Int.repr (Byte.unsigned a)) (Int.repr 24))
(Int.shl (Int.repr (Byte.unsigned b)) (Int.repr 16)))
(Int.shl (Int.repr (Byte.unsigned c)) (Int.repr 8)))
(Int.repr (Byte.unsigned d)).
Fixpoint bytelist_to_intlist (nl: list byte) : list int :=
match nl with
| h1::h2::h3::h4::t => bytes_to_Int h1 h2 h3 h4 :: bytelist_to_intlist t
| _ => nil
end.
Hint Rewrite Int.bits_or using omega : testbit.
Hint Rewrite Int.bits_shl using omega : testbit.
Hint Rewrite Int.bits_and using omega : testbit.
Hint Rewrite Int.bits_shru using omega : testbit.
Hint Rewrite Int.unsigned_repr using omega : testbit.
Hint Rewrite Int.testbit_repr using omega : testbit.
Hint Rewrite if_false using omega : testbit.
Hint Rewrite if_true using omega : testbit.
Hint Rewrite Z.ones_spec_low using omega : testbit.
Hint Rewrite Z.ones_spec_high using omega : testbit.
Hint Rewrite orb_false_r orb_true_r andb_false_r andb_true_r : testbit.
Hint Rewrite orb_false_l orb_true_l andb_false_l andb_true_l : testbit.
Hint Rewrite Z.add_simpl_r : testbit.
Hint Rewrite Int.unsigned_repr using rep_omega : testbit.
Hint Rewrite Byte.testbit_repr using rep_omega : testbit.
Hint Rewrite Byte.bits_above using rep_omega : testbit.
*)
(* Lemma Forall_isbyte_repr_unsigned: forall l: list int, map Int.repr (map Int.unsigned l) = l.  Lemma map_unsigned_repr_isbyte: forall l : list Z , Forall isbyteZ l -> map Int.unsigned (map Int.repr l) = l. *)

Lemma int_unsigned_inj: forall a b, Int.unsigned a = Int.unsigned b -> a=b.