From Stdlib Require Import Strings.String.
From Stdlib Require Import String Ascii.
From Stdlib Require Arith.
From stdpp Require Import base.
From stdpp Require Import fin_maps.
From stdpp Require Import gmap.
From stdpp Require Import base gmultiset.
From Stdlib Require Classical.
From Stdlib Require Import ZArith.
From stdpp.bitvector Require Import definitions tactics.
From Stdlib Require Import Sorting.Sorted.
From Stdlib Require Import Reals.Rbasic_fun.
From Stdlib Require Import Reals.Abstract.ConstructiveAbs.
From Stdlib Require Import Reals.Rdefinitions.
From stdpp Require Import list_relations.
From stdpp Require Import list_numbers.
From stdpp Require Import functions.
From Stdlib Require Import ClassicalEpsilon.
From stdpp Require Import base decidable.
From Stdlib Require Import ZArith.Zeuclid.
From Stdlib Require Import ZArith.Znumtheory.
From stdpp Require Import propset.
From Stdlib Require Import Reals.
Require Import Why3.Base.
Require Import Why3.why3.Ref.Ref.
Require Import Why3.map.Const.
Require Import Why3.map.MapEq.
Require Import Why3.mach.int.Unsigned.
Require Import Why3.mach.c.C.
Require Import multiprecision.types.Config.
Require Import multiprecision.types.Types.
Require Import multiprecision.types.Int32Eq.
Require Import multiprecision.types.UInt64Eq.
Require Import multiprecision.lemmas.Lemmas.
Require Import multiprecision.compare.Compare.
Require Import multiprecision.ptralias.Alias.
Require Import multiprecision.util.UtilOld.
Require Import multiprecision.add.AddOld.
Require Import multiprecision.sub.SubOld.
Require Import multiprecision.logical.LogicalUtil.
Require Import multiprecision.logical.LogicalOld.
Open Scope Z_scope.
Definition reciprocal (v : bv 64%N) (d : bv 64%N) := bv_unsigned v = ZEuclid.div ((18446744073709551615%Z + 1%Z) * (18446744073709551615%Z + 1%Z) - 1%Z) (bv_unsigned d) - (18446744073709551615%Z + 1%Z).
Theorem wmpn_divrem_1'vc (x : ptr (bv 64%N)) (sz : bv 32%N) (q : ptr (bv 64%N)) (y : bv 64%N) (fact0 : valid x (bv_signed sz)) (fact1 : valid q (bv_signed sz)) (fact2 : writable q = true) (fact3 : 0%Z < bv_signed sz) (fact4 : 0%Z < bv_unsigned y) : int'32_in_bounds (bv_signed sz - 1%Z) ∧ (∀(msb : bv 32%N), bv_signed msb = bv_signed sz - 1%Z -> 0%Z < bv_unsigned y ∧ (∀(clz : bv 32%N), Z.pow 2%Z (bv_signed clz) * bv_unsigned y ≤ 18446744073709551615%Z ∧ 18446744073709551615%Z < 2%Z * Z.pow 2%Z (bv_signed clz) * bv_unsigned y ∧ 0%Z ≤ bv_signed clz ∧ bv_signed clz < 64%Z -> (if decide (0%Z < bv_signed clz) then let mult : Z := Z.pow 2%Z (bv_signed clz) in 0%Z ≤ bv_signed clz ∧ (∀(o1 : bv 64%N), bv_unsigned o1 = bv_signed clz -> ((0%Z ≤ bv_unsigned o1 ∧ bv_unsigned o1 < 64%Z) ∧ Z.pow 2%Z (bv_unsigned o1) * bv_unsigned y ≤ 18446744073709551615%Z) ∧ (∀(ry : bv 64%N), bv_unsigned ry = Z.pow 2%Z (bv_unsigned o1) * bv_unsigned y -> ZEuclid.div (18446744073709551615%Z + 1%Z) 2%Z ≤ bv_unsigned ry ∧ (∀(v : bv 64%N), reciprocal v ry -> ((- 1%Z ≤ bv_signed msb ∧ bv_signed msb ≤ bv_signed msb) ∧ 0%Z < bv_unsigned ry ∧ mult * value_sub (pelts x) (offset x + bv_signed msb + 1%Z) (offset x + bv_signed sz) = value_sub (pelts q) (offset q + bv_signed msb + 1%Z) (offset q + bv_signed sz) * bv_unsigned ry + 0%Z ∧ 0%Z ≤ 18446744073709551615%Z + 1%Z - mult ∧ ZEuclid.modulo 0%Z mult = 0%Z) ∧ (∀(r : bv 64%N) (i : bv 32%N) (q1 : ptr (bv 64%N)), length (data q1) = length (data q) ∧ offset q1 = offset q ∧ min q1 = min q ∧ C.max q1 = C.max q ∧ writable q1 = writable q ∧ zone1 q1 = zone1 q -> (- 1%Z ≤ bv_signed i ∧ bv_signed i ≤ bv_signed msb) ∧ bv_unsigned r < bv_unsigned ry ∧ mult * value_sub (pelts x) (offset x + bv_signed i + 1%Z) (offset x + bv_signed sz) = value_sub (pelts q1) (offset q1 + bv_signed i + 1%Z) (offset q1 + bv_signed sz) * bv_unsigned ry + bv_unsigned r ∧ bv_unsigned r ≤ 18446744073709551615%Z + 1%Z - mult ∧ ZEuclid.modulo (bv_unsigned r) mult = 0%Z -> (if decide (0%Z ≤ bv_signed i) then (min x ≤ offset x + bv_signed i ∧ offset x + bv_signed i < C.max x) ∧ 0%Z ≤ bv_signed clz ∧ (∀(o2 : bv 64%N), bv_unsigned o2 = bv_signed clz -> (0%Z < bv_unsigned o2 ∧ bv_unsigned o2 < 64%Z) ∧ (∀(l : bv 64%N) (h : bv 64%N), bv_unsigned l + (18446744073709551615%Z + 1%Z) * bv_unsigned h = Z.pow 2%Z (bv_unsigned o2) * bv_unsigned (pelts x (offset x + bv_signed i)) ∧ ZEuclid.modulo (bv_unsigned l) (Z.pow 2%Z (bv_unsigned o2)) = 0%Z ∧ bv_unsigned l ≤ 18446744073709551615%Z + 1%Z - Z.pow 2%Z (bv_unsigned o2) ∧ bv_unsigned h < Z.pow 2%Z (bv_unsigned o2) -> uint'64_in_bounds (bv_unsigned r + bv_unsigned h) ∧ (∀(o3 : bv 64%N), bv_unsigned o3 = bv_unsigned r + bv_unsigned h -> (ZEuclid.div (18446744073709551615%Z + 1%Z) 2%Z ≤ bv_unsigned ry ∧ bv_unsigned o3 < bv_unsigned ry ∧ reciprocal v ry) ∧ (∀(qu : bv 64%N) (rem : bv 64%N), bv_unsigned qu * bv_unsigned ry + bv_unsigned rem = bv_unsigned l + (18446744073709551615%Z + 1%Z) * bv_unsigned o3 ∧ 0%Z ≤ bv_unsigned rem ∧ bv_unsigned rem < bv_unsigned ry -> ¬ mult = 0%Z ∧ (let o4 : Z := offset q1 + bv_signed sz in let o5 : Z := offset q1 + 1%Z + bv_signed i in let o6 : Z := offset q1 + bv_signed i in let o7 : Z -> bv 64%N := pelts q1 in (o5 ≤ o4 ∧ (o6 < o5 ∨ o4 ≤ o6)) ∧ (value_sub o7 o5 o4 = value_sub (fun_updt o7 o6 qu) o5 o4 -> ((min q1 ≤ offset q1 + bv_signed i ∧ offset q1 + bv_signed i < C.max q1) ∧ writable q1 = true) ∧ (∀(q2 : ptr (bv 64%N)), length (data q2) = length (data q1) ∧ offset q2 = offset q1 ∧ min q2 = min q1 ∧ C.max q2 = C.max q1 ∧ writable q2 = writable q1 ∧ zone1 q2 = zone1 q1 -> pelts q2 = fun_updt (pelts q1) (offset q2 + bv_signed i) qu ∧ pelts q2 (offset q2 + bv_signed i) = qu -> int'32_in_bounds (bv_signed i - 1%Z) ∧ (∀(o8 : bv 32%N), bv_signed o8 = bv_signed i - 1%Z -> bv_signed o8 < bv_signed i ∧ (- 1%Z ≤ bv_signed o8 ∧ bv_signed o8 ≤ bv_signed msb) ∧ bv_unsigned rem < bv_unsigned ry ∧ mult * value_sub (pelts x) (offset x + bv_signed o8 + 1%Z) (offset x + bv_signed sz) = value_sub (pelts q2) (offset q2 + bv_signed o8 + 1%Z) (offset q2 + bv_signed sz) * bv_unsigned ry + bv_unsigned rem ∧ bv_unsigned rem ≤ 18446744073709551615%Z + 1%Z - mult ∧ ZEuclid.modulo (bv_unsigned rem) mult = 0%Z)))))))) else 0%Z ≤ bv_signed clz ∧ (∀(o2 : bv 64%N), bv_unsigned o2 = bv_signed clz -> ((0%Z ≤ bv_unsigned o2 ∧ bv_unsigned o2 < 64%Z) ∧ ZEuclid.modulo (bv_unsigned r) (Z.pow 2%Z (bv_unsigned o2)) = 0%Z) ∧ (∀(res : bv 64%N), bv_unsigned r = Z.pow 2%Z (bv_unsigned o2) * bv_unsigned res -> 0%Z ≤ bv_signed clz ∧ (∀(o3 : bv 64%N), bv_unsigned o3 = bv_signed clz -> ((0%Z ≤ bv_unsigned o3 ∧ bv_unsigned o3 < 64%Z) ∧ ZEuclid.modulo (bv_unsigned r) (Z.pow 2%Z (bv_unsigned o3)) = 0%Z) ∧ (∀(result : bv 64%N), bv_unsigned r = Z.pow 2%Z (bv_unsigned o3) * bv_unsigned result -> value x (bv_signed sz) = value q1 (bv_signed sz) * bv_unsigned y + bv_unsigned result ∧ bv_unsigned result < bv_unsigned y))))))))) else ZEuclid.div (18446744073709551615%Z + 1%Z) 2%Z ≤ bv_unsigned y ∧ (∀(v : bv 64%N), reciprocal v y -> ((- 1%Z ≤ bv_signed msb ∧ bv_signed msb ≤ bv_signed msb) ∧ 0%Z < bv_unsigned y ∧ value_sub (pelts x) (offset x + bv_signed msb + 1%Z) (offset x + bv_signed sz) = value_sub (pelts q) (offset q + bv_signed msb + 1%Z) (offset q + bv_signed sz) * bv_unsigned y + 0%Z) ∧ (∀(r : bv 64%N) (i : bv 32%N) (q1 : ptr (bv 64%N)), length (data q1) = length (data q) ∧ offset q1 = offset q ∧ min q1 = min q ∧ C.max q1 = C.max q ∧ writable q1 = writable q ∧ zone1 q1 = zone1 q -> (- 1%Z ≤ bv_signed i ∧ bv_signed i ≤ bv_signed msb) ∧ bv_unsigned r < bv_unsigned y ∧ value_sub (pelts x) (offset x + bv_signed i + 1%Z) (offset x + bv_signed sz) = value_sub (pelts q1) (offset q1 + bv_signed i + 1%Z) (offset q1 + bv_signed sz) * bv_unsigned y + bv_unsigned r -> (if decide (0%Z ≤ bv_signed i) then (min x ≤ offset x + bv_signed i ∧ offset x + bv_signed i < C.max x) ∧ (ZEuclid.div (18446744073709551615%Z + 1%Z) 2%Z ≤ bv_unsigned y ∧ bv_unsigned r < bv_unsigned y ∧ reciprocal v y) ∧ (∀(qu : bv 64%N) (rem : bv 64%N), bv_unsigned qu * bv_unsigned y + bv_unsigned rem = bv_unsigned (pelts x (offset x + bv_signed i)) + (18446744073709551615%Z + 1%Z) * bv_unsigned r ∧ 0%Z ≤ bv_unsigned rem ∧ bv_unsigned rem < bv_unsigned y -> (let o1 : Z := offset q1 + bv_signed sz in let o2 : Z := offset q1 + 1%Z + bv_signed i in let o3 : Z := offset q1 + bv_signed i in let o4 : Z -> bv 64%N := pelts q1 in (o2 ≤ o1 ∧ (o3 < o2 ∨ o1 ≤ o3)) ∧ (value_sub o4 o2 o1 = value_sub (fun_updt o4 o3 qu) o2 o1 -> ((min q1 ≤ offset q1 + bv_signed i ∧ offset q1 + bv_signed i < C.max q1) ∧ writable q1 = true) ∧ (∀(q2 : ptr (bv 64%N)), length (data q2) = length (data q1) ∧ offset q2 = offset q1 ∧ min q2 = min q1 ∧ C.max q2 = C.max q1 ∧ writable q2 = writable q1 ∧ zone1 q2 = zone1 q1 -> pelts q2 = fun_updt (pelts q1) (offset q2 + bv_signed i) qu ∧ pelts q2 (offset q2 + bv_signed i) = qu -> int'32_in_bounds (bv_signed i - 1%Z) ∧ (∀(o5 : bv 32%N), bv_signed o5 = bv_signed i - 1%Z -> bv_signed o5 < bv_signed i ∧ (- 1%Z ≤ bv_signed o5 ∧ bv_signed o5 ≤ bv_signed msb) ∧ bv_unsigned rem < bv_unsigned y ∧ value_sub (pelts x) (offset x + bv_signed o5 + 1%Z) (offset x + bv_signed sz) = value_sub (pelts q2) (offset q2 + bv_signed o5 + 1%Z) (offset q2 + bv_signed sz) * bv_unsigned y + bv_unsigned rem))))) else value x (bv_signed sz) = value q1 (bv_signed sz) * bv_unsigned y + bv_unsigned r ∧ bv_unsigned r < bv_unsigned y)))))).
Admitted.
