You are an expert Lean4 and formal verification agent proving a Lean4 theorem. Your output **must** strictly adhere to the specified format.

### Input Information
You will receive the following components, relevant to the target theorem:
* <all_available_defs>: Definitions available from imported modules (either from the current Lean repository or from Mathlib)
* <all_available_lemmas>: Lemmas/theorems available that may assist the proof.
* <local_ctx>...</local_ctx>: The local file context (imports, namespaces, definitions, comments, etc.) from the top of the file up to—but not including—the target theorem or any previously defined local lemmas/theorems.
* <target_theorem>...</target_theorem>: The target theorem statement, ending with `:=`.

**Notes**
1. Definitions include their full bodies, but for definitions whose bodies contain proofs, the proof parts are replaced by `admit` (i.e., admit /- proof elided -/), while the rest of the definition is kept unchanged; lemmas include only their statements.
2. You may freely reference any definition or lemma contained in these tags without redefining them.
3. The tags for available definitions and lemmas (all_available_defs, all_available_lemmas) may be omitted if empty.

### Output Format & Requirements
Your output MUST contain a complete, syntactically correct Lean 4 proof for the target theorem.

**Strict Output Structure:**
<reasoning> 
...
</reasoning> 

<lean4_invented_lemmas>
-- each lemma is a full Lean 4 declaration with a complete proof
...
</lean4_invented_lemmas>

<lean4_proof>
-- Lean 4 proof body of the target theorem
...
</lean4_proof>

**Requirements:**
1. <reasoning> and <lean4_invented_lemmas> are OPTIONAL. Include them only if they aid proof construction.
2. <lean4_proof> MUST contain only the proof body (tactics/terms), starting by "by", NOT the theorem declaration.
3. <lean4_invented_lemmas> (if present) MUST contain syntactically correct lemma declarations that type checks AND complete proof bodies. Defining a lemma using `axiom` is NOT allowed.
4. <reasoning> contains high-level proof planning.
5. If you create a lemma under <lean4_invented_lemmas> whose name is namespaced (e.g., X.Y.Z), you MUST always refer to it using its fully qualified name. Do NOT rely on shortened names. For example, write rw [X.Y.Z], not rw [Z] for invented lemmas.
6. All Lean 4 code MUST be syntactically correct. No `sorry`, `admit`, or non-Lean text. Comments allowed using `--` or `/- ... -/`.
7. Follow the tags and structure EXACTLY. No extra text before, between, or after the sections.
8. Do NOT wrap invented lemmas in a `mutual` block unless they have genuine mutual recursion. Declare each lemma independently.

### Examples are provided here (example input are under "User Prompt", and example assistant response are under "Agent Response"):
Example 1 ------------------- 
User Prompt:
<all_available_defs>
structure BitVec (w : Nat) where
  /-- Construct a `BitVec w` from a number less than `2^w`.
  O(1), because we use `Fin` as the internal representation of a bitvector. -/
  ofFin ::

  /-- Interpret a bitvector as a number less than `2^w`.
  O(1), because we use `Fin` as the internal representation of a bitvector. -/
  toFin : Fin (hPow 2 w)
</all_available_defs>

<all_available_lemmas>
theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) : (l₁ ++ l₂)[i] = l₁[i]
theorem getElem_eq_testBit_toNat (x : BitVec w) (i : Nat) (h : i < w) :
  x[i] = x.toNat.testBit i := rfl
@[simp, grind =] theorem toNat_cons (b : Bool) (x : BitVec w) :
    (cons b x).toNat = (b.toNat <<< w) ||| x.toNat
@[simp, grind =] theorem getLsbD_of_ge (x : BitVec w) (i : Nat) (ge : w ≤ i) : getLsbD x i = false
theorem testBit_toNat (x : BitVec w) : x.toNat.testBit i = x.getLsbD i
</all_available_lemmas>

<local_ctx>
import Mathlib.Computability.NFA
import Mathlib.Data.FinEnum
import Mathlib.Data.Rel
import Mathlib.Data.Vector.Basic
import Blase.AutoStructs.ForLean

open Set
open Mathlib
open SetRel

-- this is better because card is defeq to n
instance (α : Type) : Inter (Language α) := ⟨Set.inter⟩
instance (α : Type) : Union (Language α) := ⟨Set.union⟩

/--
The set of `n`-tuples of bit vectors of an arbitrary width.
-/
structure BitVecs (n : Nat) where
  w : Nat
  bvs : List.Vector (BitVec w) n

def BitVecs.cast (bvs : BitVecs n) (h : n = n') : BitVecs n' :=
  { w := bvs.w, bvs := h ▸ bvs.bvs }

abbrev BitVecs.empty : BitVecs n := ⟨0, List.Vector.replicate n .nil⟩
abbrev BitVecs.singleton {w : Nat} (bv : BitVec w) : BitVecs 1 := ⟨w, bv ::ᵥ .nil⟩
abbrev BitVecs.pair {w : Nat} (bv1 bv2 : BitVec w) : BitVecs 2 := ⟨w, bv1 ::ᵥ bv2 ::ᵥ .nil⟩

/--
The set of `n`-tuples of bit vectors of an arbitrary width, encoded as a list of
bit vectors of width `n`. The width of the encoded bit vectors is the length of
the list.
-/
abbrev BitVecs' (n : Nat) := List (BitVec n)

@[simps]
def dec (bvs' : BitVecs' n) : BitVecs n where
  w := bvs'.length
  bvs := List.Vector.ofFn fun k => BitVec.ofFn fun i => bvs'[i].getLsbD k

@[simp]
</local_ctx>

<target_theorem>
lemma dec_snoc n (bvs' : BitVecs' n) (a : BitVec n) :
  dec (bvs' ++ [a]) =
    { w := bvs'.length + 1
      bvs := List.Vector.ofFn fun k =>
        BitVec.cons (a.getLsbD k) ((dec bvs').bvs.get k) } :=
</target_theorem>

Agent Response:
<reasoning> 
The goal is to understand what `dec` does after appending one more bitvector `a` to `bvs'`. By definition, `dec` builds a width `= length` and a vector of bitvectors whose `i`-th bit at position `k` is `bvs'[i].getLsbD k`. So for `bvs' ++ [a]`, we expect the width to increase by 1 and each resulting bitvector to be `BitVec.cons` of the new bit coming from `a`.

First, I use `ext` twice: once on the record to focus on the `bvs` field, and once on the resulting bitvector. This reduces everything to a pointwise statement:
for fixed `k` and `i` with `i < bvs'.length + 1`,
the bit `(bvs' ++ [a])[i].getLsbD k` should match the bit at index `i` of `BitVec.cons (a.getLsbD k) ((dec bvs').bvs.get k)`.

At this point I need a clean description of indexing into `BitVec.cons`: if we have `x : BitVec n`, then `(cons b x)[i]` should give `b` at the new “last” index `n` and `x[i]` otherwise. That motivates an auxiliary lemma `getElem_cons` expressing exactly this behavior, proved via the `testBit`/`toNat` characterization and a case split on `i < n`, `i = n`, `i > n`.

Using `getElem_cons`, the RHS becomes an `if` on whether `i = bvs'.length`. So I split into cases:
- If `i = bvs'.length`, then `(bvs' ++ [a])[i]` is the appended `a`, so both sides reduce to `a.getLsbD k`.
- If `i ≠ bvs'.length`, the bound `i < bvs'.length + 1` forces `i < bvs'.length`. Then `(bvs' ++ [a])[i] = bvs'[i]` by `List.getElem_append_left`, and the RHS takes the “else” branch and likewise gives the bit from `bvs'[i]`. In both subcases, `simp` (plus the definition of `dec`) finishes.

So the whole proof is: `ext` to bit level, unfold `dec` with `simp_all`, rewrite with `getElem_cons`, split on the boundary index `i = length bvs'`, and in the “< length” branch use `List.getElem_append_left` and bounds to line up both sides.
</reasoning> 

<lean4_invented_lemmas>
@[grind =]
theorem getElem_cons {b : Bool} {n} {x : BitVec n} {i : Nat} (h : i < n + 1) :
    (cons b x)[i] = if h : i = n then b else x[i] := by
  simp only [BitVec.getElem_eq_testBit_toNat, BitVec.toNat_cons, Nat.testBit_or]
  rw [Nat.testBit_shiftLeft]
  rcases Nat.lt_trichotomy i n with i_lt_n | i_eq_n | n_lt_i
  · have p1 : ¬(n ≤ i) := by omega
    have p2 : i ≠ n := by omega
    simp [p1, p2]
  · simp only [i_eq_n, ge_iff_le, Nat.le_refl, decide_true, Nat.sub_self, Nat.testBit_zero,
    Bool.true_and, BitVec.testBit_toNat, BitVec.getLsbD_of_ge, Bool.or_false]
    cases b <;> trivial
  · have p1 : i ≠ n := by omega
    have p2 : i - n ≠ 0 := by omega
    simp [p1, p2, Nat.testBit_bool_toNat]
</lean4_invented_lemmas>

<lean4_proof>
by
  ext k i hi <;> simp_all
  rw [getElem_cons]
  split
  next heq => simp_all
  next h =>
    have hlt : i < List.length bvs' := by simp at hi; omega
    rw [List.getElem_append_left hlt]
    simp
</lean4_proof>

### Your task:
<all_available_defs>
BitVec in Init.Prelude
Nat in Init.Prelude
List in Init.Prelude
List.Vector in Mathlib.Data.Vector.Defs
Set in Mathlib.Data.Set.Defs
NFA in Mathlib.Computability.NFA
DecidableEq in Init.Prelude
Fintype in Mathlib.Data.Fintype.Defs
Repr in Init.Data.Repr
NFA.accept in Mathlib.Computability.NFA
NFA.start in Mathlib.Computability.NFA
NFA.step in Mathlib.Computability.NFA
Unit in Init.Prelude
cmp in Mathlib.Data.Ordering.Basic
BitVec.ofNat in Init.Prelude
NFA.stepSet in Mathlib.Computability.NFA
BitVec.cons in Init.Data.BitVec.Basic
Language in Mathlib.Computability.Language
List.Vector.ofFn in Mathlib.Data.Vector.Defs
List.Vector.replicate in Mathlib.Data.Vector.Defs
Bool in Init.Prelude
Fin in Init.Prelude
BitVec.iunfoldr in Init.Data.BitVec.Folds
List.finRange in Init.Data.List.FinRange
List.reverseRecOn in Mathlib.Data.List.Induction
FinEnum in Mathlib.Data.FinEnum
BitVec.ofFin in Init.Prelude
BitVec.ule in Init.Data.BitVec.Basic
BitVec.ult in Init.Data.BitVec.Basic
BitVec.sle in Init.Data.BitVec.Basic
BitVec.slt in Init.Data.BitVec.Basic

structure BitVecs (n : Nat) where
  w : Nat
  bvs : List.Vector (BitVec w) n

inductive RelationOrdering
| lt | le | gt | ge
deriving Repr, Fintype

structure NFA' (n : Nat) where
  σ : Type
  M : NFA (BitVec n) σ

inductive Relation
| eq
| signed (ord : RelationOrdering)
| unsigned (ord : RelationOrdering)
deriving Repr

def evalRelation (rel : Relation) {w} (bv1 bv2 : BitVec w) : Prop :=
  match rel with
  | .eq => bv1 = bv2
  | .signed .lt => bv1.slt bv2
  | .signed .le => bv1.sle  bv2
  | .signed .gt => bv2.slt bv1
  | .signed .ge => bv2.sle bv1
  | .unsigned .lt => bv1.ult bv2
  | .unsigned .le => bv1.ule bv2
  | .unsigned .gt => bv2.ult bv1
  | .unsigned .ge => bv2.ule bv1

def bv2 : BitVec 4 := BitVec.ofNat 4 1

def bv1 : BitVec 4 := BitVec.ofNat 4 5

def accepts (M : NFA' n) : Set (BitVecs n) := dec '' M.accepts'

def accepts' (M : NFA' n) : Set (BitVecs' n) := M.M.accepts

abbrev BitVecs' (n : Nat) := List (BitVec n)

@[simps]
def dec (bvs' : BitVecs' n) : BitVecs n where
  w := bvs'.length
  bvs := List.Vector.ofFn fun k => BitVec.ofFn fun i => bvs'[i].getLsbD k

def BitVec.ofFn {w : Nat} (f : Fin w → Bool) : BitVec w :=
  BitVec.iunfoldr (fun i _ => ((), f i)) () |>.2

def BitStream : Type := Nat → Bool

def enc (bvs : BitVecs n) : BitVecs' n :=
  (List.finRange bvs.w).map (fun i =>
    BitVec.ofFn (fun (k : Fin n) => (bvs.bvs.get k)[i]))

instance instFinEnumBV : FinEnum (BitVec w) where
  card := 2^w
  equiv := {
    toFun := fun x => x.toFin
    invFun := fun x => BitVec.ofFin x
    left_inv := by admit /- proof elided -/

instance : Quote Int := ⟨fun n => Syntax.mkNumLit <| n.repr⟩

def lshrult_02_09_exact_after := [llvm|
{
^0(%arg124 : i4):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def scalar_i32_lshr_and_signbit_eq_before := [llvm|
{
^0(%arg31 : i32, %arg32 : i32):
  %0 = llvm.mlir.constant(-2147483648 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.lshr %arg31, %arg32 : i32
  %3 = llvm.and %2, %0 : i32
  %4 = llvm.icmp "eq" %3, %1 : i32
  "llvm.return"(%4) : (i1) -> ()
}
]

def slt_or_not_max_logical_before := [llvm|
{
^0(%arg60 : i8, %arg61 : i8):
  %0 = llvm.mlir.constant(127 : i8) : i8
  %1 = llvm.mlir.constant(true) : i1
  %2 = llvm.icmp "slt" %arg60, %arg61 : i8
  %3 = llvm.icmp "ne" %arg60, %0 : i8
  %4 = "llvm.select"(%2, %1, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def test_before := [llvm|
{
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.mlir.constant(2 : i32) : i32
  %2 = llvm.icmp "eq" %0, %1 : i32
  %3 = llvm.zext %2 : i1 to i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def p1_scalar_urem_by_nonconst_before := [llvm|
{
^0(%arg18 : i32, %arg19 : i32):
  %0 = llvm.mlir.constant(128 : i32) : i32
  %1 = llvm.mlir.constant(6 : i32) : i32
  %2 = llvm.mlir.constant(0 : i32) : i32
  %3 = llvm.and %arg18, %0 : i32
  %4 = llvm.or %arg19, %1 : i32
  %5 = llvm.urem %3, %4 : i32
  %6 = llvm.icmp "eq" %5, %2 : i32
  "llvm.return"(%6) : (i1) -> ()
}
]

def alive_AddSub_1043_tgt  (w : Nat)  :=
[llvm( w )| {
^bb0(%C1 : _, %Z : _, %RHS : _):
  %v1 = llvm.not %C1
  %v2 = llvm.or %Z, %v1
  %v3 = llvm.and %Z, %C1
  %v4 = llvm.xor %v3, %C1
  %v5 = llvm.mlir.constant 1
  %v6 = llvm.add %v4, %v5
  %v7 = llvm.sub %RHS, %v2
  llvm.return %v7
}]

def fold_xor_zext_sandwich_after := [llvm|
{
^0(%arg101 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.xor %arg101, %0 : i1
  %2 = llvm.zext %1 : i1 to i64
  "llvm.return"(%2) : (i64) -> ()
}
]

def scalar_i32_lshr_and_negC_slt_before := [llvm|
{
^0(%arg4 : i32, %arg5 : i32):
  %0 = llvm.mlir.constant(-8 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.lshr %arg4, %arg5 : i32
  %3 = llvm.and %2, %0 : i32
  %4 = llvm.icmp "slt" %3, %1 : i32
  "llvm.return"(%4) : (i1) -> ()
}
]

def or_logic_or_logic_and_5_after := [llvm|
{
^0(%arg36 : i1, %arg37 : i1, %arg38 : i1):
  %0 = llvm.mlir.constant(false) : i1
  %1 = llvm.mlir.constant(true) : i1
  %2 = "llvm.select"(%arg37, %arg38, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %3 = "llvm.select"(%arg36, %1, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def nfa' : NFA' n :=
  { σ := _, M := nfa inits final f }

EmptyCollection in Init.Core

def same_signbit_wrong_type_before := [llvm|
{
^0(%arg34 : i8, %arg35 : i32):
  %0 = llvm.mlir.constant(7 : i8) : i8
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.lshr %arg34, %0 : i8
  %3 = llvm.icmp "sgt" %arg35, %1 : i32
  %4 = llvm.zext %3 : i1 to i8
  %5 = llvm.icmp "ne" %2, %4 : i8
  "llvm.return"(%5) : (i1) -> ()
}
]

def udiv_c_i32_before := [llvm|
{
^0(%arg6 : i8):
  %0 = llvm.mlir.constant(10 : i32) : i32
  %1 = llvm.zext %arg6 : i8 to i32
  %2 = llvm.udiv %0, %1 : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def fold_sext_to_and_wrong3_before := [llvm|
{
^0(%arg7 : i8):
  %0 = llvm.mlir.constant(128 : i32) : i32
  %1 = llvm.mlir.constant(-2147483648 : i32) : i32
  %2 = llvm.sext %arg7 : i8 to i32
  %3 = llvm.and %2, %0 : i32
  %4 = llvm.icmp "eq" %3, %1 : i32
  "llvm.return"(%4) : (i1) -> ()
}
]

def test4_after := [llvm|
{
^0(%arg1 : i8):
  %0 = llvm.mlir.constant(127 : i8) : i8
  %1 = llvm.icmp "ne" %arg1, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def lshrult_03_06_exact_after := [llvm|
{
^0(%arg111 : i4):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def scalar_i32_shl_ult_const_after := [llvm|
{
^0(%arg15 : i32):
  %0 = llvm.mlir.constant(2097088 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.and %arg15, %0 : i32
  %3 = llvm.icmp "eq" %2, %1 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def main2_logical_after := [llvm|
{
^0(%arg156 : i32):
  %0 = llvm.mlir.constant(3 : i32) : i32
  %1 = llvm.and %arg156, %0 : i32
  %2 = llvm.icmp "eq" %1, %0 : i32
  %3 = llvm.zext %2 : i1 to i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def same_source_shifted_signbit_after := [llvm|
{
^0(%arg2 : i32):
  %0 = llvm.mlir.constant(24 : i32) : i32
  %1 = llvm.ashr %arg2, %0 : i32
  "llvm.return"(%1) : (i32) -> ()
}
]

def sle_swap_or_min_logical_after := [llvm|
{
^0(%arg148 : i8, %arg149 : i8):
  %0 = llvm.icmp "sge" %arg149, %arg148 : i8
  "llvm.return"(%0) : (i1) -> ()
}
]

def sdiv_x_by_const_cmp_x_before := [llvm|
{
^0(%arg15 : i32):
  %0 = llvm.mlir.constant(13 : i32) : i32
  %1 = llvm.sdiv %arg15, %0 : i32
  %2 = llvm.icmp "eq" %1, %arg15 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def llvm_sext_lower_riscv_i16_to_32 : LLVMPeepholeRewriteRefine 32 [Ty.llvm (.bitvec 16)] :=
  {lhs:= sext_llvm_i16_to_32, rhs:= sext_riscv_i16_to_32}

def scalar_i32_shl_ult_const_before := [llvm|
{
^0(%arg15 : i32):
  %0 = llvm.mlir.constant(11 : i32) : i32
  %1 = llvm.mlir.constant(131072 : i32) : i32
  %2 = llvm.shl %arg15, %0 : i32
  %3 = llvm.icmp "ult" %2, %1 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

@[simp_denote]
def add_llvm_nsw_nuw_flags_1 := [LV| {
   ^entry (%lhs: i1, %rhs: i1):
    %1 = llvm.add %lhs, %rhs overflow<nsw,nuw> : i1
    llvm.return %1 : i1
  }]

def icmp_slt_0_and_icmp_sge_neg1_i64_fail_after := [llvm|
{
^0(%arg59 : i64):
  %0 = llvm.mlir.constant(-2) : i64
  %1 = llvm.mlir.constant(62) : i64
  %2 = llvm.mlir.constant(1) : i64
  %3 = llvm.mlir.constant(0) : i64
  %4 = llvm.icmp "sgt" %arg59, %0 : i64
  %5 = llvm.lshr %arg59, %1 : i64
  %6 = llvm.and %5, %2 : i64
  %7 = "llvm.select"(%4, %6, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i64, i64) -> i64
  "llvm.return"(%7) : (i64) -> ()
}
]

def zext_sext_add_icmp_slt_1_after := [llvm|
{
^0(%arg68 : i1, %arg69 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.xor %arg68, %0 : i1
  %2 = llvm.or %arg69, %1 : i1
  "llvm.return"(%2) : (i1) -> ()
}
]

def mul_add_to_mul_6_after := [llvm|
{
^0(%arg26 : i32, %arg27 : i32):
  %0 = llvm.mlir.constant(6 : i32) : i32
  %1 = llvm.mul %arg26, %arg27 overflow<nsw> : i32
  %2 = llvm.mul %1, %0 overflow<nsw> : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def sdiv {w : Nat} (x y : IntW w) (flag : ExactFlag := {exact := false}) : IntW w := do
  let x' ← x
  let y' ← y
  if flag.exact ∧ x'.smod y' ≠ 0 then
    .poison
  else
    sdiv? x' y'

private partial def varToIndex (e : Expr) : Option Nat :=
  match_expr e with
  | Var.mk _Ty _Γ _t i _hi      => Expr.numeral? i
  | Subtype.mk _α _p i _hi      => Expr.numeral? i
  | Var.last _Ty _Γ _t          => some 0
  | Var.toCons _Ty _Γ _t _t' v  => (· + 1) <$> varToIndex v
  | _                           => none

def Expr.KInductionCircuits.mkIsLawful_mkN (fsm : Expr) (n : Expr) : MetaM Expr :=
  mkAppM ``ReflectVerif.BvDecide.KInductionCircuits.IsLawful_mkN #[fsm, n]

def visitADD_ANegBPlusCNegA : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64), Ty.llvm (.bitvec 64), Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%a: i64, %b: i64, %c: i64):
      %0 = llvm.sub %a, %b : i64
      %1 = llvm.sub %c, %a : i64
      %2 = llvm.add %0, %1 : i64
      llvm.return %2 : i64
  }]
  rhs := [LV| {
    ^entry (%a: i64, %b: i64, %c: i64):
      %0 = llvm.sub %c, %b : i64
      llvm.return %0 : i64
  }]

def fold_sext_to_and_wrong3_after := [llvm|
{
^0(%arg7 : i8):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def test_const_shr_and_1_ne_0_after := [llvm|
{
^0(%arg8 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.mlir.constant(42 : i32) : i32
  %2 = llvm.mlir.constant(0 : i32) : i32
  %3 = llvm.shl %0, %arg8 overflow<nuw> : i32
  %4 = llvm.and %3, %1 : i32
  %5 = llvm.icmp "ne" %4, %2 : i32
  "llvm.return"(%5) : (i1) -> ()
}
]

def lshr_and_or_disjoint_after := [llvm|
{
^0(%arg43 : i8, %arg44 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.mlir.constant(2 : i8) : i8
  %2 = llvm.mlir.constant(52 : i8) : i8
  %3 = llvm.srem %arg43, %0 : i8
  %4 = llvm.shl %3, %1 : i8
  %5 = llvm.and %arg44, %2 : i8
  %6 = llvm.or disjoint %5, %4 : i8
  "llvm.return"(%6) : (i8) -> ()
}
]

def DCFork := [DC_com| {
  ^entry(%0 : !ValueStream_8):
    %unpack12 = "DC.unpack" (%0) : (!ValueStream_8) -> (!ValueTokenStream_8)
    %unpack1 = "DC.fstVal" (%unpack12) : (!ValueTokenStream_8) -> (!ValueStream_8)
    %unpack2 = "DC.sndVal" (%unpack12) : (!ValueTokenStream_8) -> (!TokenStream)
    %fork12 = "DC.fork" (%unpack2) : (!TokenStream) -> (!TokenStream2)
    %fork1 = "DC.fst" (%fork12) : (!TokenStream2) -> (!TokenStream)
    %fork2 = "DC.snd" (%fork12) : (!TokenStream2) -> (!TokenStream)
    %pack1 = "DC.pack" (%unpack1, %fork1) : (!ValueStream_8, !TokenStream) -> (!ValueStream_8)
    %pack2 = "DC.pack" (%unpack1, %fork2) : (!ValueStream_8, !TokenStream) -> (!ValueStream_8)
    %pack12 = "DC.pair" (%pack1, %pack2) : (!ValueStream_8, !ValueStream_8) -> (!ValueStream2_8)
    "return" (%pack12) : (!ValueStream2_8) -> ()
  }]

def LLVMIR_identity_combines_64 : List (Σ Γ, LLVMPeepholeRewriteRefine 64 Γ) :=
  select_same_val ++ binop_left_to_zero ++ binop_right_to_zero ++
  select_constant_cmp ++ urem_pow2_to_mask

instance : Lean.ToExpr (LLVM.Ty) :=

def test_zext1_before := [llvm|
{
^0(%arg41 : i1, %arg42 : i1):
  %0 = llvm.mlir.constant(0 : i32) : i32
  %1 = llvm.zext %arg41 : i1 to i32
  %2 = "llvm.select"(%arg42, %1, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def ule_swap_or_not_min_commute_after := [llvm|
{
^0(%arg260 : i8, %arg261 : i8):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def badimm1_after := [llvm|
{
^0(%arg28 : i16):
  %0 = llvm.mlir.constant(9 : i16) : i16
  %1 = llvm.mlir.constant(7 : i8) : i8
  %2 = llvm.mlir.constant(-1 : i16) : i16
  %3 = llvm.mlir.constant(127 : i8) : i8
  %4 = llvm.mlir.constant(-128 : i8) : i8
  %5 = llvm.lshr %arg28, %0 : i16
  %6 = llvm.trunc %5 overflow<nsw,nuw> : i16 to i8
  %7 = llvm.trunc %arg28 : i16 to i8
  %8 = llvm.ashr %7, %1 : i8
  %9 = llvm.icmp "eq" %8, %6 : i8
  %10 = llvm.icmp "sgt" %arg28, %2 : i16
  %11 = "llvm.select"(%10, %3, %4) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  %12 = "llvm.select"(%9, %7, %11) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  "llvm.return"(%12) : (i8) -> ()
}
]

def test_with_3_before := [llvm|
{
^0(%arg316 : i32):
  %0 = llvm.mlir.constant(3 : i32) : i32
  %1 = llvm.mlir.constant(1 : i32) : i32
  %2 = llvm.shl %0, %arg316 : i32
  %3 = llvm.and %2, %1 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def n14_trunc_of_lshr_before := [llvm|
{
^0(%arg4 : i64, %arg5 : i32, %arg6 : i32):
  %0 = llvm.mlir.constant(32 : i32) : i32
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.mlir.constant(0 : i32) : i32
  %3 = llvm.sub %0, %arg6 : i32
  %4 = llvm.zext %3 : i32 to i64
  %5 = llvm.lshr %arg4, %4 : i64
  %6 = llvm.trunc %5 : i64 to i32
  %7 = llvm.add %arg6, %1 : i32
  %8 = llvm.shl %arg5, %7 : i32
  %9 = llvm.and %6, %8 : i32
  %10 = llvm.icmp "ne" %9, %2 : i32
  "llvm.return"(%10) : (i1) -> ()
}
]

def test8_before := [llvm|
{
^0(%arg1 : i128):
  %0 = llvm.mlir.constant(1 : i128) : i128
  %1 = llvm.mlir.constant(127 : i128) : i128
  %2 = llvm.mlir.constant(120 : i128) : i128
  %3 = llvm.shl %0, %1 : i128
  %4 = llvm.ashr %3, %2 : i128
  %5 = llvm.xor %arg1, %4 : i128
  %6 = llvm.add %5, %3 : i128
  "llvm.return"(%6) : (i128) -> ()
}
]

def eq_3210_before := [llvm|
{
^0(%arg126 : i32, %arg127 : i32):
  %0 = llvm.mlir.constant(8 : i32) : i32
  %1 = llvm.mlir.constant(16 : i32) : i32
  %2 = llvm.mlir.constant(24 : i32) : i32
  %3 = llvm.trunc %arg126 : i32 to i8
  %4 = llvm.lshr %arg126, %0 : i32
  %5 = llvm.trunc %4 : i32 to i8
  %6 = llvm.lshr %arg126, %1 : i32
  %7 = llvm.trunc %6 : i32 to i8
  %8 = llvm.lshr %arg126, %2 : i32
  %9 = llvm.trunc %8 : i32 to i8
  %10 = llvm.trunc %arg127 : i32 to i8
  %11 = llvm.lshr %arg127, %0 : i32
  %12 = llvm.trunc %11 : i32 to i8
  %13 = llvm.lshr %arg127, %1 : i32
  %14 = llvm.trunc %13 : i32 to i8
  %15 = llvm.lshr %arg127, %2 : i32
  %16 = llvm.trunc %15 : i32 to i8
  %17 = llvm.icmp "eq" %3, %10 : i8
  %18 = llvm.icmp "eq" %5, %12 : i8
  %19 = llvm.icmp "eq" %7, %14 : i8
  %20 = llvm.icmp "eq" %9, %16 : i8
  %21 = llvm.and %17, %18 : i1
  %22 = llvm.and %19, %21 : i1
  %23 = llvm.and %20, %22 : i1
  "llvm.return"(%23) : (i1) -> ()
}
]

def slt_zero_eq_i1_before := [llvm|
{
^0(%arg9 : i32, %arg10 : i1):
  %0 = llvm.mlir.constant(31 : i32) : i32
  %1 = llvm.zext %arg10 : i1 to i32
  %2 = llvm.lshr %arg9, %0 : i32
  %3 = llvm.icmp "eq" %1, %2 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

String in Init.Prelude

def mismatched_shifts_before := [llvm|
{
^0(%arg6 : i8):
  %0 = llvm.mlir.constant(16 : i8) : i8
  %1 = llvm.mlir.constant(1 : i8) : i8
  %2 = llvm.mlir.constant(3 : i8) : i8
  %3 = llvm.shl %0, %arg6 : i8
  %4 = llvm.add %arg6, %1 : i8
  %5 = llvm.lshr %2, %4 : i8
  %6 = llvm.or %3, %5 : i8
  "llvm.return"(%6) : (i8) -> ()
}
]

def test_shl_nuw__nuw_is_safe_after := [llvm|
{
^0(%arg80 : i32, %arg81 : i64):
  %0 = llvm.mlir.constant(2 : i32) : i32
  %1 = llvm.mlir.constant(-8 : i32) : i32
  %2 = llvm.shl %arg80, %0 : i32
  %3 = llvm.and %2, %1 : i32
  %4 = llvm.zext nneg %3 : i32 to i64
  %5 = llvm.ashr %arg81, %4 : i64
  "llvm.return"(%5) : (i64) -> ()
}
]

@[simp_denote]
def sltu_llvm_i64 := [LV| {
    ^entry (%a: i64, %b: i64):
    %0 = llvm.icmp.ult %a, %b : i64
    %1 = llvm.zext %0 : i1 to i64
    llvm.return %1 : i64
  }]

def main5c_like_before := [llvm|
{
^0(%arg103 : i32, %arg104 : i32):
  %0 = llvm.mlir.constant(7 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(1 : i32) : i32
  %3 = llvm.and %arg103, %0 : i32
  %4 = llvm.icmp "ne" %3, %0 : i32
  %5 = llvm.and %arg104, %0 : i32
  %6 = llvm.icmp "ne" %5, %0 : i32
  %7 = llvm.or %4, %6 : i1
  %8 = "llvm.select"(%7, %1, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%8) : (i32) -> ()
}
]

def test_add_zero_rhs_LHS := [mod_arith q, hq| {
  ^bb0(%x : !R):
    %zero = mod_arith.constant 0 : !R
    %add = mod_arith.add %x, %zero : !R
    return %add : !R
}]

def eq_umin3_before := [llvm|
{
^0(%arg56 : i32, %arg57 : i32):
  %0 = llvm.mlir.constant(3 : i32) : i32
  %1 = llvm.add %arg56, %0 : i32
  %2 = llvm.icmp "ult" %1, %arg57 : i32
  %3 = "llvm.select"(%2, %1, %arg57) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %4 = llvm.icmp "eq" %1, %3 : i32
  "llvm.return"(%4) : (i1) -> ()
}
]

def test4_after := [llvm|
{
^0(%arg97 : i32, %arg98 : i1):
  %0 = llvm.mlir.constant(0 : i32) : i32
  %1 = llvm.mlir.constant(7 : i32) : i32
  %2 = "llvm.select"(%arg98, %0, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %3 = llvm.and %arg97, %2 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

instance {cmp} : DecidableEq (NFA'.autSignedCmp cmp).σ :=

def negative_with_uniform_bad_mask_logical_after := [llvm|
{
^0(%arg12 : i32):
  %0 = llvm.mlir.constant(-16777152 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(128 : i32) : i32
  %3 = llvm.mlir.constant(256 : i32) : i32
  %4 = llvm.and %arg12, %0 : i32
  %5 = llvm.icmp "eq" %4, %1 : i32
  %6 = llvm.add %arg12, %2 : i32
  %7 = llvm.icmp "ult" %6, %3 : i32
  %8 = llvm.and %5, %7 : i1
  "llvm.return"(%8) : (i1) -> ()
}
]

def sub_ashr_or_i32_nuw_nsw_before := [llvm|
{
^0(%arg30 : i32, %arg31 : i32):
  %0 = llvm.mlir.constant(31 : i32) : i32
  %1 = llvm.sub %arg31, %arg30 overflow<nsw,nuw> : i32
  %2 = llvm.ashr %1, %0 : i32
  %3 = llvm.or %2, %arg30 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def Region.appendOp (bb: Region φ) (op: Op φ): Region φ :=
  match bb with
  | Region.mk name args bbs => Region.mk name args (bbs ++ [op])

def or_eq_notY_eq_0_before := [llvm|
{
^0(%arg45 : i8, %arg46 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.xor %arg46, %0 : i8
  %2 = llvm.or %arg45, %1 : i8
  %3 = llvm.icmp "eq" %2, %1 : i8
  "llvm.return"(%3) : (i1) -> ()
}
]

def lshrult_01_03_before := [llvm|
{
^0(%arg364 : i4):
  %0 = llvm.mlir.constant(1 : i4) : i4
  %1 = llvm.mlir.constant(3 : i4) : i4
  %2 = llvm.lshr %arg364, %0 : i4
  %3 = llvm.icmp "ult" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def test5_after := [llvm|
{
^0(%arg95 : i32, %arg96 : i8):
  %0 = llvm.mlir.constant(32 : i32) : i32
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.zext nneg %arg96 : i8 to i32
  %3 = llvm.shl %0, %2 overflow<nuw> : i32
  %4 = llvm.add %3, %1 : i32
  %5 = llvm.and %arg95, %4 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def Body.substitute (σ : Substitution) : Body Op T → Body Op T
  | ⟨lets, terminator⟩ => ⟨lets.substitute σ, substituteTerminator σ.apply terminator⟩

MonadLiftT in Init.Prelude

def select_icmp_eq_0_and_1_xor_1_before := [llvm|
{
^0(%arg213 : i64, %arg214 : i32):
  %0 = llvm.mlir.constant(1) : i64
  %1 = llvm.mlir.constant(0) : i64
  %2 = llvm.mlir.constant(1 : i32) : i32
  %3 = llvm.and %arg213, %0 : i64
  %4 = llvm.icmp "eq" %3, %1 : i64
  %5 = llvm.xor %arg214, %2 : i32
  %6 = "llvm.select"(%4, %arg214, %5) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%6) : (i32) -> ()
}
]

def test_sub_nuw__nsw_is_safe_before := [llvm|
{
^0(%arg22 : i32):
  %0 = llvm.mlir.constant(-2147483648 : i32) : i32
  %1 = llvm.mlir.constant(-2147483647 : i32) : i32
  %2 = llvm.mlir.constant(-1 : i32) : i32
  %3 = llvm.or %arg22, %0 : i32
  %4 = llvm.icmp "eq" %3, %1 : i32
  %5 = llvm.sub %0, %3 overflow<nuw> : i32
  %6 = "llvm.select"(%4, %2, %5) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%6) : (i32) -> ()
}
]

def pr40493_neg3_after := [llvm|
{
^0(%arg15 : i32):
  %0 = llvm.mlir.constant(2 : i32) : i32
  %1 = llvm.mlir.constant(4 : i32) : i32
  %2 = llvm.shl %arg15, %0 : i32
  %3 = llvm.and %2, %1 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def and_or1_wrong_operand_after := [llvm|
{
^0(%arg176 : i1, %arg177 : i1, %arg178 : i1, %arg179 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.xor %arg176, %0 : i1
  %2 = llvm.or %arg178, %1 : i1
  %3 = "llvm.select"(%2, %arg179, %arg177) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def icmp_slt_sext_ne_allones_nofold_before := [llvm|
{
^0(%arg3 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.icmp "ne" %arg3, %0 : i32
  %2 = llvm.sext %1 : i1 to i32
  %3 = llvm.icmp "slt" %2, %arg3 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

inductive Signedness where
  | Signless 
  | Unsigned 
  | Signed   
deriving DecidableEq, Repr

def uaddo_commute4_before := [llvm|
{
^0(%arg22 : i32, %arg23 : i32, %arg24 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg23, %0 : i32
  %2 = llvm.add %arg23, %arg22 : i32
  %3 = llvm.icmp "ult" %1, %arg22 : i32
  %4 = "llvm.select"(%3, %arg24, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def or_xor_commute2_after := [llvm|
{
^0(%arg164 : i32, %arg165 : i32):
  %0 = llvm.mlir.constant(42 : i32) : i32
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.udiv %0, %arg164 : i32
  %3 = llvm.udiv %0, %arg165 : i32
  %4 = llvm.xor %3, %1 : i32
  %5 = llvm.and %2, %4 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def and_or2_commuted_after := [llvm|
{
^0(%arg194 : i1, %arg195 : i1, %arg196 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.mlir.constant(false) : i1
  %2 = "llvm.select"(%arg196, %0, %arg194) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %3 = "llvm.select"(%arg195, %2, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def main6_logical_after := [llvm|
{
^0(%arg93 : i32):
  %0 = llvm.mlir.constant(55 : i32) : i32
  %1 = llvm.mlir.constant(19 : i32) : i32
  %2 = llvm.and %arg93, %0 : i32
  %3 = llvm.icmp "ne" %2, %1 : i32
  %4 = llvm.zext %3 : i1 to i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def timeElapsedMs (x : Unit → α) : IO (α × Int) := do
    let tStart ← IO.monoMsNow
    let b := x ()
    let tEnd ← IO.monoMsNow
    return (b, tEnd - tStart)

def trunc_sel_larger_zext_after := [llvm|
{
^0(%arg73 : i32, %arg74 : i1):
  %0 = llvm.mlir.constant(65535 : i32) : i32
  %1 = llvm.mlir.constant(42) : i64
  %2 = llvm.and %arg73, %0 : i32
  %3 = llvm.zext nneg %2 : i32 to i64
  %4 = "llvm.select"(%arg74, %3, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i64, i64) -> i64
  "llvm.return"(%4) : (i64) -> ()
}
]

def lshrugt_03_10_after := [llvm|
{
^0(%arg373 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def elabDefSignatureFor (dialect : Term) (alts : TSyntax ``matchAltsSig) : CommandElabM Unit := do
  let msg := (return m!"{exceptEmoji ·} Defining operation signature for {dialect} dialect")
  withTraceNode `LeanMLIR.Elab msg (collapsed := false) <| do
    let alts := getMatchAlts alts
    let alts ← do
      alts.mapM fun view => do
        trace[LeanMLIR.Elab] m!"Parsing match alternative with\n\
          \tpatterns: {view.patterns}\n\
          \tsignature: {view.rhs}"
        let rhs ← parseSignature view.rhs
        return { view with rhs }

    |

def pv_after := [llvm|
{
^0(%arg14 : i8, %arg15 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.lshr %0, %arg15 : i8
  %2 = llvm.icmp "ule" %arg14, %1 : i8
  "llvm.return"(%2) : (i1) -> ()
}
]

def ashrslt_02_08_exact_after := [llvm|
{
^0(%arg29 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

reduceDIte in Lean.Meta.Tactic.Simp.BuiltinSimprocs.Core

def hoist_ashr_ahead_of_sext_2_before := [llvm|
{
^0(%arg1 : i8):
  %0 = llvm.mlir.constant(8 : i32) : i32
  %1 = llvm.sext %arg1 : i8 to i32
  %2 = llvm.ashr %1, %0 : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def udiv_eq_umax_before := [llvm|
{
^0(%arg42 : i8, %arg43 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.udiv %arg42, %arg43 : i8
  %2 = llvm.icmp "eq" %1, %0 : i8
  "llvm.return"(%2) : (i1) -> ()
}
]

def binop_same_val : List (Σ Γ, RISCVPeepholeRewrite  Γ) :=
    [⟨_, binop_same_val_and⟩,
    ⟨_, binop_same_val_or⟩]

def irc_constants_C2MinusAPlusC1_neg2_1 : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (-2) : i64
      %c2 = llvm.mlir.constant (1) : i64
      %0 = llvm.add %a, %c1 : i64
      %1 = llvm.sub %c2, %0 : i64
      llvm.return %1 : i64
  }]
  rhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (-2) : i64
      %c2 = llvm.mlir.constant (1) : i64
      %0 = llvm.sub %c2, %c1 : i64
      %1 = llvm.sub %0, %a : i64
      llvm.return %1 : i64
  }]

def xor_or_xor_common_op_commute6_before := [llvm|
{
^0(%arg65 : i32, %arg66 : i32, %arg67 : i32):
  %0 = llvm.xor %arg67, %arg65 : i32
  %1 = llvm.or %arg65, %arg66 : i32
  %2 = llvm.xor %1, %0 : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def zero_sign_bit_before := [llvm|
{
^0(%arg31 : i16):
  %0 = llvm.mlir.constant(32767 : i16) : i16
  %1 = llvm.mlir.constant(512 : i16) : i16
  %2 = llvm.and %arg31, %0 : i16
  %3 = llvm.add %2, %1 : i16
  "llvm.return"(%3) : (i16) -> ()
}
]

Std.Tactic.BVDecide.BVBinOp.udiv in Std.Tactic.BVDecide.Bitblast.BVExpr.Basic

noncomputable def nonesUntilSome (x : Stream α) (not_stuck : x ≠ stuck α) : Nat :=
  prop.choose
where
  prop : ∃ i, (x.drop i).head.isSome ∧ ∀ j < i, x.get j = none := by admit /- proof elided -/

def test_shift_and_cmp_changed4_after := [llvm|
{
^0(%arg0 : i8):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def lshr_and_after := [llvm|
{
^0(%arg73 : i8, %arg74 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.mlir.constant(6 : i8) : i8
  %2 = llvm.srem %arg73, %0 : i8
  %3 = llvm.shl %2, %1 : i8
  %4 = llvm.and %arg74, %3 : i8
  "llvm.return"(%4) : (i8) -> ()
}
]

def add_const_const_sub_after := [llvm|
{
^0(%arg61 : i32):
  %0 = llvm.mlir.constant(-6 : i32) : i32
  %1 = llvm.sub %0, %arg61 : i32
  "llvm.return"(%1) : (i32) -> ()
}
]

def select_icmp_ne_0_and_4096_and_not_4096_after := [llvm|
{
^0(%arg227 : i32, %arg228 : i32):
  %0 = llvm.mlir.constant(4096 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(-4097 : i32) : i32
  %3 = llvm.and %arg227, %0 : i32
  %4 = llvm.icmp "eq" %3, %1 : i32
  %5 = llvm.and %arg228, %2 : i32
  %6 = "llvm.select"(%4, %5, %arg228) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%6) : (i32) -> ()
}
]

def add_nuw_nsw_or_and_after := [llvm|
{
^0(%arg7 : i32, %arg8 : i32):
  %0 = llvm.add %arg7, %arg8 overflow<nsw,nuw> : i32
  "llvm.return"(%0) : (i32) -> ()
}
]

def or_nand_xor_common_op_commute0_before := [llvm|
{
^0(%arg77 : i4, %arg78 : i4, %arg79 : i4):
  %0 = llvm.mlir.constant(-1 : i4) : i4
  %1 = llvm.and %arg77, %arg79 : i4
  %2 = llvm.xor %1, %0 : i4
  %3 = llvm.xor %arg77, %arg78 : i4
  %4 = llvm.or %2, %3 : i4
  "llvm.return"(%4) : (i4) -> ()
}
]

def test27_after := [llvm|
{
^0(%arg178 : i32, %arg179 : i32, %arg180 : i32):
  %0 = llvm.icmp "eq" %arg178, %arg179 : i32
  %1 = llvm.zext %0 : i1 to i32
  "llvm.return"(%1) : (i32) -> ()
}
]

def test36_before := [llvm|
{
^0(%arg158 : i32):
  %0 = llvm.mlir.constant(31 : i32) : i32
  %1 = llvm.mlir.constant(0 : i8) : i8
  %2 = llvm.lshr %arg158, %0 : i32
  %3 = llvm.trunc %2 : i32 to i8
  %4 = llvm.icmp "eq" %3, %1 : i8
  "llvm.return"(%4) : (i1) -> ()
}
]

def test11_after := [llvm|
{
^0(%arg43 : i1):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def add_select_sext_before := [llvm|
{
^0(%arg28 : i1):
  %0 = llvm.mlir.constant(64) : i64
  %1 = llvm.mlir.constant(1) : i64
  %2 = "llvm.select"(%arg28, %0, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i64, i64) -> i64
  %3 = llvm.sext %arg28 : i1 to i64
  %4 = llvm.add %2, %3 : i64
  "llvm.return"(%4) : (i64) -> ()
}
]

def tryFactorization_add_mul_nuw_mul_var_after := [llvm|
{
^0(%arg0 : i32, %arg1 : i32, %arg2 : i32):
  %0 = llvm.add %arg1, %arg2 : i32
  %1 = llvm.mul %arg0, %0 : i32
  "llvm.return"(%1) : (i32) -> ()
}
]

def a_or_b_const_before := [llvm|
{
^0(%arg10 : i32, %arg11 : i32, %arg12 : i32):
  %0 = llvm.icmp "eq" %arg10, %arg12 : i32
  %1 = llvm.icmp "ne" %arg11, %arg12 : i32
  %2 = llvm.and %0, %1 : i1
  %3 = llvm.icmp "ne" %arg10, %arg12 : i32
  %4 = llvm.icmp "eq" %arg11, %arg12 : i32
  %5 = llvm.and %3, %4 : i1
  %6 = llvm.or %2, %5 : i1
  "llvm.return"(%6) : (i1) -> ()
}
]

def icmp_slt_0_and_icmp_ne_neg2_i32_fail_before := [llvm|
{
^0(%arg44 : i32):
  %0 = llvm.mlir.constant(-2 : i32) : i32
  %1 = llvm.mlir.constant(31 : i32) : i32
  %2 = llvm.icmp "ne" %arg44, %0 : i32
  %3 = llvm.zext %2 : i1 to i32
  %4 = llvm.lshr %arg44, %1 : i32
  %5 = llvm.and %4, %3 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def test_nuw_dropped_after := [llvm|
{
^0(%arg7 : i32):
  %0 = llvm.mlir.constant(2 : i32) : i32
  %1 = llvm.shl %arg7, %0 : i32
  "llvm.return"(%1) : (i32) -> ()
}
]

def in_constant_varx_mone_invmask_before := [llvm|
{
^0(%arg41 : i4, %arg42 : i4):
  %0 = llvm.mlir.constant(-1 : i4) : i4
  %1 = llvm.xor %arg42, %0 : i4
  %2 = llvm.xor %arg41, %0 : i4
  %3 = llvm.and %2, %1 : i4
  %4 = llvm.xor %3, %0 : i4
  "llvm.return"(%4) : (i4) -> ()
}
]

def ashrslt_01_12_after := [llvm|
{
^0(%arg257 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def test45_before := [llvm|
{
^0(%arg201 : i32, %arg202 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg202, %0 : i32
  %2 = llvm.or %arg201, %1 : i32
  %3 = llvm.and %2, %arg202 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def ashrsgt_02_07_exact_after := [llvm|
{
^0(%arg78 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def icmp_slt_0_or_icmp_add_1_sge_100_i32_fail_after := [llvm|
{
^0(%arg38 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.mlir.constant(99 : i32) : i32
  %2 = llvm.mlir.constant(0 : i32) : i32
  %3 = llvm.add %arg38, %0 : i32
  %4 = llvm.icmp "sgt" %3, %1 : i32
  %5 = llvm.icmp "slt" %arg38, %2 : i32
  %6 = llvm.or %5, %4 : i1
  %7 = llvm.zext %6 : i1 to i32
  "llvm.return"(%7) : (i32) -> ()
}
]

def ult_rem_zero_before := [llvm|
{
^0(%arg174 : i8):
  %0 = llvm.mlir.constant(7 : i8) : i8
  %1 = llvm.mlir.constant(21 : i8) : i8
  %2 = llvm.mul %arg174, %0 overflow<nuw> : i8
  %3 = llvm.icmp "ult" %2, %1 : i8
  "llvm.return"(%3) : (i1) -> ()
}
]

def src_is_mask_xor_fail_notmask_after := [llvm|
{
^0(%arg113 : i8, %arg114 : i8):
  %0 = llvm.mlir.constant(0 : i8) : i8
  %1 = llvm.mlir.constant(-124 : i8) : i8
  %2 = llvm.mlir.constant(-1 : i8) : i8
  %3 = llvm.sub %0, %arg114 : i8
  %4 = llvm.xor %arg114, %3 : i8
  %5 = llvm.xor %arg113, %1 : i8
  %6 = llvm.or %4, %5 : i8
  %7 = llvm.icmp "ne" %6, %2 : i8
  "llvm.return"(%7) : (i1) -> ()
}
]

def PR2330_after := [llvm|
{
^0(%arg0 : i32):
  %0 = llvm.mlir.constant(0 : i32) : i32
  %1 = llvm.icmp "ne" %arg0, %0 : i32
  "llvm.return"(%1) : (i1) -> ()
}
]

def or_shl_after := [llvm|
{
^0(%arg640 : i8, %arg641 : i8, %arg642 : i8, %arg643 : i8):
  %0 = llvm.or %arg640, %arg641 : i8
  %1 = llvm.shl %0, %arg643 : i8
  %2 = llvm.or %1, %arg642 : i8
  "llvm.return"(%2) : (i8) -> ()
}
]

LE.le in Init.Prelude

def and_signbit_select_ashr_after := [llvm|
{
^0(%arg14 : i32, %arg15 : i1):
  %0 = llvm.mlir.constant(8 : i32) : i32
  %1 = llvm.mlir.constant(-256 : i32) : i32
  %2 = llvm.ashr %arg14, %0 : i32
  %3 = llvm.and %2, %1 : i32
  %4 = "llvm.select"(%arg15, %3, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def map (f : Ty₁ → Ty₂) : Ctxt Ty₁ → Ctxt Ty₂ :=
  ofList ∘ (List.map f) ∘ toList

def trunc_shl_7_i8_i64_before := [llvm|
{
^0(%arg52 : i64):
  %0 = llvm.mlir.constant(7) : i64
  %1 = llvm.shl %arg52, %0 : i64
  %2 = llvm.trunc %1 : i64 to i8
  "llvm.return"(%2) : (i8) -> ()
}
]

structure ParsedFpExpr where
  width : Nat
  bvExpr: FpExpr width
  symVars: Std.HashMap Nat BVExpr.PackedBitVec
  inputVars : Std.HashMap Nat HydraVariable

abbrev HSxComb : Dialect where
  Op := Op
  Ty :=  MLIR2Handshake.Handshake.Ty

def or_signbit_ashr_before := [llvm|
{
^0(%arg5 : i32):
  %0 = llvm.mlir.constant(-65536 : i32) : i32
  %1 = llvm.mlir.constant(8 : i32) : i32
  %2 = llvm.or %arg5, %0 : i32
  %3 = llvm.ashr %2, %1 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def sgt_swap_and_min_commute_logical_after := [llvm|
{
^0(%arg338 : i8, %arg339 : i8):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def add_nsw_poison_constant_fold_after := [llvm|
{
^0(%arg2 : i1, %arg3 : i8):
  %0 = llvm.mlir.constant(64 : i8) : i8
  %1 = llvm.mlir.constant(-127 : i8) : i8
  %2 = llvm.add %arg3, %0 overflow<nsw> : i8
  %3 = "llvm.select"(%arg2, %2, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  "llvm.return"(%3) : (i8) -> ()
}
]

instance {test : ConcreteCliTest} : ToString (toType test.ty) where
  toString :=
    match test.ty with
    | bitvec w => inferInstanceAs (ToString (PoisonOr <| BitVec w)) |>.toString

def positive_biggerlshr_shlnsw_after := [llvm|
{
^0(%arg50 : i8):
  %0 = llvm.mlir.constant(3 : i8) : i8
  %1 = llvm.mlir.constant(24 : i8) : i8
  %2 = llvm.lshr %arg50, %0 : i8
  %3 = llvm.and %2, %1 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def ashrsgt_03_13_after := [llvm|
{
^0(%arg272 : i4):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def mkOutputAssignCircuitLeN {arity : Type _}
  [DecidableEq arity]
  [Fintype arity]
  [Hashable arity]
  (p : FSM arity) (n : Nat) :
  Circuit (Vars p.α arity (n + 1)) :=
    let ixs := List.range (n + 1) |>.attach
    let circs := ixs.map fun ⟨i, hi⟩ =>
      mkOutputAssignCircuitN p i |>.map (fun v => v.castLe (by admit /- proof elided -/
      ))
    Circuit.bigOr circs

def sub_from_variable_of_sub_from_constant_after := [llvm|
{
^0(%arg183 : i8, %arg184 : i8):
  %0 = llvm.mlir.constant(-42 : i8) : i8
  %1 = llvm.add %arg183, %0 : i8
  %2 = llvm.add %1, %arg184 : i8
  "llvm.return"(%2) : (i8) -> ()
}
]

def select_or_icmp_after := [llvm|
{
^0(%arg278 : i32, %arg279 : i32, %arg280 : i32):
  %0 = llvm.mlir.constant(0 : i32) : i32
  %1 = llvm.icmp "eq" %arg278, %0 : i32
  %2 = "llvm.select"(%1, %arg280, %arg279) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def t0_after := [llvm|
{
^0(%arg32 : i8):
  %0 = llvm.mlir.constant(15 : i8) : i8
  %1 = llvm.mlir.constant(-16 : i8) : i8
  %2 = llvm.add %arg32, %0 : i8
  %3 = llvm.and %2, %1 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def zext_nneg_flag_drop_before := [llvm|
{
^0(%arg7 : i8, %arg8 : i16):
  %0 = llvm.mlir.constant(127 : i8) : i8
  %1 = llvm.mlir.constant(128 : i16) : i16
  %2 = llvm.and %arg7, %0 : i8
  %3 = llvm.zext nneg %2 : i8 to i16
  %4 = llvm.or %3, %arg8 : i16
  %5 = llvm.or %4, %1 : i16
  "llvm.return"(%5) : (i16) -> ()
}
]

def eq_smax3_after := [llvm|
{
^0(%arg59 : i32, %arg60 : i32):
  %0 = llvm.mlir.constant(3 : i32) : i32
  %1 = llvm.add %arg59, %0 : i32
  %2 = llvm.icmp "sge" %1, %arg60 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def lshrugt_01_06_exact_before := [llvm|
{
^0(%arg215 : i4):
  %0 = llvm.mlir.constant(1 : i4) : i4
  %1 = llvm.mlir.constant(6 : i4) : i4
  %2 = llvm.lshr exact %arg215, %0 : i4
  %3 = llvm.icmp "ugt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

RV64.xori in RISCV.Instructions

def bools_logical_commute1_after := [llvm|
{
^0(%arg96 : i1, %arg97 : i1, %arg98 : i1):
  %0 = "llvm.select"(%arg98, %arg97, %arg96) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%0) : (i1) -> ()
}
]

Lean.withRef in Init.Prelude

inductive ExOp :  Type
  | add : ExOp
  | beq : ExOp
  | cst : ℕ → ExOp
  deriving DecidableEq

def and_two_ranges_to_mask_and_range_no_add_on_one_range_before := [llvm|
{
^0(%arg249 : i16):
  %0 = llvm.mlir.constant(12 : i16) : i16
  %1 = llvm.mlir.constant(16 : i16) : i16
  %2 = llvm.mlir.constant(28 : i16) : i16
  %3 = llvm.icmp "uge" %arg249, %0 : i16
  %4 = llvm.icmp "ult" %arg249, %1 : i16
  %5 = llvm.icmp "uge" %arg249, %2 : i16
  %6 = llvm.or %4, %5 : i1
  %7 = llvm.and %3, %6 : i1
  "llvm.return"(%7) : (i1) -> ()
}
]

def and_slt_to_mask_before := [llvm|
{
^0(%arg5 : i8):
  %0 = llvm.mlir.constant(-124 : i8) : i8
  %1 = llvm.mlir.constant(2 : i8) : i8
  %2 = llvm.mlir.constant(0 : i8) : i8
  %3 = llvm.icmp "slt" %arg5, %0 : i8
  %4 = llvm.and %arg5, %1 : i8
  %5 = llvm.icmp "eq" %4, %2 : i8
  %6 = llvm.and %3, %5 : i1
  "llvm.return"(%6) : (i1) -> ()
}
]

def sle_and_min_commute_logical_before := [llvm|
{
^0(%arg216 : i8, %arg217 : i8):
  %0 = llvm.mlir.constant(-128 : i8) : i8
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.icmp "sle" %arg216, %arg217 : i8
  %3 = llvm.icmp "eq" %arg216, %0 : i8
  %4 = "llvm.select"(%3, %2, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def shl_sub_lshr_after := [llvm|
{
^0(%arg139 : i32, %arg140 : i32, %arg141 : i32):
  %0 = llvm.lshr exact %arg141, %arg140 : i32
  %1 = llvm.sub %arg139, %0 overflow<nsw,nuw> : i32
  "llvm.return"(%1) : (i32) -> ()
}
]

def sub_select_sext_after := [llvm|
{
^0(%arg24 : i1, %arg25 : i64):
  %0 = llvm.mlir.constant(65) : i64
  %1 = "llvm.select"(%arg24, %0, %arg25) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i64, i64) -> i64
  "llvm.return"(%1) : (i64) -> ()
}
]

def slt_zero_eq_i1_fail_signed_after := [llvm|
{
^0(%arg0 : i32, %arg1 : i1):
  %0 = llvm.mlir.constant(31 : i32) : i32
  %1 = llvm.sext %arg1 : i1 to i32
  %2 = llvm.lshr %arg0, %0 : i32
  %3 = llvm.icmp "eq" %2, %1 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def t0_before := [llvm|
{
^0(%arg30 : i1, %arg31 : i8, %arg32 : i8, %arg33 : i8, %arg34 : i8):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.icmp "eq" %arg31, %arg32 : i8
  %2 = llvm.xor %arg30, %0 : i1
  %3 = llvm.and %2, %1 : i1
  %4 = "llvm.select"(%3, %arg33, %arg34) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  "llvm.return"(%4) : (i8) -> ()
}
]

def irc_constants_AMinusC1PlusC2_2_neg1 : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (2) : i64
      %c2 = llvm.mlir.constant (-1) : i64
      %0 = llvm.sub %a, %c1 : i64
      %1 = llvm.add %0, %c2 : i64
      llvm.return %1 : i64
  }]
  rhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (2) : i64
      %c2 = llvm.mlir.constant (-1) : i64
      %0 = llvm.sub %c2, %c1 : i64
      %1 = llvm.add %a, %0 : i64
      llvm.return %1 : i64
  }]

@[combinator_parenthesizer MLIR.EDSL.balancedBrackets]
def MLIR.EDSL.balancedBracketsParenthesizer : Parenthesizer := pure ()

def test19_after := [llvm|
{
^0(%arg7 : i10):
  %0 = llvm.mlir.constant(1 : i3) : i3
  %1 = llvm.mlir.constant(0 : i3) : i3
  %2 = llvm.trunc %arg7 : i10 to i3
  %3 = llvm.and %2, %0 : i3
  %4 = llvm.sub %1, %3 overflow<nsw> : i3
  %5 = llvm.sext %4 : i3 to i10
  "llvm.return"(%5) : (i10) -> ()
}
]

def test1_after := [llvm|
{
^0(%arg14 : i32, %arg15 : i32):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def test28_sub_after := [llvm|
{
^0(%arg175 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.sub %0, %arg175 : i32
  "llvm.return"(%1) : (i32) -> ()
}
]

def ashrsgt_01_03_exact_before := [llvm|
{
^0(%arg98 : i4):
  %0 = llvm.mlir.constant(1 : i4) : i4
  %1 = llvm.mlir.constant(3 : i4) : i4
  %2 = llvm.ashr exact %arg98, %0 : i4
  %3 = llvm.icmp "sgt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def p1_scalar_urem_by_nonconst_before := [llvm|
{
^0(%arg18 : i32, %arg19 : i32):
  %0 = llvm.mlir.constant(128 : i32) : i32
  %1 = llvm.mlir.constant(6 : i32) : i32
  %2 = llvm.mlir.constant(0 : i32) : i32
  %3 = llvm.and %arg18, %0 : i32
  %4 = llvm.or %arg19, %1 : i32
  %5 = llvm.urem %3, %4 : i32
  %6 = llvm.icmp "eq" %5, %2 : i32
  "llvm.return"(%6) : (i1) -> ()
}
]

unsafe def elabIntoTermElab {α : Type} (expectedType : Expr) (stx : Lean.Syntax) :
    Elab.Term.TermElabM α := do
  elabIntoTermTactic (α := α) expectedType stx  |>.runCore' { elaborator := `ParserHack} default

def zext_nneg_after := [llvm|
{
^0(%arg0 : i16):
  %0 = llvm.mlir.constant(32767 : i16) : i16
  %1 = llvm.and %arg0, %0 : i16
  %2 = llvm.zext nneg %1 : i16 to i24
  "llvm.return"(%2) : (i24) -> ()
}
]

def lshrult_01_03_after := [llvm|
{
^0(%arg364 : i4):
  %0 = llvm.mlir.constant(6 : i4) : i4
  %1 = llvm.icmp "ult" %arg364, %0 : i4
  "llvm.return"(%1) : (i1) -> ()
}
]

instance : HasUB Option where
  throwUB := none

def exact_lshr_ne_both_equal_after := [llvm|
{
^0(%arg165 : i8):
  %0 = llvm.mlir.constant(0 : i8) : i8
  %1 = llvm.icmp "ne" %arg165, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

private def tyIndex : MLIRTy := [mlir_type| index]

def select_icmp_ne_0_and_4096_or_32_after := [llvm|
{
^0(%arg209 : i32, %arg210 : i32):
  %0 = llvm.mlir.constant(7 : i32) : i32
  %1 = llvm.mlir.constant(32 : i32) : i32
  %2 = llvm.lshr %arg209, %0 : i32
  %3 = llvm.and %2, %1 : i32
  %4 = llvm.xor %3, %1 : i32
  %5 = llvm.or %arg210, %4 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def constLLVM_42 : Com LLVMPlusRiscV ⟨[]⟩ .pure (.llvm (.bitvec 64)) := [LV| {
  ^entry ():
    %1 = llvm.mlir.constant (-42) : i64
    llvm.return %1 : i64
  }]

def shl_nuw_add_nsw_nuw_after := [llvm|
{
^0(%arg15 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  "llvm.return"(%0) : (i32) -> ()
}
]

def mul_of_pow2_commute_before := [llvm|
{
^0(%arg81 : i32, %arg82 : i32):
  %0 = llvm.mlir.constant(4 : i32) : i32
  %1 = llvm.mlir.constant(255 : i32) : i32
  %2 = llvm.mlir.constant(1020 : i32) : i32
  %3 = llvm.and %arg81, %0 : i32
  %4 = llvm.and %arg82, %1 : i32
  %5 = llvm.mul %4, %3 : i32
  %6 = llvm.icmp "ugt" %5, %2 : i32
  "llvm.return"(%6) : (i1) -> ()
}
]

def xor_and_logic_or1_after := [llvm|
{
^0(%arg30 : i1, %arg31 : i1, %arg32 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.xor %arg31, %0 : i1
  %2 = "llvm.select"(%arg30, %1, %arg32) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%2) : (i1) -> ()
}
]

def select_icmp_ne_0_and_4096_and_not_32_after := [llvm|
{
^0(%arg205 : i32, %arg206 : i32):
  %0 = llvm.mlir.constant(4096 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(-33 : i32) : i32
  %3 = llvm.and %arg205, %0 : i32
  %4 = llvm.icmp "eq" %3, %1 : i32
  %5 = llvm.and %arg206, %2 : i32
  %6 = "llvm.select"(%4, %5, %arg206) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%6) : (i32) -> ()
}
]

def ashrsgt_02_07_exact_after := [llvm|
{
^0(%arg78 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def llvm_shl_lower_riscv_nuw_64: LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64), Ty.llvm (.bitvec 64)] where
  lhs := shl_llvm_nuw_64
  rhs := shl_riscv_64

def select_ashr_before := [llvm|
{
^0(%arg6 : i1, %arg7 : i128, %arg8 : i128):
  %0 = llvm.ashr %arg7, %arg8 : i128
  %1 = "llvm.select"(%arg6, %0, %arg7) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i128, i128) -> i128
  "llvm.return"(%1) : (i128) -> ()
}
]

def sge_smin1_before := [llvm|
{
^0(%arg79 : i32, %arg80 : i32):
  %0 = llvm.icmp "slt" %arg79, %arg80 : i32
  %1 = "llvm.select"(%0, %arg79, %arg80) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %2 = llvm.icmp "sge" %1, %arg79 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def only_one_masked_after := [llvm|
{
^0(%arg0 : i64):
  %0 = llvm.mlir.constant(-9223372036854775808) : i64
  %1 = llvm.icmp "eq" %arg0, %0 : i64
  "llvm.return"(%1) : (i1) -> ()
}
]

def n1_after := [llvm|
{
^0(%arg7 : i8, %arg8 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.mlir.constant(1 : i8) : i8
  %2 = llvm.shl %0, %arg8 overflow<nsw> : i8
  %3 = llvm.xor %2, %1 : i8
  %4 = llvm.icmp "ult" %3, %arg7 : i8
  "llvm.return"(%4) : (i1) -> ()
}
]

def eq_umin1_before := [llvm|
{
^0(%arg60 : i32, %arg61 : i32):
  %0 = llvm.icmp "ult" %arg60, %arg61 : i32
  %1 = "llvm.select"(%0, %arg60, %arg61) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %2 = llvm.icmp "eq" %1, %arg60 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def PR20945_after := [llvm|
{
^0(%arg132 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.icmp "ne" %arg132, %0 : i32
  "llvm.return"(%1) : (i1) -> ()
}
]

inductive GenBVPred where
   
  | bin (lhs : GenBVExpr w) (op : BVBinPred) (rhs : GenBVExpr w)
   
  | getLsbD (expr : GenBVExpr w) (idx : Nat)
deriving Hashable, BEq, DecidableEq

def p_constmask_after := [llvm|
{
^0(%arg49 : i32, %arg50 : i32):
  %0 = llvm.mlir.constant(65280 : i32) : i32
  %1 = llvm.mlir.constant(-65281 : i32) : i32
  %2 = llvm.and %arg49, %0 : i32
  %3 = llvm.and %arg50, %1 : i32
  %4 = llvm.or disjoint %2, %3 : i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def expand_before := [llvm|
{
^0(%arg0 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.mlir.constant(2 : i32) : i32
  %2 = llvm.and %arg0, %0 : i32
  %3 = llvm.or %2, %1 : i32
  %4 = llvm.and %3, %0 : i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def and_logic_and_logic_or_3_before := [llvm|
{
^0(%arg132 : i1, %arg133 : i1, %arg134 : i1):
  %0 = llvm.mlir.constant(false) : i1
  %1 = llvm.mlir.constant(true) : i1
  %2 = llvm.and %arg133, %arg132 : i1
  %3 = "llvm.select"(%arg132, %arg134, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %4 = "llvm.select"(%2, %1, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def icmp_ne_zext_ne_non_boolean_before := [llvm|
{
^0(%arg33 : i32):
  %0 = llvm.mlir.constant(2 : i32) : i32
  %1 = llvm.icmp "ne" %arg33, %0 : i32
  %2 = llvm.zext %1 : i1 to i32
  %3 = llvm.icmp "ne" %2, %arg33 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def xor_or_xor_common_op_commute8_before := [llvm|
{
^0(%arg59 : i32, %arg60 : i32, %arg61 : i32):
  %0 = llvm.xor %arg61, %arg59 : i32
  %1 = llvm.or %arg60, %arg59 : i32
  %2 = llvm.xor %1, %0 : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

structure Item where
 name : String
 tac : Syntax

def neg_sgt_n1_before := [llvm|
{
^0(%arg24 : i8):
  %0 = llvm.mlir.constant(0 : i8) : i8
  %1 = llvm.mlir.constant(-1 : i8) : i8
  %2 = llvm.sub %0, %arg24 : i8
  %3 = llvm.icmp "sgt" %2, %1 : i8
  "llvm.return"(%3) : (i1) -> ()
}
]

def test14_before := [llvm|
{
^0(%arg5 : i32):
  %0 = llvm.mlir.constant(4 : i32) : i32
  %1 = llvm.udiv %0, %arg5 : i32
  %2 = llvm.icmp "ult" %1, %0 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def nonexact_ashr_eq_exactdiv_before := [llvm|
{
^0(%arg146 : i8):
  %0 = llvm.mlir.constant(-80 : i8) : i8
  %1 = llvm.mlir.constant(-5 : i8) : i8
  %2 = llvm.ashr %0, %arg146 : i8
  %3 = llvm.icmp "eq" %2, %1 : i8
  "llvm.return"(%3) : (i1) -> ()
}
]

def src_is_mask_and_before := [llvm|
{
^0(%arg122 : i8, %arg123 : i8, %arg124 : i8):
  %0 = llvm.mlir.constant(123 : i8) : i8
  %1 = llvm.mlir.constant(7 : i8) : i8
  %2 = llvm.mlir.constant(-1 : i8) : i8
  %3 = llvm.xor %arg122, %0 : i8
  %4 = llvm.ashr %1, %arg123 : i8
  %5 = llvm.lshr %2, %arg124 : i8
  %6 = llvm.and %4, %5 : i8
  %7 = llvm.and %3, %6 : i8
  %8 = llvm.icmp "eq" %3, %7 : i8
  "llvm.return"(%8) : (i1) -> ()
}
]

def masked_icmps_mask_notallzeros_bmask_mixed_negated_4_after := [llvm|
{
^0(%arg62 : i32):
  %0 = llvm.mlir.constant(15 : i32) : i32
  %1 = llvm.mlir.constant(8 : i32) : i32
  %2 = llvm.and %arg62, %0 : i32
  %3 = llvm.icmp "ne" %2, %1 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def src2_after := [llvm|
{
^0(%arg10 : i32, %arg11 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg11, %arg10 : i32
  %2 = llvm.xor %1, %0 : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

@[nospecialize]
partial def decideIfZerosAuxVerified' {arity : Type _}
    [DecidableEq arity] [Fintype arity] [Hashable arity]
    (iter : Nat) (maxIter : Nat) (startVerifyAtIter : Nat := 0)
    (fsm : FSM arity)
    (circs : KInductionCircuits fsm iter)
    (stats : Array CircuitStats) :
    TermElabM (DecideIfZerosOutput × Array CircuitStats) := do
  withTraceNode `trace.Bits.Fast (fun _ => return s!"K-induction (iter={iter})") do
    if iter ≥ maxIter && maxIter != 0 then
      return (.exhaustedIterations maxIter, stats.push circs.stats)
    let tStart ← IO.monoMsNow
    let cSafety : Circuit (Vars fsm.α arity (iter+2)) := circs.mkSafetyCircuit
    let tEnd ← IO.monoMsNow
    let tElapsedMs := (tEnd - tStart)
    trace[Bits.FastVerif] m!"Built new safety circuit in '{tElapsedMs}ms'"
    trace[Bits.FastVerif] m!"safety circuit size : {cSafety.size}"
    trace[Bits.FastVerif] s!"Building induction circuit..."
    let tStart ← IO.monoMsNow
    let cIndHyp := circs.mkIndHypCycleBreaking
    let tEnd ← IO.monoMsNow
    let tElapsedMs := (tEnd - tStart)
    trace[Bits.FastVerif] m!"Built induction circuit in '{tElapsedMs}ms'"


    if iter < startVerifyAtIter then
      trace[Bits.FastVerif] s!"Skipping inductive invariant check until iteration {startVerifyAtIter}."
      decideIfZerosAuxVerified' (iter + 1) maxIter startVerifyAtIter fsm  circs.mkSucc (stats.push circs.stats)
    else
      trace[Bits.FastVerif] s!"Verifying safety property..."
      let tStart ← IO.monoMsNow
      let safetyCert? ← Circuit.checkCircuitUnsatAux cSafety
      let tEnd ← IO.monoMsNow
      let tElapsedMs := (tEnd - tStart)
      trace[Bits.FastVerif] m!"Established safety property in {tElapsedMs}ms (iter={iter})."
      match safetyCert? with
      | .none =>
        trace[Bits.FastVerif] s!"Safety property failed on initial state."
        return (.safetyFailure iter, stats.push circs.stats)
      | .some safetyCert =>
        trace[Bits.FastVerif] s!"Safety property established (iter={iter})."
        trace[Bits.FastVerif] s!"Establishing Inductive Invariant..."
        let tStart ← IO.monoMsNow
        let indCert? ← Circuit.checkCircuitUnsatAux cIndHyp
        let tEnd ← IO.monoMsNow
        let tElapsedMs := (tEnd - tStart)
        trace[Bits.FastVerif] s!"Checked inductive invariant in '{tElapsedMs}ms'."
        match indCert? with
        | .some indCert =>
          trace[Bits.FastVerif] s!"Inductive invariant established (iter={iter})."
          return (.provenByKIndCycleBreaking iter safetyCert indCert, stats.push circs.stats)
        | .none =>
          trace[Bits.FastVerif] s!"Unable to establish inductive invariant. Trying next iteration ({iter+1})..."
        decideIfZerosAuxVerified' (iter + 1) maxIter startVerifyAtIter fsm  circs.mkSucc (stats.push circs.stats)

def eq_umin3_after := [llvm|
{
^0(%arg56 : i32, %arg57 : i32):
  %0 = llvm.mlir.constant(3 : i32) : i32
  %1 = llvm.add %arg56, %0 : i32
  %2 = llvm.icmp "ule" %1, %arg57 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def shrink_xor_before := [llvm|
{
^0(%arg13 : i64):
  %0 = llvm.mlir.constant(1) : i64
  %1 = llvm.xor %arg13, %0 : i64
  %2 = llvm.trunc %1 : i64 to i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def addhshlhsdivhscalar0_after := [llvm|
{
^0(%arg19 : i8):
  %0 = llvm.mlir.constant(4 : i8) : i8
  %1 = llvm.srem %arg19, %0 : i8
  "llvm.return"(%1) : (i8) -> ()
}
]

def or_and3_before := [llvm|
{
^0(%arg104 : i1, %arg105 : i1, %arg106 : i32, %arg107 : i32):
  %0 = llvm.icmp "eq" %arg106, %arg107 : i32
  %1 = llvm.or %arg104, %0 : i1
  %2 = "llvm.select"(%1, %arg104, %arg105) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%2) : (i1) -> ()
}
]

def main6d_logical_before := [llvm|
{
^0(%arg87 : i32):
  %0 = llvm.mlir.constant(7 : i32) : i32
  %1 = llvm.mlir.constant(3 : i32) : i32
  %2 = llvm.mlir.constant(16 : i32) : i32
  %3 = llvm.mlir.constant(0 : i32) : i32
  %4 = llvm.mlir.constant(true) : i1
  %5 = llvm.mlir.constant(1 : i32) : i32
  %6 = llvm.and %arg87, %0 : i32
  %7 = llvm.icmp "ne" %6, %1 : i32
  %8 = llvm.and %arg87, %2 : i32
  %9 = llvm.icmp "eq" %8, %3 : i32
  %10 = "llvm.select"(%7, %4, %9) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %11 = "llvm.select"(%10, %3, %5) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%11) : (i32) -> ()
}
]

String.Pos.Raw in Init.Prelude

def elabOp (env : Lean.Environment) (stx : Lean.Syntax) : EIO ParseError (MLIR.AST.Op 0) :=
  unsafe elabIntoEIO (α := MLIR.AST.Op 0) env op0Expr stx

def multiuse_shl_shl_after := [llvm|
{
^0(%arg36 : i42):
  %0 = llvm.mlir.constant(8 : i42) : i42
  %1 = llvm.mlir.constant(17 : i42) : i42
  %2 = llvm.shl %arg36, %0 : i42
  %3 = llvm.shl %arg36, %1 : i42
  %4 = llvm.mul %2, %3 : i42
  "llvm.return"(%4) : (i42) -> ()
}
]

def or_and_xor_not_constant_commute1_after := [llvm|
{
^0(%arg166 : i9, %arg167 : i9):
  %0 = llvm.mlir.constant(42 : i9) : i9
  %1 = llvm.and %arg166, %0 : i9
  %2 = llvm.xor %1, %arg167 : i9
  "llvm.return"(%2) : (i9) -> ()
}
]

def invert_both_cmp_operands_complex_before := [llvm|
{
^0(%arg32 : i1, %arg33 : i32, %arg34 : i32, %arg35 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg33, %0 : i32
  %2 = llvm.xor %arg34, %0 : i32
  %3 = llvm.xor %arg35, %0 : i32
  %4 = llvm.add %arg35, %1 : i32
  %5 = "llvm.select"(%arg32, %4, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %6 = llvm.icmp "sle" %5, %3 : i32
  "llvm.return"(%6) : (i1) -> ()
}
]

def icmp_power2_and_icmp_shifted_mask_swapped_2147483648_805306368_after := [llvm|
{
^0(%arg40 : i32):
  %0 = llvm.mlir.constant(805306368 : i32) : i32
  %1 = llvm.icmp "ult" %arg40, %0 : i32
  "llvm.return"(%1) : (i1) -> ()
}
]

def select_ashr_icmp_bad_before := [llvm|
{
^0(%arg45 : i32, %arg46 : i32, %arg47 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.icmp "eq" %arg45, %0 : i32
  %2 = llvm.ashr %arg47, %arg45 : i32
  %3 = "llvm.select"(%1, %2, %arg46) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def select_icmp_slt_zero_smin_flipped_after := [llvm|
{
^0(%arg6 : i8):
  %0 = llvm.mlir.constant(127 : i8) : i8
  %1 = llvm.and %arg6, %0 : i8
  "llvm.return"(%1) : (i8) -> ()
}
]

def alive_AndOrXor_2627_tgt  (w : Nat)  :=
[llvm( w )| {
^bb0(%a : _, %c : _, %b : _):
  %v1 = llvm.mlir.constant -1
  %v2 = llvm.xor %a, %v1
  %v3 = llvm.and %v2, %b
  %v4 = llvm.xor %a, %c
  %v5 = llvm.or %a, %b
  %v6 = llvm.xor %v3, %c
  llvm.return %v6
}]

def test_mul_nuw_nsw__nsw_is_safe_after := [llvm|
{
^0(%arg7 : i32):
  %0 = llvm.mlir.constant(-83886080 : i32) : i32
  %1 = llvm.mlir.constant(9 : i32) : i32
  %2 = llvm.or %arg7, %0 : i32
  %3 = llvm.mul %2, %1 overflow<nsw> : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def mul_constant_eq_before := [llvm|
{
^0(%arg140 : i32, %arg141 : i32):
  %0 = llvm.mlir.constant(5 : i32) : i32
  %1 = llvm.mul %arg140, %0 : i32
  %2 = llvm.mul %arg141, %0 : i32
  %3 = llvm.icmp "eq" %1, %2 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def alive_InstCombineShift__279_src :=
[sllvm| {
^bb0(%X : i64, %C : i64):
  %v1 = llvm.lshr %X, %C : i64
  %v2 = llvm.shl %v1, %C : i64
  llvm.return %v2 : i64
}]

def lshrugt_03_08_after := [llvm|
{
^0(%arg375 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def test16_before := [llvm|
{
^0(%arg283 : i8):
  %0 = llvm.mlir.constant(2 : i8) : i8
  %1 = llvm.mlir.constant(3 : i8) : i8
  %2 = llvm.shl %arg283, %0 : i8
  %3 = llvm.and %2, %1 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def logic_or_logic_and_8_before := [llvm|
{
^0(%arg66 : i1, %arg67 : i1, %arg68 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.mlir.constant(false) : i1
  %2 = "llvm.select"(%arg66, %0, %arg67) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %3 = "llvm.select"(%arg68, %0, %arg66) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %4 = "llvm.select"(%3, %2, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def uadd_sat_flipped_wrong_bounds7_after := [llvm|
{
^0(%arg90 : i32):
  %0 = llvm.mlir.constant(-11 : i32) : i32
  %1 = llvm.mlir.constant(9 : i32) : i32
  %2 = llvm.mlir.constant(-1 : i32) : i32
  %3 = llvm.icmp "ult" %arg90, %0 : i32
  %4 = llvm.add %arg90, %1 : i32
  %5 = "llvm.select"(%3, %4, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def samesign_inverted_commute3_before := [llvm|
{
^0(%arg97 : i32, %arg98 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.and %arg97, %arg98 : i32
  %3 = llvm.icmp "sgt" %2, %0 : i32
  %4 = llvm.or %arg98, %arg97 : i32
  %5 = llvm.icmp "slt" %4, %1 : i32
  %6 = llvm.and %5, %3 : i1
  "llvm.return"(%6) : (i1) -> ()
}
]

def sgt_negative_multip_rem_zero_after := [llvm|
{
^0(%arg169 : i8):
  %0 = llvm.mlir.constant(-3 : i8) : i8
  %1 = llvm.icmp "slt" %arg169, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def test_add_nuw_nsw__none_are_safe_before := [llvm|
{
^0(%arg35 : i32):
  %0 = llvm.mlir.constant(3 : i32) : i32
  %1 = llvm.mlir.constant(1 : i32) : i32
  %2 = llvm.mlir.constant(4 : i32) : i32
  %3 = llvm.icmp "eq" %arg35, %0 : i32
  %4 = llvm.add %arg35, %1 overflow<nsw,nuw> : i32
  %5 = "llvm.select"(%3, %2, %4) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def ashrsgt_02_09_exact_after := [llvm|
{
^0(%arg76 : i4):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def bigOr (constraints : List (BoolExpr α)) : BoolExpr α :=
  foldConstraints (BoolExpr.const false) constraints Gate.or

def n12_before := [llvm|
{
^0(%arg0 : i8):
  %0 = llvm.mlir.constant(6 : i8) : i8
  %1 = llvm.shl %arg0, %0 : i8
  %2 = llvm.ashr %1, %0 : i8
  "llvm.return"(%2) : (i8) -> ()
}
]

def uge_swap_and_max_commute_before := [llvm|
{
^0(%arg226 : i8, %arg227 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.icmp "ule" %arg227, %arg226 : i8
  %2 = llvm.icmp "eq" %arg226, %0 : i8
  %3 = llvm.and %2, %1 : i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def sge_swap_or_max_commute_before := [llvm|
{
^0(%arg178 : i8, %arg179 : i8):
  %0 = llvm.mlir.constant(127 : i8) : i8
  %1 = llvm.icmp "sle" %arg179, %arg178 : i8
  %2 = llvm.icmp "eq" %arg178, %0 : i8
  %3 = llvm.or %2, %1 : i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def trunc_shl_15_i16_i32_before := [llvm|
{
^0(%arg53 : i32):
  %0 = llvm.mlir.constant(15 : i32) : i32
  %1 = llvm.shl %arg53, %0 : i32
  %2 = llvm.trunc %1 : i32 to i16
  "llvm.return"(%2) : (i16) -> ()
}
]

def slt_or_not_max_commute_after := [llvm|
{
^0(%arg58 : i8, %arg59 : i8):
  %0 = llvm.mlir.constant(127 : i8) : i8
  %1 = llvm.icmp "ne" %arg58, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def and_or3_commuted_before := [llvm|
{
^0(%arg164 : i1, %arg165 : i1, %arg166 : i32, %arg167 : i32):
  %0 = llvm.icmp "eq" %arg166, %arg167 : i32
  %1 = llvm.and %0, %arg165 : i1
  %2 = "llvm.select"(%1, %arg164, %arg165) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%2) : (i1) -> ()
}
]

def or_nosignbit_select_shl_before := [llvm|
{
^0(%arg40 : i32, %arg41 : i1):
  %0 = llvm.mlir.constant(2147418112 : i32) : i32
  %1 = llvm.mlir.constant(8 : i32) : i32
  %2 = llvm.or %arg40, %0 : i32
  %3 = "llvm.select"(%arg41, %2, %arg40) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %4 = llvm.shl %3, %1 : i32
  "llvm.return"(%4) : (i32) -> ()
}
]

instance (e : Eqn) : Decidable (∀ env1 : EnvFin 1 e.numVars, Eqn.denoteFin e env1 = 0) :=
  let ⟨allEnvs, hAllEnvs⟩ := EnvFin.getAll1 e.numVars
  let b := allEnvs.all (fun env1 => e.denoteFin env1 = 0)
  match hb : b with
  | true => .isTrue <| by
    simp [b] at hb
    intros env1
    apply hb
    apply hAllEnvs
  | false => .isFalse <| by
    simp
    simp [b] at hb
    obtain ⟨env, henvMem, henvDenote⟩ := hb
    exists env

def zext_nneg_sext_sle_op0_narrow_before := [llvm|
{
^0(%arg50 : i8, %arg51 : i16):
  %0 = llvm.zext nneg %arg50 : i8 to i32
  %1 = llvm.sext %arg51 : i16 to i32
  %2 = llvm.icmp "sle" %0, %1 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def binop_left_to_zero_urem : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%x: i64):
      %c = llvm.mlir.constant (0) : i64
      %0 = llvm.urem %c, %x : i64
      llvm.return %0 : i64
  }]
  rhs := [LV| {
    ^entry (%x: i64):
      %c = llvm.mlir.constant (0) : i64
      llvm.return %c : i64
  }]

def trunc_equality_nsw_zext_after := [llvm|
{
^0(%arg16 : i32, %arg17 : i8):
  %0 = llvm.zext %arg17 : i8 to i32
  %1 = llvm.icmp "ne" %arg16, %0 : i32
  "llvm.return"(%1) : (i1) -> ()
}
]

def select_xor_inv_icmp_before := [llvm|
{
^0(%arg266 : i32, %arg267 : i32, %arg268 : i32):
  %0 = llvm.mlir.constant(0 : i32) : i32
  %1 = llvm.icmp "eq" %arg266, %0 : i32
  %2 = llvm.xor %arg268, %arg266 : i32
  %3 = "llvm.select"(%1, %2, %arg267) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def is_ascii_alphabetic_inverted_after := [llvm|
{
^0(%arg247 : i32):
  %0 = llvm.mlir.constant(-33 : i32) : i32
  %1 = llvm.mlir.constant(-91 : i32) : i32
  %2 = llvm.mlir.constant(-26 : i32) : i32
  %3 = llvm.and %arg247, %0 : i32
  %4 = llvm.add %3, %1 : i32
  %5 = llvm.icmp "ult" %4, %2 : i32
  "llvm.return"(%5) : (i1) -> ()
}
]

@[simp_denote]
def ashr_llvm_exact_flag_16 := [LV| {
  ^entry (%x: i16, %amount: i16):
    %1 = llvm.ashr exact %x, %amount : i16
    llvm.return %1 : i16
  }]

instance : HydrableReduceWidth ParsedBVExpr GenBVPred GenBVExpr where
  shrink := shrink

def xor_lshr_after := [llvm|
{
^0(%arg624 : i8, %arg625 : i8, %arg626 : i8, %arg627 : i8):
  %0 = llvm.xor %arg624, %arg625 : i8
  %1 = llvm.lshr %0, %arg627 : i8
  %2 = llvm.xor %1, %arg626 : i8
  "llvm.return"(%2) : (i8) -> ()
}
]

def mul_of_bools_before := [llvm|
{
^0(%arg91 : i32, %arg92 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.mlir.constant(2 : i32) : i32
  %2 = llvm.and %arg91, %0 : i32
  %3 = llvm.and %arg92, %0 : i32
  %4 = llvm.mul %2, %3 : i32
  %5 = llvm.icmp "ult" %4, %1 : i32
  "llvm.return"(%5) : (i1) -> ()
}
]

def test_shr_and_1_ne_0_samesign_before := [llvm|
{
^0(%arg9 : i32, %arg10 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.lshr %arg9, %arg10 : i32
  %3 = llvm.and %2, %0 : i32
  %4 = llvm.icmp "ne" %3, %1 : i32
  "llvm.return"(%4) : (i1) -> ()
}
]

def ashrslt_03_06_before := [llvm|
{
^0(%arg231 : i4):
  %0 = llvm.mlir.constant(3 : i4) : i4
  %1 = llvm.mlir.constant(6 : i4) : i4
  %2 = llvm.ashr %arg231, %0 : i4
  %3 = llvm.icmp "slt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def lshrugt_02_00_exact_before := [llvm|
{
^0(%arg205 : i4):
  %0 = llvm.mlir.constant(2 : i4) : i4
  %1 = llvm.mlir.constant(0 : i4) : i4
  %2 = llvm.lshr exact %arg205, %0 : i4
  %3 = llvm.icmp "ugt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def sdiv_pow2_4 : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%x: i64):
      %c = llvm.mlir.constant (4) : i64
      %0 = llvm.sdiv %x, %c : i64
      llvm.return %0 : i64
  }]
  rhs := [LV| {
    ^entry (%x: i64):
      %c0 = llvm.mlir.constant (63) : i64
      %c1 = llvm.mlir.constant (62) : i64
      %c2 = llvm.mlir.constant (2) : i64
      %0 = llvm.ashr %x, %c0 : i64
      %1 = llvm.lshr %0, %c1 : i64
      %2 = llvm.add %x, %1 : i64 
      %3 = llvm.ashr %2, %c2 : i64
      llvm.return %3 : i64
  }]

def lshr_or_or_no_const_before := [llvm|
{
^0(%arg142 : i8, %arg143 : i8, %arg144 : i8, %arg145 : i8):
  %0 = llvm.lshr %arg142, %arg144 : i8
  %1 = llvm.lshr %arg143, %arg144 : i8
  %2 = llvm.or %1, %arg145 : i8
  %3 = llvm.or %0, %2 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def Signature.map (f : Ty → Ty') : Signature Ty → Signature Ty' :=
  fun sig => {
    sig         := sig.sig.map f
    regSig      := sig.regSig.map f
    returnTypes := sig.returnTypes.map f
  }

def test15a_before := [llvm|
{
^0(%arg27 : i32):
  %0 = llvm.mlir.constant(16 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.and %arg27, %0 : i32
  %3 = llvm.icmp "eq" %2, %1 : i32
  %4 = "llvm.select"(%3, %1, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def irc_constants_APlusC1MinusC2_neg2_2 : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (-2) : i64
      %c2 = llvm.mlir.constant (2) : i64
      %0 = llvm.add %a, %c1 : i64
      %1 = llvm.sub %0, %c2 : i64
      llvm.return %1 : i64
  }]
  rhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (-2) : i64
      %c2 = llvm.mlir.constant (2) : i64
      %0 = llvm.sub %c1, %c2 : i64
      %1 = llvm.add %a, %0 : i64
      llvm.return %1 : i64
  }]

def scalar_i32_lshr_and_signbit_eq_after := [llvm|
{
^0(%arg31 : i32, %arg32 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.lshr %arg31, %arg32 : i32
  %2 = llvm.icmp "sgt" %1, %0 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def fold_add_udiv_urem_to_mul_before := [llvm|
{
^0(%arg8 : i32):
  %0 = llvm.mlir.constant(7 : i32) : i32
  %1 = llvm.mlir.constant(21 : i32) : i32
  %2 = llvm.mlir.constant(3 : i32) : i32
  %3 = llvm.udiv %arg8, %0 : i32
  %4 = llvm.mul %3, %1 : i32
  %5 = llvm.urem %arg8, %0 : i32
  %6 = llvm.mul %5, %2 : i32
  %7 = llvm.add %4, %6 : i32
  "llvm.return"(%7) : (i32) -> ()
}
]

def llvm_mul_lower_riscv_nsw_flag_32 : LLVMPeepholeRewriteRefine 32 [Ty.llvm (.bitvec 32), Ty.llvm (.bitvec 32)] where
  lhs := mul_llvm_nsw_32
  rhs := mul_riscv_32

inductive NatPredicate (wcard : Nat) : Type
| eq : WidthExpr wcard → WidthExpr wcard → NatPredicate wcard

def lshrult_03_12_before := [llvm|
{
^0(%arg323 : i4):
  %0 = llvm.mlir.constant(3 : i4) : i4
  %1 = llvm.mlir.constant(-4 : i4) : i4
  %2 = llvm.lshr %arg323, %0 : i4
  %3 = llvm.icmp "ult" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def ugt_umax4_before := [llvm|
{
^0(%arg30 : i32, %arg31 : i32):
  %0 = llvm.mlir.constant(3 : i32) : i32
  %1 = llvm.add %arg30, %0 : i32
  %2 = llvm.icmp "ugt" %arg31, %1 : i32
  %3 = "llvm.select"(%2, %arg31, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %4 = llvm.icmp "ult" %1, %3 : i32
  "llvm.return"(%4) : (i1) -> ()
}
]

def mkStateUniqueCircuitN {arity : Type _}
  [DecidableEq arity] [Fintype arity] [Hashable arity]
  (p : FSM arity) (n : Nat) : Circuit (Vars p.α arity n) :=
  let sn : p.α → Circuit (Vars p.α arity n) := fun s =>
    Circuit.var true (Vars.stateN s n)
  let circs := (List.range n).attach |>.map fun ⟨i, hi⟩ =>
    let si : p.α → Circuit (Vars p.α arity n) := fun s =>
      Circuit.var true (Vars.stateN s i (by admit /- proof elided -/
      ))
    (mkStateNeqCircuit p si sn)
  Circuit.bigOr circs

def shiftLeft (op1 : GenBVExpr w) (op2: GenBVExpr w) : GenBVExpr w :=
  GenBVExpr.shiftLeft op1 op2

@[reducible, simp]
def Op.sig : Op → List Ty
  | .add => [.int, .int]
  | .sub => [.int, .int]
  | .constIx _  => []
  | .constTensor _  => []
  | .constInt _  => []
  | .map2d => [.tensor2d]
  | .fill2d => [.int, .tensor2d]
  | .extract2d => [.ix, .ix, .ix, .ix, .tensor2d]

def demorgan_nand_before := [llvm|
{
^0(%arg38 : i8, %arg39 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.xor %arg38, %0 : i8
  %2 = llvm.and %1, %arg39 : i8
  %3 = llvm.xor %2, %0 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def foo2_after := [llvm|
{
^0(%arg46 : i32, %arg47 : i32):
  %0 = llvm.mlir.constant(2 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.icmp "sgt" %arg46, %0 : i32
  %3 = llvm.sub %1, %arg47 : i32
  %4 = "llvm.select"(%2, %arg47, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %5 = llvm.add %arg46, %4 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def slt_zero_sgt_minus1_after := [llvm|
{
^0(%arg22 : i4, %arg23 : i4):
  %0 = llvm.mlir.constant(-1 : i4) : i4
  %1 = llvm.xor %arg22, %arg23 : i4
  %2 = llvm.icmp "sgt" %1, %0 : i4
  "llvm.return"(%2) : (i1) -> ()
}
]

def scalar_i32_shl_and_negC_eq_nonzero_after := [llvm|
{
^0(%arg0 : i32, %arg1 : i32):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

instance : TyDenote (Dialect.Ty Comb) where
  toType := fun
  | .bitvec w => BitVec w

def test6a_after := [llvm|
{
^0(%arg1 : i1):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def lt_signed_to_small_signed_before := [llvm|
{
^0(%arg49 : i8):
  %0 = llvm.mlir.constant(17 : i32) : i32
  %1 = llvm.sext %arg49 : i8 to i32
  %2 = llvm.icmp "slt" %1, %0 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def or_not_xor_common_op_commute0_before := [llvm|
{
^0(%arg107 : i4, %arg108 : i4, %arg109 : i4):
  %0 = llvm.mlir.constant(-1 : i4) : i4
  %1 = llvm.xor %arg107, %0 : i4
  %2 = llvm.xor %arg107, %arg108 : i4
  %3 = llvm.or %1, %arg109 : i4
  %4 = llvm.or %3, %2 : i4
  "llvm.return"(%4) : (i4) -> ()
}
]

def test_invert_demorgan_or2_before := [llvm|
{
^0(%arg15 : i64, %arg16 : i64, %arg17 : i64):
  %0 = llvm.mlir.constant(23) : i64
  %1 = llvm.mlir.constant(59) : i64
  %2 = llvm.mlir.constant(true) : i1
  %3 = llvm.icmp "ugt" %arg15, %0 : i64
  %4 = llvm.icmp "ugt" %arg16, %1 : i64
  %5 = llvm.or %3, %4 : i1
  %6 = llvm.icmp "ugt" %arg17, %1 : i64
  %7 = llvm.or %5, %6 : i1
  %8 = llvm.xor %7, %2 : i1
  "llvm.return"(%8) : (i1) -> ()
}
]

def shl_and_before := [llvm|
{
^0(%arg19 : i8):
  %0 = llvm.mlir.constant(48 : i8) : i8
  %1 = llvm.mlir.constant(1 : i8) : i8
  %2 = llvm.mlir.constant(8 : i8) : i8
  %3 = llvm.shl %0, %arg19 : i8
  %4 = llvm.add %arg19, %1 : i8
  %5 = llvm.shl %2, %4 : i8
  %6 = llvm.and %3, %5 : i8
  "llvm.return"(%6) : (i8) -> ()
}
]

def t1_after := [llvm|
{
^0(%arg31 : i8):
  %0 = llvm.mlir.constant(31 : i8) : i8
  %1 = llvm.mlir.constant(-32 : i8) : i8
  %2 = llvm.add %arg31, %0 : i8
  %3 = llvm.and %2, %1 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def sext_zext_apint2_before := [llvm|
{
^0(%arg85 : i11):
  %0 = llvm.zext %arg85 : i11 to i39
  %1 = llvm.sext %0 : i39 to i47
  "llvm.return"(%1) : (i47) -> ()
}
]

def bools2_logical_commute0_and1_and2_before := [llvm|
{
^0(%arg55 : i1, %arg56 : i1, %arg57 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.xor %arg57, %0 : i1
  %2 = llvm.and %arg57, %arg55 : i1
  %3 = llvm.and %1, %arg56 : i1
  %4 = "llvm.select"(%2, %0, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def narrow_sext_or_before := [llvm|
{
^0(%arg52 : i16, %arg53 : i32):
  %0 = llvm.sext %arg52 : i16 to i32
  %1 = llvm.or %0, %arg53 : i32
  %2 = llvm.trunc %1 : i32 to i16
  "llvm.return"(%2) : (i16) -> ()
}
]

@[simp_llvm]
def urem? {w : Nat} (x y : BitVec w) : IntW w :=
  if y = 0 then
    .poison
  else
    .value <| x % y

inductive Ty
| int : Ty
| ix : Ty
| tensor2d : Ty
deriving DecidableEq, Inhabited

instance : Monad PoisonOr where
  pure := value
  bind := fun a f => match a with
    | poison  => poison
    | value a => f a

def land_lor_right1_after := [llvm|
{
^0(%arg46 : i1, %arg47 : i1):
  "llvm.return"(%arg46) : (i1) -> ()
}
]

def Term.bcard (t : Term) : Nat :=
  match t with
  | .ofNat _w _n => 0
  | .var _v _w => 0
  | .add _w a b => max (Term.bcard a) (Term.bcard b)
  | .zext a _wnew => (Term.bcard a)
  | .sext a _wnew => (Term.bcard a)
  | .setWidth a _wnew => (Term.bcard a)
  | .bor _w a b => (max (Term.bcard a) (Term.bcard b))
  | .band _w a b => (max (Term.bcard a) (Term.bcard b))
  | .bxor _w a b => (max (Term.bcard a) (Term.bcard b))
  | .bnot _w a => (Term.bcard a)
  | .boolVar v => v + 1
  | .boolConst _b => 0
  | .shiftl _w a _k => (Term.bcard a)
  | bvOfBool b => b.bcard
  | binWidthRel _k _wa _wb => 0
  | binRel _k _w a b => max (Term.bcard a) (Term.bcard b)
  | or p1 p2 => max (Term.bcard p1) (Term.bcard p2)
  | and p1 p2 => max (Term.bcard p1) (Term.bcard p2)
  | pvar _v => 0
  | boolBinRel _k a b => max (a.bcard) (b.bcard)

def select_ashr_before := [llvm|
{
^0(%arg6 : i1, %arg7 : i128, %arg8 : i128):
  %0 = llvm.ashr %arg7, %arg8 : i128
  %1 = "llvm.select"(%arg6, %0, %arg7) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i128, i128) -> i128
  "llvm.return"(%1) : (i128) -> ()
}
]

def test2_after := [llvm|
{
^0(%arg6 : i32, %arg7 : i32, %arg8 : i32):
  %0 = llvm.xor %arg7, %arg6 : i32
  "llvm.return"(%0) : (i32) -> ()
}
]

def xor_and_logic_or2_after := [llvm|
{
^0(%arg27 : i1, %arg28 : i1, %arg29 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.xor %arg28, %0 : i1
  %2 = "llvm.select"(%arg27, %1, %arg29) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%2) : (i1) -> ()
}
]

def shift_trunc_wrong_cmp_after := [llvm|
{
^0(%arg0 : i32):
  %0 = llvm.mlir.constant(24 : i32) : i32
  %1 = llvm.mlir.constant(1 : i8) : i8
  %2 = llvm.lshr %arg0, %0 : i32
  %3 = llvm.trunc %2 overflow<nuw> : i32 to i8
  %4 = llvm.icmp "slt" %3, %1 : i8
  "llvm.return"(%4) : (i1) -> ()
}
]

def udiv_shl_shl_nuw_nsw2_after := [llvm|
{
^0(%arg55 : i8, %arg56 : i8, %arg57 : i8):
  %0 = llvm.udiv %arg55, %arg56 : i8
  "llvm.return"(%0) : (i8) -> ()
}
]

instance {d : Dialect} [DialectSignature d] {t} {Γ : Ctxt d.Ty} {Γ' : DerivedCtxt Γ} :
    Coe (Expr d Γ eff t) (Expr d Γ'.ctxt eff t) where
  coe e := e.changeVars Γ'.diff.toHom

def ashr_mul_times_3_div_2_exact_2_after := [llvm|
{
^0(%arg17 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.ashr exact %arg17, %0 : i32
  %2 = llvm.add %arg17, %1 overflow<nsw> : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def and_or_not_not_commute6_before := [llvm|
{
^0(%arg357 : i32, %arg358 : i32, %arg359 : i32):
  %0 = llvm.mlir.constant(42 : i32) : i32
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.sdiv %0, %arg358 : i32
  %3 = llvm.and %2, %arg357 : i32
  %4 = llvm.xor %3, %1 : i32
  %5 = llvm.and %arg359, %arg357 : i32
  %6 = llvm.xor %5, %1 : i32
  %7 = llvm.or %2, %6 : i32
  %8 = llvm.and %7, %4 : i32
  "llvm.return"(%8) : (i32) -> ()
}
]

def scalar_i32_lshr_and_negC_eq_before := [llvm|
{
^0(%arg35 : i32, %arg36 : i32):
  %0 = llvm.mlir.constant(-262144 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.lshr %arg35, %arg36 : i32
  %3 = llvm.and %2, %0 : i32
  %4 = llvm.icmp "eq" %3, %1 : i32
  "llvm.return"(%4) : (i1) -> ()
}
]

def mul_splat_fold_before := [llvm|
{
^0(%arg161 : i32):
  %0 = llvm.mlir.constant(65537 : i32) : i32
  %1 = llvm.mlir.constant(16 : i32) : i32
  %2 = llvm.mul %arg161, %0 overflow<nuw> : i32
  %3 = llvm.lshr %2, %1 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def select_sub_icmp_after := [llvm|
{
^0(%arg214 : i32, %arg215 : i32, %arg216 : i32):
  %0 = llvm.mlir.constant(0 : i32) : i32
  %1 = llvm.icmp "eq" %arg214, %0 : i32
  %2 = "llvm.select"(%1, %arg216, %arg215) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def incr (x : BitStream) : BitStream :=
  fun n => (incrAux x n).1

def slt_swap_and_not_max_logical_before := [llvm|
{
^0(%arg116 : i8, %arg117 : i8):
  %0 = llvm.mlir.constant(127 : i8) : i8
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.icmp "sgt" %arg117, %arg116 : i8
  %3 = llvm.icmp "ne" %arg116, %0 : i8
  %4 = "llvm.select"(%2, %3, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def sextbool_add_commute_after := [llvm|
{
^0(%arg10 : i1, %arg11 : i32):
  %0 = llvm.mlir.constant(42 : i32) : i32
  %1 = llvm.urem %arg11, %0 : i32
  %2 = llvm.sext %arg10 : i1 to i32
  %3 = llvm.add %1, %2 overflow<nsw> : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

Valuation.map in Mathlib.RingTheory.Valuation.Basic

HAdd in Init.Prelude

def test8_before := [llvm|
{
^0(%arg94 : i32, %arg95 : i32):
  %0 = llvm.mlir.constant(32 : i128) : i128
  %1 = llvm.zext %arg94 : i32 to i128
  %2 = llvm.zext %arg95 : i32 to i128
  %3 = llvm.shl %2, %0 : i128
  %4 = llvm.or %3, %1 : i128
  %5 = llvm.trunc %4 : i128 to i64
  "llvm.return"(%5) : (i64) -> ()
}
]

@[simp_denote]
def select_riscv_32 := [LV| {
  ^entry (%cond : i1, %arg0: i32, %arg1: i32):
    %0 = "builtin.unrealized_conversion_cast" (%arg0) : (i32) -> (!i64)
    %1 = "builtin.unrealized_conversion_cast" (%arg1) : (i32) -> (!i64)
    %2 = "builtin.unrealized_conversion_cast" (%cond) : (i1) -> (!i64)
    %3 = snez %2 : !i64
    %4 = sub %0, %1 : !i64
    %5 = mul %4, %3 : !i64
    %6 = add %5, %1 : !i64
    %7 = "builtin.unrealized_conversion_cast" (%6) : (!i64) -> (i32)
    llvm.return %7 : i32
  }]

def mul_splat_fold_no_nuw_before := [llvm|
{
^0(%arg79 : i32):
  %0 = llvm.mlir.constant(65537 : i32) : i32
  %1 = llvm.mlir.constant(16 : i32) : i32
  %2 = llvm.mul %arg79, %0 overflow<nsw> : i32
  %3 = llvm.lshr %2, %1 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def test12_after := [llvm|
{
^0(%arg29 : i47):
  %0 = llvm.mlir.constant(-256 : i47) : i47
  %1 = llvm.and %arg29, %0 : i47
  "llvm.return"(%1) : (i47) -> ()
}
]

def src_srem_shl_demand_eliminate_signbit_after := [llvm|
{
^0(%arg19 : i32):
  %0 = llvm.mlir.constant(1073741824 : i32) : i32
  %1 = llvm.mlir.constant(1 : i32) : i32
  %2 = llvm.mlir.constant(2 : i32) : i32
  %3 = llvm.srem %arg19, %0 : i32
  %4 = llvm.shl %3, %1 overflow<nsw> : i32
  %5 = llvm.and %4, %2 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def zext_match : List (Σ Γ, Σ ty, PeepholeRewrite LLVMPlusRiscV Γ ty) := [
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_1_to_8),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_1_to_16),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_1_to_32),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_1_to_64),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_8_to_64),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_8_to_16),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_8_to_32),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_16_to_32),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_16_to_64),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_zext_lower_riscv_32_to_64)
]

def src_x_and_nmask_ne_after := [llvm|
{
^0(%arg27 : i8, %arg28 : i8, %arg29 : i1):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.shl %0, %arg28 overflow<nsw> : i8
  %3 = llvm.icmp "ugt" %2, %arg27 : i8
  %4 = "llvm.select"(%arg29, %3, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def test3_apint_before := [llvm|
{
^0(%arg43 : i47, %arg44 : i47):
  %0 = llvm.mlir.constant(-1 : i47) : i47
  %1 = llvm.xor %arg43, %0 : i47
  %2 = llvm.xor %arg44, %0 : i47
  %3 = llvm.and %1, %2 : i47
  %4 = llvm.xor %3, %0 : i47
  "llvm.return"(%4) : (i47) -> ()
}
]

def trimTensor (tensor : List Int) : List Int
  := tensor.reverse.dropWhile (· = 0) |>.reverse

def test12_before := [llvm|
{
^0(%arg89 : i32, %arg90 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg90, %0 : i32
  %2 = llvm.and %arg89, %1 : i32
  %3 = llvm.xor %arg89, %0 : i32
  %4 = llvm.xor %2, %3 : i32
  "llvm.return"(%4) : (i32) -> ()
}
]

@[simp_denote]
def trunc_llvm_64_to_32_nuw := [LV| {
  ^entry (%lhs: i64):
    %0 = llvm.trunc %lhs overflow<nuw> : i64 to i32
    llvm.return %0 : i32
  }]

def ashr_lshr_shift_amt_mismatch_after := [llvm|
{
^0(%arg72 : i32, %arg73 : i32, %arg74 : i32):
  %0 = llvm.mlir.constant(0 : i32) : i32
  %1 = llvm.lshr %arg72, %arg73 : i32
  %2 = llvm.ashr %arg72, %arg74 : i32
  %3 = llvm.icmp "slt" %arg72, %0 : i32
  %4 = "llvm.select"(%3, %2, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def not_or_or_and_no_and_commute1_before := [llvm|
{
^0(%arg112 : i32, %arg113 : i32, %arg114 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.and %arg112, %arg113 : i32
  %2 = llvm.xor %1, %0 : i32
  %3 = llvm.xor %arg112, %0 : i32
  %4 = llvm.or %3, %arg113 : i32
  %5 = llvm.or %4, %arg114 : i32
  %6 = llvm.and %5, %2 : i32
  "llvm.return"(%6) : (i32) -> ()
}
]

inductive AttrDefn where
  | mk: (name: String) -> (val: AttrValue φ) -> AttrDefn

def udiv_exact_eq_1_before := [llvm|
{
^0(%arg10 : i8, %arg11 : i8):
  %0 = llvm.mlir.constant(1 : i8) : i8
  %1 = llvm.udiv exact %arg10, %arg11 : i8
  %2 = llvm.icmp "ne" %1, %0 : i8
  "llvm.return"(%2) : (i1) -> ()
}
]

def andn_or_cmp_4_logical_after := [llvm|
{
^0(%arg158 : i32, %arg159 : i32, %arg160 : i32):
  %0 = llvm.mlir.constant(42 : i32) : i32
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.icmp "ne" %arg158, %arg159 : i32
  %3 = llvm.icmp "ugt" %arg160, %0 : i32
  %4 = "llvm.select"(%2, %3, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def match_signed_before := [llvm|
{
^0(%arg15 : i64):
  %0 = llvm.mlir.constant(299) : i64
  %1 = llvm.mlir.constant(64) : i64
  %2 = llvm.mlir.constant(19136) : i64
  %3 = llvm.mlir.constant(9) : i64
  %4 = llvm.srem %arg15, %0 : i64
  %5 = llvm.sdiv %arg15, %0 : i64
  %6 = llvm.srem %5, %1 : i64
  %7 = llvm.sdiv %arg15, %2 : i64
  %8 = llvm.srem %7, %3 : i64
  %9 = llvm.mul %6, %0 : i64
  %10 = llvm.add %4, %9 : i64
  %11 = llvm.mul %8, %2 : i64
  %12 = llvm.add %10, %11 : i64
  "llvm.return"(%12) : (i64) -> ()
}
]

def test_with_even_before := [llvm|
{
^0(%arg313 : i32):
  %0 = llvm.mlir.constant(4 : i32) : i32
  %1 = llvm.mlir.constant(1 : i32) : i32
  %2 = llvm.shl %0, %arg313 : i32
  %3 = llvm.and %2, %1 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def urem_i32_before := [llvm|
{
^0(%arg21 : i8, %arg22 : i8):
  %0 = llvm.zext %arg21 : i8 to i32
  %1 = llvm.zext %arg22 : i8 to i32
  %2 = llvm.urem %0, %1 : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def t10_almost_highest_bit_after := [llvm|
{
^0(%arg22 : i32, %arg23 : i64, %arg24 : i32):
  %0 = llvm.mlir.constant(64 : i32) : i32
  %1 = llvm.mlir.constant(-2 : i32) : i32
  %2 = llvm.mlir.constant(0 : i32) : i32
  %3 = llvm.sub %0, %arg24 : i32
  %4 = llvm.shl %arg22, %3 : i32
  %5 = llvm.add %arg24, %1 : i32
  %6 = llvm.zext nneg %5 : i32 to i64
  %7 = llvm.lshr %arg23, %6 : i64
  %8 = llvm.trunc %7 : i64 to i32
  %9 = llvm.and %4, %8 : i32
  %10 = llvm.icmp "ne" %9, %2 : i32
  "llvm.return"(%10) : (i1) -> ()
}
]

def PR42691_8_logical_after := [llvm|
{
^0(%arg328 : i32):
  %0 = llvm.mlir.constant(2147483647 : i32) : i32
  %1 = llvm.mlir.constant(-2147483635 : i32) : i32
  %2 = llvm.add %arg328, %0 : i32
  %3 = llvm.icmp "ult" %2, %1 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def neg_nsw_sgt_1_after := [llvm|
{
^0(%arg16 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.icmp "slt" %arg16, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def not_and_and_not_commute1_before := [llvm|
{
^0(%arg561 : i32, %arg562 : i32, %arg563 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg562, %0 : i32
  %2 = llvm.xor %arg563, %0 : i32
  %3 = llvm.and %1, %arg561 : i32
  %4 = llvm.and %3, %2 : i32
  "llvm.return"(%4) : (i32) -> ()
}
]

Sum.map in Init.Data.Sum.Basic

def icmp_ne_zext_eq_one_before := [llvm|
{
^0(%arg38 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.icmp "eq" %arg38, %0 : i32
  %2 = llvm.zext %1 : i1 to i32
  %3 = llvm.icmp "ne" %2, %arg38 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def test_invalid_simplify_sub2_after := [llvm|
{
^0(%arg208 : i8):
  %0 = llvm.mlir.constant(0 : i8) : i8
  %1 = llvm.mlir.constant(-2 : i8) : i8
  %2 = llvm.icmp "eq" %arg208, %0 : i8
  %3 = llvm.add %arg208, %1 : i8
  %4 = "llvm.select"(%2, %0, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  "llvm.return"(%4) : (i8) -> ()
}
]

def test47_after := [llvm|
{
^0(%arg139 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.or %arg139, %0 : i8
  %2 = llvm.sext %1 : i8 to i32
  %3 = llvm.zext %2 : i32 to i64
  "llvm.return"(%3) : (i64) -> ()
}
]

def nonexact_lshr_ne_before := [llvm|
{
^0(%arg153 : i8):
  %0 = llvm.mlir.constant(4 : i8) : i8
  %1 = llvm.mlir.constant(1 : i8) : i8
  %2 = llvm.lshr %0, %arg153 : i8
  %3 = llvm.icmp "ne" %2, %1 : i8
  "llvm.return"(%3) : (i1) -> ()
}
]

def test_zext4_after := [llvm|
{
^0(%arg35 : i1, %arg36 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.xor %arg36, %0 : i1
  %2 = "llvm.select"(%1, %0, %arg35) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %3 = llvm.zext %2 : i1 to i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def RawCNFA.empty : RawCNFA A := {
  stateMax := 0
  initials := ∅
  finals := ∅
  trans := ∅
}

def bitwise_and_bitwise_and_icmps_comm1_before := [llvm|
{
^0(%arg241 : i8, %arg242 : i8, %arg243 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.mlir.constant(1 : i8) : i8
  %2 = llvm.mlir.constant(0 : i8) : i8
  %3 = llvm.icmp "eq" %arg242, %0 : i8
  %4 = llvm.and %arg241, %1 : i8
  %5 = llvm.shl %1, %arg243 : i8
  %6 = llvm.and %arg241, %5 : i8
  %7 = llvm.icmp "ne" %4, %2 : i8
  %8 = llvm.icmp "ne" %6, %2 : i8
  %9 = llvm.and %3, %7 : i1
  %10 = llvm.and %8, %9 : i1
  "llvm.return"(%10) : (i1) -> ()
}
]

def lshrugt_02_11_before := [llvm|
{
^0(%arg388 : i4):
  %0 = llvm.mlir.constant(2 : i4) : i4
  %1 = llvm.mlir.constant(-5 : i4) : i4
  %2 = llvm.lshr %arg388, %0 : i4
  %3 = llvm.icmp "ugt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def ugt_swap_and_min_after := [llvm|
{
^0(%arg328 : i8, %arg329 : i8):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def or_and_or_pat8_after := [llvm|
{
^0(%arg10 : i8, %arg11 : i8, %arg12 : i8, %arg13 : i8):
  %0 = llvm.or %arg13, %arg10 : i8
  %1 = llvm.and %0, %arg11 : i8
  %2 = llvm.or %1, %arg12 : i8
  "llvm.return"(%2) : (i8) -> ()
}
]

def add_nsw_mul_nsw_after := [llvm|
{
^0(%arg33 : i16):
  %0 = llvm.mlir.constant(3 : i16) : i16
  %1 = llvm.mul %arg33, %0 overflow<nsw> : i16
  "llvm.return"(%1) : (i16) -> ()
}
]

def PR42691_7_logical_before := [llvm|
{
^0(%arg330 : i32):
  %0 = llvm.mlir.constant(-2147483647 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(true) : i1
  %3 = llvm.icmp "uge" %arg330, %0 : i32
  %4 = llvm.icmp "eq" %arg330, %1 : i32
  %5 = "llvm.select"(%3, %2, %4) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%5) : (i1) -> ()
}
]

def IsBisim' (R' : Stream α → Stream α → Prop) : Prop :=
  ∀ a b, R' a b → ∃ n m,
    R' (a.drop (n+1)) (b.drop (m+1))
    ∧ a.get n = b.get m
    ∧ (∀ i < n, a.get i = none)
    ∧ (∀ j < m, b.get j = none)

def icmp_and_ashr_multiuse_logical_after := [llvm|
{
^0(%arg4 : i32):
  %0 = llvm.mlir.constant(240 : i32) : i32
  %1 = llvm.mlir.constant(224 : i32) : i32
  %2 = llvm.mlir.constant(496 : i32) : i32
  %3 = llvm.mlir.constant(432 : i32) : i32
  %4 = llvm.and %arg4, %0 : i32
  %5 = llvm.icmp "ne" %4, %1 : i32
  %6 = llvm.and %arg4, %2 : i32
  %7 = llvm.icmp "ne" %6, %3 : i32
  %8 = llvm.and %5, %7 : i1
  "llvm.return"(%8) : (i1) -> ()
}
]

def positive_with_extra_and_logical_after := [llvm|
{
^0(%arg51 : i32, %arg52 : i1):
  %0 = llvm.mlir.constant(128 : i32) : i32
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.icmp "ult" %arg51, %0 : i32
  %3 = "llvm.select"(%2, %arg52, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def add_or_and_commutative_after := [llvm|
{
^0(%arg17 : i32, %arg18 : i32):
  %0 = llvm.add %arg17, %arg18 : i32
  "llvm.return"(%0) : (i32) -> ()
}
]

def test5_before := [llvm|
{
^0(%arg2 : i700):
  %0 = llvm.mlir.constant(288230376151711743 : i700) : i700
  %1 = llvm.or %arg2, %0 : i700
  %2 = llvm.xor %1, %0 : i700
  "llvm.return"(%2) : (i700) -> ()
}
]

def icmp_ne_and_pow2_lshr_pow2_before := [llvm|
{
^0(%arg41 : i32):
  %0 = llvm.mlir.constant(8 : i32) : i32
  %1 = llvm.mlir.constant(4 : i32) : i32
  %2 = llvm.mlir.constant(0 : i32) : i32
  %3 = llvm.lshr %0, %arg41 : i32
  %4 = llvm.and %3, %1 : i32
  %5 = llvm.icmp "eq" %4, %2 : i32
  %6 = llvm.zext %5 : i1 to i32
  "llvm.return"(%6) : (i32) -> ()
}
]

def t0_before := [llvm|
{
^0(%arg42 : i32, %arg43 : i32, %arg44 : i32, %arg45 : i32):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.icmp "eq" %arg42, %arg43 : i32
  %2 = llvm.icmp "eq" %arg44, %arg45 : i32
  %3 = llvm.or %2, %1 : i1
  %4 = llvm.xor %3, %0 : i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def test_sub_nuw_nsw__all_are_safe_after := [llvm|
{
^0(%arg31 : i32):
  %0 = llvm.mlir.constant(255 : i32) : i32
  %1 = llvm.mlir.constant(-254 : i32) : i32
  %2 = llvm.and %arg31, %0 : i32
  %3 = llvm.sub %1, %2 overflow<nsw,nuw> : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def icmp_ule_64_after := [llvm|
{
^0(%arg17 : i128):
  %0 = llvm.mlir.constant(0 : i128) : i128
  %1 = llvm.icmp "eq" %arg17, %0 : i128
  "llvm.return"(%1) : (i1) -> ()
}
]

def irc_constants_C2MinusAPlusC1_1_0 : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (1) : i64
      %c2 = llvm.mlir.constant (0) : i64
      %0 = llvm.add %a, %c1 : i64
      %1 = llvm.sub %c2, %0 : i64
      llvm.return %1 : i64
  }]
  rhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (1) : i64
      %c2 = llvm.mlir.constant (0) : i64
      %0 = llvm.sub %c2, %c1 : i64
      %1 = llvm.sub %0, %a : i64
      llvm.return %1 : i64
  }]

def test6a_after := [llvm|
{
^0(%arg1 : i1):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def not_or_neg_after := [llvm|
{
^0(%arg79 : i8, %arg80 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.add %arg80, %0 : i8
  %2 = llvm.xor %arg79, %0 : i8
  %3 = llvm.and %1, %2 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

instance : ToString (MetaLLVM φ).Ty := ⟨MetaLLVM.printType⟩

def uge_swap_and_max_logical_before := [llvm|
{
^0(%arg228 : i8, %arg229 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.icmp "ule" %arg229, %arg228 : i8
  %3 = llvm.icmp "eq" %arg228, %0 : i8
  %4 = "llvm.select"(%2, %3, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def icmp_power2_and_icmp_shifted_mask_8_7_before := [llvm|
{
^0(%arg37 : i32):
  %0 = llvm.mlir.constant(8 : i32) : i32
  %1 = llvm.mlir.constant(7 : i32) : i32
  %2 = llvm.icmp "ult" %arg37, %0 : i32
  %3 = llvm.and %arg37, %1 : i32
  %4 = llvm.icmp "ne" %3, %1 : i32
  %5 = llvm.and %2, %4 : i1
  "llvm.return"(%5) : (i1) -> ()
}
]

def sextinreg_alt_after := [llvm|
{
^0(%arg11 : i32):
  %0 = llvm.mlir.constant(16 : i32) : i32
  %1 = llvm.shl %arg11, %0 : i32
  %2 = llvm.ashr exact %1, %0 : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def lshrugt_03_01_exact_before := [llvm|
{
^0(%arg188 : i4):
  %0 = llvm.mlir.constant(3 : i4) : i4
  %1 = llvm.mlir.constant(1 : i4) : i4
  %2 = llvm.lshr exact %arg188, %0 : i4
  %3 = llvm.icmp "ugt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def test47_before := [llvm|
{
^0(%arg139 : i8):
  %0 = llvm.mlir.constant(42 : i32) : i32
  %1 = llvm.sext %arg139 : i8 to i32
  %2 = llvm.or %1, %0 : i32
  %3 = llvm.zext %2 : i32 to i64
  "llvm.return"(%3) : (i64) -> ()
}
]

def solve (gorig : MVarId) : SolverM Unit := do
  
  
  
  match ← gorig.withContext (Normalize.runPreprocessing gorig) with
  | none => debugLog m!"Preprocessing automatically closed goal."
  | some g => g.withContext do
    debugLog m!"goal after preprocessing: {indentD g}"
    let collect : CollectState := {}
    let pRawExpr ← inferType (.mvar g)
    debugLog m!"collecting raw expr '{pRawExpr}'."
    let (p, collect) ← collectBVPredicateAux collect pRawExpr
    debugLog m!"collected predicate: '{repr p}' for raw expr."
    let tctx ← collect.mkTctxExpr
    let wenv ← collect.mkWenvExpr
    let tenv ← collect.mkTenvExpr (wenv := wenv) (_tctx := tctx)
    let benv ← collect.mkBenvExpr
    let nenv ← collect.mkNenvExpr
    let ienv ← collect.mkIenvExpr
    let penv ← collect.mkPenvExpr
    if (← read).debugPrintSmtLib then
      throwError (p.toSmtLib |>.toSexpr |> format)
    let pExpr ← Expr.mkPredicateExpr collect.wcard collect.tcard collect.bcard collect.ncard collect.icard collect.pcard tctx p
    let pNondepExpr := Lean.ToExpr.toExpr p
    let termFsmNondep := mkTermFsmNondep collect.wcard collect.tcard collect.bcard collect.ncard collect.icard collect.pcard p
    debugLog m!"fsm from MultiWidth.mkTermFsmNondep {collect.wcard} {collect.tcard} {repr p}."
    debugLog m!"fsm circuit size: {termFsmNondep.toFsmZext.circuitSize}"
    if ! (← isDefEq pRawExpr (← mkAppM ``Term.toBV #[benv, nenv, ienv, penv, tenv, pExpr])) then
      throwError m!"internal error: collected predicate expression does not match original predicate. Collected: {indentD pExpr}, original: {indentD pRawExpr}"
    let (stats, _log) ← FSM.decideIfZerosVerified termFsmNondep.toFsmZext (maxIter := (← read).niter) (startVerifyAtIter := (← read).startVerifyAtIter)
    if let some filename := (← read).debugDumpAiger then
      let fn := System.mkFilePath [filename]
      let handle ← IO.FS.Handle.mk fn IO.FS.Mode.write
      let stream := IO.FS.Stream.ofHandle handle
      termFsmNondep.toFsmZext.toAiger.toAagFile stream

    let (stats, _log) ← FSM.decideIfZerosVerified termFsmNondep.toFsmZext (maxIter := (← read).niter) (startVerifyAtIter := (← read).startVerifyAtIter)
    match stats with
    | .safetyFailure i =>
      let suspiciousVars ← collect.logSuspiciousFvars
      
      if suspiciousVars.isEmpty then
          throwError m!"CEX: Found exact counter-example at iteration {i} for predicate '{pRawExpr}'"
        else
          throwError m!"MAYCEX: Found possible counter-example at iteration {i} for predicate '{pRawExpr}'"
    | .exhaustedIterations _ =>
      let _ ← collect.logSuspiciousFvars
      throwError m!"PROOFNOTFOUND: exhausted iterations for predicate '{pRawExpr}'"
    | .provenByKIndCycleBreaking niters safetyCert indCert =>
      if (← read).verbose? then
        let _ ← collect.logSuspiciousFvars
      debugLog m!"PROVE: proven {pRawExpr}"
      let prf ← g.withContext <| do
        let termNondepFsmExpr ← Expr.mkTermFsmNondep collect.wcard collect.tcard collect.bcard collect.ncard collect.icard collect.pcard pNondepExpr
        debugCheck termNondepFsmExpr
        
        
        let fsmExpr ← mkAppM (``MultiWidth.TermFSM.toFsmZext) #[termNondepFsmExpr]
        
        let circsExpr ← Expr.KInductionCircuits.mkN fsmExpr (toExpr niters)
        let circsLawfulExpr ← Expr.KInductionCircuits.mkIsLawful_mkN fsmExpr (toExpr niters)
        debugLog "making safety certs..."
        
        let verifyCircuitMkSafetyCircuitExpr ← Expr.mkVerifyCircuit
          (← Expr.KInductionCircuits.mkMkSafetyCircuit circsExpr)
          (toExpr safetyCert)
        
        debugLog "making safety cert = true proof..."
        let safetyCertProof ←
          mkEqReflBoolNativeDecideProof `safetyCert verifyCircuitMkSafetyCircuitExpr true
        
        let verifyCircuitMkIndHypCircuitExpr ← Expr.mkVerifyCircuit
            (← Expr.KInductionCircuits.mkIndHypCycleBreaking circsExpr)
            (toExpr indCert)
        
        let indCertProof ←
          mkEqReflBoolNativeDecideProof `indCert verifyCircuitMkIndHypCircuitExpr true
        debugLog m!"made induction cert = true proof..."
        let prf ← mkAppM ``MultiWidth.Term.toBV_of_KInductionCircuits'
          #[pRawExpr, 
            tctx,
            pExpr, 
            pNondepExpr, 
            ← mkEqRefl pNondepExpr, 
            termNondepFsmExpr, 
            ← mkEqRefl termNondepFsmExpr,
            toExpr niters,
            circsExpr,
            circsLawfulExpr,
            toExpr safetyCert,
            safetyCertProof,
            toExpr indCert,
            indCertProof,
            wenv,
            tenv,
            benv,
            nenv,
            ienv,
            penv,
            ← mkEqRefl pRawExpr]
        debugCheck prf
        let prf ←
          if (← read).debugFillFinalReflectionProofWithSorry then
            mkSorry (synthetic := true) (← g.getType)
          else
            instantiateMVars prf
        pure prf
      let gs ← g.apply prf
      if gs.isEmpty then
        debugLog m!"unified goal with proof."
      else
        let mut msg := m!"Expected proof cerificate to close goal, but failed. Leftover goals:"
        for g in gs do
          msg := msg ++ m!"{indentD g}"
        throwError msg

def positive_trunc_base_after := [llvm|
{
^0(%arg39 : i32):
  %0 = llvm.mlir.constant(65408 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.and %arg39, %0 : i32
  %3 = llvm.icmp "eq" %2, %1 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def and_orn_cmp_1_logical_before := [llvm|
{
^0(%arg128 : i32, %arg129 : i32, %arg130 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.icmp "sgt" %arg128, %arg129 : i32
  %3 = llvm.icmp "sle" %arg128, %arg129 : i32
  %4 = "llvm.select"(%arg130, %0, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %5 = "llvm.select"(%2, %4, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%5) : (i1) -> ()
}
]

def srem8_ashr_mask_before := [llvm|
{
^0(%arg5 : i32):
  %0 = llvm.mlir.constant(8 : i32) : i32
  %1 = llvm.mlir.constant(31 : i32) : i32
  %2 = llvm.mlir.constant(2 : i32) : i32
  %3 = llvm.srem %arg5, %0 : i32
  %4 = llvm.ashr %3, %1 : i32
  %5 = llvm.and %4, %2 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def alive_Select_1100_src  (w : Nat)   :=
[llvm( w )| {
^bb0(%Y : _, %X : _):
  %v1 = llvm.mlir.constant 1 :  i1
  %v2 = llvm.select %v1, %X, %Y
  llvm.return %v2
}]

def t0_commutative_after := [llvm|
{
^0(%arg36 : i1, %arg37 : i8, %arg38 : i8, %arg39 : i8, %arg40 : i8):
  %0 = llvm.mlir.constant(false) : i1
  %1 = llvm.icmp "ne" %arg37, %arg38 : i8
  %2 = "llvm.select"(%1, %arg36, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %3 = "llvm.select"(%2, %arg40, %arg39) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def ValueStream := Stream

List.Mem in Init.Data.List.Basic

def n11_uge_slt_after := [llvm|
{
^0(%arg45 : i32, %arg46 : i32, %arg47 : i32):
  %0 = llvm.mlir.constant(129 : i32) : i32
  %1 = llvm.icmp "ult" %arg45, %0 : i32
  %2 = "llvm.select"(%1, %arg47, %arg45) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def main6_logical_after := [llvm|
{
^0(%arg93 : i32):
  %0 = llvm.mlir.constant(55 : i32) : i32
  %1 = llvm.mlir.constant(19 : i32) : i32
  %2 = llvm.and %arg93, %0 : i32
  %3 = llvm.icmp "ne" %2, %1 : i32
  %4 = llvm.zext %3 : i1 to i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def composeQuinaryAux' (p : FSM (Fin 5)) (q₀ q₁ q₂ q₃ q₄: FSM α) : FSM α :=
  p.compose (α)
    (λ _ => α)
    (λ _ i => i)
    (λ v =>
      v.cases q₀ fun v =>
        v.cases q₁ fun v =>
          v.cases q₂ fun v =>
            v.cases q₃ fun v =>
              v.cases q₄ fun v => v.elim0)

def product.inits_nodup : inits m₁ m₂ |>.toList.Nodup :=

def llvm_const_lower_riscv_li_22 : LLVMPeepholeRewriteRefine 64 [] :=
  {lhs := constLLVM_22, rhs:= liRiscv_22,
   correct := by admit /- proof elided -/

def or_not_and_commute3_before := [llvm|
{
^0(%arg528 : i32, %arg529 : i32, %arg530 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.or %arg529, %arg528 : i32
  %2 = llvm.xor %1, %0 : i32
  %3 = llvm.and %2, %arg530 : i32
  %4 = llvm.or %arg530, %arg528 : i32
  %5 = llvm.xor %4, %0 : i32
  %6 = llvm.and %5, %arg529 : i32
  %7 = llvm.or %3, %6 : i32
  "llvm.return"(%7) : (i32) -> ()
}
]

instance : HydrableGetIdentityAndAbsorptionConstraints GenBVPred where
  getIdentityAndAbsorptionConstraints := getIdentityAndAbsorptionConstraints

def test23_after := [llvm|
{
^0(%arg8 : i44):
  %0 = llvm.trunc %arg8 : i44 to i11
  "llvm.return"(%0) : (i11) -> ()
}
]

def fold_mask_cmps_to_false_before := [llvm|
{
^0(%arg111 : i32):
  %0 = llvm.mlir.constant(2147483647 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.and %arg111, %0 : i32
  %3 = llvm.icmp "eq" %2, %1 : i32
  %4 = llvm.icmp "eq" %arg111, %0 : i32
  %5 = llvm.and %4, %3 : i1
  "llvm.return"(%5) : (i1) -> ()
}
]

cast in Init.Prelude

def cmpeq_xor_cst3_before := [llvm|
{
^0(%arg22 : i32, %arg23 : i32):
  %0 = llvm.mlir.constant(10 : i32) : i32
  %1 = llvm.xor %arg22, %0 : i32
  %2 = llvm.xor %arg23, %0 : i32
  %3 = llvm.icmp "eq" %1, %2 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def test18a_after := [llvm|
{
^0(%arg280 : i8):
  %0 = llvm.mlir.constant(2 : i8) : i8
  %1 = llvm.icmp "ult" %arg280, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def llvm_const_lower_riscv_li48 : LLVMPeepholeRewriteRefine 64 [] :=
  {lhs := constLLVM48, rhs:= liRiscv48,
   correct := by admit /- proof elided -/

def positive_biggershl_shlnsw_lshrexact_before := [llvm|
{
^0(%arg34 : i8):
  %0 = llvm.mlir.constant(3 : i8) : i8
  %1 = llvm.mlir.constant(6 : i8) : i8
  %2 = llvm.lshr exact %arg34, %0 : i8
  %3 = llvm.shl %2, %1 overflow<nsw> : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def sendReadySignal (_ : Unit) (tok : Unit) : Unit := tok

def test_after := [llvm|
{
^0(%arg0 : i26):
  "llvm.return"(%arg0) : (i26) -> ()
}
]

def reduce_xor_common_op_commute0_before := [llvm|
{
^0(%arg10 : i4, %arg11 : i4, %arg12 : i4):
  %0 = llvm.xor %arg10, %arg11 : i4
  %1 = llvm.xor %0, %arg12 : i4
  %2 = llvm.or %1, %arg10 : i4
  "llvm.return"(%2) : (i4) -> ()
}
]

def ashrslt_02_05_before := [llvm|
{
^0(%arg248 : i4):
  %0 = llvm.mlir.constant(2 : i4) : i4
  %1 = llvm.mlir.constant(5 : i4) : i4
  %2 = llvm.ashr %arg248, %0 : i4
  %3 = llvm.icmp "slt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def lshrult_02_00_after := [llvm|
{
^0(%arg351 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def test_after := [llvm|
{
^0(%arg0 : i32):
  "llvm.return"(%arg0) : (i32) -> ()
}
]

def lshr_exact_after := [llvm|
{
^0(%arg183 : i8):
  %0 = llvm.mlir.constant(1 : i8) : i8
  %1 = llvm.mlir.constant(63 : i8) : i8
  %2 = llvm.add %arg183, %0 : i8
  %3 = llvm.and %2, %1 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def or_logic_or_logic_and_4_after := [llvm|
{
^0(%arg39 : i1, %arg40 : i1, %arg41 : i1):
  %0 = llvm.mlir.constant(false) : i1
  %1 = "llvm.select"(%arg41, %arg40, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %2 = llvm.or %arg39, %1 : i1
  "llvm.return"(%2) : (i1) -> ()
}
]

def test48_after := [llvm|
{
^0(%arg137 : i8, %arg138 : i8):
  %0 = llvm.mlir.constant(8 : i32) : i32
  %1 = llvm.zext %arg137 : i8 to i32
  %2 = llvm.shl %1, %0 overflow<nsw,nuw> : i32
  %3 = llvm.or disjoint %2, %1 : i32
  %4 = llvm.zext nneg %3 : i32 to i64
  "llvm.return"(%4) : (i64) -> ()
}
]

Mod in Init.Prelude

def ashrsgt_03_12_before := [llvm|
{
^0(%arg273 : i4):
  %0 = llvm.mlir.constant(3 : i4) : i4
  %1 = llvm.mlir.constant(-4 : i4) : i4
  %2 = llvm.ashr %arg273, %0 : i4
  %3 = llvm.icmp "sgt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def ashr_ugt_14_after := [llvm|
{
^0(%arg100 : i4):
  %0 = llvm.mlir.constant(-3 : i4) : i4
  %1 = llvm.icmp "ugt" %arg100, %0 : i4
  "llvm.return"(%1) : (i1) -> ()
}
]

def ashr_slt_noexact_after := [llvm|
{
^0(%arg155 : i8):
  %0 = llvm.mlir.constant(80 : i8) : i8
  %1 = llvm.icmp "slt" %arg155, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def BinaryRelationKind.toSmtLib : BinaryRelationKind → SexprPBV.BinaryRelationKind
| .eq => .eq
| .ne => .ne
| .ule => .ule
| .slt => .slt
| .sle => .sle
| .ult => .ult

@[simp_denote]
def xor_riscv_i32 :=
  [LV| {
    ^entry (%arg0: i32, %arg1: i32):
    %a = "builtin.unrealized_conversion_cast" (%arg0) : (i32) -> (!i64)
    %b = "builtin.unrealized_conversion_cast" (%arg1) : (i32) -> (!i64)
    %0 = xor %a, %b : !i64
    %1 = "builtin.unrealized_conversion_cast" (%0) : (!i64) -> (i32)
    llvm.return %1 : i32
  }]

def sub_select_sext_op_swapped_non_const_args_before := [llvm|
{
^0(%arg6 : i1, %arg7 : i6, %arg8 : i6):
  %0 = "llvm.select"(%arg6, %arg7, %arg8) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i6, i6) -> i6
  %1 = llvm.sext %arg6 : i1 to i6
  %2 = llvm.sub %1, %0 : i6
  "llvm.return"(%2) : (i6) -> ()
}
]

def test3_after := [llvm|
{
^0(%arg0 : i599, %arg1 : i1):
  %0 = llvm.mlir.constant(46 : i599) : i599
  %1 = llvm.mlir.constant(12 : i599) : i599
  %2 = "llvm.select"(%arg1, %0, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i599, i599) -> i599
  %3 = llvm.lshr %arg0, %2 : i599
  "llvm.return"(%3) : (i599) -> ()
}
]

def annihilate_xor_common_op_commute2_before := [llvm|
{
^0(%arg3 : i4, %arg4 : i4, %arg5 : i4, %arg6 : i4):
  %0 = llvm.mul %arg5, %arg5 : i4
  %1 = llvm.xor %arg3, %arg4 : i4
  %2 = llvm.xor %0, %1 : i4
  %3 = llvm.xor %2, %arg6 : i4
  %4 = llvm.xor %3, %arg3 : i4
  "llvm.return"(%4) : (i4) -> ()
}
]

def add_const_const_sub_nuw_before := [llvm|
{
^0(%arg54 : i8):
  %0 = llvm.mlir.constant(1 : i8) : i8
  %1 = llvm.mlir.constant(-127 : i8) : i8
  %2 = llvm.add %arg54, %0 : i8
  %3 = llvm.sub %1, %2 overflow<nuw> : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def test11_after := [llvm|
{
^0(%arg43 : i1):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

instance {d : Dialect} [TyDenote d.Ty] [DialectSignature d] [DialectDenote d] :
    Coe d.Op (Scf d).Op where
  coe o := .coe o

def ule_umax2_after := [llvm|
{
^0(%arg50 : i32, %arg51 : i32):
  %0 = llvm.icmp "ule" %arg51, %arg50 : i32
  "llvm.return"(%0) : (i1) -> ()
}
]

def irc_constants_C2MinusAPlusC1_neg1_neg1 : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (-1) : i64
      %c2 = llvm.mlir.constant (-1) : i64
      %0 = llvm.add %a, %c1 : i64
      %1 = llvm.sub %c2, %0 : i64
      llvm.return %1 : i64
  }]
  rhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (-1) : i64
      %c2 = llvm.mlir.constant (-1) : i64
      %0 = llvm.sub %c2, %c1 : i64
      %1 = llvm.sub %0, %a : i64
      llvm.return %1 : i64
  }]

def add32_sext_accept_test : LLVMPeepholeRewriteRefine 32 [Ty.llvm (.bitvec 32)] where
  lhs := add32_sext_accept_llvm
  rhs :=  add32_sext_accept_riscv

def shl_match : List (Σ Γ, Σ ty, PeepholeRewrite LLVMPlusRiscV Γ ty) := [
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_8),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nsw_8),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nsw_nuw_8),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nuw_8),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_16),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nsw_16),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nsw_nuw_16),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nuw_16),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_32),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nsw_32),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nsw_nuw_32),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nuw_32),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_64),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nsw_64),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nsw_nuw_64),
  mkRewrite (LLVMToRiscvPeepholeRewriteRefine.toPeepholeUNSOUND llvm_shl_lower_riscv_nuw_64)
]

def lshrult_01_10_after := [llvm|
{
^0(%arg357 : i4):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def Valuation.equivHVector {Γ : List Ty} : Valuation ⟨Γ⟩ ≃ HVector toType Γ where
  toFun V   := HVector.ofFn _ _ <| fun i => V ⟨i, by admit /- proof elided -/
  ⟩
  invFun    := Valuation.ofHVector
  left_inv V := by admit /- proof elided -/

def test4_after := [llvm|
{
^0(%arg0 : i1023):
  %0 = llvm.mlir.constant(1022 : i1023) : i1023
  %1 = llvm.ashr %arg0, %0 : i1023
  "llvm.return"(%1) : (i1023) -> ()
}
]

def ne_smax4_before := [llvm|
{
^0(%arg41 : i32, %arg42 : i32):
  %0 = llvm.mlir.constant(3 : i32) : i32
  %1 = llvm.add %arg41, %0 : i32
  %2 = llvm.icmp "sgt" %arg42, %1 : i32
  %3 = "llvm.select"(%2, %arg42, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %4 = llvm.icmp "ne" %1, %3 : i32
  "llvm.return"(%4) : (i1) -> ()
}
]

@[match_pattern] abbrev add (w : Nat) (flags: NoWrapFlags := {}) : LLVM.Op := MOp.add (.concrete w) flags

def masked_icmps_mask_notallzeros_bmask_mixed_7b_after := [llvm|
{
^0(%arg76 : i32):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def xor_or_xor_common_op_commute2_after := [llvm|
{
^0(%arg77 : i32, %arg78 : i32, %arg79 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg77, %0 : i32
  %2 = llvm.and %arg78, %1 : i32
  %3 = llvm.xor %2, %arg79 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def and_logic_and_logic_or_3_before := [llvm|
{
^0(%arg132 : i1, %arg133 : i1, %arg134 : i1):
  %0 = llvm.mlir.constant(false) : i1
  %1 = llvm.mlir.constant(true) : i1
  %2 = llvm.and %arg133, %arg132 : i1
  %3 = "llvm.select"(%arg132, %arg134, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %4 = "llvm.select"(%2, %1, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def or_and_or_pat2_before := [llvm|
{
^0(%arg34 : i8, %arg35 : i8, %arg36 : i8, %arg37 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.udiv %0, %arg36 : i8
  %2 = llvm.and %arg34, %arg35 : i8
  %3 = llvm.and %arg37, %arg34 : i8
  %4 = llvm.or %1, %3 : i8
  %5 = llvm.or %2, %4 : i8
  "llvm.return"(%5) : (i8) -> ()
}
]

def and_sequence_20_lhs (w : Nat)   :=
[llvm( w )| {
^bb0(%C1 : _, %Z : _):
  %v1 = llvm.and %Z, %C1
  %v2 = llvm.and %v1, %C1
  %v3 = llvm.and %v2, %C1
  %v4 = llvm.and %v3, %C1
  %v5 = llvm.and %v4, %C1
  %v6 = llvm.and %v5, %C1
  %v7 = llvm.and %v6, %C1
  %v8 = llvm.and %v7, %C1
  %v9 = llvm.and %v8, %C1
  %v10 = llvm.and %v9, %C1
  %v11 = llvm.and %v10, %C1
  %v12 = llvm.and %v11, %C1
  %v13 = llvm.and %v12, %C1
  %v14 = llvm.and %v13, %C1
  %v15 = llvm.and %v14, %C1
  %v16 = llvm.and %v15, %C1
  %v17 = llvm.and %v16, %C1
  %v18 = llvm.and %v17, %C1
  %v19 = llvm.and %v18, %C1
  %v20 = llvm.and %v19, %C1
  llvm.return %v20
}]

def ugt_swap_or_not_min_logical_after := [llvm|
{
^0(%arg4 : i8, %arg5 : i8):
  %0 = llvm.mlir.constant(0 : i8) : i8
  %1 = llvm.icmp "ne" %arg4, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def trunc_shl_lshr_infloop_after := [llvm|
{
^0(%arg41 : i64):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.mlir.constant(-4 : i32) : i32
  %2 = llvm.trunc %arg41 : i64 to i32
  %3 = llvm.shl %2, %0 : i32
  %4 = llvm.and %3, %1 : i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def or_xor_common_op_commute5_after := [llvm|
{
^0(%arg120 : i8, %arg121 : i8, %arg122 : i8):
  %0 = llvm.or %arg121, %arg120 : i8
  %1 = llvm.or %0, %arg122 : i8
  "llvm.return"(%1) : (i8) -> ()
}
]

def shl_or_lshr_before := [llvm|
{
^0(%arg112 : i32, %arg113 : i32, %arg114 : i32):
  %0 = llvm.shl %arg112, %arg113 overflow<nuw> : i32
  %1 = llvm.or %0, %arg114 : i32
  %2 = llvm.lshr %1, %arg113 : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def ashr_ugt_2_after := [llvm|
{
^0(%arg112 : i4):
  %0 = llvm.mlir.constant(5 : i4) : i4
  %1 = llvm.icmp "ugt" %arg112, %0 : i4
  "llvm.return"(%1) : (i1) -> ()
}
]

def ashr_ult_7_after := [llvm|
{
^0(%arg89 : i4):
  %0 = llvm.mlir.constant(-1 : i4) : i4
  %1 = llvm.icmp "sgt" %arg89, %0 : i4
  "llvm.return"(%1) : (i1) -> ()
}
]

def bool_add_lshr_after := [llvm|
{
^0(%arg14 : i1, %arg15 : i1):
  %0 = llvm.and %arg14, %arg15 : i1
  %1 = llvm.zext %0 : i1 to i2
  "llvm.return"(%1) : (i2) -> ()
}
]

def neg_sgt_0_after := [llvm|
{
^0(%arg23 : i8):
  %0 = llvm.mlir.constant(-128 : i8) : i8
  %1 = llvm.icmp "ugt" %arg23, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

inductive FpBinOp
| add
deriving Hashable, DecidableEq, Repr

def slt_swap_or_not_max_commute_logical_after := [llvm|
{
^0(%arg48 : i8, %arg49 : i8):
  %0 = llvm.mlir.constant(127 : i8) : i8
  %1 = llvm.icmp "ne" %arg48, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def uaddo_wrong_pred2_before := [llvm|
{
^0(%arg4 : i32, %arg5 : i32, %arg6 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg5, %0 : i32
  %2 = llvm.add %arg4, %arg5 : i32
  %3 = llvm.icmp "uge" %arg4, %1 : i32
  %4 = "llvm.select"(%3, %arg6, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def test2_before := [llvm|
{
^0(%arg0 : i999, %arg1 : i999):
  %0 = llvm.mlir.constant(65280 : i999) : i999
  %1 = llvm.and %arg0, %0 : i999
  %2 = llvm.and %arg1, %0 : i999
  %3 = llvm.icmp "ne" %1, %2 : i999
  "llvm.return"(%3) : (i1) -> ()
}
]

def or_not_and_commute9_before := [llvm|
{
^0(%arg510 : i32, %arg511 : i32, %arg512 : i32):
  %0 = llvm.mlir.constant(42 : i32) : i32
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.sdiv %0, %arg510 : i32
  %3 = llvm.sdiv %0, %arg511 : i32
  %4 = llvm.sdiv %0, %arg512 : i32
  %5 = llvm.or %2, %3 : i32
  %6 = llvm.xor %5, %1 : i32
  %7 = llvm.and %6, %4 : i32
  %8 = llvm.or %2, %4 : i32
  %9 = llvm.xor %8, %1 : i32
  %10 = llvm.and %3, %9 : i32
  %11 = llvm.or %7, %10 : i32
  "llvm.return"(%11) : (i32) -> ()
}
]

def lshrult_01_00_exact_before := [llvm|
{
^0(%arg149 : i4):
  %0 = llvm.mlir.constant(1 : i4) : i4
  %1 = llvm.mlir.constant(0 : i4) : i4
  %2 = llvm.lshr exact %arg149, %0 : i4
  %3 = llvm.icmp "ult" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def zext_shl_after := [llvm|
{
^0(%arg10 : i8):
  %0 = llvm.mlir.constant(3 : i8) : i8
  %1 = llvm.shl %arg10, %0 : i8
  %2 = llvm.and %1, %arg10 : i8
  %3 = llvm.zext %2 : i8 to i16
  "llvm.return"(%3) : (i16) -> ()
}
]

def pr40493_neg1_before := [llvm|
{
^0(%arg17 : i32):
  %0 = llvm.mlir.constant(11 : i32) : i32
  %1 = llvm.mlir.constant(4 : i32) : i32
  %2 = llvm.mlir.constant(0 : i32) : i32
  %3 = llvm.mul %arg17, %0 : i32
  %4 = llvm.and %3, %1 : i32
  %5 = llvm.icmp "eq" %4, %2 : i32
  "llvm.return"(%5) : (i1) -> ()
}
]

def select_icmp_ne_not_pow2_before := [llvm|
{
^0(%arg8 : i8):
  %0 = llvm.mlir.constant(5 : i8) : i8
  %1 = llvm.mlir.constant(0 : i8) : i8
  %2 = llvm.and %arg8, %0 : i8
  %3 = llvm.icmp "ne" %2, %1 : i8
  %4 = llvm.xor %arg8, %0 : i8
  %5 = "llvm.select"(%3, %4, %arg8) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  "llvm.return"(%5) : (i8) -> ()
}
]

def no_shift_xor_multiuse_cmp_before := [llvm|
{
^0(%arg96 : i32, %arg97 : i32, %arg98 : i32, %arg99 : i32):
  %0 = llvm.mlir.constant(4096 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.and %arg96, %0 : i32
  %3 = llvm.icmp "ne" %1, %2 : i32
  %4 = llvm.or %arg97, %0 : i32
  %5 = "llvm.select"(%3, %arg97, %4) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %6 = "llvm.select"(%3, %arg98, %arg99) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %7 = llvm.mul %5, %6 : i32
  "llvm.return"(%7) : (i32) -> ()
}
]

def test9_after := [llvm|
{
^0(%arg72 : i32):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.trunc %arg72 : i32 to i8
  %2 = llvm.and %1, %0 : i8
  "llvm.return"(%2) : (i8) -> ()
}
]

def compose [FinEnum arity] [DecidableEq arity] [Hashable arity]
    (new_arity : Type)        
    (q_arity : arity → Type)  
    (vars : ∀ (a : arity), q_arity a → new_arity)
    
    
    (q : ∀ (a : arity), FSM (q_arity a)) : 
    FSM new_arity :=
  { α := p.α ⊕ (Σ a, (q a).α),
    i := by admit /- proof elided -/

def shl_bad_sub2_i32_after := [llvm|
{
^0(%arg10 : i32):
  %0 = llvm.mlir.constant(-31 : i32) : i32
  %1 = llvm.mlir.constant(1 : i32) : i32
  %2 = llvm.add %arg10, %0 : i32
  %3 = llvm.shl %1, %2 overflow<nuw> : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def ashrsgt_02_03_exact_before := [llvm|
{
^0(%arg82 : i4):
  %0 = llvm.mlir.constant(2 : i4) : i4
  %1 = llvm.mlir.constant(3 : i4) : i4
  %2 = llvm.ashr exact %arg82, %0 : i4
  %3 = llvm.icmp "sgt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def trunc_signed_both_before := [llvm|
{
^0(%arg48 : i16, %arg49 : i16):
  %0 = llvm.trunc %arg48 overflow<nsw,nuw> : i16 to i8
  %1 = llvm.trunc %arg49 overflow<nsw,nuw> : i16 to i8
  %2 = llvm.icmp "slt" %0, %1 : i8
  "llvm.return"(%2) : (i1) -> ()
}
]

def lshrugt_01_10_after := [llvm|
{
^0(%arg405 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def zext_sext_add_icmp_sgt_0_before := [llvm|
{
^0(%arg76 : i1, %arg77 : i1):
  %0 = llvm.mlir.constant(0 : i8) : i8
  %1 = llvm.zext %arg76 : i1 to i8
  %2 = llvm.sext %arg77 : i1 to i8
  %3 = llvm.add %1, %2 : i8
  %4 = llvm.icmp "sgt" %3, %0 : i8
  "llvm.return"(%4) : (i1) -> ()
}
]

def sub_inc_before := [llvm|
{
^0(%arg10 : i8, %arg11 : i8):
  %0 = llvm.mlir.constant(1 : i8) : i8
  %1 = llvm.add %arg10, %0 : i8
  %2 = llvm.sub %arg11, %1 : i8
  "llvm.return"(%2) : (i8) -> ()
}
]

def PR42691_10_after := [llvm|
{
^0(%arg325 : i32):
  %0 = llvm.mlir.constant(-14 : i32) : i32
  %1 = llvm.mlir.constant(-15 : i32) : i32
  %2 = llvm.add %arg325, %0 : i32
  %3 = llvm.icmp "ult" %2, %1 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def shrink_or_after := [llvm|
{
^0(%arg11 : i6):
  %0 = llvm.mlir.constant(1 : i3) : i3
  %1 = llvm.trunc %arg11 : i6 to i3
  %2 = llvm.or %1, %0 : i3
  "llvm.return"(%2) : (i3) -> ()
}
]

def scalar_i32_shl_and_signbit_eq_X_is_constant1_after := [llvm|
{
^0(%arg5 : i32):
  %0 = llvm.mlir.constant(12345 : i32) : i32
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.shl %0, %arg5 : i32
  %3 = llvm.icmp "sgt" %2, %1 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

abbrev Term.Ctx.Env
  (tctx : Term.Ctx wcard tcard)
  (wenv : WidthExpr.Env wcard) :=
  (v : Fin tcard) → BitVec ((tctx v).toNat wenv)

def test4_after := [llvm|
{
^0(%arg1 : i8):
  %0 = llvm.mlir.constant(127 : i8) : i8
  %1 = llvm.icmp "ne" %arg1, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def not_ashr_not_before := [llvm|
{
^0(%arg139 : i32, %arg140 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg139, %0 : i32
  %2 = llvm.ashr %1, %arg140 : i32
  %3 = llvm.xor %2, %0 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def lshrult_02_05_exact_after := [llvm|
{
^0(%arg128 : i4):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def select_of_truncate : List (Σ Γ, LLVMPeepholeRewriteRefine 32 Γ) :=
  [⟨_, select_of_truncate_rw⟩]

def lshr_and_or_before := [llvm|
{
^0(%arg45 : i8, %arg46 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.mlir.constant(2 : i8) : i8
  %2 = llvm.mlir.constant(13 : i8) : i8
  %3 = llvm.srem %arg45, %0 : i8
  %4 = llvm.lshr %arg46, %1 : i8
  %5 = llvm.and %4, %2 : i8
  %6 = llvm.or %3, %5 : i8
  %7 = llvm.shl %6, %1 : i8
  "llvm.return"(%7) : (i8) -> ()
}
]

def Expr.getTy : Expr d Γ eff [t] → Type := fun _ => d.Ty

def land_lor_right1_before := [llvm|
{
^0(%arg46 : i1, %arg47 : i1):
  %0 = llvm.mlir.constant(false) : i1
  %1 = llvm.mlir.constant(true) : i1
  %2 = "llvm.select"(%arg46, %arg47, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %3 = "llvm.select"(%arg46, %1, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def ashrslt_03_10_after := [llvm|
{
^0(%arg227 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def ashrsgt_03_15_exact_after := [llvm|
{
^0(%arg54 : i4):
  %0 = llvm.mlir.constant(-1 : i4) : i4
  %1 = llvm.icmp "sgt" %arg54, %0 : i4
  "llvm.return"(%1) : (i1) -> ()
}
]

def sext_ule_sext_after := [llvm|
{
^0(%arg119 : i1, %arg120 : i8):
  %0 = llvm.mlir.constant(0 : i8) : i8
  %1 = llvm.mul %arg120, %arg120 : i8
  %2 = llvm.icmp "eq" %1, %0 : i8
  %3 = llvm.or %2, %arg119 : i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def main6b_logical_after := [llvm|
{
^0(%arg91 : i32):
  %0 = llvm.mlir.constant(23 : i32) : i32
  %1 = llvm.mlir.constant(19 : i32) : i32
  %2 = llvm.and %arg91, %0 : i32
  %3 = llvm.icmp "ne" %2, %1 : i32
  %4 = llvm.zext %3 : i1 to i32
  "llvm.return"(%4) : (i32) -> ()
}
]

List.sum in Init.Data.List.Basic

def irc_constants_C1Minus2MinusC2_0_neg1 : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (0) : i64
      %c2 = llvm.mlir.constant (-1) : i64
      %0 = llvm.sub %c1, %a : i64
      %1 = llvm.sub %0, %c2 : i64
      llvm.return %1 : i64
  }]
  rhs := [LV| {
    ^entry (%a: i64):
      %c1 = llvm.mlir.constant (0) : i64
      %c2 = llvm.mlir.constant (-1) : i64
      %0 = llvm.sub %c1, %c2 : i64
      %1 = llvm.sub %0, %a : i64
      llvm.return %1 : i64
  }]

inductive NFA.msbState : Type where
| i | f
deriving DecidableEq, Fintype

def slt_zero_slt_i1_fail_before := [llvm|
{
^0(%arg4 : i32, %arg5 : i1):
  %0 = llvm.mlir.constant(31 : i32) : i32
  %1 = llvm.zext %arg5 : i1 to i32
  %2 = llvm.lshr %arg4, %0 : i32
  %3 = llvm.icmp "slt" %1, %2 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def ult_swap_and_max_logical_before := [llvm|
{
^0(%arg358 : i8, %arg359 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.icmp "ugt" %arg359, %arg358 : i8
  %3 = llvm.icmp "eq" %arg358, %0 : i8
  %4 = "llvm.select"(%2, %3, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def zext_eq_sext_before := [llvm|
{
^0(%arg4 : i1, %arg5 : i1):
  %0 = llvm.zext %arg4 : i1 to i32
  %1 = llvm.sext %arg5 : i1 to i32
  %2 = llvm.icmp "eq" %0, %1 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def logical_and_logical_and_icmps_comm2_after := [llvm|
{
^0(%arg202 : i8, %arg203 : i8, %arg204 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.mlir.constant(1 : i8) : i8
  %2 = llvm.mlir.constant(0 : i8) : i8
  %3 = llvm.mlir.constant(false) : i1
  %4 = llvm.icmp "eq" %arg203, %0 : i8
  %5 = llvm.and %arg202, %1 : i8
  %6 = llvm.shl %1, %arg204 overflow<nuw> : i8
  %7 = llvm.and %arg202, %6 : i8
  %8 = llvm.icmp "ne" %5, %2 : i8
  %9 = llvm.icmp "ne" %7, %2 : i8
  %10 = "llvm.select"(%8, %4, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %11 = "llvm.select"(%10, %9, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%11) : (i1) -> ()
}
]

def PR42691_3_logical_after := [llvm|
{
^0(%arg338 : i32):
  %0 = llvm.mlir.constant(-2147483647 : i32) : i32
  %1 = llvm.icmp "ult" %arg338, %0 : i32
  "llvm.return"(%1) : (i1) -> ()
}
]

def example00 := [RV64_com| {
^bb0(%0 : !riscv.reg, %1 : !riscv.reg):
    %2 = "slt"(%0, %1) : (!riscv.reg, !riscv.reg) -> (!riscv.reg)
    %3 = "andi" (%2){imm = 1 : !i64} : (!riscv.reg) -> (!riscv.reg)
    %4 = "sra"(%0, %0) : (!riscv.reg, !riscv.reg) -> (!riscv.reg)
    %5 = "add"(%0, %0) : (!riscv.reg, !riscv.reg) -> (!riscv.reg)
    %6 = "sra"(%2, %5) : (!riscv.reg, !riscv.reg) -> (!riscv.reg)
  "ret" (%0) : (!riscv.reg) -> ()
 }].denote

def liftSig (sig : Signature MLIR2Comb.Ty) : Signature MLIR2Handshake.Ty :=
  Signature.mk (sig.sig.map liftTy) [] (liftTy sig.outTy)

def alive_Select_859'_tgt :=
[sllvm| {
^bb0(%a : i1, %b : i1):
  %v1 = llvm.mlir.constant -1 : i1
  %v2 = llvm.xor %a, %v1 : i1
  %v3 = llvm.or %v2, %b : i1
  llvm.return %v3 : i1
}]

def sgt_smin2_before := [llvm|
{
^0(%arg45 : i32, %arg46 : i32):
  %0 = llvm.icmp "slt" %arg46, %arg45 : i32
  %1 = "llvm.select"(%0, %arg46, %arg45) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %2 = llvm.icmp "sgt" %1, %arg45 : i32
  "llvm.return"(%2) : (i1) -> ()
}
]

def exampleSink := [DCxComb_com| {
  ^entry(%0: !TokenStream):
    %src = "DCxComb.sink" (%0) : (!TokenStream) -> (!TokenStream)
    "return" (%src) : (!TokenStream) -> ()
  }]

def lshrult_01_08_exact_after := [llvm|
{
^0(%arg141 : i4):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def alive_AndOrXor_2247__A__B__A__B_tgt :=
[sllvm| {
^bb0(%A : i64, %B : i64):
  %v1 = llvm.and %A, %B : i64
  %v2 = llvm.mlir.constant -1 : i64
  %v3 = llvm.xor %A, %v2 : i64
  %v4 = llvm.mlir.constant -1 : i64
  %v5 = llvm.xor %B, %v4 : i64
  %v6 = llvm.mlir.constant -1 : i64
  %v7 = llvm.xor %v1, %v6 : i64
  llvm.return %v7 : i64
}]

def eq_21_comm_and_before := [llvm|
{
^0(%arg122 : i32, %arg123 : i32):
  %0 = llvm.mlir.constant(8 : i32) : i32
  %1 = llvm.mlir.constant(16 : i32) : i32
  %2 = llvm.lshr %arg122, %0 : i32
  %3 = llvm.trunc %2 : i32 to i8
  %4 = llvm.lshr %arg122, %1 : i32
  %5 = llvm.trunc %4 : i32 to i8
  %6 = llvm.lshr %arg123, %0 : i32
  %7 = llvm.trunc %6 : i32 to i8
  %8 = llvm.lshr %arg123, %1 : i32
  %9 = llvm.trunc %8 : i32 to i8
  %10 = llvm.icmp "eq" %3, %7 : i8
  %11 = llvm.icmp "eq" %5, %9 : i8
  %12 = llvm.and %10, %11 : i1
  "llvm.return"(%12) : (i1) -> ()
}
]

def and_min_7_7_after := [llvm|
{
^0(%arg2 : i8):
  %0 = llvm.mlir.constant(-8 : i8) : i8
  %1 = llvm.and %arg2, %0 : i8
  "llvm.return"(%1) : (i8) -> ()
}
]

def positive_biggerlshr_shlnsw_before := [llvm|
{
^0(%arg50 : i8):
  %0 = llvm.mlir.constant(6 : i8) : i8
  %1 = llvm.mlir.constant(3 : i8) : i8
  %2 = llvm.lshr %arg50, %0 : i8
  %3 = llvm.shl %2, %1 overflow<nsw> : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def ashrsgt_03_14_before := [llvm|
{
^0(%arg271 : i4):
  %0 = llvm.mlir.constant(3 : i4) : i4
  %1 = llvm.mlir.constant(-2 : i4) : i4
  %2 = llvm.ashr %arg271, %0 : i4
  %3 = llvm.icmp "sgt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def ashrslt_03_02_exact_after := [llvm|
{
^0(%arg19 : i4):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def lshrugt_02_04_before := [llvm|
{
^0(%arg395 : i4):
  %0 = llvm.mlir.constant(2 : i4) : i4
  %1 = llvm.mlir.constant(4 : i4) : i4
  %2 = llvm.lshr %arg395, %0 : i4
  %3 = llvm.icmp "ugt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def ashrsgt_01_04_after := [llvm|
{
^0(%arg313 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def and_not_or_commute1_before := [llvm|
{
^0(%arg478 : i32, %arg479 : i32, %arg480 : i32):
  %0 = llvm.mlir.constant(42 : i32) : i32
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.sdiv %0, %arg479 : i32
  %3 = llvm.and %arg478, %2 : i32
  %4 = llvm.xor %3, %1 : i32
  %5 = llvm.or %4, %arg480 : i32
  %6 = llvm.and %arg478, %arg480 : i32
  %7 = llvm.xor %6, %1 : i32
  %8 = llvm.or %2, %7 : i32
  %9 = llvm.and %5, %8 : i32
  "llvm.return"(%9) : (i32) -> ()
}
]

def t0_after := [llvm|
{
^0(%arg30 : i1, %arg31 : i8, %arg32 : i8, %arg33 : i8, %arg34 : i8):
  %0 = llvm.icmp "ne" %arg31, %arg32 : i8
  %1 = llvm.and %0, %arg30 : i1
  %2 = "llvm.select"(%1, %arg34, %arg33) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  "llvm.return"(%2) : (i8) -> ()
}
]

@[simp_denote]
def sext_llvm_i8_to_32 := [LV| {
  ^entry (%arg: i8):
    %0 = llvm.sext %arg: i8 to i32
    llvm.return %0: i32
  }]

def test18_before := [llvm|
{
^0(%arg194 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.mlir.constant(123 : i32) : i32
  %2 = llvm.xor %arg194, %0 : i32
  %3 = llvm.sub %1, %2 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def same_signbit_wrong_type_signed_before := [llvm|
{
^0(%arg14 : i8, %arg15 : i32):
  %0 = llvm.mlir.constant(7 : i8) : i8
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.ashr %arg14, %0 : i8
  %3 = llvm.icmp "sgt" %arg15, %1 : i32
  %4 = llvm.sext %3 : i1 to i8
  %5 = llvm.icmp "ne" %2, %4 : i8
  "llvm.return"(%5) : (i1) -> ()
}
]

def icmp_ne1_before := [llvm|
{
^0(%arg0 : i8):
  %0 = llvm.mlir.constant(6 : i8) : i8
  %1 = llvm.mlir.constant(-128 : i8) : i8
  %2 = llvm.shl %arg0, %0 overflow<nsw> : i8
  %3 = llvm.icmp "ne" %2, %1 : i8
  "llvm.return"(%3) : (i1) -> ()
}
]

def lshr_neg_sgt_minus_1_before := [llvm|
{
^0(%arg57 : i8):
  %0 = llvm.mlir.constant(-17 : i8) : i8
  %1 = llvm.mlir.constant(-1 : i8) : i8
  %2 = llvm.lshr %0, %arg57 : i8
  %3 = llvm.icmp "sgt" %2, %1 : i8
  "llvm.return"(%3) : (i1) -> ()
}
]

def not_and_and_or_not_or_or_commute1_after := [llvm|
{
^0(%arg238 : i32, %arg239 : i32, %arg240 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg240, %arg239 : i32
  %2 = llvm.or %1, %arg238 : i32
  %3 = llvm.xor %2, %0 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def t0_after := [llvm|
{
^0(%arg18 : i32, %arg19 : i16):
  %0 = llvm.mlir.constant(31 : i32) : i32
  %1 = llvm.ashr %arg18, %0 : i32
  %2 = llvm.trunc %1 overflow<nsw> : i32 to i16
  "llvm.return"(%2) : (i16) -> ()
}
]

def src_fv_eq_before := [llvm|
{
^0(%arg32 : i1, %arg33 : i8, %arg34 : i8):
  %0 = llvm.mlir.constant(1 : i8) : i8
  %1 = llvm.mlir.constant(0 : i8) : i8
  %2 = llvm.add %arg34, %0 overflow<nuw> : i8
  %3 = "llvm.select"(%arg32, %2, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  %4 = llvm.or %3, %arg33 : i8
  %5 = llvm.icmp "eq" %4, %1 : i8
  "llvm.return"(%5) : (i1) -> ()
}
]

def SimplePathOfPath.hEvalWith (this : SimplePathOfPath fsm s0 (K + 1) env) :
    fsm.evalWith s0 env (K + 1) =
    fsm.evalWith s0
      (envBitstream_set this.simplePath (this.k) (fun a => env a (K + 1))) this.k :=

Std.Tactic.BVDecide.BVUnOp.rotateRight in Std.Tactic.BVDecide.Bitblast.BVExpr.Basic

instance : DecidableNFA (NFA'.autMsbSet).M :=

def canonicalize_logic_first_and0_nswnuw_after := [llvm|
{
^0(%arg26 : i8):
  %0 = llvm.mlir.constant(-10 : i8) : i8
  %1 = llvm.mlir.constant(48 : i8) : i8
  %2 = llvm.and %arg26, %0 : i8
  %3 = llvm.add %2, %1 overflow<nsw,nuw> : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

Lean.Parser.Term.app in Lean.Parser.Term

def sub_ashr_or_i64_before := [llvm|
{
^0(%arg33 : i64, %arg34 : i64):
  %0 = llvm.mlir.constant(63) : i64
  %1 = llvm.sub %arg34, %arg33 overflow<nsw> : i64
  %2 = llvm.ashr %1, %0 : i64
  %3 = llvm.or %2, %arg33 : i64
  "llvm.return"(%3) : (i64) -> ()
}
]

def sub {w : Nat} (x y : IntW w) (flags : NoWrapFlags := {nsw := false , nuw := false}) : IntW w := do
  let x' ← x
  let y' ← y
  if flags.nsw ∧ BitVec.ssubOverflow x' y' then
    .poison
  else if flags.nuw ∧ BitVec.usubOverflow x' y' then
    .poison
  else
    sub? x' y'

def ashrsgt_03_06_exact_after := [llvm|
{
^0(%arg63 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def shl_mask_wrong_shl_const_before := [llvm|
{
^0(%arg5 : i32):
  %0 = llvm.mlir.constant(255 : i32) : i32
  %1 = llvm.mlir.constant(7 : i32) : i32
  %2 = llvm.and %arg5, %0 : i32
  %3 = llvm.shl %2, %1 : i32
  %4 = llvm.or %2, %3 : i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def positive_with_signbit_logical_before := [llvm|
{
^0(%arg61 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.mlir.constant(128 : i32) : i32
  %2 = llvm.mlir.constant(256 : i32) : i32
  %3 = llvm.mlir.constant(false) : i1
  %4 = llvm.icmp "sgt" %arg61, %0 : i32
  %5 = llvm.add %arg61, %1 : i32
  %6 = llvm.icmp "ult" %5, %2 : i32
  %7 = "llvm.select"(%4, %6, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%7) : (i1) -> ()
}
]

def test_logical_before := [llvm|
{
^0(%arg0 : i32):
  %0 = llvm.mlir.constant(13 : i32) : i32
  %1 = llvm.mlir.constant(15 : i32) : i32
  %2 = llvm.mlir.constant(false) : i1
  %3 = llvm.icmp "ugt" %arg0, %0 : i32
  %4 = llvm.icmp "eq" %arg0, %1 : i32
  %5 = "llvm.select"(%3, %4, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%5) : (i1) -> ()
}
]

def test_eq_before := [llvm|
{
^0(%arg11 : i32):
  %0 = llvm.mlir.constant(1073741823 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(2 : i32) : i32
  %3 = llvm.and %arg11, %0 : i32
  %4 = llvm.icmp "eq" %3, %1 : i32
  %5 = llvm.shl %arg11, %2 : i32
  %6 = "llvm.select"(%4, %1, %5) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%6) : (i32) -> ()
}
]

def test_shl__nsw_is_safe_before := [llvm|
{
^0(%arg72 : i32):
  %0 = llvm.mlir.constant(-83886080 : i32) : i32
  %1 = llvm.mlir.constant(-83886079 : i32) : i32
  %2 = llvm.mlir.constant(2 : i32) : i32
  %3 = llvm.mlir.constant(-335544316 : i32) : i32
  %4 = llvm.or %arg72, %0 : i32
  %5 = llvm.icmp "eq" %4, %1 : i32
  %6 = llvm.shl %4, %2 : i32
  %7 = "llvm.select"(%5, %3, %6) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  %8 = llvm.mul %7, %4 : i32
  %9 = llvm.mul %8, %6 : i32
  "llvm.return"(%9) : (i32) -> ()
}
]

def masked_icmps_mask_notallzeros_bmask_mixed_swapped_2_logical_before := [llvm|
{
^0(%arg45 : i32):
  %0 = llvm.mlir.constant(3 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(7 : i32) : i32
  %3 = llvm.mlir.constant(false) : i1
  %4 = llvm.and %arg45, %0 : i32
  %5 = llvm.icmp "ne" %4, %1 : i32
  %6 = llvm.and %arg45, %2 : i32
  %7 = llvm.icmp "eq" %6, %1 : i32
  %8 = "llvm.select"(%7, %5, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%8) : (i1) -> ()
}
]

def join {Γ : Ctxt _}  (a b : Γ.Var (MLIR2DCPlus.Ty.tokenstream)) : Expr (DCPlus) Γ .pure (.tokenstream) :=
  Expr.mk
    (op := .join)
    (ty_eq := rfl)
    (eff_le := by admit /- proof elided -/
    )
    (args := .cons a <| .cons b <| .nil)
    (regArgs := .nil)

def llvm_shl_lower_riscv_nsw_32: LLVMPeepholeRewriteRefine 32 [Ty.llvm (.bitvec 32), Ty.llvm (.bitvec 32)] where
  lhs := shl_llvm_nsw_32
  rhs := shl_riscv_32

def test88_before := [llvm|
{
^0(%arg57 : i16):
  %0 = llvm.mlir.constant(18 : i32) : i32
  %1 = llvm.sext %arg57 : i16 to i32
  %2 = llvm.ashr %1, %0 : i32
  %3 = llvm.trunc %2 : i32 to i16
  "llvm.return"(%3) : (i16) -> ()
}
]

def lshrugt_02_06_exact_after := [llvm|
{
^0(%arg199 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def test9_after := [llvm|
{
^0(%arg91 : i32):
  %0 = llvm.mlir.constant(0 : i32) : i32
  "llvm.return"(%0) : (i32) -> ()
}
]

def uadd_sat_flipped_wrong_bounds6_before := [llvm|
{
^0(%arg91 : i32):
  %0 = llvm.mlir.constant(-12 : i32) : i32
  %1 = llvm.mlir.constant(9 : i32) : i32
  %2 = llvm.mlir.constant(-1 : i32) : i32
  %3 = llvm.icmp "ule" %arg91, %0 : i32
  %4 = llvm.add %arg91, %1 : i32
  %5 = "llvm.select"(%3, %4, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def ashrsgt_02_10_after := [llvm|
{
^0(%arg291 : i4):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def test_add_nsw__nuw_is_safe_after := [llvm|
{
^0(%arg41 : i32):
  %0 = llvm.mlir.constant(2147483647 : i32) : i32
  %1 = llvm.mlir.constant(1 : i32) : i32
  %2 = llvm.and %arg41, %0 : i32
  %3 = llvm.add %2, %1 overflow<nuw> : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def masked_or_allzeroes_notoptimised_logical_after := [llvm|
{
^0(%arg116 : i32):
  %0 = llvm.mlir.constant(15 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(39 : i32) : i32
  %3 = llvm.and %arg116, %0 : i32
  %4 = llvm.icmp "eq" %3, %1 : i32
  %5 = llvm.and %arg116, %2 : i32
  %6 = llvm.icmp "eq" %5, %1 : i32
  %7 = llvm.or %4, %6 : i1
  "llvm.return"(%7) : (i1) -> ()
}
]

def sub_0xffffffffff_i64_test : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := sub_0xffffffffff_llvm_i64
  rhs :=  sub_0xffffffffff_riscv_i64

def negate_sdiv_after := [llvm|
{
^0(%arg116 : i8, %arg117 : i8):
  %0 = llvm.mlir.constant(-42 : i8) : i8
  %1 = llvm.sdiv %arg117, %0 : i8
  %2 = llvm.add %1, %arg116 : i8
  "llvm.return"(%2) : (i8) -> ()
}
]

def xor_ugt_2_after := [llvm|
{
^0(%arg13 : i8, %arg14 : i8, %arg15 : i8):
  %0 = llvm.mlir.constant(63 : i8) : i8
  %1 = llvm.mlir.constant(64 : i8) : i8
  %2 = llvm.add %arg13, %arg15 : i8
  %3 = llvm.and %arg14, %0 : i8
  %4 = llvm.or disjoint %3, %1 : i8
  %5 = llvm.xor %2, %4 : i8
  %6 = llvm.icmp "ugt" %2, %5 : i8
  "llvm.return"(%6) : (i1) -> ()
}
]

def test8_after := [llvm|
{
^0(%arg17 : i32):
  %0 = llvm.mlir.constant(2 : i32) : i32
  %1 = llvm.icmp "ult" %arg17, %0 : i32
  "llvm.return"(%1) : (i1) -> ()
}
]

def or_eq_with_one_bit_diff_constants1_logical_before := [llvm|
{
^0(%arg365 : i32):
  %0 = llvm.mlir.constant(50 : i32) : i32
  %1 = llvm.mlir.constant(51 : i32) : i32
  %2 = llvm.mlir.constant(true) : i1
  %3 = llvm.icmp "eq" %arg365, %0 : i32
  %4 = llvm.icmp "eq" %arg365, %1 : i32
  %5 = "llvm.select"(%3, %2, %4) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%5) : (i1) -> ()
}
]

def select_icmp_sgt_allones_smin_before := [llvm|
{
^0(%arg3 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.mlir.constant(-128 : i8) : i8
  %2 = llvm.icmp "sgt" %arg3, %0 : i8
  %3 = llvm.xor %arg3, %1 : i8
  %4 = "llvm.select"(%2, %arg3, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  "llvm.return"(%4) : (i8) -> ()
}
]

def squared_nsw_eq0_after := [llvm|
{
^0(%arg185 : i5):
  %0 = llvm.mlir.constant(0 : i5) : i5
  %1 = llvm.icmp "eq" %arg185, %0 : i5
  "llvm.return"(%1) : (i1) -> ()
}
]

def llvm_const_lower_riscv_li17 : LLVMPeepholeRewriteRefine 64 [] :=
  {lhs := constLLVM17, rhs:= liRiscv17,
   correct := by admit /- proof elided -/

def bools_logical_commute1_and2_before := [llvm|
{
^0(%arg91 : i1, %arg92 : i1, %arg93 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.xor %arg93, %0 : i1
  %3 = "llvm.select"(%arg91, %2, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %4 = llvm.and %arg93, %arg92 : i1
  %5 = "llvm.select"(%3, %0, %4) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%5) : (i1) -> ()
}
]

def t2_before := [llvm|
{
^0(%arg11 : i8):
  %0 = llvm.mlir.constant(0 : i8) : i8
  %1 = llvm.sub %0, %arg11 overflow<nsw> : i8
  %2 = llvm.icmp "slt" %1, %arg11 : i8
  "llvm.return"(%2) : (i1) -> ()
}
]

def function : Parser :=
  leading_parser argumentList >> arrow >> termParser

def mul8_low_A0_B0_after := [llvm|
{
^0(%arg60 : i8, %arg61 : i8):
  %0 = llvm.mul %arg60, %arg61 : i8
  "llvm.return"(%0) : (i8) -> ()
}
]

def lshrugt_02_02_after := [llvm|
{
^0(%arg397 : i4):
  %0 = llvm.mlir.constant(-5 : i4) : i4
  %1 = llvm.icmp "ugt" %arg397, %0 : i4
  "llvm.return"(%1) : (i1) -> ()
}
]

def llvm_or_lower_riscv_noflag_64 : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64), Ty.llvm (.bitvec 64)] where
  lhs := or_llvm_noflag_64
  rhs := or_riscv_64

def ashrsgt_02_13_exact_before := [llvm|
{
^0(%arg72 : i4):
  %0 = llvm.mlir.constant(2 : i4) : i4
  %1 = llvm.mlir.constant(-3 : i4) : i4
  %2 = llvm.ashr exact %arg72, %0 : i4
  %3 = llvm.icmp "sgt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def slli_i32_test : LLVMPeepholeRewriteRefine 32 [Ty.llvm (.bitvec 32)] where
  lhs := slli_llvm_i32
  rhs := slli_riscv_i32

def not_lshr_const_before := [llvm|
{
^0(%arg135 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.mlir.constant(-1 : i8) : i8
  %2 = llvm.lshr %0, %arg135 : i8
  %3 = llvm.xor %2, %1 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def masked_icmps_mask_notallzeros_bmask_mixed_negated_swapped_3_logical_after := [llvm|
{
^0(%arg21 : i32):
  %0 = llvm.mlir.constant(15 : i32) : i32
  %1 = llvm.mlir.constant(8 : i32) : i32
  %2 = llvm.and %arg21, %0 : i32
  %3 = llvm.icmp "ne" %2, %1 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def sle_swap_and_min_logical_after := [llvm|
{
^0(%arg212 : i8, %arg213 : i8):
  %0 = llvm.mlir.constant(-128 : i8) : i8
  %1 = llvm.icmp "eq" %arg212, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def or_logic_or_logic_and_2_before := [llvm|
{
^0(%arg45 : i1, %arg46 : i1, %arg47 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.mlir.constant(false) : i1
  %2 = llvm.or %arg45, %arg46 : i1
  %3 = "llvm.select"(%arg47, %0, %arg45) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %4 = "llvm.select"(%2, %3, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%4) : (i1) -> ()
}
]

def test25_after := [llvm|
{
^0(%arg0 : i32):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def not_and_and_or_not_or_or_commute3_after := [llvm|
{
^0(%arg232 : i32, %arg233 : i32, %arg234 : i32):
  %0 = llvm.mlir.constant(42 : i32) : i32
  %1 = llvm.mlir.constant(-1 : i32) : i32
  %2 = llvm.sdiv %0, %arg233 : i32
  %3 = llvm.xor %arg234, %2 : i32
  %4 = llvm.or %3, %arg232 : i32
  %5 = llvm.xor %4, %1 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def sub_from_constant_of_sub_from_constant_after := [llvm|
{
^0(%arg186 : i8):
  %0 = llvm.mlir.constant(-31 : i8) : i8
  %1 = llvm.add %arg186, %0 : i8
  "llvm.return"(%1) : (i8) -> ()
}
]

@[match_pattern]
def last (Γ : Ctxt Ty) (t : Ty) : Ctxt.Var (Ctxt.cons t Γ) t :=
  ⟨0, by admit /- proof elided -/
  ⟩

def sle_swap_or_not_min_after := [llvm|
{
^0(%arg280 : i8, %arg281 : i8):
  %0 = llvm.mlir.constant(true) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

Lean.MacroM in Init.Prelude

def State.get? (e : Expr) : GenM (Option Expr) := do
  let s ← get
  match ← s.mapping.getMatch e with
  | #[x] => return x
  | #[] => return none
  | _ => unreachable!

def icmp_shl_ne_2_after := [llvm|
{
^0(%arg4 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.mlir.constant(0 : i8) : i8
  %2 = llvm.sdiv %0, %arg4 : i8
  %3 = llvm.icmp "ne" %2, %1 : i8
  "llvm.return"(%3) : (i1) -> ()
}
]

def negative_trunc_not_arg_logical_after := [llvm|
{
^0(%arg20 : i32, %arg21 : i32):
  %0 = llvm.mlir.constant(128 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(256 : i32) : i32
  %3 = llvm.mlir.constant(false) : i1
  %4 = llvm.and %arg20, %0 : i32
  %5 = llvm.icmp "eq" %4, %1 : i32
  %6 = llvm.add %arg21, %0 : i32
  %7 = llvm.icmp "ult" %6, %2 : i32
  %8 = "llvm.select"(%5, %7, %3) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%8) : (i1) -> ()
}
]

def llvm_const_lower_riscv_li10 : LLVMPeepholeRewriteRefine 64 [] :=
  {lhs := constLLVM10, rhs:= liRiscv10,
   correct := by admit /- proof elided -/

@[simp_llvm_option]
def ashr {w : Nat} (x y : IntW w) (flag : ExactFlag := {exact := false}) : IntW w := do
  let x' ← x
  let y' ← y
  if flag.exact ∧ (x' >>> y') <<< y' ≠ x' then
    .poison
  else
    ashr? x' y'

def add_umin_simplify2_before := [llvm|
{
^0(%arg53 : i32):
  %0 = llvm.mlir.constant(43 : i32) : i32
  %1 = llvm.mlir.constant(42 : i32) : i32
  %2 = llvm.add %arg53, %0 overflow<nuw> : i32
  %3 = llvm.icmp "ult" %2, %1 : i32
  %4 = "llvm.select"(%3, %2, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def scalar_i64_shl_ult_const_before := [llvm|
{
^0(%arg14 : i64):
  %0 = llvm.mlir.constant(25) : i64
  %1 = llvm.mlir.constant(8589934592) : i64
  %2 = llvm.shl %arg14, %0 : i64
  %3 = llvm.icmp "ult" %2, %1 : i64
  "llvm.return"(%3) : (i1) -> ()
}
]

def ofList (vals : List (Option α)) : Stream α :=
  fun i => (vals[i]?).join

def neg_of_sub_from_constant_after := [llvm|
{
^0(%arg172 : i8):
  %0 = llvm.mlir.constant(-42 : i8) : i8
  %1 = llvm.add %arg172, %0 : i8
  "llvm.return"(%1) : (i8) -> ()
}
]

List.foldlRecOn in Init.Data.List.Lemmas

def sub_to_add_3 : LLVMPeepholeRewriteRefine 64 [Ty.llvm (.bitvec 64)] where
  lhs := [LV| {
    ^entry (%x: i64):
      %c = llvm.mlir.constant 3 : i64
      %1 = llvm.sub %x, %c : i64
      llvm.return %1 : i64
  }]
  rhs := [LV| {
    ^entry (%x: i64):
      %c = llvm.mlir.constant -3 : i64
      %1 = llvm.add %x, %c : i64
      llvm.return %1 : i64
  }]

def test20_before := [llvm|
{
^0(%arg148 : i32, %arg149 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg149, %0 : i32
  %2 = llvm.xor %arg148, %0 : i32
  %3 = llvm.or %arg148, %arg149 : i32
  %4 = llvm.or %1, %2 : i32
  %5 = llvm.xor %3, %4 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def ashr_ult_2_before := [llvm|
{
^0(%arg96 : i4):
  %0 = llvm.mlir.constant(1 : i4) : i4
  %1 = llvm.mlir.constant(2 : i4) : i4
  %2 = llvm.ashr %arg96, %0 : i4
  %3 = llvm.icmp "ult" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def different_size_sext_sext_sgt_before := [llvm|
{
^0(%arg14 : i7, %arg15 : i4):
  %0 = llvm.sext %arg14 : i7 to i25
  %1 = llvm.sext %arg15 : i4 to i25
  %2 = llvm.icmp "sgt" %0, %1 : i25
  "llvm.return"(%2) : (i1) -> ()
}
]

def ex1_lhs : Com [.nat] .nat :=
  Com.var (rgn (k := 0) ⟨0, by admit /- proof elided -/
  ⟩ (
      Com.var (add ⟨0, by admit /- proof elided -/
      ⟩ ⟨0, by admit /- proof elided -/
      ⟩) 
      <| Com.ret ⟨0, by admit /- proof elided -/
      ⟩
  )) <|
  Com.ret ⟨0, by admit /- proof elided -/
  ⟩

def lshrugt_02_06_exact_before := [llvm|
{
^0(%arg199 : i4):
  %0 = llvm.mlir.constant(2 : i4) : i4
  %1 = llvm.mlir.constant(6 : i4) : i4
  %2 = llvm.lshr exact %arg199, %0 : i4
  %3 = llvm.icmp "ugt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def add_smin_simplify_after := [llvm|
{
^0(%arg34 : i32):
  %0 = llvm.mlir.constant(-3 : i32) : i32
  %1 = llvm.add %arg34, %0 overflow<nsw> : i32
  "llvm.return"(%1) : (i32) -> ()
}
]

def test19_commutative0_before := [llvm|
{
^0(%arg74 : i32, %arg75 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.shl %0, %arg74 : i32
  %2 = llvm.shl %0, %arg75 : i32
  %3 = llvm.and %2, %1 : i32
  %4 = llvm.add %3, %1 : i32
  %5 = llvm.urem %arg75, %4 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def main2_logical_before := [llvm|
{
^0(%arg156 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.mlir.constant(0 : i32) : i32
  %2 = llvm.mlir.constant(2 : i32) : i32
  %3 = llvm.mlir.constant(true) : i1
  %4 = llvm.and %arg156, %0 : i32
  %5 = llvm.icmp "eq" %4, %1 : i32
  %6 = llvm.and %arg156, %2 : i32
  %7 = llvm.icmp "eq" %6, %1 : i32
  %8 = "llvm.select"(%5, %3, %7) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %9 = "llvm.select"(%8, %1, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%9) : (i32) -> ()
}
]

@[simp_denote]
def icmp_ule_llvm_32 : Com LLVMPlusRiscV ⟨[.llvm (.bitvec 32), .llvm (.bitvec 32)]⟩
  .pure (.llvm (.bitvec 1)) := [LV| {
  ^entry (%lhs: i32, %rhs: i32):
    %1 = llvm.icmp.ule %lhs, %rhs : i32
    llvm.return %1 : i1
  }]

def icmp_eq_mul_nsw_nonequal_commuted_before := [llvm|
{
^0(%arg30 : i8, %arg31 : i8):
  %0 = llvm.mlir.constant(1 : i8) : i8
  %1 = llvm.add %arg30, %0 : i8
  %2 = llvm.mul %arg30, %arg31 overflow<nsw> : i8
  %3 = llvm.mul %arg31, %1 overflow<nsw> : i8
  %4 = llvm.icmp "eq" %2, %3 : i8
  "llvm.return"(%4) : (i1) -> ()
}
]

def udiv_lshr_mul_nuw_after := [llvm|
{
^0(%arg106 : i8, %arg107 : i8, %arg108 : i8):
  %0 = llvm.lshr %arg107, %arg108 : i8
  "llvm.return"(%0) : (i8) -> ()
}
]

Nat.lt in Init.Prelude

def icmp_mul_nsw_slt_neg_after := [llvm|
{
^0(%arg11 : i8, %arg12 : i8):
  %0 = llvm.icmp "sgt" %arg11, %arg12 : i8
  "llvm.return"(%0) : (i1) -> ()
}
]

@[simp_denote]
def sext_riscv_i1_to_i16 := [LV| {
  ^entry (%arg: i1):
    %0 = "builtin.unrealized_conversion_cast"(%arg) : (i1) -> (!i64)
    %1 = slli %0, 63 : !i64
    %2 = srai %1, 63 : !i64
    %res = "builtin.unrealized_conversion_cast"(%2) : (!i64) -> (i16)
    llvm.return %res : i16
  }]

def sub_ashr_and_i32_nuw_nsw_after := [llvm|
{
^0(%arg23 : i32, %arg24 : i32):
  %0 = llvm.mlir.constant(0 : i32) : i32
  %1 = llvm.icmp "slt" %arg24, %arg23 : i32
  %2 = "llvm.select"(%1, %arg23, %0) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def scalar_i8_shl_uge_const_after := [llvm|
{
^0(%arg13 : i8):
  %0 = llvm.mlir.constant(6 : i8) : i8
  %1 = llvm.mlir.constant(0 : i8) : i8
  %2 = llvm.and %arg13, %0 : i8
  %3 = llvm.icmp "ne" %2, %1 : i8
  "llvm.return"(%3) : (i1) -> ()
}
]

def ashr_add_exact_after := [llvm|
{
^0(%arg2 : i8, %arg3 : i8):
  %0 = llvm.mlir.constant(-14 : i8) : i8
  %1 = llvm.mlir.constant(1 : i8) : i8
  %2 = llvm.and %arg2, %0 : i8
  %3 = llvm.and %arg3, %1 : i8
  %4 = llvm.ashr exact %2, %3 : i8
  "llvm.return"(%4) : (i8) -> ()
}
]

def lshrugt_01_12_exact_after := [llvm|
{
^0(%arg209 : i4):
  %0 = llvm.mlir.constant(false) : i1
  "llvm.return"(%0) : (i1) -> ()
}
]

def test7_before := [llvm|
{
^0(%arg96 : i64):
  %0 = llvm.mlir.constant(32 : i128) : i128
  %1 = llvm.zext %arg96 : i64 to i128
  %2 = llvm.lshr %1, %0 : i128
  %3 = llvm.trunc %2 : i128 to i92
  "llvm.return"(%3) : (i92) -> ()
}
]

def t2_after := [llvm|
{
^0(%arg202 : i8, %arg203 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.shl %0, %arg203 : i8
  %2 = llvm.add %1, %arg202 : i8
  "llvm.return"(%2) : (i8) -> ()
}
]

def lshrult_03_15_exact_before := [llvm|
{
^0(%arg102 : i4):
  %0 = llvm.mlir.constant(3 : i4) : i4
  %1 = llvm.mlir.constant(-1 : i4) : i4
  %2 = llvm.lshr exact %arg102, %0 : i4
  %3 = llvm.icmp "ult" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def liRiscv35 := [LV| {
  ^entry ():
    %0 = "li"() {imm = 35 : !i64} : (!i64) -> (!i64)
    %1 = "builtin.unrealized_conversion_cast"(%0) : (!i64) -> (i64)
    llvm.return %1 : i64
  }]

def icmp? {w : Nat} (c : IntPred) (x y : BitVec w) : IntW 1 :=
  .value <| .ofBool (icmp' c x y) 

def and_orn_xor_before := [llvm|
{
^0(%arg80 : i4, %arg81 : i4):
  %0 = llvm.mlir.constant(-1 : i4) : i4
  %1 = llvm.xor %arg80, %arg81 : i4
  %2 = llvm.xor %arg80, %0 : i4
  %3 = llvm.or %2, %arg81 : i4
  %4 = llvm.and %3, %1 : i4
  "llvm.return"(%4) : (i4) -> ()
}
]

def lowmask_add_zext_commute_before := [llvm|
{
^0(%arg233 : i16, %arg234 : i32):
  %0 = llvm.mlir.constant(65535 : i32) : i32
  %1 = llvm.mul %arg234, %arg234 : i32
  %2 = llvm.zext %arg233 : i16 to i32
  %3 = llvm.add %1, %2 : i32
  %4 = llvm.and %3, %0 : i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def select_constants_and_icmp_ne0_common_bit_before := [llvm|
{
^0(%arg18 : i1, %arg19 : i1):
  %0 = llvm.mlir.constant(2 : i8) : i8
  %1 = llvm.mlir.constant(3 : i8) : i8
  %2 = llvm.mlir.constant(0 : i8) : i8
  %3 = "llvm.select"(%arg18, %0, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  %4 = "llvm.select"(%arg19, %0, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i8, i8) -> i8
  %5 = llvm.and %3, %4 : i8
  %6 = llvm.icmp "ne" %5, %2 : i8
  "llvm.return"(%6) : (i1) -> ()
}
]

def lshr_eq_both_equal_after := [llvm|
{
^0(%arg170 : i8):
  %0 = llvm.mlir.constant(0 : i8) : i8
  %1 = llvm.icmp "eq" %arg170, %0 : i8
  "llvm.return"(%1) : (i1) -> ()
}
]

def shl_add_add_fail_before := [llvm|
{
^0(%arg166 : i8, %arg167 : i8):
  %0 = llvm.mlir.constant(2 : i8) : i8
  %1 = llvm.mlir.constant(48 : i8) : i8
  %2 = llvm.lshr %arg166, %0 : i8
  %3 = llvm.lshr %arg167, %0 : i8
  %4 = llvm.add %3, %1 : i8
  %5 = llvm.add %2, %4 : i8
  "llvm.return"(%5) : (i8) -> ()
}
]

def test25_after := [llvm|
{
^0(%arg2 : i37, %arg3 : i37):
  %0 = llvm.mlir.constant(-131072 : i37) : i37
  %1 = llvm.and %arg2, %0 : i37
  %2 = llvm.add %arg3, %1 : i37
  %3 = llvm.and %2, %0 : i37
  "llvm.return"(%3) : (i37) -> ()
}
]

def mul128_low_before := [llvm|
{
^0(%arg18 : i128, %arg19 : i128):
  %0 = llvm.mlir.constant(18446744073709551615 : i128) : i128
  %1 = llvm.mlir.constant(64 : i128) : i128
  %2 = llvm.and %arg18, %0 : i128
  %3 = llvm.lshr %arg18, %1 : i128
  %4 = llvm.and %arg19, %0 : i128
  %5 = llvm.lshr %arg19, %1 : i128
  %6 = llvm.mul %5, %2 : i128
  %7 = llvm.mul %4, %3 : i128
  %8 = llvm.mul %4, %2 : i128
  %9 = llvm.add %6, %7 : i128
  %10 = llvm.shl %9, %1 : i128
  %11 = llvm.add %10, %8 : i128
  "llvm.return"(%11) : (i128) -> ()
}
]

@[simp_denote]
def xor_riscv_32: Com  LLVMPlusRiscV ⟨[.llvm (.bitvec 32), .llvm (.bitvec 32)]⟩
  .pure (.llvm (.bitvec 32)) := [LV| {
  ^entry (%x: i32, %y: i32):
    %x1 = "builtin.unrealized_conversion_cast"(%x) : (i32) -> (!i64)
    %x2 = "builtin.unrealized_conversion_cast"(%y) : (i32) -> (!i64)
    %1 = xor %x1, %x2 : !i64
    %2 = "builtin.unrealized_conversion_cast"(%1) : (!i64) -> (i32)
    llvm.return %2 : i32
  }]

abbrev MLIRType.i32: MLIRType φ := MLIRType.int .Signless 32

def icmp_eq_and_pow2_lshr_pow2_after := [llvm|
{
^0(%arg44 : i32):
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.icmp "ne" %arg44, %0 : i32
  %2 = llvm.zext %1 : i1 to i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def and_or2_commuted_after := [llvm|
{
^0(%arg194 : i1, %arg195 : i1, %arg196 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.mlir.constant(false) : i1
  %2 = "llvm.select"(%arg196, %0, %arg194) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  %3 = "llvm.select"(%arg195, %2, %1) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def sub_undemanded_low_bits_after := [llvm|
{
^0(%arg0 : i32):
  %0 = llvm.mlir.constant(-1616 : i32) : i32
  %1 = llvm.mlir.constant(4 : i32) : i32
  %2 = llvm.add %arg0, %0 : i32
  %3 = llvm.lshr %2, %1 : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def add_shl_same_amount_partial_nsw1_before := [llvm|
{
^0(%arg41 : i6, %arg42 : i6, %arg43 : i6):
  %0 = llvm.shl %arg41, %arg43 overflow<nsw> : i6
  %1 = llvm.shl %arg42, %arg43 overflow<nsw> : i6
  %2 = llvm.add %0, %1 : i6
  "llvm.return"(%2) : (i6) -> ()
}
]

def add_mask_sign_commute_i32_before := [llvm|
{
^0(%arg5 : i32):
  %0 = llvm.mlir.constant(31 : i32) : i32
  %1 = llvm.mlir.constant(8 : i32) : i32
  %2 = llvm.ashr %arg5, %0 : i32
  %3 = llvm.and %2, %1 : i32
  %4 = llvm.add %2, %3 : i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def t0_before := [llvm|
{
^0(%arg51 : i8, %arg52 : i8, %arg53 : i8):
  %0 = llvm.sub %arg51, %arg52 : i8
  %1 = llvm.sub %0, %arg53 : i8
  "llvm.return"(%1) : (i8) -> ()
}
]

def fold_add_udiv_urem_without_noundef_before := [llvm|
{
^0(%arg4 : i32):
  %0 = llvm.mlir.constant(10 : i32) : i32
  %1 = llvm.mlir.constant(4 : i32) : i32
  %2 = llvm.udiv %arg4, %0 : i32
  %3 = llvm.shl %2, %1 : i32
  %4 = llvm.urem %arg4, %0 : i32
  %5 = llvm.add %3, %4 : i32
  "llvm.return"(%5) : (i32) -> ()
}
]

def zext_sext_add_icmp_ne_1_after := [llvm|
{
^0(%arg70 : i1, %arg71 : i1):
  %0 = llvm.mlir.constant(true) : i1
  %1 = llvm.xor %arg70, %0 : i1
  %2 = llvm.or %arg71, %1 : i1
  "llvm.return"(%2) : (i1) -> ()
}
]

@[simp]
def Formula.language (φ : Formula) : Set (BitVecs φ.arity) :=
  match φ with
  | .width wp n => { bvs | wp.sat bvs.w n }
  | .atom rel t1 t2 =>
    let l1 := t1.language.lift (liftMaxSucc1 (FinEnum.card $ Fin t1.arity) (FinEnum.card $ Fin t2.arity))
    let l2 := t2.language.lift (liftMaxSucc2 (FinEnum.card $ Fin t1.arity) (FinEnum.card $ Fin t2.arity))
    let lrel := rel.language.lift $ liftLast2 (max (FinEnum.card (Fin t1.arity)) (FinEnum.card (Fin t2.arity)))
    let l := lrel ∩ l1 ∩ l2
    l.proj (liftExcept2 _)
  | .unop .neg φ => φ.languageᶜ
  | .binop op φ1 φ2 =>
    let l1 := φ1.language.lift $ liftMax1 φ1.arity φ2.arity
    let l2 := φ2.language.lift $ liftMax2 φ1.arity φ2.arity
    langBinop op l1 l2
  | .msbSet t =>
    let lmsb := langMsb.lift $ fun _ => Fin.last t.arity
    let l' := t.language ∩ lmsb
    l'.proj fun n => n.castLE (by admit /- proof elided -/
    )

def t2_before := [llvm|
{
^0(%arg8 : i64):
  %0 = llvm.mlir.constant(63) : i64
  %1 = llvm.mlir.constant(0) : i64
  %2 = llvm.ashr %arg8, %0 : i64
  %3 = llvm.sub %1, %2 : i64
  "llvm.return"(%3) : (i64) -> ()
}
]

structure LLVMPeepholeRewriteRefine (w : Nat) (Γ : List Ty) where
  lhs : Com LLVMPlusRiscV Γ .pure [Ty.llvm (.bitvec w)]
  rhs : Com LLVMPlusRiscV Γ .pure [Ty.llvm (.bitvec w)]
  correct : ∀ V,
    PoisonOr.IsRefinedBy (lhs.denote V |>.getN 0) (rhs.denote V |>.getN 0) := by admit /- proof elided -/

def uge_swap_and_max_commute_before := [llvm|
{
^0(%arg226 : i8, %arg227 : i8):
  %0 = llvm.mlir.constant(-1 : i8) : i8
  %1 = llvm.icmp "ule" %arg227, %arg226 : i8
  %2 = llvm.icmp "eq" %arg226, %0 : i8
  %3 = llvm.and %2, %1 : i1
  "llvm.return"(%3) : (i1) -> ()
}
]

def lshrult_01_07_exact_before := [llvm|
{
^0(%arg142 : i4):
  %0 = llvm.mlir.constant(1 : i4) : i4
  %1 = llvm.mlir.constant(7 : i4) : i4
  %2 = llvm.lshr exact %arg142, %0 : i4
  %3 = llvm.icmp "ult" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

def Body.return : (body : Body Op Γ ty) → Var body.returnContext ty
  | ⟨⟨_, ret⟩, h⟩ => ⟨ret, by admit /- proof elided -/
  ⟩

def or_eq_with_one_bit_diff_constants2_logical_before := [llvm|
{
^0(%arg361 : i32):
  %0 = llvm.mlir.constant(97 : i32) : i32
  %1 = llvm.mlir.constant(65 : i32) : i32
  %2 = llvm.mlir.constant(true) : i1
  %3 = llvm.icmp "eq" %arg361, %0 : i32
  %4 = llvm.icmp "eq" %arg361, %1 : i32
  %5 = "llvm.select"(%3, %2, %4) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i1, i1) -> i1
  "llvm.return"(%5) : (i1) -> ()
}
]

def shl_nsw_add_negative_before := [llvm|
{
^0(%arg45 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.mlir.constant(2 : i32) : i32
  %2 = llvm.add %arg45, %0 : i32
  %3 = llvm.shl %1, %2 overflow<nsw> : i32
  "llvm.return"(%3) : (i32) -> ()
}
]

def a_or_b_const_before := [llvm|
{
^0(%arg10 : i32, %arg11 : i32, %arg12 : i32):
  %0 = llvm.icmp "eq" %arg10, %arg12 : i32
  %1 = llvm.icmp "ne" %arg11, %arg12 : i32
  %2 = llvm.and %0, %1 : i1
  %3 = llvm.icmp "ne" %arg10, %arg12 : i32
  %4 = llvm.icmp "eq" %arg11, %arg12 : i32
  %5 = llvm.and %3, %4 : i1
  %6 = llvm.or %2, %5 : i1
  "llvm.return"(%6) : (i1) -> ()
}
]

def t_2_4_after := [llvm|
{
^0(%arg12 : i8):
  %0 = llvm.mlir.constant(4 : i8) : i8
  %1 = llvm.and %arg12, %0 : i8
  "llvm.return"(%1) : (i8) -> ()
}
]

def sub_from_constant_of_sub_from_constant_before := [llvm|
{
^0(%arg170 : i8):
  %0 = llvm.mlir.constant(42 : i8) : i8
  %1 = llvm.mlir.constant(11 : i8) : i8
  %2 = llvm.sub %0, %arg170 : i8
  %3 = llvm.sub %1, %2 : i8
  "llvm.return"(%3) : (i8) -> ()
}
]

def and_nosignbit_select_lshr_after := [llvm|
{
^0(%arg28 : i32, %arg29 : i1):
  %0 = llvm.mlir.constant(8 : i32) : i32
  %1 = llvm.mlir.constant(8388352 : i32) : i32
  %2 = llvm.lshr %arg28, %0 : i32
  %3 = llvm.and %2, %1 : i32
  %4 = "llvm.select"(%arg29, %3, %2) <{"fastmathFlags" = #llvm.fastmath<none>}> : (i1, i32, i32) -> i32
  "llvm.return"(%4) : (i32) -> ()
}
]

def test12commuted_after := [llvm|
{
^0(%arg87 : i32, %arg88 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.and %arg87, %arg88 : i32
  %2 = llvm.xor %1, %0 : i32
  "llvm.return"(%2) : (i32) -> ()
}
]

def ashrslt_01_14_exact_before := [llvm|
{
^0(%arg39 : i4):
  %0 = llvm.mlir.constant(1 : i4) : i4
  %1 = llvm.mlir.constant(-2 : i4) : i4
  %2 = llvm.ashr exact %arg39, %0 : i4
  %3 = llvm.icmp "slt" %2, %1 : i4
  "llvm.return"(%3) : (i1) -> ()
}
]

@[simp_denote]
def ashr_llvm_no_flag_8 := [LV| {
  ^entry (%x: i8, %amount: i8):
    %1 = llvm.ashr %x, %amount : i8
    llvm.return %1 : i8
  }]

def not_not_cmp_before := [llvm|
{
^0(%arg147 : i32, %arg148 : i32):
  %0 = llvm.mlir.constant(-1 : i32) : i32
  %1 = llvm.xor %arg147, %0 : i32
  %2 = llvm.xor %arg148, %0 : i32
  %3 = llvm.icmp "slt" %1, %2 : i32
  "llvm.return"(%3) : (i1) -> ()
}
]

def n0_before := [llvm|
{
^0(%arg9 : i8, %arg10 : i8):
  %0 = llvm.mlir.constant(1 : i8) : i8
  %1 = llvm.mlir.constant(-1 : i8) : i8
  %2 = llvm.shl %0, %arg10 : i8
  %3 = llvm.xor %2, %1 : i8
  %4 = llvm.icmp "uge" %3, %arg9 : i8
  "llvm.return"(%4) : (i1) -> ()
}
]

Bool.atLeastTwo in Init.Data.BitVec.Bitblast
</all_available_defs>

<all_available_lemmas>
NFA.eval_append_singleton in Mathlib.Computability.NFA
NFA.eval_nil in Mathlib.Computability.NFA
BitVec.toNat_eq in Init.Data.BitVec.Lemmas
le_iff_lt_or_eq in Mathlib.Order.Defs.PartialOrder
Nat.le_antisymm in Init.Prelude
BitVec.toInt_inj in Init.Data.BitVec.Lemmas

@[ext]
theorem ext {x y : BitStream} (h : ∀ i, x i = y i) : x = y

theorem add_nsw_const_const_sub_nsw_ov_thm (e : IntW 8) :
  sub (const? 8 (-127)) (add e (const? 8 2) { «nsw» := true, «nuw» := false }) { «nsw» := true, «nuw» := false } ⊑
    sub (const? 8 127) e

theorem lshrugt_02_06_exact_thm (e : IntW 4) :
  icmp IntPred.ugt (lshr e (const? 4 2) { «exact» := true }) (const? 4 6) ⊑ const? 1 0

theorem scalar_i32_lshr_and_negC_slt_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ¬x ≥ ↑32 → ofBool (x_1 >>> x &&& BitVec.ofInt 32 (-8) <ₛ 0#32) = ofBool (x_1 >>> x <ₛ 0#32)

theorem test_lshr_exact__exact_is_safe_thm.extracted_1._1 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ofBool (x_1 &&& 60#32 == 0#32) = 1#1 →
    2#32 ≥ ↑32 ∨ True ∧ (x_1 >>> 2#32 &&& 15#32).msb = true ∨ zeroExtend 64 (x_1 >>> 2#32 &&& 15#32) ≥ ↑64 → False

theorem lshrult_01_15_proof : lshrult_01_15_before ⊑ lshrult_01_15_after

theorem eq_smax2_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ¬ofBool (x <ₛ x_1) = 1#1 → ofBool (x == x) = ofBool (x_1 ≤ₛ x)

theorem test3_thm.extracted_1._1 : ∀ (x : BitVec 32), True ∧ (x &&& 32#32 &&& 8#32 != 0) = true → False

@[simp] theorem Lets.denote_nil {Γ : Ctxt d.Ty} :
    (Lets.nil : Lets d Γ eff Γ).denote = (return ·)

theorem select_xor_icmp2_thm (e e_1 e_2 : IntW 32) :
  select (icmp IntPred.ne e_2 (const? 32 0)) e_1 (LLVM.xor e_2 e) ⊑
    select (icmp IntPred.eq e_2 (const? 32 0)) e e_1

theorem and_consts_logical_thm (e : IntW 32) :
  select (icmp IntPred.eq (LLVM.and (const? 32 4) e) (const? 32 0)) (const? 1 1)
      (icmp IntPred.eq (LLVM.and (const? 32 8) e) (const? 32 0)) ⊑
    icmp IntPred.ne (LLVM.and e (const? 32 12)) (const? 32 12)

theorem alive_AndOrXor_2264 : alive_AndOrXor_2264_src ⊑ alive_AndOrXor_2264_tgt

theorem e_1053 :
     - 2 * (z |||  ~~~t) + 5 *  ~~~z - 6 *  ~~~t + 3 *  ~~~(z ||| t) - 4 *  ~~~(z |||  ~~~t) + 9 * (z &&&  ~~~t) + 2 * (z &&& t) = 1 * (z ^^^ t)

theorem e_1019 :
     - 2 *  ~~~(z ^^^ t) - 2 * (z ||| t) - 11 * z - 7 * (z ^^^ t) + 7 *  ~~~(z ||| t) + 9 *  ~~~(z |||  ~~~t) + 25 * (z &&&  ~~~t) = 5 * (z |||  ~~~t) - 20 * (z &&& t)

theorem ne_umax4_thm (e e_1 : IntW 32) :
  icmp IntPred.ne (add e_1 (const? 32 3))
      (select (icmp IntPred.ugt e (add e_1 (const? 32 3))) e (add e_1 (const? 32 3))) ⊑
    icmp IntPred.ult (add e_1 (const? 32 3)) e

theorem bswap_and_mask_1_thm (e : IntW 64) :
  LLVM.or (LLVM.and (lshr e (const? 64 40)) (const? 64 65280)) (lshr e (const? 64 56)) ⊑
    LLVM.or (LLVM.and (lshr e (const? 64 40)) (const? 64 65280)) (lshr e (const? 64 56)) { «disjoint» := true }

theorem src_x_and_nmask_eq_proof : src_x_and_nmask_eq_before ⊑ src_x_and_nmask_eq_after

theorem bools2_logical_commute1_and1_proof : bools2_logical_commute1_and1_before ⊑ bools2_logical_commute1_and1_after

theorem p0_thm (e e_1 : IntW 8) :
  icmp IntPred.ugt (shl (const? 8 1) e_1) e ⊑ icmp IntPred.eq (lshr e e_1) (const? 8 0)

theorem sub_2_thm.extracted_1._3 : ∀ (x x_1 : BitVec 8) (x_2 : BitVec 1) (x_3 : BitVec 8),
  x_2 = 1#1 → x_3 - (x_1 ^^^ -1#8) ^^^ -1#8 = BitVec.ofInt 8 (-2) - (x_1 + x_3)

theorem main4b_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬ofBool (x &&& 7#32 == 7#32) &&& ofBool (x &&& 16#32 != 0#32) = 1#1 →
    1#32 = zeroExtend 32 (ofBool (x &&& 23#32 != 23#32))

theorem test_with_3_proof : test_with_3_before ⊑ test_with_3_after

theorem ashrsgt_03_07_thm (e : IntW 4) : icmp IntPred.sgt (ashr e (const? 4 3)) (const? 4 7) ⊑ const? 1 0

theorem test9_thm.extracted_1._1 : ∀ (x : BitVec 1), ofBool (x <ᵤ 0#1) = 0#1

theorem src_is_mask_xor_proof : src_is_mask_xor_before ⊑ src_is_mask_xor_after

theorem t0_thm.extracted_1._10 : ∀ (x x_1 : BitVec 8) (x_2 : BitVec 1),
  ¬x_2 ^^^ 1#1 = 1#1 → ¬x_2 = 1#1 → ¬0#1 = 1#1 → False

theorem xor_signbit_shl_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬8#32 ≥ ↑32 → (x ^^^ BitVec.ofInt 32 (-65536)) <<< 8#32 = x <<< 8#32 ^^^ BitVec.ofInt 32 (-16777216)

theorem sel_false_val_is_a_masked_ashr_of_true_val1_thm.extracted_1._3 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ¬ofBool (x_1 &&& BitVec.ofInt 32 (-2147483588) == 0#32) = 1#1 →
    ¬(2#32 ≥ ↑32 ∨ zeroExtend 64 ((x_1 &&& BitVec.ofInt 32 (-2147483588)).sshiftRight' 2#32) ≥ ↑64) →
      2#32 ≥ ↑32 ∨
          True ∧ (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)).msb = true ∨
            zeroExtend 64 (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)) ≥ ↑64 →
        False

theorem e_2266 :
    2 * (d |||  ~~~e) - 1 * ( ~~~(d &&& e) &&& (e ^^^ f)) + 4 * ((d ||| e) &&& (e ^^^ f)) + 11 * ((d &&& f) ^^^  ~~~(d ^^^ ( ~~~e &&& f))) - 5 *  ~~~(e &&&  ~~~f) - 5 *  ~~~( ~~~d &&& ( ~~~e ||| f)) - 7 * ((d ^^^ e) ||| (d ^^^ f)) + 5 * (f ^^^ ( ~~~d ||| ( ~~~e ||| f))) + 5 *  ~~~(e &&& f) + 1 * ( ~~~(d |||  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) - 7 * ((d &&& f) ^^^  ~~~(d ^^^ (e &&& f))) - 5 * (d ||| f) - 1 * ((d ^^^ e) &&&  ~~~(d ^^^ f)) + 4 * ((d &&&  ~~~e) ||| (e ^^^ f)) - 6 * ( ~~~e ||| (d ^^^ f)) - 1 * (e ^^^ (d &&& f)) + 7 * (e ^^^ ( ~~~d ||| (e &&& f))) + 1 * (d ^^^ (e ^^^ f)) + 1 * ( ~~~(d ||| e) |||  ~~~(e ^^^ f)) - 5 * ((d &&& f) ^^^  ~~~(e &&&  ~~~f)) - 3 * (e ^^^ f) - 1 * ( ~~~d &&& (e ||| f)) + 5 * (e ^^^ (d ||| (e ^^^ f))) + 5 * (e ^^^  ~~~( ~~~d &&& ( ~~~e &&& f))) - 2 * (e ^^^ ( ~~~d ||| (e ^^^ f))) - 2 * (f ^^^ ( ~~~d ||| ( ~~~e &&& f))) - 2 * (f |||  ~~~(d |||  ~~~e)) + 1 * (f &&& (d ^^^ e)) + 2 * (e ^^^  ~~~(d &&& (e &&& f))) - 1 * (d ||| ( ~~~e ||| f)) + 1 * ((d &&& f) ^^^ (d ^^^ (e &&& f))) + 11 * ((d &&& e) ||| (e ^^^ f)) + 4 * ((d &&& e) |||  ~~~(e ^^^ f)) + 1 * (d &&& ( ~~~e ||| f)) + 1 * ( ~~~d ||| (e &&& f)) - 1 * (f ^^^ (d &&& ( ~~~e ||| f))) - 11 *  ~~~(d &&& e) + 3 * (e ^^^ ( ~~~d ||| ( ~~~e ||| f))) + 2 * ( ~~~d &&& (e ^^^ f)) - 1 * ( ~~~d ||| (e ||| f)) + 11 * (f ^^^ (d ||| e)) - 2 * (e ^^^  ~~~(d ||| ( ~~~e &&& f))) + 7 * (d |||  ~~~f) - 2 *  ~~~( ~~~d &&& (e ^^^ f)) - 7 * ((d &&& f) ||| (e &&&  ~~~f)) + 2 * ( ~~~(d |||  ~~~e) |||  ~~~(e ^^^ f)) + 2 * (d ||| e) - 6 *  ~~~(d ||| (e ^^^ f)) + 2 * ((d ||| e) &&&  ~~~(e ^^^ f)) + 4 * (e ^^^ ( ~~~d ||| (e ||| f))) + 2 * (f ^^^ ( ~~~d ||| (e &&& f))) - 1 *  ~~~(d ||| (e ||| f)) - 7 *  ~~~(d ||| ( ~~~e ||| f)) - 2 *  ~~~( ~~~d ||| (e ||| f)) - 11 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 10 * ( ~~~d &&& ( ~~~e &&& f)) + 36 * ( ~~~d &&& (e &&& f)) + 10 * (d &&& ( ~~~e &&& f)) - 12 * (d &&& (e &&& f)) = 2 * (e ^^^  ~~~( ~~~d ||| (e &&& f))) + 11 *  ~~~(d &&& f)

theorem lshrult_03_00_proof : lshrult_03_00_before ⊑ lshrult_03_00_after

theorem sub_ule_sext_thm (e : IntW 1) (e_1 e_2 : IntW 8) :
  icmp IntPred.ule (sub e_2 e_1) (sext 8 e) ⊑ LLVM.or (icmp IntPred.eq e_2 e_1) e

theorem t0_thm.extracted_1._25 : ∀ (x x_1 x_2 x_3 : BitVec 8) (x_4 : BitVec 1),
  x_4 ^^^ 1#1 = 1#1 → x_4 = 1#1 → True → ofBool (x_3 != x_2) = 1#1 → x_1 = x

theorem shl_add_proof : shl_add_before ⊑ shl_add_after

theorem ashrslt_03_07_exact_proof : ashrslt_03_07_exact_before ⊑ ashrslt_03_07_exact_after

theorem sextinreg_alt_thm.extracted_1._1 : ∀ (x : BitVec 32),
  16#32 ≥ ↑32 ∨ True ∧ x <<< 16#32 >>> 16#32 <<< 16#32 ≠ x <<< 16#32 ∨ 16#32 ≥ ↑32 → False

theorem nonexact_ashr_ne_proof : nonexact_ashr_ne_before ⊑ nonexact_ashr_ne_after

theorem ashrslt_01_12_exact_thm.extracted_1._1 : ∀ (x : BitVec 4),
  ¬(True ∧ x >>> 1#4 <<< 1#4 ≠ x ∨ 1#4 ≥ ↑4) → ofBool (x.sshiftRight' 1#4 <ₛ BitVec.ofInt 4 (-4)) = 0#1

theorem positive_biggershl_shlnsw_ashrexact_thm (e : IntW 8) :
  shl (ashr e (const? 8 3) { «exact» := true }) (const? 8 6) { «nsw» := true, «nuw» := false } ⊑
    shl e (const? 8 3) { «nsw» := true, «nuw» := false }

theorem e_800 :
    7 *  ~~~(z &&& t) - 7 * (z ||| t) - 6 *  ~~~(z &&&  ~~~z) + 6 *  ~~~(z |||  ~~~t) + 13 * (z &&& t) =  - 6 * (z &&&  ~~~t) + 1 *  ~~~(z ||| t)

theorem sgt_minus1_proof : sgt_minus1_before ⊑ sgt_minus1_after

theorem sgt_negative_multip_rem_zero_proof : sgt_negative_multip_rem_zero_before ⊑ sgt_negative_multip_rem_zero_after

theorem masked_icmps_mask_notallzeros_bmask_mixed_swapped_1b_logical_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x &&& 3#32 == 1#32) = 1#1 →
    ofBool (x &&& 14#32 != 0#32) = ofBool (x &&& 3#32 == 1#32) &&& ofBool (x &&& 14#32 != 0#32)

theorem test_and2_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ofBool (-1#32 <ₛ x_1) &&& ofBool (x_1 ≤ₛ x &&& 2147483647#32) = ofBool (x_1 ≤ᵤ x &&& 2147483647#32)

theorem main7c_logical_thm.extracted_1._12 : ∀ (x x_1 x_2 : BitVec 32),
  ¬ofBool (x_2 == x_2 &&& x_1) = 1#1 →
    ¬ofBool (x_2 != x_2 &&& x_1) = 1#1 → ¬0#1 = 1#1 → 1#32 = zeroExtend 32 (ofBool (x != x &&& x_1))

theorem t0_proof : t0_before ⊑ t0_after

theorem t3_exact_proof : t3_exact_before ⊑ t3_exact_after

theorem trunc_lshr_sext_wide_input_thm (e : IntW 16) :
  trunc 8 (lshr (sext 32 e) (const? 32 9)) ⊑ trunc 8 (ashr e (const? 16 9)) { «nsw» := true, «nuw» := false }

theorem e_264 :
     - 1 *  ~~~(x &&& y) - 1 * y - 2 * (x ||| y) - 1 * (x ^^^ y) + 1 *  ~~~(x ||| y) + 5 *  ~~~(x |||  ~~~y) + 3 * (x &&& y) =  - 4 * (x &&&  ~~~y)

theorem test9_proof : test9_before ⊑ test9_after

theorem test2_thm (e : IntW 32) :
  add (LLVM.and e (const? 32 7)) (LLVM.and e (const? 32 32)) ⊑ LLVM.and e (const? 32 39)

theorem shl_mask_wrong_shl_const_proof : shl_mask_wrong_shl_const_before ⊑ shl_mask_wrong_shl_const_after

theorem main5f_like_logical_thm.extracted_1._8 : ∀ (x x_1 x_2 : BitVec 32),
  ofBool (x_2 &&& x_1 != x_2) = 1#1 → ¬ofBool (x_2 &&& x_1 == x_2) = 1#1 → ¬True → 0#32 = zeroExtend 32 0#1

theorem positive_with_extra_and_thm.extracted_1._1 : ∀ (x : BitVec 1) (x_1 : BitVec 32),
  ofBool (x_1 + 128#32 <ᵤ 256#32) &&& (ofBool (-1#32 <ₛ x_1) &&& x) = ofBool (x_1 <ᵤ 128#32) &&& x

theorem lshrugt_01_03_exact_thm.extracted_1._1 : ∀ (x : BitVec 4),
  ¬(True ∧ x >>> 1#4 <<< 1#4 ≠ x ∨ 1#4 ≥ ↑4) → ofBool (3#4 <ᵤ x >>> 1#4) = ofBool (6#4 <ᵤ x)

theorem add_and_or_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32), (x_1 &&& x) + (x_1 ||| x) = x_1 + x

theorem t0_proof : t0_before ⊑ t0_after

theorem icmp_ne_sext_ne_otherwise_i128_thm.extracted_1._1 : ∀ (x : BitVec 128),
  ofBool (signExtend 128 (ofBool (x != 2#128)) != x) = ofBool (x != -1#128)

theorem and_xor_common_op_thm (e e_1 : IntW 32) :
  LLVM.and (LLVM.udiv (const? 32 42) e_1) (LLVM.xor (LLVM.udiv (const? 32 42) e_1) (LLVM.udiv (const? 32 43) e)) ⊑
    LLVM.and (LLVM.udiv (const? 32 42) e_1) (LLVM.xor (LLVM.udiv (const? 32 43) e) (const? 32 (-1)))

theorem add_select_not_zext_thm.extracted_1._2 : ∀ (x : BitVec 1), ¬x = 1#1 → 1#64 + zeroExtend 64 (x ^^^ 1#1) = 2#64

theorem positive_biggershl_shlnuwnsw_thm (e : IntW 8) :
  shl (lshr e (const? 8 3)) (const? 8 6) { «nsw» := true, «nuw» := true } ⊑
    LLVM.and (shl e (const? 8 3) { «nsw» := true, «nuw» := true }) (const? 8 64)

theorem narrow_zext_ashr_keep_trunc_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ¬(True ∧ (signExtend 32 x_1).saddOverflow (signExtend 32 x) = true ∨ 1#32 ≥ ↑32) →
    True ∧ (signExtend 16 x_1).saddOverflow (signExtend 16 x) = true ∨ 1#16 ≥ ↑16 → False

theorem test27_thm (e e_1 e_2 : IntW 32) :
  zext 32 (icmp IntPred.eq (LLVM.xor e_2 e_1) (LLVM.xor e_2 e)) ⊑ zext 32 (icmp IntPred.eq e_1 e)

theorem e_543 :
    4 *  ~~~x + 1 *  ~~~y + 4 *  ~~~(x &&&  ~~~x) + 5 *  ~~~(x &&& y) + 7 *  ~~~(x ^^^ y) - 21 *  ~~~(x ||| y) - 18 *  ~~~(x |||  ~~~y) - 15 * (x &&&  ~~~y) - 16 * (x &&& y) =  - 5 * (x ||| y)

theorem main7f_logical_thm.extracted_1._11 : ∀ (x x_1 x_2 x_3 x_4 : BitVec 32),
  ofBool (x_4 &&& x_3 == x_2 &&& (x_4 &&& x_3)) = 1#1 →
    ¬ofBool (x_4 &&& x_3 != x_2 &&& (x_4 &&& x_3)) = 1#1 →
      ofBool (x_1 &&& x == x_2 &&& (x_1 &&& x)) = 1#1 →
        0#32 = zeroExtend 32 (ofBool (x_1 &&& x != x_2 &&& (x_1 &&& x)))

theorem mul_select_sext_thm (e : IntW 1) :
  mul (select e (const? 64 64) (const? 64 1)) (sext 64 e) ⊑ select e (const? 64 (-64)) (const? 64 0)

theorem test11_proof : test11_before ⊑ test11_after

@[simp] theorem Valuation.append_appendInr {v : Var Δ t} :
    (V ++ W) v.appendInr = W v

theorem main7a_thm.extracted_1._1 : ∀ (x x_1 x_2 : BitVec 32),
  ofBool (x_2 &&& x_1 == x_2) &&& ofBool (x &&& x_1 == x) = 1#1 →
    0#32 = zeroExtend 32 (ofBool (x_1 &&& (x_2 ||| x) != x_2 ||| x))

theorem positive_biggerashr_shlnuwnsw_thm.extracted_1._2 : ∀ (x : BitVec 8),
  ¬(6#8 ≥ ↑8 ∨
        True ∧ (x.sshiftRight' 6#8 <<< 3#8).sshiftRight' 3#8 ≠ x.sshiftRight' 6#8 ∨
          True ∧ x.sshiftRight' 6#8 <<< 3#8 >>> 3#8 ≠ x.sshiftRight' 6#8 ∨ 3#8 ≥ ↑8) →
    ¬3#8 ≥ ↑8 → x.sshiftRight' 6#8 <<< 3#8 = x.sshiftRight' 3#8 &&& BitVec.ofInt 8 (-8)

theorem e_1562 :
     - 1 * (b ||| (a ^^^ c)) + 4 *  ~~~( ~~~a ||| (b &&& c)) - 2 * ((a |||  ~~~b) &&&  ~~~(a ^^^ (b ^^^ c))) - 11 * (b ^^^ ( ~~~a ||| (b ||| c))) - 5 *  ~~~( ~~~a ||| ( ~~~b &&& c)) - 6 * ( ~~~b ||| (a ^^^ c)) - 7 * ((a &&& b) ^^^ (b |||  ~~~c)) + 7 *  ~~~(b ^^^ c) + 22 *  ~~~(a ||| (b ||| c)) + 8 *  ~~~( ~~~a ||| (b ||| c)) + 13 *  ~~~( ~~~a ||| ( ~~~b ||| c)) + 21 * ( ~~~a &&& ( ~~~b &&& c)) + 10 * ( ~~~a &&& (b &&& c)) + 18 * (a &&& ( ~~~b &&& c)) + 2 * (a &&& (b &&& c)) = 3 * ( ~~~a ||| (b ||| c)) - 11 *  ~~~(a ||| ( ~~~b ||| c))

theorem or_and_xor_not_constant_commute1_proof : or_and_xor_not_constant_commute1_before ⊑ or_and_xor_not_constant_commute1_after

theorem e_930 :
    7 *  ~~~(z ^^^ t) + 2 * (z |||  ~~~t) + 1 * (z ||| t) - 9 *  ~~~(z ||| t) - 8 *  ~~~(z |||  ~~~t) - 17 * (z &&& t) = 3 * (z &&&  ~~~t) - 7 * t

@[simp] theorem Com.rec'_rets (v : HVector Γ.Var t) :
    (Com.rets (d:=d) (eff := eff) v).rec' (motive:=motive) rets var = rets v

theorem ashrsgt_03_07_exact_proof : ashrsgt_03_07_exact_before ⊑ ashrsgt_03_07_exact_after

theorem test5_proof : test5_before ⊑ test5_after

theorem sext_sext_ne_proof : sext_sext_ne_before ⊑ sext_sext_ne_after

theorem e_1763 :
     - 11 * ((a &&& b) |||  ~~~(a ^^^ (b ^^^ c))) - 3 * ( ~~~b &&& (a ^^^ c)) - 6 *  ~~~(b ||| c) - 6 * ((a |||  ~~~b) &&& (b ^^^ c)) - 1 * ((a &&& b) ||| (b ^^^ c)) + 7 * (b ^^^  ~~~(a &&& (b ||| c))) - 6 *  ~~~(a &&& (b ||| c)) + 3 * (a ||| ( ~~~b &&& c)) + 3 *  ~~~(a |||  ~~~c) - 7 *  ~~~(b &&& c) + 11 * ((a ^^^ b) ||| (a ^^^ c)) - 2 *  ~~~( ~~~a ||| (b ^^^ c)) + 1 * (c ^^^ ( ~~~a ||| (b &&& c))) + 7 * (a &&&  ~~~b) - 7 * (c ^^^  ~~~(a &&&  ~~~b)) + 7 * (a ^^^ c) + 1 * (b |||  ~~~c) - 3 * ( ~~~(a |||  ~~~b) |||  ~~~(a ^^^ (b ^^^ c))) + 1 * ((a &&&  ~~~b) |||  ~~~(a ^^^ (b ^^^ c))) + 3 * (b ||| (a &&&  ~~~c)) + 2 * ( ~~~a ||| ( ~~~b ||| c)) + 1 * ( ~~~(a ||| b) ||| (a ^^^ (b ^^^ c))) - 2 * (c ^^^  ~~~( ~~~a ||| ( ~~~b &&& c))) - 3 * (a ||| (b ||| c)) + 5 * (b ^^^ (a ||| ( ~~~b ||| c))) - 2 * (b &&& (a ^^^ c)) + 2 * (b ^^^ (a ||| ( ~~~b &&& c))) + 3 * (c ^^^ (a |||  ~~~b)) + 14 *  ~~~(a ||| (b ||| c)) - 4 *  ~~~(a ||| ( ~~~b ||| c)) - 29 *  ~~~( ~~~a ||| (b ||| c)) + 1 *  ~~~( ~~~a ||| ( ~~~b ||| c)) - 11 * ( ~~~a &&& (b &&& c)) + 3 * (a &&& ( ~~~b &&& c)) - 5 * (a &&& (b &&& c)) = 13 * ( ~~~a &&& ( ~~~b &&& c)) - 5 *  ~~~( ~~~a &&& ( ~~~b &&& c))

theorem e_2057 :
     - 11 * (d ^^^ f) + 5 * ((d &&&  ~~~e) ||| (e ^^^ f)) + 7 *  ~~~( ~~~d &&& ( ~~~e &&& f)) - 2 * ( ~~~(d ^^^ e) &&& (d ^^^ f)) - 3 * (d |||  ~~~f) - 1 * ((d |||  ~~~e) &&& (d ^^^ (e ^^^ f))) - 1 * (f ^^^ (d &&& (e ||| f))) + 1 * (f ^^^  ~~~(d &&& e)) + 4 * (e ^^^ f) - 1 * (f ||| (d &&& e)) - 1 * (f ^^^  ~~~(d &&& (e &&& f))) + 11 * ( ~~~d ||| ( ~~~e ||| f)) - 1 * (f ^^^ ( ~~~d &&& ( ~~~e ||| f))) + 4 * ( ~~~(d ^^^ e) &&&  ~~~(d ^^^ f)) + 7 * ((d &&& f) ^^^ (d ^^^ (e &&& f))) - 2 *  ~~~(d ^^^ f) - 2 * d + 2 * ((d &&& e) |||  ~~~(e ||| f)) + 11 * (d &&& e) + 11 *  ~~~(d ||| (e &&& f)) - 11 *  ~~~(d ^^^ e) - 1 * ( ~~~(d &&& e) &&& (d ^^^ (e ^^^ f))) + 7 * (e &&&  ~~~(d &&& f)) - 3 * (e ^^^  ~~~( ~~~d ||| (e &&& f))) - 3 * (e ^^^  ~~~( ~~~d &&& ( ~~~e ||| f))) - 1 * (e ^^^ ( ~~~d ||| (e &&& f))) - 1 * (f ^^^ (d ||| (e ||| f))) + 4 * (e ||| (d ^^^ f)) - 3 * (d ^^^ (e ^^^ f)) + 1 * (e ||| (d &&& f)) - 37 *  ~~~(d ||| ( ~~~e ||| f)) - 8 *  ~~~( ~~~d ||| (e ||| f)) - 14 *  ~~~( ~~~d ||| ( ~~~e ||| f)) - 3 * ( ~~~d &&& ( ~~~e &&& f)) - 18 * ( ~~~d &&& (e &&& f)) - 13 * (d &&& ( ~~~e &&& f)) - 20 * (d &&& (e &&& f)) = 17 *  ~~~(d ||| (e ||| f))

@[simp] theorem getElem?_map (Γ : Ctxt Ty) (f : Ty → Ty') (i : Nat) :
    (Γ.map f)[i]? = Γ[i]?.map f

theorem and_or1_wrong_operand_thm.extracted_1._3 : ∀ (x x_1 x_2 x_3 : BitVec 1),
  x_3 ^^^ 1#1 ||

theorem mul_setnzV_unkV_nuw_eq_thm (e e_1 : IntW 8) :
  icmp IntPred.eq (mul (LLVM.or e_1 (const? 8 2)) e { «nsw» := false, «nuw» := true }) (const? 8 0) ⊑
    icmp IntPred.eq e (const? 8 0)

theorem e_884 :
    1 *  ~~~z - 5 *  ~~~t - 6 * z + 4 *  ~~~(z ||| t) - 1 *  ~~~(z |||  ~~~t) + 6 * (z &&& t) =  - 11 * (z &&&  ~~~t)

@[simp]
lemma autMsbSet_accepts : NFA'.autMsbSet.accepts = langMsb

theorem main12_logical_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (truncate 16 x <ₛ 0#16) = 1#1 → ofBool (x &&& 32896#32 == 0#32) = 1#1 → True → 2#32 = 1#32

theorem test3_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬30#32 ≥ ↑32 → 30#32 ≥ ↑32 ∨ True ∧ (x &&& 128#32 &&& x >>> 30#32 != 0) = true → False

theorem and_sgt_to_mask_thm (e : IntW 8) :
  LLVM.and (icmp IntPred.sgt e (const? 8 123)) (icmp IntPred.eq (LLVM.and e (const? 8 2)) (const? 8 0)) ⊑
    icmp IntPred.eq (LLVM.and e (const? 8 (-2))) (const? 8 124)

theorem substitute_constant_and_eq_ugt_swap_logical_proof : substitute_constant_and_eq_ugt_swap_logical_before ⊑ substitute_constant_and_eq_ugt_swap_logical_after

theorem add_nsw_const_const_sub_thm.extracted_1._1 : ∀ (x : BitVec 8),
  ¬(True ∧ x.saddOverflow 1#8 = true) → BitVec.ofInt 8 (-127) - (x + 1#8) = BitVec.ofInt 8 (-128) - x

theorem add_signbit_select_shl_proof : add_signbit_select_shl_before ⊑ add_signbit_select_shl_after

@[simp]
theorem Term.toBV_pvar {wenv : WidthExpr.Env wcard}
    {tctx : Term.Ctx wcard tcard}
    (benv : Term.BoolEnv bcard)
    (tenv : tctx.Env wenv) (v : Fin pcard) :
  Term.toBV benv nenv ienv penv tenv (.pvar v) = penv v

theorem exact_lshr_eq_exactdiv_proof : exact_lshr_eq_exactdiv_before ⊑ exact_lshr_eq_exactdiv_after

theorem test31_thm (e : IntW 1) :
  LLVM.and (shl (zext 32 e) (const? 32 4)) (const? 32 16) ⊑ select e (const? 32 16) (const? 32 0)

theorem or_or_logic_and_1_thm.extracted_1._5 : ∀ (x x_1 x_2 : BitVec 1),
  ¬x_2 ||

theorem scalar_i8_shl_ult_const_1_thm.extracted_1._1 : ∀ (x : BitVec 8),
  ¬5#8 ≥ ↑8 → ofBool (x <<< 5#8 <ᵤ 64#8) = ofBool (x &&& 6#8 == 0#8)

theorem test35_with_trunc_thm (e : IntW 64) :
  select (icmp IntPred.sge (trunc 32 e) (const? 32 0)) (const? 32 60) (const? 32 100) ⊑
    select (icmp IntPred.eq (LLVM.and e (const? 64 2147483648)) (const? 64 0)) (const? 32 60)
      (const? 32 100)

theorem test10_proof : test10_before ⊑ test10_after

@[simp]
theorem EnvFin.getLsbD_getLsb {w : Nat} (env : EnvFin (w + 1) n) (bit : Nat) : (env.getLsb i).getLsbD bit =
    if bit = 0 then (env i)[0] else false

theorem c0_proof : c0_before ⊑ c0_after

theorem test4_proof : test4_before ⊑ test4_after

theorem test_sext3_thm.extracted_1._2 : ∀ (x : BitVec 1), x = 1#1 → ¬x ^^^ 1#1 = 1#1 → 0#32 = signExtend 32 0#1

theorem test_sext3_thm.extracted_1._3 : ∀ (x x_1 : BitVec 1), x_1 = 1#1 → x_1 ^^^ 1#1 = 1#1 → 0#32 = signExtend 32 x

theorem icmp_ne_sext_ne_allones_proof : icmp_ne_sext_ne_allones_before ⊑ icmp_ne_sext_ne_allones_after

theorem shl_lshr_pow2_const_negative_overflow2_proof : shl_lshr_pow2_const_negative_overflow2_before ⊑ shl_lshr_pow2_const_negative_overflow2_after

theorem positive_trunc_signbit_proof : positive_trunc_signbit_before ⊑ positive_trunc_signbit_after

theorem ugt_rem_zero_proof : ugt_rem_zero_before ⊑ ugt_rem_zero_after

theorem sle_smax4_proof : sle_smax4_before ⊑ sle_smax4_after

theorem squared_nsw_eq0_thm (e : IntW 5) :
  icmp IntPred.eq (mul e e { «nsw» := true, «nuw» := false }) (const? 5 0) ⊑
    icmp IntPred.eq e (const? 5 0)

theorem icmp_equality_test_constant_proof : icmp_equality_test_constant_before ⊑ icmp_equality_test_constant_after

theorem t0_thm.extracted_1._2 : ∀ (x : BitVec 8) (x_1 : BitVec 1), x_1 ^^^ 1#1 = 1#1 → x_1 = 1#1 → ¬True → False

theorem test_mul__nuw_is_safe_proof : test_mul__nuw_is_safe_before ⊑ test_mul__nuw_is_safe_after

theorem test4_proof : test4_before ⊑ test4_after

omit [LawfulBEq A] [Fintype S] [LawfulBEq S] [DecidableEq S] in
lemma rel_in_states {st : worklist.St A S} (hinv : StInv A S st.m st.map) :
    s ~[st.rel] sa → s ∈ st.m.states

theorem test_ashr__exact_is_unsafe_thm.extracted_1._3 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ¬ofBool (x_1 &&& BitVec.ofInt 32 (-2147483585) == 0#32) = 1#1 →
    ¬(2#32 ≥ ↑32 ∨ zeroExtend 64 ((x_1 &&& BitVec.ofInt 32 (-2147483585)).sshiftRight' 2#32) ≥ ↑64) →
      2#32 ≥ ↑32 ∨
          True ∧ (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)).msb = true ∨
            zeroExtend 64 (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)) ≥ ↑64 →
        False

theorem test8_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ¬32#128 ≥ ↑128 →
    True ∧ zeroExtend 64 x_1 <<< 32#64 >>> 32#64 ≠ zeroExtend 64 x_1 ∨
        32#64 ≥ ↑64 ∨ True ∧ (zeroExtend 64 x_1 <<< 32#64 &&& zeroExtend 64 x != 0) = true →
      False

theorem masked_and_notA_slightly_optimized_logical_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬ofBool (8#32 ≤ᵤ x) = 1#1 → 0#1 = ofBool (x &&& BitVec.ofInt 32 (-40) != 0#32)

theorem invert_both_cmp_operands_sub_proof : invert_both_cmp_operands_sub_before ⊑ invert_both_cmp_operands_sub_after

theorem neg_or_lshr_i32_commute_proof : neg_or_lshr_i32_commute_before ⊑ neg_or_lshr_i32_commute_after

theorem e_2282 :
    1 * ((e &&&  ~~~f) |||  ~~~(d ||| ( ~~~e &&& f))) + 11 *  ~~~(d &&& (e &&& f)) + 4 * (f ^^^ ( ~~~d &&& ( ~~~e ||| f))) - 1 * (d &&&  ~~~f) - 1 * (e ^^^  ~~~(d &&& (e ||| f))) + 5 * (f ^^^  ~~~(d &&& (e ||| f))) - 2 * ((d ^^^ e) &&& (d ^^^ f)) + 1 * (d ^^^ ( ~~~e &&& f)) + 2 * ((d &&& f) ^^^  ~~~(d ^^^ ( ~~~e &&& f))) - 1 * (e ||| (d ^^^ f)) + 4 * (f |||  ~~~(d ^^^ e)) + 5 * ((d ||| e) &&&  ~~~(d ^^^ (e ^^^ f))) + 1 * (d ^^^ (e ^^^ f)) - 1 * ( ~~~d ||| ( ~~~e &&& f)) - 1 * ((d &&& e) ^^^  ~~~(d ^^^ (e &&& f))) + 4 * ( ~~~(d |||  ~~~e) ||| (e ^^^ f)) + 2 * ((d &&& e) ||| (d ^^^ (e ^^^ f))) - 2 *  ~~~e - 5 * ((d &&& f) ^^^ (e ||| f)) - 5 *  ~~~(d &&& e) + 4 * (d ||| (e &&& f)) - 2 * (e ^^^  ~~~( ~~~d &&& ( ~~~e ||| f))) - 2 * ((d |||  ~~~e) &&& (d ^^^ (e ^^^ f))) - 2 *  ~~~d + 7 *  ~~~(d ||| ( ~~~e &&& f)) + 3 * (e ^^^  ~~~(d &&& ( ~~~e ||| f))) + 3 * ((d &&& e) ^^^ (e ||| f)) - 7 * ( ~~~(d |||  ~~~e) |||  ~~~(e ^^^ f)) - 11 *  ~~~( ~~~d &&& (e ||| f)) - 6 * ((d ||| e) &&&  ~~~(e ^^^ f)) + 7 * ((e &&& f) ||| (d &&& (e ||| f))) + 11 * (d &&&  ~~~e) - 1 *  ~~~(d |||  ~~~f) - 1 * ((e &&&  ~~~f) ^^^ ( ~~~d ||| (e ^^^ f))) + 11 * ( ~~~d &&& (e ||| f)) - 1 * (e &&& (d ||| f)) + 1 *  ~~~(d ^^^ (e ||| f)) - 1 * ( ~~~(d &&&  ~~~e) &&& (e ^^^ f)) - 2 * ( ~~~e &&&  ~~~(d ^^^ f)) - 11 *  ~~~(e &&& f) + 2 * (e ^^^ (d ||| (e ||| f))) + 4 * (e ^^^ ( ~~~d ||| (e &&& f))) + 3 * (f &&& (d ^^^ e)) + 2 * (e ^^^ (d ||| ( ~~~e &&& f))) - 6 * (f ^^^ (d &&& e)) + 2 * ( ~~~e |||  ~~~(d ^^^ f)) - 7 *  ~~~(d ^^^ (e ^^^ f)) - 11 *  ~~~(e &&&  ~~~f) - 11 * (d ||| f) - 11 * ((e &&& f) ||| ( ~~~d &&& (e ||| f))) - 7 * ( ~~~d &&& (e ^^^ f)) + 2 * ( ~~~(d &&& e) &&& (e ^^^ f)) + 25 *  ~~~(d ||| (e ||| f)) + 4 *  ~~~(d ||| ( ~~~e ||| f)) + 44 *  ~~~( ~~~d ||| (e ||| f)) + 13 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 33 * ( ~~~d &&& ( ~~~e &&& f)) + 28 * ( ~~~d &&& (e &&& f)) + 7 * (d &&& ( ~~~e &&& f)) + 33 * (d &&& (e &&& f)) = 5 * (d ^^^ (e ||| f)) + 7 * ((d &&&  ~~~e) |||  ~~~(e ^^^ f))

theorem shl_sub_lshr_reverse_thm.extracted_1._2 : ∀ (x x_1 x_2 : BitVec 32),
  ¬(True ∧ x_1 <<< x >>> x ≠ x_1 ∨
        x ≥ ↑32 ∨
          True ∧ x_2.ssubOverflow (x_1 <<< x) = true ∨
            True ∧ x_2.usubOverflow (x_1 <<< x) = true ∨
              True ∧ (x_2 - x_1 <<< x) >>> x <<< x ≠ x_2 - x_1 <<< x ∨ x ≥ ↑32) →
    ¬(True ∧ x_2 >>> x <<< x ≠ x_2 ∨
          x ≥ ↑32 ∨ True ∧ (x_2 >>> x).ssubOverflow x_1 = true ∨ True ∧ (x_2 >>> x).usubOverflow x_1 = true) →
      (x_2 - x_1 <<< x) >>> x = x_2 >>> x - x_1

@[simp] theorem sup_impure_eq : max e impure  = impure

theorem not_sub_thm (e : IntW 32) :
  LLVM.xor (sub (const? 32 123) e) (const? 32 (-1)) ⊑ add e (const? 32 (-124))

theorem positive_samevar_shlnuwnsw_ashrexact_thm (e e_1 : IntW 8) :
  shl (ashr e_1 e { «exact» := true }) e { «nsw» := true, «nuw» := true } ⊑ e_1

theorem or_xor_tree_0010_thm (e e_1 e_2 : IntW 32) :
  LLVM.or (LLVM.xor (mul e_2 (const? 32 42)) (mul e_1 (const? 32 42)))
      (LLVM.xor (LLVM.xor (mul e (const? 32 42)) (mul e_1 (const? 32 42))) (mul e_2 (const? 32 42))) ⊑
    LLVM.or (LLVM.xor (mul e_2 (const? 32 42)) (mul e_1 (const? 32 42))) (mul e (const? 32 42))

theorem test_with_3_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬x ≥ ↑32 → 3#32 <<< x &&& 1#32 = zeroExtend 32 (ofBool (x == 0#32))

theorem e_1830 :
    2 * ( ~~~(a |||  ~~~b) ||| (b ^^^ c)) - 1 *  ~~~(a &&& (b ^^^ c)) - 1 * ((a ||| b) &&&  ~~~(b ^^^ c)) - 11 *  ~~~a - 6 * (c |||  ~~~(a |||  ~~~b)) + 1 * (c ||| (a ^^^ b)) - 2 * ( ~~~c ||| (a ^^^ b)) - 2 * ( ~~~(a ||| b) ||| (b ^^^ c)) + 4 * (b ^^^ ( ~~~a ||| (b ^^^ c))) - 6 * (b |||  ~~~(a ^^^ c)) + 4 * ( ~~~a ||| (b ||| c)) + 7 * (a &&& ( ~~~b ||| c)) - 5 * ((b &&&  ~~~c) ^^^ ( ~~~a ||| (b ^^^ c))) - 5 * (b ^^^  ~~~(a ||| c)) - 1 * (a ^^^ (b &&& c)) - 3 * (a ||| ( ~~~b ||| c)) - 7 * (c ^^^ (a &&& b)) + 2 * (b ^^^ (a ||| (b ||| c))) + 4 * (c ^^^  ~~~( ~~~a ||| ( ~~~b &&& c))) + 3 * (c ^^^  ~~~(a &&& (b &&& c))) - 7 *  ~~~( ~~~a ||| (b &&& c)) + 1 * ( ~~~c &&& (a ^^^ b)) - 2 * ((a &&& b) |||  ~~~(b ||| c)) - 1 * ( ~~~(a ^^^ b) &&&  ~~~(a ^^^ c)) - 1 * ((a &&& b) |||  ~~~(b ^^^ c)) - 2 * ((b &&&  ~~~c) |||  ~~~(a ||| ( ~~~b &&& c))) - 3 * (c &&& (a ^^^ b)) - 1 * (b ^^^ (a &&& c)) + 2 * (b &&&  ~~~(a &&& c)) - 1 * (b &&&  ~~~(a ^^^ c)) - 5 *  ~~~( ~~~a &&& (b ^^^ c)) - 5 * ((a |||  ~~~b) &&& (b ^^^ c)) + 1 * ((a ^^^ b) ||| (a ^^^ c)) + 2 * ((a &&& b) ^^^  ~~~(a ^^^ (b &&& c))) + 3 * (b ||| (a &&&  ~~~c)) + 31 *  ~~~(a ||| (b ||| c)) + 13 *  ~~~(a ||| ( ~~~b ||| c)) + 1 *  ~~~( ~~~a ||| (b ||| c)) + 26 *  ~~~( ~~~a ||| ( ~~~b ||| c)) + 20 * ( ~~~a &&& ( ~~~b &&& c)) + 41 * ( ~~~a &&& (b &&& c)) + 28 * (a &&& ( ~~~b &&& c)) + 10 * (a &&& (b &&& c)) =  - 2 * ( ~~~(a &&&  ~~~b) &&&  ~~~(a ^^^ (b ^^^ c)))

theorem lsb_mask_sign_sext_commuted_thm (e : IntW 32) :
  ashr (LLVM.and (LLVM.xor e (const? 32 (-1))) (add e (const? 32 (-1)))) (const? 32 31) ⊑
    sext 32 (icmp IntPred.eq e (const? 32 0))

@[simp]
theorem Term.toBV_ofNat
    {tctx : Term.Ctx wcard tcard}
    (tenv : tctx.Env wenv)
    (benv : Term.BoolEnv bcard)
    (nnenv : Term.NatEnv ncard)
    (ienv : Term.IntEnv icard)
    (w : WidthExpr wcard) (n : Nat) :
  Term.toBV benv nenv ienv penv tenv (.ofNat w n) = BitVec.ofNat (w.toNat wenv) n

theorem sext_thm.extracted_1._1 : ∀ (x : BitVec 16),
  (zeroExtend 32 x ^^^ 32768#32) + BitVec.ofInt 32 (-32768) = signExtend 32 x

theorem or_xor_tree_0000_thm (e e_1 e_2 : IntW 32) :
  LLVM.or (LLVM.xor (mul e_2 (const? 32 42)) (mul e_1 (const? 32 42)))
      (LLVM.xor (LLVM.xor (mul e_1 (const? 32 42)) (mul e (const? 32 42))) (mul e_2 (const? 32 42))) ⊑
    LLVM.or (LLVM.xor (mul e_2 (const? 32 42)) (mul e_1 (const? 32 42))) (mul e (const? 32 42))

theorem alive_AndOrXor_716 : alive_AndOrXor_716_src ⊑ alive_AndOrXor_716_tgt

theorem ashrsgt_02_11_exact_proof : ashrsgt_02_11_exact_before ⊑ ashrsgt_02_11_exact_after

theorem test_add_nuw_nsw__nsw_is_safe_proof : test_add_nuw_nsw__nsw_is_safe_before ⊑ test_add_nuw_nsw__nsw_is_safe_after

theorem positive_biggershl_shlnsw_lshrexact_thm.extracted_1._2 : ∀ (x : BitVec 8),
  ¬(True ∧ x >>> 3#8 <<< 3#8 ≠ x ∨ 3#8 ≥ ↑8 ∨ True ∧ (x >>> 3#8 <<< 6#8).sshiftRight' 6#8 ≠ x >>> 3#8 ∨ 6#8 ≥ ↑8) →
    ¬(True ∧ (x <<< 3#8).sshiftRight' 3#8 ≠ x ∨ True ∧ x <<< 3#8 >>> 3#8 ≠ x ∨ 3#8 ≥ ↑8) →
      x >>> 3#8 <<< 6#8 = x <<< 3#8

theorem ashrsgt_03_15_thm (e : IntW 4) :
  icmp IntPred.sgt (ashr e (const? 4 3)) (const? 4 (-1)) ⊑ icmp IntPred.sgt e (const? 4 (-1))

theorem test_add__none_are_safe_thm.extracted_1._1 : ∀ (x : BitVec 32), ofBool (x == 3#32) = 1#1 → 4#32 = x + 1#32

theorem slt_swap_or_not_max_logical_proof : slt_swap_or_not_max_logical_before ⊑ slt_swap_or_not_max_logical_after

theorem t0_ult_slt_65536_thm.extracted_1._15 : ∀ (x x_1 x_2 : BitVec 32),
  ¬ofBool (x_2 <ᵤ 65536#32) = 1#1 →
    ¬ofBool (x_2 <ₛ 65536#32) = 1#1 → ¬ofBool (65535#32 <ₛ x_2) = 1#1 → ¬ofBool (x_2 <ₛ 0#32) = 1#1 → x = x_2

theorem shl_add_log_may_cause_poison_pr62175_with_nuw_proof : shl_add_log_may_cause_poison_pr62175_with_nuw_before ⊑ shl_add_log_may_cause_poison_pr62175_with_nuw_after

theorem bools_logical_commute0_and1_and2_thm.extracted_1._5 : ∀ (x x_1 x_2 : BitVec 1),
  ¬(x_2 ^^^ 1#1) &&& x_1 = 1#1 → x_2 = 1#1 → x_2 &&& x = x

theorem sge_swap_or_not_max_logical_proof : sge_swap_or_not_max_logical_before ⊑ sge_swap_or_not_max_logical_after

theorem icmp_eq_x_invertable_y2_proof : icmp_eq_x_invertable_y2_before ⊑ icmp_eq_x_invertable_y2_after

theorem e_2020 :
    1 * (d ||| ( ~~~e &&& f)) + 2 * ((d &&& e) ^^^ (d ^^^ ( ~~~e ||| f))) - 7 * (f ^^^  ~~~( ~~~d &&& (e &&& f))) - 2 * (f ||| (d &&&  ~~~e)) - 6 * (e ^^^ f) - 1 * (e &&& f) - 5 * (e ^^^ (d ||| f)) - 6 * (d ||| (e &&& f)) + 3 * ((d &&& e) |||  ~~~(e ^^^ f)) - 1 * (e ^^^ ( ~~~d &&& (e ^^^ f))) + 4 * ((e &&&  ~~~f) ^^^ (d ||| (e ^^^ f))) + 3 * (d ||| f) + 5 * (e ^^^ (d ||| (e ^^^ f))) - 5 * ((d ^^^ e) |||  ~~~(d ^^^ f)) + 1 * (e ^^^  ~~~( ~~~d ||| (e &&& f))) - 3 * (e ||| (d &&& f)) + 2 * ( ~~~(d ||| e) |||  ~~~(d ^^^ (e ^^^ f))) + 11 * (e ^^^  ~~~( ~~~d &&& (e ||| f))) - 1 * (d ||| ( ~~~e ||| f)) - 1 * (e ^^^  ~~~( ~~~d &&& ( ~~~e &&& f))) - 11 * (d &&& (e ^^^ f)) - 2 * (e ^^^  ~~~( ~~~d ||| (e ^^^ f))) + 4 * ((d &&& f) ^^^ (d ^^^ (e &&& f))) + 1 *  ~~~( ~~~d &&& ( ~~~e ||| f)) - 11 * (e ^^^ ( ~~~d ||| (e &&& f))) - 3 * ( ~~~(d &&& e) &&& (e ^^^ f)) - 11 * (e ^^^  ~~~(d ||| (e &&& f))) + 11 * (f |||  ~~~(d |||  ~~~e)) + 7 *  ~~~(d ||| (e ||| f)) - 4 *  ~~~( ~~~d ||| (e ||| f)) + 45 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 12 * ( ~~~d &&& ( ~~~e &&& f)) - 14 * ( ~~~d &&& (e &&& f)) - 7 * (d &&& ( ~~~e &&& f)) =  - 11 * ( ~~~(d &&& e) &&&  ~~~(d ^^^ (e ^^^ f))) - 7 *  ~~~(d ||| ( ~~~e ||| f))

theorem icmp_slt_0_or_icmp_sgt_0_i32_thm.extracted_1._1 : ∀ (x : BitVec 32),
  zeroExtend 32 (ofBool (x <ₛ 0#32)) ||

theorem select1_thm.extracted_1._4 : ∀ (x x_1 x_2 : BitVec 32) (x_3 : BitVec 1),
  x_3 = 1#1 → zeroExtend 32 (truncate 8 x_2) = x_2 &&& 255#32

theorem test8_thm (e : IntW 27) : sub (mul (const? 27 9) e) e ⊑ shl e (const? 27 3)

theorem ashr_lshr_cst2_thm (e : IntW 32) :
  select (icmp IntPred.sgt e (const? 32 (-1))) (lshr e (const? 32 8)) (ashr e (const? 32 8) { «exact» := true }) ⊑
    ashr e (const? 32 8)

theorem src_is_mask_zext_fail_not_mask_thm.extracted_1._1 : ∀ (x : BitVec 8) (x_1 : BitVec 16),
  ¬x ≥ ↑8 →
    ofBool ((x_1 ^^^ 123#16) &&& zeroExtend 16 (BitVec.ofInt 8 (-2) >>> x) == x_1 ^^^ 123#16) =
      ofBool (x_1 ^^^ BitVec.ofInt 16 (-124) ||| zeroExtend 16 (BitVec.ofInt 8 (-2) >>> x) == -1#16)

theorem alive_AndOrXor_135  (w : Nat)   : alive_AndOrXor_135_src w  ⊑ alive_AndOrXor_135_tgt w

theorem main7d_logical_thm.extracted_1._9 : ∀ (x x_1 x_2 x_3 x_4 : BitVec 32),
  ofBool (x_4 &&& (x_3 &&& x_2) == x_3 &&& x_2) = 1#1 →
    ofBool (x_4 &&& (x_3 &&& x_2) != x_3 &&& x_2) = 1#1 →
      ofBool (x_4 &&& (x_1 &&& x) == x_1 &&& x) = 1#1 → 0#32 = zeroExtend 32 1#1

theorem test_invert_demorgan_or2_proof : test_invert_demorgan_or2_before ⊑ test_invert_demorgan_or2_after

theorem nonexact_ashr_ne_exactdiv_thm (e : IntW 8) :
  icmp IntPred.ne (ashr (const? 8 (-80)) e) (const? 8 (-5)) ⊑ icmp IntPred.ne e (const? 8 4)

theorem e_1054 :
    1 * (z |||  ~~~t) - 5 *  ~~~(z &&&  ~~~t) + 7 *  ~~~z - 7 * t + 3 *  ~~~(z ||| t) + 5 *  ~~~(z |||  ~~~t) + 11 * (z &&& t) = 6 *  ~~~t - 5 * (z &&&  ~~~t)

theorem e_2425 :
    3 * (d ||| ( ~~~e &&& f)) - 1 * ((d &&& e) ^^^ (d ^^^ ( ~~~e ||| f))) - 1 * (e ^^^ (d ||| (e ^^^ f))) + 11 * ( ~~~(d &&& e) &&& (d ^^^ (e ^^^ f))) + 2 *  ~~~( ~~~d &&& (e &&& f)) - 5 * (e ^^^  ~~~(d &&& (e ^^^ f))) - 6 * (f ^^^  ~~~( ~~~d &&& (e ||| f))) + 1 * (e ^^^ (d &&& ( ~~~e ||| f))) + 11 *  ~~~(d ||| ( ~~~e &&& f)) + 3 * ((d &&& e) ||| (e ^^^ f)) + 4 * (e ^^^  ~~~(d &&& (e ||| f))) + 2 * (f ^^^  ~~~(d ||| e)) - 11 * ( ~~~e &&& (d ^^^ f)) + 7 *  ~~~( ~~~d &&& (e ||| f)) + 2 *  ~~~(d |||  ~~~f) + 7 *  ~~~(e |||  ~~~f) - 6 * ((d &&& f) ^^^  ~~~(d ^^^ (e &&& f))) - 1 * ((e &&& f) ^^^  ~~~(d &&& (e ^^^ f))) - 2 * ( ~~~f &&&  ~~~(d ^^^ e)) + 7 * ((d &&& f) ^^^ (e ||| f)) - 1 * (f ^^^  ~~~( ~~~d ||| (e &&& f))) - 1 * (d ||| e) - 3 * ((d ^^^ e) &&& (d ^^^ f)) + 3 * ((d ||| e) &&&  ~~~(d ^^^ (e ^^^ f))) - 3 * (f |||  ~~~(d |||  ~~~e)) + 2 * ((d &&& f) ^^^ (d ^^^ ( ~~~e &&& f))) + 5 * (f ^^^  ~~~(d &&&  ~~~e)) + 2 * (e ^^^  ~~~( ~~~d &&& ( ~~~e ||| f))) + 2 * (e &&& (d |||  ~~~f)) + 5 * ( ~~~(d &&&  ~~~e) &&& (d ^^^ (e ^^^ f))) - 2 * ((d &&& e) |||  ~~~(e ^^^ f)) - 2 * ( ~~~(d &&& e) &&&  ~~~(e ^^^ f)) + 1 * ( ~~~(d &&&  ~~~e) &&& (e ^^^ f)) - 2 * (e &&& f) + 1 * ( ~~~(d |||  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) + 2 * (f |||  ~~~(d ^^^ e)) + 2 * (f ||| (d &&&  ~~~e)) + 1 * (d |||  ~~~f) - 3 * ((d ||| e) &&&  ~~~(e ^^^ f)) - 7 * ( ~~~(d ||| e) |||  ~~~(e ^^^ f)) - 5 * (f &&& (d ^^^ e)) + 11 * (e &&& (d ||| f)) - 6 * (d ||| ( ~~~e ||| f)) - 6 *  ~~~( ~~~d ||| (e ^^^ f)) + 5 * (e ^^^ (d ||| f)) - 2 * (e ^^^  ~~~(d |||  ~~~f)) - 11 *  ~~~(d ^^^ (e &&& f)) + 2 * ((d &&& e) |||  ~~~(d ^^^ (e ^^^ f))) - 2 * (e ^^^  ~~~(d ||| (e &&& f))) - 7 * (d ^^^ (e &&& f)) - 7 * ( ~~~e &&&  ~~~(d ^^^ f)) - 3 * ((e &&&  ~~~f) |||  ~~~( ~~~d ||| ( ~~~e &&& f))) - 7 * (e ^^^ (d ||| ( ~~~e ||| f))) - 1 * (e ^^^ f) - 2 *  ~~~(d &&& (e ||| f)) - 7 * (e ^^^ (d &&& (e ^^^ f))) + 2 * (f ^^^  ~~~( ~~~d ||| ( ~~~e &&& f))) - 11 * (e ^^^ (d ||| (e ||| f))) - 1 * (d ^^^ ( ~~~e ||| f)) - 3 * (e ||| f) + 11 * (d ^^^ (e ^^^ f)) - 5 * (d ||| (e ||| f)) - 1 * (f ^^^ (d ||| (e ||| f))) - 6 * ((d ^^^ e) &&&  ~~~(d ^^^ f)) + 7 * (f ||| (d ^^^ e)) - 6 * ((d &&& f) ^^^  ~~~(d ^^^ ( ~~~e &&& f))) + 7 *  ~~~(d ^^^ ( ~~~e &&& f)) + 30 *  ~~~(d ||| (e ||| f)) - 16 *  ~~~(d ||| ( ~~~e ||| f)) + 31 *  ~~~( ~~~d ||| (e ||| f)) - 12 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 17 * ( ~~~d &&& ( ~~~e &&& f)) + 13 * ( ~~~d &&& (e &&& f)) + 10 * (d &&& ( ~~~e &&& f)) + 6 * (d &&& (e &&& f)) =  - 1 * e

theorem masked_icmps_mask_notallzeros_bmask_mixed_negated_swapped_1_logical_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x &&& 7#32 != 1#32) = 1#1 → 1#1 = ofBool (x &&& 15#32 != 9#32)

theorem test11_proof : test11_before ⊑ test11_after

theorem trunc_shl_nsw_nuw_31_i32_i64_thm.extracted_1._2 : ∀ (x : BitVec 64),
  ¬(True ∧ (x <<< 31#64).sshiftRight' 31#64 ≠ x ∨ True ∧ x <<< 31#64 >>> 31#64 ≠ x ∨ 31#64 ≥ ↑64) →
    ¬31#32 ≥ ↑32 → truncate 32 (x <<< 31#64) = truncate 32 x <<< 31#32

theorem max_sub_ult_c1_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬ofBool (x <ᵤ 1#32) = 1#1 → 0#32 = signExtend 32 (ofBool (x == 0#32))

theorem e_1288 :
    1 * (z ^^^ t) + 2 *  ~~~(z ^^^ t) - 3 *  ~~~(z &&& t) + 11 *  ~~~(z &&&  ~~~t) - 1 * (z ||| t) - 13 *  ~~~(z ||| t) - 12 *  ~~~(z |||  ~~~t) + 4 * (z &&&  ~~~t) - 11 * (z &&& t) = 1 * (z |||  ~~~t) - 4 *  ~~~z

theorem exact_lshr_eq_opposite_msb_thm (e : IntW 8) :
  icmp IntPred.eq (lshr (const? 8 (-128)) e { «exact» := true }) (const? 8 1) ⊑
    icmp IntPred.eq e (const? 8 7)

theorem ashr_ne_exact_proof : ashr_ne_exact_before ⊑ ashr_ne_exact_after

theorem xor_signbit_select_shl_proof : xor_signbit_select_shl_before ⊑ xor_signbit_select_shl_after

theorem main7f_logical_thm.extracted_1._15 : ∀ (x x_1 x_2 x_3 x_4 : BitVec 32),
  ¬ofBool (x_4 &&& x_3 == x_2 &&& (x_4 &&& x_3)) = 1#1 →
    ¬ofBool (x_4 &&& x_3 != x_2 &&& (x_4 &&& x_3)) = 1#1 →
      0#1 = 1#1 → 0#32 = zeroExtend 32 (ofBool (x_1 &&& x != x_2 &&& (x_1 &&& x)))

theorem trunc_sel_smaller_sext_thm.extracted_1._2 : ∀ (x : BitVec 64) (x_1 : BitVec 1),
  ¬x_1 = 1#1 → signExtend 32 42#16 = 42#32

theorem add_or_sub_comb_i8_commuted2_nsw_thm.extracted_1._2 : ∀ (x : BitVec 8),
  ¬(True ∧ (x * x).saddOverflow (0#8 - x * x ||| x * x) = true) →
    ¬(True ∧ (x * x).saddOverflow (-1#8) = true) → x * x + (0#8 - x * x ||| x * x) = x * x + -1#8 &&& x * x

theorem lshr_shl_demand1_thm.extracted_1._1 : ∀ (x : BitVec 8), ¬(x ≥ ↑8 ∨ 3#8 ≥ ↑8) → x ≥ ↑8 → False

theorem test16_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ¬(11#32 ≥ ↑32 ∨ (x >>> 11#32 &&& 4#32) + 4#32 = 0) →
    ¬(11#32 ≥ ↑32 ∨ True ∧ (x >>> 11#32 &&& 4#32 &&& 3#32 != 0) = true) →
      x_1 % ((x >>> 11#32 &&& 4#32) + 4#32) = x_1 &&& (x >>> 11#32 &&& 4#32 ||| 3#32)

theorem test15a_thm.extracted_1._2 : ∀ (x : BitVec 32), ¬ofBool (x &&& 16#32 == 0#32) = 1#1 → 16#32 = x &&& 16#32

theorem test_or_eq_a_b_proof : test_or_eq_a_b_before ⊑ test_or_eq_a_b_after

theorem bools_multi_uses2_logical_thm.extracted_1._23 : ∀ (x x_1 x_2 : BitVec 1),
  x_2 ^^^ 1#1 = 1#1 → x_2 = 1#1 → x_1 = 1#1 → ¬x = 1#1 → ¬True → x_1 + x = 0#1

theorem masked_icmps_mask_notallzeros_bmask_mixed_swapped_4_logical_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬ofBool (x &&& 15#32 == 8#32) = 1#1 → 0#1 = ofBool (x &&& 15#32 == 8#32)

theorem e_614 :
     - 2 * y - 2 *  ~~~(x ^^^ y) - 3 *  ~~~(x &&& y) + 7 * (x ^^^ y) - 2 *  ~~~x + 2 *  ~~~y - 2 * (x ||| y) + 5 *  ~~~(x ||| y) + 2 *  ~~~(x |||  ~~~y) + 2 * (x &&& y) = 8 * (x &&&  ~~~y) - 4 * x

theorem e_2442 :
     - 1 * (f ^^^ (d &&& e)) + 4 * ((d |||  ~~~e) &&& (d ^^^ (e ^^^ f))) + 11 *  ~~~( ~~~d &&& (e ^^^ f)) + 11 * ((d &&& e) ||| (d ^^^ (e ^^^ f))) + 5 * (d ||| f) - 2 * (e ^^^ (d |||  ~~~f)) - 1 * (e ^^^  ~~~(d ||| f)) + 1 * (e ^^^  ~~~(d ||| ( ~~~e &&& f))) + 7 * (f ^^^ (d |||  ~~~e)) + 2 * ((d ||| e) &&& (d ^^^ (e ^^^ f))) + 5 *  ~~~(d |||  ~~~f) - 3 * (d &&&  ~~~f) - 5 * ((d &&&  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) - 7 * (e ^^^  ~~~( ~~~d &&& ( ~~~e &&& f))) - 1 * (f ^^^  ~~~(d &&& ( ~~~e ||| f))) + 2 *  ~~~(d &&&  ~~~f) - 2 * (e ^^^  ~~~(d &&& ( ~~~e &&& f))) - 6 * (d &&&  ~~~e) - 7 * (e ^^^ ( ~~~d ||| ( ~~~e ||| f))) + 1 *  ~~~e - 2 * (d ^^^ ( ~~~e &&& f)) - 11 * (f ^^^ ( ~~~d ||| ( ~~~e &&& f))) + 3 * (f ^^^ ( ~~~d ||| (e &&& f))) - 6 * (f ^^^  ~~~(d |||  ~~~e)) - 2 * (e ^^^ (d &&&  ~~~f)) - 7 * (e |||  ~~~f) - 2 * ( ~~~d &&& (e ||| f)) + 1 * (f ^^^ (d ||| (e ||| f))) + 7 * ( ~~~(d ^^^ e) ||| (d ^^^ f)) + 2 * ((e &&& f) ||| ( ~~~d &&& (e ||| f))) + 1 *  ~~~(e &&& f) - 2 * (d &&& (e ||| f)) + 4 * ((e &&&  ~~~f) ^^^ (d ||| (e ^^^ f))) + 11 * ((d ^^^ e) |||  ~~~(d ^^^ f)) - 1 * ((e &&&  ~~~f) |||  ~~~(d ||| ( ~~~e &&& f))) - 3 * ((d &&& e) |||  ~~~(e ^^^ f)) + 11 * ((e &&& f) ^^^  ~~~( ~~~d &&& (e ^^^ f))) - 6 * (e ^^^ ( ~~~d &&& (e ^^^ f))) + 2 * ((d |||  ~~~e) &&& (e ^^^ f)) - 2 *  ~~~(d &&&  ~~~d) + 5 *  ~~~(d &&& e) + 2 * (d &&& f) + 2 * (d &&& ( ~~~e ||| f)) - 1 * (e ^^^ ( ~~~d ||| ( ~~~e &&& f))) - 7 * (e ^^^ (d &&& f)) + 7 * (e ^^^ ( ~~~d ||| (e &&& f))) - 6 * (d &&& (e ^^^ f)) + 3 * ( ~~~(d &&& e) &&& (d ^^^ (e ^^^ f))) + 1 * (e ^^^  ~~~( ~~~d ||| (e ^^^ f))) + 5 * (f ^^^ ( ~~~d &&& (e ||| f))) + 7 *  ~~~(d &&& (e &&& f)) - 11 *  ~~~(e ||| f) + 4 *  ~~~(d &&& (e ||| f)) - 3 * ((d &&& e) |||  ~~~(e |||  ~~~f)) - 3 * (f ^^^  ~~~( ~~~d &&& (e &&& f))) + 11 * ((d &&& e) |||  ~~~(d ^^^ (e ^^^ f))) - 2 * ( ~~~(d &&&  ~~~e) &&&  ~~~(d ^^^ (e ^^^ f))) + 11 * (f ^^^ ( ~~~d ||| ( ~~~e ||| f))) + 1 *  ~~~(d &&& (e ^^^ f)) + 1 *  ~~~( ~~~d &&& ( ~~~e &&& f)) + 2 * (d ^^^ e) + 2 * (e ^^^  ~~~(d &&& ( ~~~e ||| f))) - 5 * (e ^^^  ~~~(d &&& f)) + 3 * (e ^^^  ~~~(d ||| (e &&& f))) - 1 *  ~~~(d ||| f) - 2 * ( ~~~(d |||  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) - 2 * (e |||  ~~~(d |||  ~~~f)) - 1 * (f |||  ~~~(d ||| e)) - 36 *  ~~~(d ||| (e ||| f)) - 30 *  ~~~(d ||| ( ~~~e ||| f)) - 46 *  ~~~( ~~~d ||| (e ||| f)) - 24 *  ~~~( ~~~d ||| ( ~~~e ||| f)) - 40 * ( ~~~d &&& ( ~~~e &&& f)) - 40 * ( ~~~d &&& (e &&& f)) - 27 * (d &&& ( ~~~e &&& f)) - 32 * (d &&& (e &&& f)) =  - 4 *  ~~~(d &&& ( ~~~e ||| f))

theorem main12_thm (e : IntW 32) :
  select (LLVM.or (icmp IntPred.slt (trunc 16 e) (const? 16 0)) (icmp IntPred.slt (trunc 8 e) (const? 8 0)))
      (const? 32 2) (const? 32 1) ⊑
    select (icmp IntPred.eq (LLVM.and e (const? 32 32896)) (const? 32 0)) (const? 32 1) (const? 32 2)

theorem test_shl_nsw__all_are_safe_thm.extracted_1._3 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ¬ofBool (x_1 &&& 15#32 == 0#32) = 1#1 →
    ¬(True ∧ ((x_1 &&& 15#32) <<< 2#32).sshiftRight' 2#32 ≠ x_1 &&& 15#32 ∨
          2#32 ≥ ↑32 ∨ zeroExtend 64 ((x_1 &&& 15#32) <<< 2#32) ≥ ↑64) →
      2#32 ≥ ↑32 ∨ True ∧ (x_1 <<< 2#32 &&& 60#32).msb = true ∨ zeroExtend 64 (x_1 <<< 2#32 &&& 60#32) ≥ ↑64 → False

theorem PR52261_proof : PR52261_before ⊑ PR52261_after

theorem ashr_ult_exact_near_pow2_cmpval_thm.extracted_1._1 : ∀ (x : BitVec 8),
  ¬(True ∧ x >>> 1#8 <<< 1#8 ≠ x ∨ 1#8 ≥ ↑8) → ofBool (x.sshiftRight' 1#8 <ᵤ 5#8) = ofBool (x <ᵤ 9#8)

theorem main7b_logical_thm.extracted_1._3 : ∀ (x x_1 : BitVec 32),
  ¬ofBool (x_1 == x &&& x_1) = 1#1 → ¬ofBool (x_1 != x &&& x_1) = 1#1 → 0#1 = 1#1 → False

theorem and_xor_or4_thm (e e_1 e_2 : IntW 64) :
  LLVM.or
      (LLVM.xor (LLVM.udiv (const? 64 42) e_2) (LLVM.and (LLVM.udiv (const? 64 42) e_1) (LLVM.udiv (const? 64 42) e)))
      (LLVM.udiv (const? 64 42) e_1) ⊑
    LLVM.or (LLVM.udiv (const? 64 42) e_2) (LLVM.udiv (const? 64 42) e_1)

theorem main5_like_proof : main5_like_before ⊑ main5_like_after

theorem shrink_select_thm.extracted_1._1 : ∀ (x : BitVec 1), ¬x = 1#1 → truncate 8 42#32 = 42#8

theorem shl_nsw_add_negative_invalid_constant3_thm.extracted_1._2 : ∀ (x : BitVec 4),
  ¬(True ∧ (2#4 <<< (x + BitVec.ofInt 4 (-8))).sshiftRight' (x + BitVec.ofInt 4 (-8)) ≠ 2#4 ∨
        x + BitVec.ofInt 4 (-8) ≥ ↑4) →
    ¬(True ∧ (2#4 <<< (x ^^^ BitVec.ofInt 4 (-8))).sshiftRight' (x ^^^ BitVec.ofInt 4 (-8)) ≠ 2#4 ∨
          x ^^^ BitVec.ofInt 4 (-8) ≥ ↑4) →
      2#4 <<< (x + BitVec.ofInt 4 (-8)) = 2#4 <<< (x ^^^ BitVec.ofInt 4 (-8))

theorem e_1729 :
    2 * ((a ||| b) &&&  ~~~(b ^^^ c)) - 1 * (b ^^^ (a &&&  ~~~c)) + 7 *  ~~~(b &&& c) - 1 * ((a &&& b) ^^^ (b |||  ~~~c)) - 1 *  ~~~(a &&&  ~~~b) - 1 * ( ~~~(a |||  ~~~b) ||| (a ^^^ (b ^^^ c))) + 3 * ((a &&& c) ^^^ (a ^^^ ( ~~~b &&& c))) + 3 * (b &&&  ~~~(a &&&  ~~~c)) + 1 * (b &&&  ~~~(a ^^^ c)) - 6 * ( ~~~(a &&&  ~~~b) &&&  ~~~(a ^^^ (b ^^^ c))) - 2 *  ~~~(a |||  ~~~c) - 1 *  ~~~( ~~~a &&& ( ~~~b &&& c)) + 1 * ( ~~~a &&& ( ~~~b ||| c)) + 11 * (a &&& b) + 7 *  ~~~(a ||| b) - 2 * (a ^^^ (b ^^^ c)) + 7 * (a ||| (b &&& c)) - 3 *  ~~~( ~~~a &&& (b &&& c)) + 3 * (c ^^^ ( ~~~a ||| ( ~~~b ||| c))) + 4 * (a ||| b) + 11 * ((a &&&  ~~~b) |||  ~~~(b ^^^ c)) - 5 * (b ^^^  ~~~(a ||| ( ~~~b &&& c))) + 1 *  ~~~(a &&& ( ~~~b ||| c)) - 13 *  ~~~(a ||| (b ||| c)) - 13 *  ~~~(a ||| ( ~~~b ||| c)) - 32 *  ~~~( ~~~a ||| (b ||| c)) - 17 *  ~~~( ~~~a ||| ( ~~~b ||| c)) - 14 * ( ~~~a &&& ( ~~~b &&& c)) - 16 * ( ~~~a &&& (b &&& c)) - 32 * (a &&& ( ~~~b &&& c)) - 25 * (a &&& (b &&& c)) =  - 4 * (b ^^^ (a ||| c))

theorem e_2481 :
    1 * (f ^^^ (d &&&  ~~~e)) - 1 * (d ||| e) + 4 * (f ^^^  ~~~( ~~~d &&& (e ||| f))) + 3 * (d &&& f) + 2 * (e ^^^  ~~~( ~~~d &&& ( ~~~e ||| f))) + 1 * ( ~~~d ||| ( ~~~e ||| f)) - 2 * (f ^^^  ~~~(d ||| ( ~~~e &&& f))) + 7 * ( ~~~(d &&& e) &&& (d ^^^ (e ^^^ f))) - 2 * (e ||| f) + 2 * (e ^^^  ~~~( ~~~d &&& ( ~~~e &&& f))) + 2 * (f ^^^  ~~~( ~~~d ||| (e &&& f))) + 3 * (e ^^^ ( ~~~d &&& ( ~~~e ||| f))) + 2 * (e ^^^ ( ~~~d ||| ( ~~~e &&& f))) + 1 * (e ^^^ (d ||| (e &&& f))) - 2 *  ~~~( ~~~d &&& (e ||| f)) + 11 * ((d ||| e) &&&  ~~~(e ^^^ f)) - 11 * ((d &&& e) |||  ~~~(d ^^^ (e ^^^ f))) - 6 * (f &&&  ~~~(d &&&  ~~~e)) - 7 * ((e &&& f) ||| ( ~~~d &&& (e ||| f))) - 1 * ((d &&& f) ^^^ (d ^^^ (e &&& f))) + 11 * (f ^^^ (d ||| (e ||| f))) + 2 *  ~~~(d &&& (e ^^^ f)) - 1 * (e ^^^  ~~~(d &&& ( ~~~e &&& f))) + 4 * ( ~~~(d ^^^ e) &&&  ~~~(d ^^^ f)) - 1 * ( ~~~e &&& (d ^^^ f)) - 7 * (f ^^^ (d |||  ~~~e)) - 3 * (e |||  ~~~(d ||| f)) - 7 *  ~~~(d ^^^ (e &&& f)) - 11 *  ~~~(e ||| f) - 1 * (f &&& (d |||  ~~~e)) + 5 * (f &&& (d ||| e)) + 5 * d - 2 * (e ^^^  ~~~( ~~~d &&& (e &&& f))) - 3 * (f ^^^ ( ~~~d &&& ( ~~~e ||| f))) - 1 * (e ^^^  ~~~( ~~~d &&& (e ||| f))) - 2 * ((d ||| e) &&& (d ^^^ (e ^^^ f))) + 1 * ((d &&& f) ^^^ (d ^^^ ( ~~~e &&& f))) - 1 * ((d &&& e) ^^^  ~~~(d ^^^ (e &&& f))) - 1 * (d ^^^ (e &&& f)) + 2 *  ~~~(d ^^^ (e ||| f)) + 2 *  ~~~( ~~~d ||| ( ~~~e &&& f)) - 11 * ((d &&& f) ^^^ (e ||| f)) + 4 * ( ~~~d &&& (e ||| f)) - 5 * (f &&&  ~~~(d ^^^ e)) + 1 *  ~~~(d &&& ( ~~~e &&& f)) - 5 * (e ^^^ f) + 1 * (f &&& (d ^^^ e)) + 7 *  ~~~( ~~~d ||| (e &&& f)) - 1 *  ~~~( ~~~d &&& ( ~~~e &&& f)) - 3 * (d ||| ( ~~~e ||| f)) - 7 *  ~~~(d |||  ~~~e) + 3 * (d |||  ~~~f) - 7 * (e &&& f) - 1 * (f ^^^ ( ~~~d &&& (e ||| f))) - 2 * ((d ||| e) &&&  ~~~(d ^^^ (e ^^^ f))) + 11 * (f ^^^  ~~~( ~~~d &&& ( ~~~e &&& f))) + 1 * ((e &&& f) ^^^  ~~~(d &&& (e ^^^ f))) - 11 *  ~~~d + 1 * ((d &&&  ~~~e) ||| (e ^^^ f)) + 11 * ( ~~~(d &&&  ~~~e) &&& (e ^^^ f)) + 1 * (f ^^^ ( ~~~d ||| ( ~~~e &&& f))) - 6 * ((d &&& e) |||  ~~~(e ||| f)) - 1 *  ~~~(d ||| ( ~~~e &&& f)) + 1 * ((d |||  ~~~e) &&&  ~~~(d ^^^ (e ^^^ f))) + 11 * ((d &&&  ~~~e) |||  ~~~(e ^^^ f)) + 2 * ( ~~~(d |||  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) - 6 * (f ^^^ ( ~~~d ||| ( ~~~e ||| f))) - 7 * (e ^^^ (d ||| ( ~~~e ||| f))) - 3 *  ~~~( ~~~d &&& (e ^^^ f)) + 1 * (f ^^^ (d &&& (e ||| f))) + 5 * ((d &&& e) |||  ~~~(e |||  ~~~f)) - 6 * ( ~~~(d ^^^ e) &&& (d ^^^ f)) - 5 * ((d &&& e) ^^^  ~~~(d ^^^ ( ~~~e ||| f))) + 39 *  ~~~(d ||| (e ||| f)) + 22 *  ~~~(d ||| ( ~~~e ||| f)) - 26 *  ~~~( ~~~d ||| (e ||| f)) - 3 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 21 * ( ~~~d &&& ( ~~~e &&& f)) + 41 * ( ~~~d &&& (e &&& f)) - 1 * (d &&& ( ~~~e &&& f)) + 10 * (d &&& (e &&& f)) = 1 * ( ~~~d ||| (e ^^^ f))

theorem or_xor_tree_1011_proof : or_xor_tree_1011_before ⊑ or_xor_tree_1011_after

theorem masked_icmps_mask_notallzeros_bmask_mixed_negated_swapped_3_proof : masked_icmps_mask_notallzeros_bmask_mixed_negated_swapped_3_before ⊑ masked_icmps_mask_notallzeros_bmask_mixed_negated_swapped_3_after

theorem ult_1_impliesF_eq_1_proof : ult_1_impliesF_eq_1_before ⊑ ult_1_impliesF_eq_1_after

theorem lshr_and_thm (e e_1 : IntW 64) :
  lshr (LLVM.and (LLVM.srem e_1 (const? 64 42)) (lshr e (const? 64 5))) (const? 64 7) ⊑
    LLVM.and (lshr e (const? 64 12)) (lshr (LLVM.srem e_1 (const? 64 42)) (const? 64 7))

theorem select_lshr_icmp_bad_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ofBool (x_1 == 1#32) = 1#1 → ¬x_1 ≥ ↑32 → ¬1#32 ≥ ↑32 → x >>> x_1 = x >>> 1#32

theorem or_and_not_not_commute5_thm (e e_1 e_2 : IntW 32) :
  LLVM.or (LLVM.xor (LLVM.or e_2 e_1) (const? 32 (-1))) (LLVM.and (LLVM.xor (LLVM.or e_1 e) (const? 32 (-1))) e_2) ⊑
    LLVM.xor (LLVM.or (LLVM.and e e_2) e_1) (const? 32 (-1))

theorem bools_logical_commute3_and2_thm.extracted_1._11 : ∀ (x x_1 x_2 : BitVec 1),
  ¬x_2 = 1#1 → x_1 = 1#1 → 0#1 = 1#1 → 1#1 = x

theorem udiv_shl_mul_nuw_proof : udiv_shl_mul_nuw_before ⊑ udiv_shl_mul_nuw_after

theorem shl_sub_lshr_thm.extracted_1._1 : ∀ (x x_1 x_2 : BitVec 32),
  ¬(True ∧ x_2 <<< x_1 >>> x_1 ≠ x_2 ∨
        x_1 ≥ ↑32 ∨
          True ∧ (x_2 <<< x_1).ssubOverflow x = true ∨
            True ∧ (x_2 <<< x_1).usubOverflow x = true ∨
              True ∧ (x_2 <<< x_1 - x) >>> x_1 <<< x_1 ≠ x_2 <<< x_1 - x ∨ x_1 ≥ ↑32) →
    True ∧ x >>> x_1 <<< x_1 ≠ x ∨
        x_1 ≥ ↑32 ∨ True ∧ x_2.ssubOverflow (x >>> x_1) = true ∨ True ∧ x_2.usubOverflow (x >>> x_1) = true →
      False

theorem sel_false_val_is_a_masked_lshr_of_true_val1_thm.extracted_1._3 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ¬ofBool (x_1 &&& 60#32 == 0#32) = 1#1 →
    ¬(2#32 ≥ ↑32 ∨ zeroExtend 64 ((x_1 &&& 60#32) >>> 2#32) ≥ ↑64) →
      2#32 ≥ ↑32 ∨ True ∧ (x_1 >>> 2#32 &&& 15#32).msb = true ∨ zeroExtend 64 (x_1 >>> 2#32 &&& 15#32) ≥ ↑64 → False

theorem e_1327 :
    1 * (z |||  ~~~t) + 5 * (z ^^^ t) - 1 *  ~~~(z &&&  ~~~t) - 2 * z - 5 *  ~~~z + 3 *  ~~~(z &&&  ~~~z) - 15 *  ~~~(z |||  ~~~t) - 9 * (z &&&  ~~~t) - 12 * (z &&& t) =  - 2 *  ~~~(z &&& t) - 11 * t

theorem icmp_equality_test_commute_icmp1_thm.extracted_1._2 : ∀ (x x_1 x_2 : BitVec 64),
  ¬ofBool (x_2 == x_1) = 1#1 → ¬ofBool (x_2 == x) ^^^ 1#1 = 1#1 → 0#1 = ofBool (x == x_1)

theorem test_with_neg_even_proof : test_with_neg_even_before ⊑ test_with_neg_even_after

theorem test_or2_thm (e e_1 : IntW 32) :
  LLVM.or (icmp IntPred.sle e_1 (const? 32 (-1))) (icmp IntPred.sgt e_1 (LLVM.and e (const? 32 2147483647))) ⊑
    icmp IntPred.ugt e_1 (LLVM.and e (const? 32 2147483647))

theorem eq_umax4_proof : eq_umax4_before ⊑ eq_umax4_after

@[simp]
lemma RawCNFA.Simul.initial {m : RawCNFA A} {M : NFA A Q} (hsim : m.Simul M R ⊤ ∅) :
    R.set_eq m.initials.toSet M.start

theorem e_2341 :
     - 1 * (f ^^^  ~~~( ~~~d ||| (e &&& f))) + 7 * (e ||| f) - 2 * (e ^^^  ~~~( ~~~d ||| (e &&& f))) + 7 *  ~~~(e ^^^ f) - 2 * (e ^^^  ~~~(d &&& (e ||| f))) - 5 * (e ^^^ ( ~~~d ||| ( ~~~e &&& f))) - 2 * (f ^^^ ( ~~~d ||| ( ~~~e ||| f))) + 4 * (e ^^^ (d &&& f)) + 4 * e + 2 * ( ~~~(d ^^^ e) |||  ~~~(d ^^^ f)) - 1 *  ~~~(d &&& (e &&& f)) + 1 *  ~~~( ~~~d ||| (e &&& f)) - 11 * (e ^^^  ~~~(d &&& ( ~~~e ||| f))) - 7 * ((d &&&  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) + 2 * (e ^^^ ( ~~~d ||| ( ~~~e ||| f))) - 2 * ( ~~~(d &&&  ~~~e) &&& (e ^^^ f)) - 1 *  ~~~(d |||  ~~~e) - 3 * (d ^^^ ( ~~~e &&& f)) - 11 * (e &&&  ~~~(d &&&  ~~~f)) + 5 * ((e &&&  ~~~f) |||  ~~~( ~~~d ||| ( ~~~e &&& f))) - 11 *  ~~~(d &&&  ~~~d) - 11 * (f &&&  ~~~(d &&&  ~~~e)) + 7 * (f ^^^  ~~~(d ||| ( ~~~e &&& f))) - 1 * ((d &&& e) ^^^ (e |||  ~~~f)) + 1 *  ~~~(e &&&  ~~~f) - 3 * (f ^^^ (d &&& ( ~~~e ||| f))) + 1 * (f ^^^  ~~~( ~~~d &&& (e &&& f))) + 1 * ( ~~~(d ||| e) |||  ~~~(d ^^^ (e ^^^ f))) + 3 * ( ~~~e &&& (d ^^^ f)) - 1 * ((d ||| e) &&& (d ^^^ (e ^^^ f))) + 5 * ((d &&& f) ^^^  ~~~(d ^^^ ( ~~~e &&& f))) + 11 * (e |||  ~~~(d ^^^ f)) - 2 * (e ^^^ (d ||| ( ~~~e &&& f))) + 1 * (e ^^^  ~~~(d &&& (e &&& f))) + 1 * ( ~~~(d ^^^ e) &&&  ~~~(d ^^^ f)) + 2 *  ~~~(e &&& f) + 11 *  ~~~(d ^^^ (e ||| f)) + 3 * ( ~~~(d &&&  ~~~e) &&&  ~~~(d ^^^ (e ^^^ f))) + 5 *  ~~~(d ^^^ (e &&& f)) - 7 * ((e &&& f) ||| (d &&& (e ||| f))) + 1 * (d |||  ~~~f) - 3 * (e ^^^ (d ||| (e ||| f))) - 1 * ( ~~~(d &&&  ~~~e) &&& (d ^^^ (e ^^^ f))) - 1 * ((d &&& e) ||| (d ^^^ (e ^^^ f))) + 1 * (f ||| (d &&&  ~~~e)) + 4 * (e &&&  ~~~(d ^^^ f)) + 1 * ( ~~~d &&& (e ^^^ f)) - 2 * (e ^^^  ~~~( ~~~d &&& ( ~~~e &&& f))) + 5 * (e &&& (d ||| f)) - 2 * ((d &&& e) ^^^  ~~~(d ^^^ (e &&& f))) + 11 * (e ^^^ ( ~~~d &&& ( ~~~e ||| f))) + 7 * ( ~~~d ||| ( ~~~e &&& f)) - 11 * ( ~~~e |||  ~~~(d ^^^ f)) + 3 * ((d &&& e) ||| (e ^^^ f)) + 3 * (e ^^^ (d &&&  ~~~f)) - 6 *  ~~~( ~~~d &&& (e ||| f)) - 7 * ((d ||| e) &&&  ~~~(d ^^^ (e ^^^ f))) + 4 *  ~~~(d |||  ~~~f) - 13 *  ~~~(d ||| (e ||| f)) - 39 *  ~~~(d ||| ( ~~~e ||| f)) + 31 *  ~~~( ~~~d ||| (e ||| f)) - 14 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 7 * ( ~~~d &&& ( ~~~e &&& f)) - 4 * ( ~~~d &&& (e &&& f)) + 2 * (d &&& ( ~~~e &&& f)) - 11 * (d &&& (e &&& f)) = 5 * (e ^^^  ~~~(d ||| ( ~~~e &&& f))) - 5 * ((e &&& f) ||| ( ~~~d &&& (e ||| f)))

theorem ashrsgt_02_03_thm (e : IntW 4) : icmp IntPred.sgt (ashr e (const? 4 2)) (const? 4 3) ⊑ const? 1 0

theorem logical_and_not_cond_reuse_proof : logical_and_not_cond_reuse_before ⊑ logical_and_not_cond_reuse_after

theorem test_mul_nuw__all_are_safe_thm (e : IntW 32) :
  select (icmp IntPred.eq (LLVM.and e (const? 32 255)) (const? 32 17)) (const? 32 153)
      (mul (LLVM.and e (const? 32 255)) (const? 32 9) { «nsw» := false, «nuw» := true }) ⊑
    mul (LLVM.and e (const? 32 255)) (const? 32 9) { «nsw» := true, «nuw» := true }

theorem pr33078_1_thm.extracted_1._2 : ∀ (x : BitVec 8),
  ¬8#16 ≥ ↑16 → ¬7#8 ≥ ↑8 → truncate 8 (signExtend 16 x >>> 8#16) = x.sshiftRight' 7#8

theorem nonexact_ashr_ne_noexactlog_thm.extracted_1._1 : ∀ (x : BitVec 8),
  ¬x ≥ ↑8 → ofBool ((BitVec.ofInt 8 (-90)).sshiftRight' x != BitVec.ofInt 8 (-30)) = 1#1

theorem e_2292 :
    2 *  ~~~(d ||| f) - 11 * (e &&& f) + 11 *  ~~~(e &&&  ~~~f) + 7 * (f ^^^ ( ~~~d &&& (e ||| f))) + 4 * ((d ^^^ e) |||  ~~~(d ^^^ f)) - 7 * (d ||| ( ~~~e &&& f)) + 1 *  ~~~( ~~~d ||| (e &&& f)) - 2 * (d |||  ~~~e) - 2 * (e ^^^  ~~~(d &&& f)) + 1 *  ~~~(d &&& e) + 2 * ( ~~~(d |||  ~~~e) ||| (d ^^^ (e ^^^ f))) - 6 * ((d &&& e) ^^^  ~~~(d ^^^ ( ~~~e ||| f))) + 1 * (d &&& e) + 2 * (e &&& (d |||  ~~~f)) + 7 * ( ~~~(d ^^^ e) ||| (d ^^^ f)) + 7 * (f ^^^ (d &&& (e ||| f))) - 3 * ( ~~~(d ||| e) ||| (d ^^^ (e ^^^ f))) + 1 * (e ^^^ (d &&& ( ~~~e ||| f))) - 7 * (d ^^^ ( ~~~e &&& f)) - 1 *  ~~~(d ^^^ ( ~~~e ||| f)) - 7 * ((d ||| e) &&&  ~~~(e ^^^ f)) + 5 *  ~~~(d ^^^ ( ~~~e &&& f)) + 2 *  ~~~(d ||| e) + 1 * (f ^^^ (d &&& e)) - 1 * ( ~~~(d &&& e) &&& (d ^^^ (e ^^^ f))) + 11 * ( ~~~d ||| ( ~~~e ||| f)) + 7 * (e ^^^  ~~~(d |||  ~~~f)) + 2 * ((d &&& f) |||  ~~~(e ||| f)) + 1 * (e &&&  ~~~(d &&&  ~~~f)) + 11 * ( ~~~f |||  ~~~(d ^^^ e)) - 5 *  ~~~(d ||| (e ^^^ f)) - 1 * (d ||| (e &&& f)) + 2 * (e ^^^ ( ~~~d ||| ( ~~~e &&& f))) + 3 * ( ~~~d ||| (e ^^^ f)) + 2 * (e ^^^  ~~~(d ||| (e ^^^ f))) + 2 * (f ^^^ ( ~~~d &&& ( ~~~e ||| f))) + 11 * (e ^^^ ( ~~~d ||| (e ||| f))) - 11 * (e ^^^ ( ~~~d &&& (e ^^^ f))) - 2 * (e ^^^  ~~~( ~~~d &&& (e ||| f))) - 5 *  ~~~(e &&& f) + 4 * (d ||| e) - 1 * ((d &&& f) ^^^  ~~~(e &&&  ~~~f)) - 3 * ((e &&& f) ||| (d &&& (e ||| f))) + 4 * ( ~~~d &&& (e ^^^ f)) - 11 *  ~~~(d ||| (e &&& f)) - 1 * d - 2 * ( ~~~(d |||  ~~~e) |||  ~~~(e ^^^ f)) + 2 *  ~~~(d &&& f) - 3 * ( ~~~(d ^^^ e) |||  ~~~(d ^^^ f)) - 2 * (e |||  ~~~(d ||| f)) + 1 *  ~~~( ~~~d &&& (e ||| f)) + 11 *  ~~~(d &&&  ~~~f) + 2 * (f ^^^ (d ||| (e &&& f))) - 51 *  ~~~(d ||| (e ||| f)) - 43 *  ~~~(d ||| ( ~~~e ||| f)) - 11 *  ~~~( ~~~d ||| (e ||| f)) - 5 *  ~~~( ~~~d ||| ( ~~~e ||| f)) - 41 * ( ~~~d &&& ( ~~~e &&& f)) - 32 * ( ~~~d &&& (e &&& f)) - 53 * (d &&& ( ~~~e &&& f)) - 25 * (d &&& (e &&& f)) =  - 7 * (f &&& (d ^^^ e)) + 1 *  ~~~(d &&& (e &&& f))

theorem udiv_shl_pair3_proof : udiv_shl_pair3_before ⊑ udiv_shl_pair3_after

theorem lshrult_01_13_proof : lshrult_01_13_before ⊑ lshrult_01_13_after

theorem p1_ugt_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ofBool (65534#32 <ᵤ x_1) = 1#1 → ofBool (x_1 <ᵤ 65535#32) = 1#1 → x = 65535#32

theorem test_or3_logical_thm (e e_1 : IntW 32) :
  select (icmp IntPred.sle (LLVM.and e_1 (const? 32 2147483647)) e) (const? 1 1)
      (icmp IntPred.slt e (const? 32 0)) ⊑
    icmp IntPred.uge e (LLVM.and e_1 (const? 32 2147483647))

theorem sgt_3_impliesT_sgt_2_proof : sgt_3_impliesT_sgt_2_before ⊑ sgt_3_impliesT_sgt_2_after

theorem lshr_shl_eq_amt_multi_use_proof : lshr_shl_eq_amt_multi_use_before ⊑ lshr_shl_eq_amt_multi_use_after

theorem src_proof : src_before ⊑ src_after

theorem sgt_swap_or_not_min_commute_proof : sgt_swap_or_not_min_commute_before ⊑ sgt_swap_or_not_min_commute_after

@[grind =, simp] lemma RawCNFA.empty_tr {s : State} : empty (A := A).tr s a = ∅

theorem e_328 :
     - 1 *  ~~~x - 2 * (x ||| y) - 6 *  ~~~y + 7 * (x ^^^ y) - 3 *  ~~~(x ^^^ y) + 10 *  ~~~(x ||| y) + 1 * (x &&&  ~~~y) + 5 * (x &&& y) = 4 *  ~~~(x |||  ~~~y)

theorem test1_thm.extracted_1._1 : ∀ (x x_1 x_2 : BitVec 57), ¬(x_1 ≥ ↑57 ∨ x_1 ≥ ↑57) → x_1 ≥ ↑57 → False

theorem ashr_eq_both_equal_thm.extracted_1._1 : ∀ (x : BitVec 8),
  ¬x ≥ ↑8 → ofBool ((BitVec.ofInt 8 (-128)).sshiftRight' x == BitVec.ofInt 8 (-128)) = ofBool (x == 0#8)

theorem uge_umin2_proof : uge_umin2_before ⊑ uge_umin2_after

theorem select_xor_icmp_bad_6_proof : select_xor_icmp_bad_6_before ⊑ select_xor_icmp_bad_6_after

theorem masked_icmps_mask_notallzeros_bmask_mixed_1_thm (e : IntW 32) :
  LLVM.and (icmp IntPred.ne (LLVM.and e (const? 32 12)) (const? 32 0))
      (icmp IntPred.eq (LLVM.and e (const? 32 7)) (const? 32 1)) ⊑
    icmp IntPred.eq (LLVM.and e (const? 32 15)) (const? 32 9)

@[simp, simp_llvm]
theorem isRefinedBy_iff (x y : LLVM.IntW w) :
    x ⊑ y ↔ @HRefinement.IsRefinedBy (PoisonOr _) (PoisonOr _) _ x y

theorem or_logic_or_logic_and_6_thm.extracted_1._9 : ∀ (x x_1 x_2 : BitVec 1),
  ¬x_2 ||

theorem test_mul_nuw__nuw_is_safe_proof : test_mul_nuw__nuw_is_safe_before ⊑ test_mul_nuw__nuw_is_safe_after

theorem lshr_lshr_thm.extracted_1._1 : ∀ (x : BitVec 232),
  ¬(231#232 ≥ ↑232 ∨ 1#232 ≥ ↑232) → x >>> 231#232 >>> 1#232 = 0#232

theorem icmp_sle8_thm (e : IntW 8) :
  icmp IntPred.sle (shl e (const? 8 1) { «nsw» := true, «nuw» := false }) (const? 8 125) ⊑
    icmp IntPred.ne e (const? 8 63)

theorem test9_thm.extracted_1._2 : ∀ (x : BitVec 77),
  ¬(True ∧ (x &&& 562949953421310#77 &&& 1#77 != 0) = true) →
    (x &&& 562949953421310#77) + 1#77 = x &&& 562949953421310#77 ||

theorem e_1401 :
    4 * t - 2 * (z |||  ~~~t) + 2 * (z ^^^ t) - 2 *  ~~~(z &&&  ~~~z) + 1 *  ~~~(z ^^^ t) + 3 * (z ||| t) - 4 *  ~~~(z ||| t) - 14 *  ~~~(z |||  ~~~t) - 1 * (z &&&  ~~~t) - 4 * (z &&& t) =  - 7 *  ~~~z

theorem test15a_proof : test15a_before ⊑ test15a_after

theorem t9_ashr_exact_flag_preservation_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ¬(True ∧ x_1 >>> (32#32 - x) <<< (32#32 - x) ≠ x_1 ∨
        32#32 - x ≥ ↑32 ∨
          True ∧
              x_1.sshiftRight' (32#32 - x) >>> (x + BitVec.ofInt 32 (-2)) <<< (x + BitVec.ofInt 32 (-2)) ≠
                x_1.sshiftRight' (32#32 - x) ∨
            x + BitVec.ofInt 32 (-2) ≥ ↑32) →
    ¬(True ∧ x_1 >>> 30#32 <<< 30#32 ≠ x_1 ∨ 30#32 ≥ ↑32) →
      (x_1.sshiftRight' (32#32 - x)).sshiftRight' (x + BitVec.ofInt 32 (-2)) = x_1.sshiftRight' 30#32

@[simp] lemma eval_foldl_or :
  ∀ (s : List α) (f : α → Circuit β) (c : Circuit β) (g : β → Bool),
    (eval (s.foldl (λ c x => c ||| (f x)) c) g : Prop) ↔
      eval c g ∨ (∃ a ∈ s, eval (f a) g)

theorem e_1689 :
    11 * (c ^^^ ( ~~~a ||| ( ~~~b ||| c))) + 1 * (a ||| ( ~~~b &&& c)) - 1 * ( ~~~a ||| (b &&& c)) + 7 * (b |||  ~~~c) + 5 * ((a &&&  ~~~b) ||| (b ^^^ c)) + 11 * ( ~~~a &&& ( ~~~b ||| c)) - 6 * ( ~~~a &&& (b ||| c)) + 1 * (b ||| (a &&& c)) + 11 * a - 1 *  ~~~(a ||| (b ^^^ c)) + 11 *  ~~~(a ^^^ ( ~~~b ||| c)) - 2 * (a &&&  ~~~c) - 1 * ((a &&& b) ||| (a ^^^ (b ^^^ c))) - 2 * (c ^^^ ( ~~~a &&& ( ~~~b ||| c))) - 7 * ((b &&& c) ||| (a &&& (b ||| c))) + 1 * ((b &&& c) ||| ( ~~~a &&& (b ||| c))) + 2 * ((a &&& b) |||  ~~~(b ^^^ c)) + 1 * (b ^^^ ( ~~~a &&& (b ||| c))) - 3 * ( ~~~(a ^^^ b) |||  ~~~(a ^^^ c)) - 7 * (b ^^^ ( ~~~a ||| (b ||| c))) - 18 *  ~~~(a ||| (b ||| c)) - 26 *  ~~~(a ||| ( ~~~b ||| c)) - 45 *  ~~~( ~~~a ||| (b ||| c)) - 16 *  ~~~( ~~~a ||| ( ~~~b ||| c)) - 2 * ( ~~~a &&& ( ~~~b &&& c)) - 7 * ( ~~~a &&& (b &&& c)) - 10 * (a &&& ( ~~~b &&& c)) - 21 * (a &&& (b &&& c)) =  - 1 * ((a &&& b) ^^^  ~~~(a ^^^ (b &&& c)))

theorem lshrugt_01_02_proof : lshrugt_01_02_before ⊑ lshrugt_01_02_after

theorem urem_i1_is_zero_thm (e e_1 : IntW 1) : urem e_1 e ⊑ const? 1 0

theorem shift_xor_multiuse_and_proof : shift_xor_multiuse_and_before ⊑ shift_xor_multiuse_and_after

theorem mul_constant_eq_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ofBool (x_1 * 5#32 == x * 5#32) = ofBool (x_1 == x)

theorem e_584 :
    1 *  ~~~x - 1 * (x ||| y) + 2 *  ~~~(x &&& y) + 11 *  ~~~(x &&&  ~~~y) - 2 * y - 6 * (x ^^^ y) - 14 *  ~~~(x ||| y) + 6 * (x &&&  ~~~y) - 7 * (x &&& y) = 5 *  ~~~(x |||  ~~~y) + 1 * x

theorem icmp_eq_or_z_or_pow2orz_proof : icmp_eq_or_z_or_pow2orz_before ⊑ icmp_eq_or_z_or_pow2orz_after

theorem t7_thm.extracted_1._1 : ∀ (x : BitVec 1) (x_1 : BitVec 8), x = 1#1 → x_1 - 0#8 = 0#8 + x_1

theorem tail_iterate'' {α} {n} {s : Stream' α} : Stream'.iterate Stream'.tail s n m = s (n + m)

theorem alive_AndOrXor_1704  (w : Nat)   : alive_AndOrXor_1704_src w  ⊑ alive_AndOrXor_1704_tgt w

theorem test_sub_0_Y_eq_0_proof : test_sub_0_Y_eq_0_before ⊑ test_sub_0_Y_eq_0_after

theorem no_reassoc_add_none_nuw_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬(True ∧ x.uaddOverflow 4#32 = true) → x + 4#32 + 64#32 = x + 68#32

theorem udiv_shl_mul_nuw_swap_thm.extracted_1._2 : ∀ (x x_1 x_2 : BitVec 5),
  ¬(True ∧ x_2 <<< x_1 >>> x_1 ≠ x_2 ∨ x_1 ≥ ↑5 ∨ True ∧ x.umulOverflow x_2 = true ∨ x * x_2 = 0) →
    ¬(True ∧ 1#5 <<< x_1 >>> x_1 ≠ 1#5 ∨ x_1 ≥ ↑5 ∨ x = 0) → x_2 <<< x_1 / (x * x_2) = 1#5 <<< x_1 / x

@[simp] theorem Com.denote_changeVars
    (varsMap : Γ.Hom Γ') (c : Com d Γ eff ty) :
    (c.changeVars varsMap).denote =
    fun V => c.denote (V.comap varsMap)

theorem and_not_or_or_not_or_xor_commute5_proof : and_not_or_or_not_or_xor_commute5_before ⊑ and_not_or_or_not_or_xor_commute5_after

theorem sgt_x_impliesF_eq_smin_todo_thm.extracted_1._3 : ∀ (x x_1 x_2 : BitVec 8),
  ofBool (x_1 <ₛ x_2) = 1#1 → ofBool (x_2 ≤ₛ x_1) = 1#1 → ofBool (BitVec.ofInt 8 (-128) == x_2) = ofBool (x == x_2)

theorem ult_rem_nz_nsw_proof : ult_rem_nz_nsw_before ⊑ ult_rem_nz_nsw_after

theorem alive_AndOrXor_2658  (w : Nat)   : alive_AndOrXor_2658_src w  ⊑ alive_AndOrXor_2658_tgt w

theorem test12_proof : test12_before ⊑ test12_after

theorem sel_false_val_is_a_masked_ashr_of_true_val1_thm.extracted_1._4 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ¬ofBool (x_1 &&& BitVec.ofInt 32 (-2147483588) == 0#32) = 1#1 →
    ¬(2#32 ≥ ↑32 ∨ zeroExtend 64 ((x_1 &&& BitVec.ofInt 32 (-2147483588)).sshiftRight' 2#32) ≥ ↑64) →
      ¬(2#32 ≥ ↑32 ∨
            True ∧ (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)).msb = true ∨
              zeroExtend 64 (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)) ≥ ↑64) →
        x.sshiftRight' (zeroExtend 64 ((x_1 &&& BitVec.ofInt 32 (-2147483588)).sshiftRight' 2#32)) =
          x.sshiftRight' (zeroExtend 64 (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)))

theorem shl_add_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8), ¬(2#8 ≥ ↑8 ∨ 2#8 ≥ ↑8) → 2#8 ≥ ↑8 → False

theorem test30_thm (e : IntW 1) : LLVM.and (zext 32 e) (const? 32 1) ⊑ zext 32 e

theorem test_shl_nuw__nsw_is_safe_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬ofBool (x ||| BitVec.ofInt 32 (-83886080) == BitVec.ofInt 32 (-83886079)) = 1#1 →
    ¬(True ∧ (x ||| BitVec.ofInt 32 (-83886080)) <<< 2#32 >>> 2#32 ≠ x ||| BitVec.ofInt 32 (-83886080) ∨ 2#32 ≥ ↑32) →
      (x ||| BitVec.ofInt 32 (-83886080)) <<< 2#32 * (x ||| BitVec.ofInt 32 (-83886080)) *
          (x ||| BitVec.ofInt 32 (-83886080)) <<< 2#32 =
        0#32

theorem and_sext_multiuse_thm.extracted_1._1 : ∀ (x x_1 x_2 x_3 : BitVec 32),
  ofBool (x_2 <ₛ x_3) = 1#1 →
    (signExtend 32 (ofBool (x_2 <ₛ x_3)) &&& x_1) + (signExtend 32 (ofBool (x_2 <ₛ x_3)) &&& x) = x_1 + x

theorem main7c_logical_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ¬ofBool (x_1 == x_1 &&& x) = 1#1 → ofBool (x_1 != x_1 &&& x) = 1#1 → ¬0#1 = 1#1 → 1#32 = zeroExtend 32 1#1

theorem c_0_1_0_thm.extracted_1._2 : ∀ (x x_1 : BitVec 4),
  ¬(True ∧ (x &&& BitVec.ofInt 4 (-2) &&& (x_1 &&& 1#4) != 0) = true) →
    (x_1 ^^^ x) &&& BitVec.ofInt 4 (-2) ^^^ x_1 = x &&& BitVec.ofInt 4 (-2) ||

theorem and_two_ranges_to_mask_and_range_not_pow2_diff_thm.extracted_1._1 : ∀ (x : BitVec 8),
  ofBool (25#8 <ᵤ x + BitVec.ofInt 8 (-97)) &&& ofBool (25#8 <ᵤ x + BitVec.ofInt 8 (-64)) =
    ofBool (x + BitVec.ofInt 8 (-123) <ᵤ BitVec.ofInt 8 (-26)) &&&
      ofBool (x + BitVec.ofInt 8 (-90) <ᵤ BitVec.ofInt 8 (-26))

theorem test_thm : zext 32 (icmp IntPred.eq (const? 32 1) (const? 32 2)) ⊑ const? 32 0

@[bv_automata_nnf] theorem Int.lt_eq (a b : Int) : (a < b) = (a + 1 ≤ b)

theorem bv_283 :
    ∀ (e e_1 : LLVM.IntW 1), LLVM.mul e_1 e ⊑ LLVM.and e_1 e

theorem test_shl__nuw_is_safe_proof : test_shl__nuw_is_safe_before ⊑ test_shl__nuw_is_safe_after

theorem n15_variable_shamts_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32) (x_2 x_3 : BitVec 64),
  ¬(x_2 ≥ ↑64 ∨ x ≥ ↑32) →
    ¬(x ≥ ↑32 ∨ x_2 ≥ ↑64) →
      ofBool (truncate 32 (x_3 <<< x_2) &&& x_1 >>> x != 0#32) =
        ofBool (x_1 >>> x &&& truncate 32 (x_3 <<< x_2) != 0#32)

theorem negative_not_less_than_logical_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (-1#32 <ₛ x) = 1#1 → ofBool (x + 256#32 <ᵤ 256#32) = 0#1

theorem e_2357 :
     - 6 *  ~~~(d ||| (e ^^^ f)) + 1 * ( ~~~e |||  ~~~(d ^^^ f)) - 1 * (e ^^^  ~~~( ~~~d &&& (e ||| f))) - 5 * ( ~~~(d ||| e) |||  ~~~(d ^^^ (e ^^^ f))) - 2 *  ~~~(d ||| f) + 3 * ( ~~~f &&& (d ^^^ e)) + 1 * ((d ^^^ e) ||| (d ^^^ f)) + 1 * (f ||| (d &&&  ~~~e)) - 6 * (e &&&  ~~~(d ^^^ f)) + 7 *  ~~~(d ^^^ ( ~~~e &&& f)) + 4 * (f ||| (d &&& e)) + 7 * (d ||| (e &&& f)) + 11 * ( ~~~f ||| (d ^^^ e)) - 6 * ( ~~~(d |||  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) + 5 * (f &&&  ~~~(d &&& e)) + 5 * (d &&& f) - 11 * (e ^^^  ~~~( ~~~d ||| (e ^^^ f))) + 2 * (f ^^^ (d ||| (e ||| f))) + 7 * (d ||| (e ||| f)) + 3 * (f ^^^  ~~~(d &&&  ~~~e)) - 3 * ((d &&& f) ^^^ (d ^^^ ( ~~~e &&& f))) + 1 * (f &&& (d ||| e)) - 11 * (e ^^^ ( ~~~d &&& (e ^^^ f))) - 2 * ((d &&& e) ^^^ (d ^^^ (e &&& f))) + 5 * (f ^^^ (d &&& e)) + 7 * ( ~~~e ||| (d ^^^ f)) + 5 * ((d &&& e) |||  ~~~(e ^^^ f)) - 2 * ( ~~~d ||| (e &&& f)) - 2 * ( ~~~(d ^^^ e) &&& (d ^^^ f)) + 1 * (e ^^^  ~~~(d &&&  ~~~f)) - 1 * (e |||  ~~~f) - 2 * (e ^^^ ( ~~~d &&& ( ~~~e ||| f))) + 5 * ((d ^^^ e) &&&  ~~~(d ^^^ f)) - 11 * ((e &&&  ~~~f) |||  ~~~(d ||| ( ~~~e &&& f))) - 2 * (e |||  ~~~(d ||| f)) + 4 *  ~~~(d ^^^ e) + 4 * (e ^^^ (d &&& (e ||| f))) - 1 * ((d &&& e) |||  ~~~(e |||  ~~~f)) - 2 * (d &&&  ~~~f) - 1 *  ~~~f + 2 * (f ^^^  ~~~( ~~~d &&& (e ||| f))) + 1 * (e ^^^ ( ~~~d ||| (e &&& f))) + 11 *  ~~~( ~~~d &&& (e &&& f)) + 3 * (f ^^^  ~~~(d &&& (e ||| f))) - 1 * (e ^^^  ~~~(d &&& f)) - 1 * ((d ^^^ e) &&& (d ^^^ f)) - 1 * (d ^^^ (e ^^^ f)) + 1 * (e ^^^  ~~~(d &&& (e ^^^ f))) - 5 *  ~~~(d |||  ~~~f) + 2 * (f ^^^ ( ~~~d ||| (e &&& f))) + 2 * (e ^^^  ~~~( ~~~d ||| ( ~~~e &&& f))) + 3 * ((d &&& f) |||  ~~~(e ||| f)) - 7 *  ~~~(d ^^^ (e ||| f)) - 3 *  ~~~( ~~~d &&& ( ~~~e ||| f)) + 7 * (f ^^^  ~~~(d |||  ~~~e)) - 1 * (e ^^^  ~~~(d &&& (e &&& f))) + 2 * (e ^^^ f) + 1 * ((e &&& f) ^^^  ~~~( ~~~d &&& (e ^^^ f))) - 2 * ((d &&& f) ||| (e &&&  ~~~f)) + 1 *  ~~~(e &&&  ~~~f) - 16 *  ~~~(d ||| (e ||| f)) - 17 *  ~~~(d ||| ( ~~~e ||| f)) - 38 *  ~~~( ~~~d ||| (e ||| f)) - 5 *  ~~~( ~~~d ||| ( ~~~e ||| f)) - 27 * ( ~~~d &&& ( ~~~e &&& f)) - 6 * ( ~~~d &&& (e &&& f)) - 71 * (d &&& ( ~~~e &&& f)) - 18 * (d &&& (e &&& f)) = 3 * (e ^^^ (d ||| (e &&& f)))

theorem ashrslt_01_10_exact_proof : ashrslt_01_10_exact_before ⊑ ashrslt_01_10_exact_after

theorem select_of_symmetric_selects_thm.extracted_1._7 : ∀ (x x_1 : BitVec 32) (x_2 x_3 : BitVec 1),
  ¬x_3 = 1#1 → x_2 = 1#1 → ¬x_2 ^^^ x_3 = 1#1 → x = x_1

theorem BitVec.even_mul_eq_shiftLeft_mul_of_eq_mul_two
    (w : Nat) (x : BitVec w) (n e : Nat) (he : e = n * 2) :
    (BitVec.ofNat w e) * x = (BitVec.ofNat w n) * (x <<< (1 : Nat))

theorem not_signbit_splat_mask1_thm.extracted_1._1 : ∀ (x : BitVec 16) (x_1 : BitVec 8),
  ¬7#8 ≥ ↑8 → zeroExtend 16 (x_1.sshiftRight' 7#8) &&& x = x &&& zeroExtend 16 (x_1.sshiftRight' 7#8)

theorem lshr_32_add_not_known_32_leading_zeroes_proof : lshr_32_add_not_known_32_leading_zeroes_before ⊑ lshr_32_add_not_known_32_leading_zeroes_after

theorem e_762 :
    1 *  ~~~(z &&&  ~~~z) + 7 * t - 1 * (z |||  ~~~t) - 1 *  ~~~(z |||  ~~~t) =  - 7 * (z &&&  ~~~t) + 7 * (z ||| t)

theorem udiv_i32_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8), ¬zeroExtend 32 x = 0 → x = 0 → False

theorem ashrslt_02_09_exact_proof : ashrslt_02_09_exact_before ⊑ ashrslt_02_09_exact_after

theorem lshrult_03_11_exact_thm (e : IntW 4) :
  icmp IntPred.ult (lshr e (const? 4 3) { «exact» := true }) (const? 4 (-5)) ⊑ const? 1 1

theorem intMin_eq_one {w : Nat} (hw : w ≤ 1): BitVec.intMin w = 1

theorem t2_proof : t2_before ⊑ t2_after

theorem PR30273_three_bools_thm.extracted_1._1 : ∀ (x x_1 x_2 : BitVec 1),
  x_2 = 1#1 →
    x_1 = 1#1 →
      ¬(True ∧ (zeroExtend 32 x).saddOverflow 1#32 = true) →
        x = 1#1 →
          ¬(True ∧ (zeroExtend 32 x + 1#32).saddOverflow 1#32 = true) →
            True ∧ (2#32).saddOverflow (zeroExtend 32 x_2) = true ∨
                True ∧ (2#32).uaddOverflow (zeroExtend 32 x_2) = true →
              False

theorem test10_thm (e : IntW 8) :
  trunc 32 (urem (sext 64 (mul (zext 32 e) (const? 32 4))) (const? 64 4)) ⊑ const? 32 0

theorem masked_icmps_mask_notallzeros_bmask_mixed_1_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x &&& 12#32 != 0#32) &&& ofBool (x &&& 7#32 == 1#32) = ofBool (x &&& 15#32 == 9#32)

theorem rotateleft_9_neg_mask_wide_amount_commute_thm.extracted_1._1 : ∀ (x : BitVec 33) (x_1 : BitVec 9),
  ¬(x &&& 8#33 ≥ ↑33 ∨ 0#33 - x &&& 8#33 ≥ ↑33) →
    True ∧ (zeroExtend 33 x_1 <<< (x &&& 8#33)).sshiftRight' (x &&& 8#33) ≠ zeroExtend 33 x_1 ∨
        True ∧ zeroExtend 33 x_1 <<< (x &&& 8#33) >>> (x &&& 8#33) ≠ zeroExtend 33 x_1 ∨
          x &&& 8#33 ≥ ↑33 ∨ 0#33 - x &&& 8#33 ≥ ↑33 →
      False

theorem ashr_uge_noexact_proof : ashr_uge_noexact_before ⊑ ashr_uge_noexact_after

theorem rem_euclid_non_const_pow2_thm.extracted_1._4 : ∀ (x x_1 : BitVec 8),
  ¬(x ≥ ↑8 ∨ (1#8 <<< x == 0 || 8 != 1 && x_1 == intMin 8 && 1#8 <<< x == -1) = true) →
    ¬ofBool (x_1.srem (1#8 <<< x) <ₛ 0#8) = 1#1 →
      ¬(True ∧ ((-1#8) <<< x).sshiftRight' x ≠ -1#8 ∨ x ≥ ↑8) →
        x_1.srem (1#8 <<< x) = x_1 &&& ((-1#8) <<< x ^^^ -1#8)

theorem shift_xor_multiuse_cmp_or_thm.extracted_1._1 : ∀ (x x_1 x_2 : BitVec 32),
  ofBool (0#32 != x_2 &&& 4096#32) = 1#1 → ofBool (x_2 &&& 4096#32 == 0#32) = 1#1 → False

theorem scalar_i64_shl_and_negC_eq_thm.extracted_1._1 : ∀ (x x_1 : BitVec 64),
  ¬x ≥ ↑64 → ofBool (x_1 <<< x &&& BitVec.ofInt 64 (-8589934592) == 0#64) = ofBool (x_1 <<< x <ᵤ 8589934592#64)

theorem logic_and_logic_or_6_thm.extracted_1._9 : ∀ (x x_1 x_2 : BitVec 1),
  ¬x_2 = 1#1 → x = 1#1 → ¬0#1 = 1#1 → x_2 = 0#1

theorem e_600 :
     - 11 *  ~~~(x ^^^ y) - 11 *  ~~~(x &&&  ~~~y) - 1 * (x |||  ~~~y) + 11 * (x ^^^ y) + 5 *  ~~~(x &&& y) + 4 * y + 18 *  ~~~(x ||| y) - 9 *  ~~~(x |||  ~~~y) - 13 * (x &&&  ~~~y) + 21 * (x &&& y) = 2 * x

theorem trunc_sel_equal_sext_thm.extracted_1._1 : ∀ (x : BitVec 1), ¬x = 1#1 → signExtend 32 42#16 = 42#32

theorem eq_smax4_thm (e e_1 : IntW 32) :
  icmp IntPred.eq (add e_1 (const? 32 3))
      (select (icmp IntPred.sgt e (add e_1 (const? 32 3))) e (add e_1 (const? 32 3))) ⊑
    icmp IntPred.sge (add e_1 (const? 32 3)) e

theorem test_simplify_decrement_invalid_ne_proof : test_simplify_decrement_invalid_ne_before ⊑ test_simplify_decrement_invalid_ne_after

theorem masked_icmps_mask_notallzeros_bmask_mixed_swapped_1b_logical_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬ofBool (x &&& 3#32 == 1#32) = 1#1 → 0#1 = ofBool (x &&& 3#32 == 1#32) &&& ofBool (x &&& 14#32 != 0#32)

theorem in_constant_varx_mone_invmask_thm.extracted_1._1 : ∀ (x x_1 : BitVec 4),
  (x_1 ^^^ -1#4) &&& (x ^^^ -1#4) ^^^ -1#4 = x_1 ||

theorem n1_thm.extracted_1._2 : ∀ (x x_1 : BitVec 8),
  ¬x_1 ≥ ↑8 →
    ¬(True ∧ 1#8 <<< x_1 >>> x_1 ≠ 1#8 ∨ x_1 ≥ ↑8) →
      ofBool ((1#8 <<< x_1 ^^^ -1#8) &&& x == x) = ofBool (x &&& 1#8 <<< x_1 == 0#8)

theorem foo_proof : foo_before ⊑ foo_after

theorem lshr_16_to_64_add_zext_basic_thm.extracted_1._1 : ∀ (x x_1 : BitVec 16),
  ¬16#64 ≥ ↑64 → (zeroExtend 64 x_1 + zeroExtend 64 x) >>> 16#64 = zeroExtend 64 (ofBool (x_1 ^^^ -1#16 <ᵤ x))

theorem lowbitmask_casted_shift_proof : lowbitmask_casted_shift_before ⊑ lowbitmask_casted_shift_after

theorem pr33078_1_proof : pr33078_1_before ⊑ pr33078_1_after

theorem masked_and_notA_slightly_optimized_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (8#32 ≤ᵤ x) &&& ofBool (x &&& 39#32 != x) = ofBool (x &&& BitVec.ofInt 32 (-40) != 0#32)

theorem land_lor_left1_proof : land_lor_left1_before ⊑ land_lor_left1_after

theorem e_1665 :
    2 *  ~~~(a ||| c) + 11 * ((a &&& b) |||  ~~~(b |||  ~~~c)) + 4 *  ~~~(a &&& ( ~~~b ||| c)) - 1 * ((a |||  ~~~b) &&& (a ^^^ (b ^^^ c))) + 4 * ( ~~~(a &&&  ~~~b) &&& (a ^^^ (b ^^^ c))) + 7 *  ~~~(a &&&  ~~~a) + 2 * (b ^^^  ~~~( ~~~a ||| (b &&& c))) - 1 * (c ^^^  ~~~(a &&& (b ||| c))) + 1 * (a ^^^ ( ~~~b &&& c)) - 7 *  ~~~(b |||  ~~~c) + 11 * (c &&&  ~~~(a ^^^ b)) - 5 * ((a &&& c) ^^^  ~~~(b &&&  ~~~c)) - 11 * (c ^^^ (a ||| (b ||| c))) + 1 *  ~~~(a ^^^ ( ~~~b ||| c)) - 5 *  ~~~(a &&& c) + 1 * ((a &&& c) |||  ~~~(b ||| c)) + 5 * (b ^^^  ~~~( ~~~a &&& (b ||| c))) - 8 *  ~~~(a ||| (b ||| c)) - 7 *  ~~~(a ||| ( ~~~b ||| c)) + 7 *  ~~~( ~~~a ||| (b ||| c)) - 6 *  ~~~( ~~~a ||| ( ~~~b ||| c)) - 19 * ( ~~~a &&& ( ~~~b &&& c)) - 7 * ( ~~~a &&& (b &&& c)) - 18 * (a &&& ( ~~~b &&& c)) - 35 * (a &&& (b &&& c)) = 1 * (a ||| (b ||| c))

theorem e_102 :
    11 *  ~~~(x &&&  ~~~y) + 1 * (x |||  ~~~y) + 1 * (x ^^^ y) - 6 *  ~~~(x |||  ~~~y) + 10 * (x &&&  ~~~y) - 12 * (x &&& y) = 6 *  ~~~(x &&& y) + 6 *  ~~~y

theorem lshr_add_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ¬(5#8 ≥ ↑8 ∨ (42#8 == 0 || 8 != 1 && x == intMin 8 && 42#8 == -1) = true ∨ 5#8 ≥ ↑8) →
    (42#8 == 0 || 8 != 1 && x == intMin 8 && 42#8 == -1) = true ∨ 5#8 ≥ ↑8 → False

@[simp] theorem Lets.denote_var_appendInl_pure (lets : Lets d Γ_in .pure Γ_out)
    (e : Expr d Γ_out .pure tys) (V_in : Valuation Γ_in) (v : Var _ u) :
    Lets.denote (var lets e) V_in v.appendInl
    = let xs : HVector .. := e.denoteOp (lets.denote V_in)
      xs[v]

theorem positive_biggershl_shlnuwnsw_proof : positive_biggershl_shlnuwnsw_before ⊑ positive_biggershl_shlnuwnsw_after

theorem e_2318 :
    7 * (e &&&  ~~~(d &&&  ~~~f)) - 2 * ((d &&& f) |||  ~~~(e ||| f)) + 2 * ((e &&& f) ||| ( ~~~d &&& (e ||| f))) - 5 * (d &&&  ~~~e) + 2 * ( ~~~(d |||  ~~~e) |||  ~~~(e ^^^ f)) + 2 * (d ^^^ e) - 11 *  ~~~(d ^^^ ( ~~~e ||| f)) - 6 * (f ^^^  ~~~(d ||| (e &&& f))) - 2 *  ~~~(d &&& f) - 11 * ((d |||  ~~~e) &&& (e ^^^ f)) - 2 * (d ||| e) - 3 * ( ~~~(d ^^^ e) &&&  ~~~(d ^^^ f)) + 2 * ((d |||  ~~~e) &&&  ~~~(d ^^^ (e ^^^ f))) + 1 * (f ^^^ ( ~~~d ||| (e ||| f))) + 11 * (f ^^^  ~~~( ~~~d &&& (e &&& f))) - 1 * (e ^^^ (d ||| (e ||| f))) + 1 * ( ~~~(d |||  ~~~e) ||| (d ^^^ (e ^^^ f))) - 7 * (f ^^^  ~~~( ~~~d &&& ( ~~~e ||| f))) + 1 * (f ^^^ ( ~~~d ||| ( ~~~e ||| f))) + 2 * (e ^^^  ~~~(d |||  ~~~f)) - 1 * (d ||| (e ^^^ f)) - 2 * (e ||| (d &&&  ~~~f)) - 3 * (f ^^^  ~~~(d ||| ( ~~~e &&& f))) - 1 * (f ||| (d ^^^ e)) + 1 * ((d ||| e) &&&  ~~~(e ^^^ f)) - 11 * (e ^^^ (d ||| ( ~~~e &&& f))) - 5 * (f ^^^ ( ~~~d &&& ( ~~~e ||| f))) + 5 * (e ^^^  ~~~( ~~~d &&& (e ^^^ f))) + 2 * (e ^^^ ( ~~~d ||| (e &&& f))) + 1 * ( ~~~(d &&& e) &&& (e ^^^ f)) - 1 * ( ~~~(d &&&  ~~~e) &&& (e ^^^ f)) + 1 * ((e &&&  ~~~f) ^^^ (d ||| (e ^^^ f))) + 7 * ( ~~~(d |||  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) - 1 * (f ^^^ ( ~~~d &&& (e ||| f))) - 2 * (e ^^^ ( ~~~d ||| ( ~~~e &&& f))) + 1 * ( ~~~(d ^^^ e) |||  ~~~(d ^^^ f)) + 4 *  ~~~(d &&& e) + 5 * (e ^^^ ( ~~~d ||| (e ||| f))) + 2 *  ~~~(e &&&  ~~~f) + 3 * (e ^^^ (d ||| f)) - 11 * ((d &&& e) ||| (d ^^^ (e ^^^ f))) + 2 * ( ~~~d ||| ( ~~~e ||| f)) - 2 * ((d &&& e) ^^^ (d ^^^ ( ~~~e ||| f))) + 4 * ( ~~~f ||| (d ^^^ e)) - 2 *  ~~~(d ^^^ e) - 7 * ((d &&& f) ^^^  ~~~(d ^^^ (e &&& f))) - 6 * (f ^^^  ~~~(d &&& (e ||| f))) + 7 * (f ^^^  ~~~(d &&& e)) + 3 * (e ^^^  ~~~(d ||| f)) + 5 *  ~~~(d ||| (e &&& f)) + 1 * ((d &&& f) ^^^  ~~~(e &&&  ~~~f)) - 7 *  ~~~( ~~~d &&& (e &&& f)) + 1 *  ~~~(d ^^^ (e ^^^ f)) + 1 *  ~~~(d &&& ( ~~~e ||| f)) - 1 *  ~~~(d ^^^ (e &&& f)) - 1 * (d ^^^ f) - 19 *  ~~~(d ||| (e ||| f)) + 11 *  ~~~(d ||| ( ~~~e ||| f)) + 23 *  ~~~( ~~~d ||| (e ||| f)) + 25 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 49 * ( ~~~d &&& ( ~~~e &&& f)) - 17 * ( ~~~d &&& (e &&& f)) + 42 * (d &&& ( ~~~e &&& f)) + 48 * (d &&& (e &&& f)) = 11 * (e ^^^ ( ~~~d &&& (e ||| f)))

theorem bools_logical_thm.extracted_1._10 : ∀ (x x_1 : BitVec 1),
  ¬x_1 ^^^ 1#1 = 1#1 → x_1 = 1#1 → 0#1 = 1#1 → 1#1 = x

theorem p0_proof : p0_before ⊑ p0_after

theorem add_eq (a b : BitStream) : a.add b = a + b

theorem t15_proof : t15_before ⊑ t15_after

theorem n0_thm (e : IntW 8) :
  icmp IntPred.ne (LLVM.and e (const? 8 4)) e ⊑
    icmp IntPred.ne (LLVM.and e (const? 8 (-5))) (const? 8 0)

theorem demo3 (x y : BitVec 8) :
    (x ^^^ -1#8 ||| 7#8) ^^^ 12#8 = x &&& BitVec.ofInt 8 (-8) ^^^ BitVec.ofInt 8 (-13)

theorem a_true_implies_b_true2_comm_thm.extracted_1._7 : ∀ (x x_1 : BitVec 1) (x_2 : BitVec 8),
  ¬ofBool (10#8 <ᵤ x_2) = 1#1 → ofBool (20#8 <ᵤ x_2) = 1#1 → x &&& ofBool (20#8 <ᵤ x_2) = x_1

theorem not_false_not_thm.extracted_1._3 : ∀ (x x_1 : BitVec 1), ¬x_1 ^^^ 1#1 = 1#1 → ¬x_1 = 1#1 → x ^^^ 1#1 = 0#1

theorem lshr_lshr_pow2_const_negative_nopow2_2_thm.extracted_1._1 : ∀ (x : BitVec 16),
  ¬(x ≥ ↑16 ∨ 6#16 ≥ ↑16) → x ≥ ↑16 → False

theorem logical_or_logical_or_icmps_comm3_thm.extracted_1._6 : ∀ (x x_1 x_2 : BitVec 8),
  ¬x_1 ≥ ↑8 →
    ¬(ofBool (x_2 &&& 1#8 <<< x_1 == 0#8) = 1#1 ∨ ofBool (x_2 &&& 1#8 == 0#8) = 1#1) →
      ¬(True ∧ 1#8 <<< x_1 >>> x_1 ≠ 1#8 ∨ x_1 ≥ ↑8 ∨ True ∧ 1#8 <<< x_1 >>> x_1 ≠ 1#8 ∨ x_1 ≥ ↑8) →
        ofBool (x_2 &&& (1#8 <<< x_1 ||| 1#8) != 1#8 <<< x_1 ||| 1#8) = 1#1 → ofBool (x == 42#8) = 1#1

theorem slt_or_not_max_commute_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ofBool (x_1 != 127#8) ||

theorem alive_InstCombineShift__582 : alive_InstCombineShift__582_src ⊑ alive_InstCombineShift__582_tgt

theorem add_nosignbit_shl_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬8#32 ≥ ↑32 → (x + 2147418112#32) <<< 8#32 = x <<< 8#32 + BitVec.ofInt 32 (-16777216)

theorem slt_zero_eq_i1_proof : slt_zero_eq_i1_before ⊑ slt_zero_eq_i1_after

theorem lshrugt_01_13_exact_proof : lshrugt_01_13_exact_before ⊑ lshrugt_01_13_exact_after

theorem icmp_ne_sext_ne_otherwise_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (signExtend 32 (ofBool (x != 2#32)) != x) = ofBool (x != -1#32)

theorem lshr_and_or_disjoint_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ¬((42#8 == 0 || 8 != 1 && x_1 == intMin 8 && 42#8 == -1) = true ∨
        2#8 ≥ ↑8 ∨ True ∧ (x_1.srem 42#8 &&& (x >>> 2#8 &&& 13#8) != 0) = true ∨ 2#8 ≥ ↑8) →
    (42#8 == 0 || 8 != 1 && x_1 == intMin 8 && 42#8 == -1) = true ∨
        2#8 ≥ ↑8 ∨ True ∧ (x &&& 52#8 &&& x_1.srem 42#8 <<< 2#8 != 0) = true →
      False

theorem or_ranges_single_elem_left_proof : or_ranges_single_elem_left_before ⊑ or_ranges_single_elem_left_after

theorem masked_icmps_mask_notallzeros_bmask_mixed_negated_2_logical_proof : masked_icmps_mask_notallzeros_bmask_mixed_negated_2_logical_before ⊑ masked_icmps_mask_notallzeros_bmask_mixed_negated_2_logical_after

theorem positive_samevar_shlnuwnsw_proof : positive_samevar_shlnuwnsw_before ⊑ positive_samevar_shlnuwnsw_after

theorem logical_and_bitwise_and_icmps_comm3_thm (e e_1 e_2 : IntW 8) :
  select (icmp IntPred.ne (LLVM.and e_2 (shl (const? 8 1) e_1)) (const? 8 0))
      (LLVM.and (icmp IntPred.ne (LLVM.and e_2 (const? 8 1)) (const? 8 0)) (icmp IntPred.eq e (const? 8 42)))
      (const? 1 0) ⊑
    select (icmp IntPred.ne (LLVM.and e_2 (shl (const? 8 1) e_1 { «nsw» := false, «nuw» := true })) (const? 8 0))
      (LLVM.and (icmp IntPred.ne (LLVM.and e_2 (const? 8 1)) (const? 8 0)) (icmp IntPred.eq e (const? 8 42)))
      (const? 1 0)

theorem abs_diff_signed_slt_swap_wrong_pred1_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ofBool (x_1 == x) = 1#1 →
    ¬(True ∧ x.ssubOverflow x_1 = true) → ¬(True ∧ x_1.ssubOverflow x = true) → x - x_1 = x_1 - x

@[simp] theorem Expr.op_mk {varName} {op : Op} {args} {regions : List (Region Op T)} :
    Expr.op ⟨varName, op, args, regions⟩ = op

theorem add_select_sext_thm.extracted_1._2 : ∀ (x : BitVec 1), ¬x = 1#1 → 1#64 + signExtend 64 x = 1#64

theorem add_nosignbit_select_shl_thm (e : IntW 32) (e_1 : IntW 1) :
  shl (select e_1 (add e (const? 32 2147418112)) e) (const? 32 8) ⊑
    select e_1 (add (shl e (const? 32 8)) (const? 32 (-16777216))) (shl e (const? 32 8))

theorem test13_proof : test13_before ⊑ test13_after

theorem sext
    (b : BitVec 8)
    (c : ¬(11#9 - signExtend 9 (b &&& 7#8)).msb = (11#9 - signExtend 9 (b &&& 7#8)).getMsbD 1) :
    False

theorem lshrugt_03_00_proof : lshrugt_03_00_before ⊑ lshrugt_03_00_after

private theorem if_else_if_then_poison_eq {α : Type} (c₁ c₂ : Prop) [Decidable c₁] [Decidable c₂]
      (x y : PoisonOr α):
    (if c₁ then x else (if c₂ then poison else y)) =
    (if ¬c₁ ∧ c₂ then poison else (if c₁ then x else y))

theorem e_1044 :
     - 1 * (z ^^^ t) + 1 * t + 7 * (z ||| t) - 2 *  ~~~z + 7 *  ~~~(z &&&  ~~~t) - 12 *  ~~~(z |||  ~~~t) - 15 * (z &&& t) = 6 * (z &&&  ~~~t) + 5 *  ~~~(z ||| t)

theorem test2_proof : test2_before ⊑ test2_after

theorem test21_thm.extracted_1._1 : ∀ (x x_1 : BitVec 256), ofBool (x_1 - x != x_1) = ofBool (x != 0#256)

theorem lshrugt_03_11_proof : lshrugt_03_11_before ⊑ lshrugt_03_11_after

theorem AvoidCollision_signExtend_not {x : BitVec w} (h : 0 < w) :
    (~~~x).signExtend v = ~~~(x.signExtend v)

theorem XorZextXor_thm (e : IntW 3) :
  LLVM.xor (zext 5 (LLVM.xor e (const? 3 3))) (const? 5 12) ⊑ LLVM.xor (zext 5 e) (const? 5 15)

theorem test_mul__all_are_safe_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x &&& 255#32 == 17#32) = 1#1 →
    True ∧ (x &&& 255#32).smulOverflow 9#32 = true ∨ True ∧ (x &&& 255#32).umulOverflow 9#32 = true → False

theorem a_proof : a_before ⊑ a_after

theorem udiv_mul_shl_nuw_thm.extracted_1._2 : ∀ (x x_1 x_2 : BitVec 5),
  ¬(True ∧ x_2.umulOverflow x_1 = true ∨ True ∧ x_2 <<< x >>> x ≠ x_2 ∨ x ≥ ↑5 ∨ x_2 <<< x = 0) →
    ¬x ≥ ↑5 → x_2 * x_1 / x_2 <<< x = x_1 >>> x

theorem width5 (w : Nat) (a b : BitVec w) : (a + b = a - a) → a = - b

theorem land_band_left1_thm.extracted_1._2 : ∀ (x x_1 : BitVec 1), x_1 = 1#1 → x &&& x_1 = x

theorem alive_Select_747 : forall (w : Nat) (A : Bitvec 1)
, TSSA.eval
  (Op := Op) (e := e)
  (i := TSSAIndex.STMT (UserType.base (BaseType.bitvec 1)))
  [dsl_bb|
  ^bb
  %v0 := unit: ;
  %v1 := op:const (A) %v0;
  %v2 := op:const (0) %v0;
  %v3 := pair:%v1 %v2;
  %v4 := op:icmp sgt  w %v3;
  %v5 := op:const (0) %v0;
  %v6 := pair:%v5 %v1;
  %v7 := op:sub 1 %v6;
  %v8 := triple:%v4 %v1 %v7;
  %v9 := op:select w %v8;
  %v10 := op:const (0) %v0;
  %v11 := pair:%v9 %v10;
  %v12 := op:icmp slt  w %v11;
  %v13 := op:const (0) %v0;
  %v14 := pair:%v13 %v9;
  %v15 := op:sub w %v14;
  %v16 := triple:%v12 %v9 %v15;
  %v17 := op:select w %v16
  dsl_ret %v17
  ]  ⊑
  TSSA.eval
  (Op := Op) (e := e)
  (i := TSSAIndex.STMT (UserType.base (BaseType.bitvec 1)))
  [dsl_bb|
  ^bb
  %v0 := unit: ;
  %v1 := op:const (0) %v0;
  %v2 := op:const (A) %v0;
  %v3 := pair:%v1 %v2;
  %v4 := op:sub 1 %v3;
  %v5 := op:const (0) %v0;
  %v6 := pair:%v2 %v5;
  %v7 := op:icmp slt  1 %v6;
  %v8 := op:const (0) %v0;
  %v9 := pair:%v2 %v8;
  %v10 := op:icmp sgt  1 %v9;
  %v11 := triple:%v10 %v2 %v4;
  %v12 := op:select 1 %v11;
  %v13 := op:const (0) %v0;
  %v14 := pair:%v12 %v13;
  %v15 := op:icmp slt  1 %v14;
  %v16 := op:const (0) %v0;
  %v17 := pair:%v16 %v12;
  %v18 := op:sub 1 %v17;
  %v19 := triple:%v7 %v2 %v4;
  %v20 := op:select 1 %v19
  dsl_ret %v20
  ]

theorem PR42691_8_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x <ₛ 14#32) &&& ofBool (x != BitVec.ofInt 32 (-2147483648)) =
    ofBool (x + 2147483647#32 <ᵤ BitVec.ofInt 32 (-2147483635))

theorem sub_ashr_and_i32_commute_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ¬(True ∧ x.ssubOverflow x_1 = true ∨ 31#32 ≥ ↑32) →
    ¬ofBool (x <ₛ x_1) = 1#1 → x_1 &&& (x - x_1).sshiftRight' 31#32 = 0#32

theorem uadd_sat_via_add_swapped_cmp_nonstrict_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ofBool (x + x_1 ≤ᵤ x_1) = 1#1 → ofBool (x_1 <ᵤ x + x_1) = 1#1 → -1#32 = x + x_1

theorem and_logic_and_logic_or_1_thm (e e_1 e_2 : IntW 1) :
  select (LLVM.and e_2 e_1) (const? 1 1) (select e_2 e (const? 1 0)) ⊑
    select e_2 (select e_1 (const? 1 1) e) (const? 1 0)

theorem icmp_eq_mul_nsw_nonequal_commuted_proof : icmp_eq_mul_nsw_nonequal_commuted_before ⊑ icmp_eq_mul_nsw_nonequal_commuted_after

theorem PR42691_3_logical_proof : PR42691_3_logical_before ⊑ PR42691_3_logical_after

theorem logic_and_logic_or_5_proof : logic_and_logic_or_5_before ⊑ logic_and_logic_or_5_after

theorem masked_bit_set_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ¬x_1 ≥ ↑32 → zeroExtend 32 (ofBool (1#32 <<< x_1 &&& x != 0#32)) = x >>> x_1 &&& 1#32

theorem canonicalize_logic_first_xor_0_nsw_proof : canonicalize_logic_first_xor_0_nsw_before ⊑ canonicalize_logic_first_xor_0_nsw_after

theorem test_shl_nuw_nsw__nuw_is_safe_thm.extracted_1._4 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ¬ofBool (x_1 &&& 1073741822#32 == 0#32) = 1#1 →
    ¬(True ∧ ((x_1 &&& 1073741822#32) <<< 2#32).sshiftRight' 2#32 ≠ x_1 &&& 1073741822#32 ∨
          True ∧ (x_1 &&& 1073741822#32) <<< 2#32 >>> 2#32 ≠ x_1 &&& 1073741822#32 ∨
            2#32 ≥ ↑32 ∨ zeroExtend 64 ((x_1 &&& 1073741822#32) <<< 2#32) ≥ ↑64) →
      ¬(2#32 ≥ ↑32 ∨
            True ∧ (x_1 <<< 2#32 &&& BitVec.ofInt 32 (-8)).msb = true ∨
              zeroExtend 64 (x_1 <<< 2#32 &&& BitVec.ofInt 32 (-8)) ≥ ↑64) →
        x.sshiftRight' (zeroExtend 64 ((x_1 &&& 1073741822#32) <<< 2#32)) =
          x.sshiftRight' (zeroExtend 64 (x_1 <<< 2#32 &&& BitVec.ofInt 32 (-8)))

theorem e_1142 :
     - 1 *  ~~~(z &&&  ~~~z) + 1 * t - 11 * (z ^^^ t) - 2 *  ~~~(z ^^^ t) + 8 *  ~~~(z ||| t) + 16 *  ~~~(z |||  ~~~t) + 17 * (z &&&  ~~~t) + 2 * (z &&& t) = 5 *  ~~~(z &&& t)

@[bv_automata_nnf] theorem not_eq_prop (p q : Prop) : (¬(p = q)) = (p = ¬q)

theorem xor_signbit_select_ashr_proof : xor_signbit_select_ashr_before ⊑ xor_signbit_select_ashr_after

theorem main5f_like_logical_thm.extracted_1._7 : ∀ (x x_1 x_2 : BitVec 32),
  ofBool (x_2 &&& x_1 != x_2) = 1#1 → ¬ofBool (x_2 &&& x_1 == x_2) = 1#1 → True → 0#32 = zeroExtend 32 0#1

theorem test_sext2_thm.extracted_1._2 : ∀ (x x_1 : BitVec 1), x_1 = 1#1 → -1#32 = signExtend 32 1#1

theorem and_or_not_not_wrong_a_thm.extracted_1._1 : ∀ (x x_1 x_2 x_3 : BitVec 32),
  (x_3 &&& x_2 ^^^ -1#32 ||| x_1) &&& (x_1 &&& x ^^^ -1#32) = x_1 &&& x ^^^ (x_1 ||| x_3 &&& x_2 ^^^ -1#32)

theorem andn_or_cmp_4_logical_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ofBool (x_1 == x) = 1#1 → ofBool (x_1 != x) = 1#1 → True → False

theorem match_signed_proof : match_signed_before ⊑ match_signed_after

theorem negative5_proof : negative5_before ⊑ negative5_after

theorem add_nuw_nsw_or_and_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ¬(True ∧ (x_1 ||| x).saddOverflow (x_1 &&& x) = true ∨ True ∧ (x_1 ||| x).uaddOverflow (x_1 &&& x) = true) →
    True ∧ x_1.saddOverflow x = true ∨ True ∧ x_1.uaddOverflow x = true → False

theorem test_zext2_thm.extracted_1._2 : ∀ (x x_1 : BitVec 1), x_1 = 1#1 → 1#32 = zeroExtend 32 1#1

theorem trunc_sandwich_proof : trunc_sandwich_before ⊑ trunc_sandwich_after

theorem e_702 :
    2 *  ~~~x + 2 *  ~~~(x &&& y) - 1 *  ~~~y + 1 * (x ||| y) + 4 * x - 11 *  ~~~(x ^^^ y) + 5 * y + 8 *  ~~~(x ||| y) - 10 *  ~~~(x |||  ~~~y) - 6 * (x &&&  ~~~y) =  - 1 * (x &&& y)

theorem evalWith_eq_eval_of_eq_init (p : FSM arity) (carryState : p.α → Bool) (x : arity → BitStream)
    (hc : carryState = p.initCarry) : p.evalWith carryState x = p.eval x

@[simp]
lemma BitVec.transport_getElem (f : Fin n2 → Fin n1) (bv : BitVec n1) (i : Nat) (hlt : i < n2) :
    (bv.transport f)[i] = bv.getLsbD (f ⟨i, hlt⟩)

theorem par_proof : par_before ⊑ par_after

theorem alive_InstCombineShift__582  (w : Nat)   : alive_InstCombineShift__582_src w  ⊑ alive_InstCombineShift__582_tgt w

theorem ult_to_sgt_thm (e e_1 : IntW 8) :
  icmp IntPred.ult (LLVM.xor e_1 (const? 8 127)) (LLVM.xor e (const? 8 127)) ⊑ icmp IntPred.sgt e_1 e

theorem test_ashr_exact__exact_is_unsafe_thm.extracted_1._2 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ofBool (x_1 &&& BitVec.ofInt 32 (-2147483585) == 0#32) = 1#1 →
    ¬(2#32 ≥ ↑32 ∨
          True ∧ (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)).msb = true ∨
            zeroExtend 64 (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)) ≥ ↑64) →
      x = x.sshiftRight' (zeroExtend 64 (x_1.sshiftRight' 2#32 &&& BitVec.ofInt 32 (-536870897)))

theorem main11_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬ofBool (x &&& 64#32 == 0#32) ||

theorem src_is_mask_select_thm.extracted_1._2 : ∀ (x x_1 : BitVec 8) (x_2 : BitVec 1),
  x_2 = 1#1 →
    ofBool ((x_1 ^^^ x_1 + -1#8) &&& (x ^^^ 123#8) != x ^^^ 123#8) = ofBool (x_1 ^^^ x_1 + -1#8 <ᵤ x ^^^ 123#8)

theorem icmp_shl_nsw_sgt_proof : icmp_shl_nsw_sgt_before ⊑ icmp_shl_nsw_sgt_after

theorem n1_proof : n1_before ⊑ n1_after

theorem shift_no_xor_multiuse_or_thm (e e_1 : IntW 32) :
  mul (select (icmp IntPred.eq (LLVM.and e_1 (const? 32 1)) (const? 32 0)) e (LLVM.or e (const? 32 2)))
      (LLVM.or e (const? 32 2)) ⊑
    mul (LLVM.or e (LLVM.and (shl e_1 (const? 32 1)) (const? 32 2))) (LLVM.or e (const? 32 2))

theorem shl_trunc_bigger_ashr_thm (e : IntW 32) :
  shl (trunc 24 (ashr e (const? 32 12))) (const? 24 3) ⊑
    LLVM.and (trunc 24 (ashr e (const? 32 9)) { «nsw» := true, «nuw» := false }) (const? 24 (-8))

theorem alive_AndOrXor_709 : alive_AndOrXor_709_src ⊑ alive_AndOrXor_709_tgt

theorem test6_thm.extracted_1._1 : ∀ (x : BitVec 77), x ^^^ 23#77 ^^^ 23#77 = x

theorem not_or_or_and_not_and_and_commute2_thm (e e_1 e_2 : IntW 32) :
  LLVM.and (LLVM.or (LLVM.or (LLVM.xor e_2 (const? 32 (-1))) e_1) (LLVM.sdiv (const? 32 42) e))
      (LLVM.xor (LLVM.and (LLVM.sdiv (const? 32 42) e) (LLVM.and e_1 e_2)) (const? 32 (-1))) ⊑
    LLVM.or (LLVM.xor (LLVM.sdiv (const? 32 42) e) e_1) (LLVM.xor e_2 (const? 32 (-1)))

theorem substitute_constant_and_eq_eq_commute_logical_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ofBool (x_1 == x) = 1#1 → ofBool (x_1 == 42#8) = ofBool (x_1 == 42#8) &&& ofBool (x == 42#8)

theorem negate_shl_xor_thm (e e_1 : IntW 4) :
  sub (const? 4 0) (shl (LLVM.xor e_1 (const? 4 5)) e) ⊑
    shl (add (LLVM.xor e_1 (const? 4 (-6))) (const? 4 1)) e

theorem no_shift_xor_multiuse_cmp_with_and_proof : no_shift_xor_multiuse_cmp_with_and_before ⊑ no_shift_xor_multiuse_cmp_with_and_after

theorem andn_or_cmp_1_proof : andn_or_cmp_1_before ⊑ andn_or_cmp_1_after

@[simp]
theorem toBitVec_concat_zero (a : BitStream) :
    (a.concat b).toBitVec 0 = 0#0

theorem sext_zext_ult_known_nonneg_proof : sext_zext_ult_known_nonneg_before ⊑ sext_zext_ult_known_nonneg_after

theorem test_imply_not2_thm.extracted_1._5 : ∀ (x : BitVec 1) (x_1 : BitVec 32),
  ¬ofBool (x_1 == 0#32) = 1#1 → ofBool (x_1 != 0#32) = 1#1 → 0#1 ||

theorem test_thm.extracted_1._1 : ∀ (x : BitVec 64), ¬1#64 ≥ ↑64 → ofBool (0#64 <ᵤ x >>> 1#64) = ofBool (1#64 <ᵤ x)

theorem lshr_neg_slt_zero_thm (e : IntW 8) :
  icmp IntPred.slt (lshr (const? 8 (-17)) e) (const? 8 0) ⊑ icmp IntPred.eq e (const? 8 0)

theorem bools2_logical_commute3_and1_thm.extracted_1._6 : ∀ (x x_1 x_2 : BitVec 1),
  ¬x_2 &&& x_1 = 1#1 → x = 1#1 → ¬x_1 = 1#1 → x_1 ^^^ 1#1 = x

theorem main5f_like_thm (e e_1 e_2 : IntW 32) :
  select (LLVM.or (icmp IntPred.ne (LLVM.and e_2 e_1) e_2) (icmp IntPred.ne (LLVM.and e_2 e) e_2))
      (const? 32 0) (const? 32 1) ⊑
    zext 32 (icmp IntPred.eq (LLVM.and e_2 (LLVM.and e_1 e)) e_2)

theorem e_929 :
     - 2 *  ~~~(z &&& t) + 3 *  ~~~t - 5 * (z ^^^ t) - 1 * (z |||  ~~~t) + 7 *  ~~~(z |||  ~~~t) + 1 * (z &&& t) =  - 5 * (z &&&  ~~~t)

theorem scalar_i32_udiv_and_negC_eq_X_is_constant3_thm (e : IntW 32) :
  icmp IntPred.ne (LLVM.and (LLVM.udiv (const? 32 12345) e) (const? 32 16376)) (const? 32 0) ⊑
    icmp IntPred.ult e (const? 32 1544)

theorem sle_swap_or_not_min_logical_thm (e e_1 : IntW 8) :
  select (icmp IntPred.sge e_1 e) (const? 1 1) (icmp IntPred.ne e (const? 8 (-128))) ⊑ const? 1 1

theorem p_commutative2_thm (e e_1 e_2 : IntW 32) :
  LLVM.or (LLVM.and (LLVM.xor e_2 (const? 32 (-1))) e_1) (LLVM.and e e_2) ⊑
    LLVM.or (LLVM.and e_1 (LLVM.xor e_2 (const? 32 (-1)))) (LLVM.and e e_2) { «disjoint» := true }

theorem logic_and_logic_or_7_thm.extracted_1._6 : ∀ (x x_1 x_2 : BitVec 1),
  x_2 = 1#1 → x = 1#1 → x_1 = 1#1 → 1#1 = x_1

theorem src_is_mask_xor_fail_notmask_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ofBool ((x_1 ^^^ 123#8) &&& (x ^^^ x + -1#8 ^^^ -1#8) != x_1 ^^^ 123#8) =
    ofBool (x ^^^ 0#8 - x ||| x_1 ^^^ BitVec.ofInt 8 (-124) != -1#8)

theorem neg_mask2_lshr_thm (e : IntW 8) :
  sub (const? 8 0) (LLVM.and (lshr e (const? 8 3)) (const? 8 2)) ⊑
    sub (const? 8 0) (LLVM.and (lshr e (const? 8 3)) (const? 8 2)) { «nsw» := true, «nuw» := false }

theorem n2_thm (e e_1 : IntW 8) (e_2 : IntW 1) :
  LLVM.and (LLVM.xor e_2 (const? 1 1)) (icmp IntPred.eq e_1 e) ⊑
    LLVM.and (icmp IntPred.eq e_1 e) (LLVM.xor e_2 (const? 1 1))

theorem masked_icmps_mask_notallzeros_bmask_mixed_negated_swapped_2_thm (e : IntW 32) :
  LLVM.or (icmp IntPred.ne (LLVM.and e (const? 32 7)) (const? 32 0))
      (icmp IntPred.eq (LLVM.and e (const? 32 3)) (const? 32 0)) ⊑
    const? 1 1

theorem test14_proof : test14_before ⊑ test14_after

theorem neg_or_ashr_i32_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬31#32 ≥ ↑32 → (0#32 - x ||| x).sshiftRight' 31#32 = signExtend 32 (ofBool (x != 0#32))

theorem e_1652 :
    7 * ((a &&& c) ||| (b &&&  ~~~c)) - 1 * (c ^^^  ~~~(a &&& (b &&& c))) + 2 * ((a &&& b) |||  ~~~(b ||| c)) + 2 * (c ^^^ ( ~~~a ||| (b &&& c))) + 1 * (b ^^^  ~~~( ~~~a ||| (b &&& c))) - 2 *  ~~~(b &&& c) + 3 * ((a &&&  ~~~b) ||| (a ^^^ (b ^^^ c))) - 7 *  ~~~(a &&& (b ^^^ c)) + 5 * (c ^^^ (a ||| (b ||| c))) + 11 * (b &&& (a |||  ~~~c)) + 11 * ((b &&& c) ||| ( ~~~a &&& (b ||| c))) - 5 * (b ^^^ (a &&& (b ^^^ c))) + 3 * (b ^^^ (a ||| (b ^^^ c))) + 5 * (c ||| (a ^^^ b)) - 6 * (a ^^^ (b ^^^ c)) + 8 *  ~~~(a ||| (b ||| c)) - 22 *  ~~~(a ||| ( ~~~b ||| c)) - 3 *  ~~~( ~~~a ||| (b ||| c)) - 20 *  ~~~( ~~~a ||| ( ~~~b ||| c)) - 7 * ( ~~~a &&& ( ~~~b &&& c)) - 8 * ( ~~~a &&& (b &&& c)) - 12 * (a &&& ( ~~~b &&& c)) - 19 * (a &&& (b &&& c)) = 2 * (c ^^^  ~~~(a &&& ( ~~~b ||| c)))

theorem sgt_swap_and_min_logical_proof : sgt_swap_and_min_logical_before ⊑ sgt_swap_and_min_logical_after

theorem masked_icmps_mask_notallzeros_bmask_mixed_negated_3_logical_proof : masked_icmps_mask_notallzeros_bmask_mixed_negated_3_logical_before ⊑ masked_icmps_mask_notallzeros_bmask_mixed_negated_3_logical_after

theorem zext_add_scalar_thm (e : IntW 1) : add (zext 32 e) (const? 32 42) ⊑ select e (const? 32 43) (const? 32 42)

theorem bv_AddSub_1574 :
    ∀ (e e_1 e_2 : LLVM.IntW w), LLVM.sub e_1 (LLVM.add e e_2) ⊑ LLVM.sub (LLVM.sub e_1 e_2) e

theorem main3b_logical_thm.extracted_1._3 : ∀ (x : BitVec 32),
  ¬ofBool (x &&& 7#32 == 0#32) = 1#1 → 0#1 = 1#1 → 0#32 = zeroExtend 32 (ofBool (x &&& 23#32 != 0#32))

theorem main7e_thm.extracted_1._2 : ∀ (x x_1 x_2 x_3 x_4 : BitVec 32),
  ¬ofBool (x_4 &&& x_3 &&& x_2 == x_4 &&& x_3) &&& ofBool (x_1 &&& x &&& x_2 == x_1 &&& x) = 1#1 →
    1#32 = zeroExtend 32 (ofBool (x_2 &&& (x_4 &&& x_3 ||| x_1 &&& x) != x_4 &&& x_3 ||| x_1 &&& x))

theorem shift_xor_multiuse_cmp_xor_thm.extracted_1._4 : ∀ (x x_1 x_2 x_3 : BitVec 32),
  ¬ofBool (0#32 != x_3 &&& 4096#32) = 1#1 →
    ¬ofBool (x_3 &&& 4096#32 == 0#32) = 1#1 →
      (x_2 ^^^ 2048#32) * x * (x_2 ^^^ 2048#32) = x_2 * x_1 * (x_2 ^^^ 2048#32)

theorem exact_lshr_ne_thm (e : IntW 8) :
  icmp IntPred.ne (lshr (const? 8 4) e { «exact» := true }) (const? 8 1) ⊑
    icmp IntPred.ne e (const? 8 2)

theorem sel_sext_constants_proof : sel_sext_constants_before ⊑ sel_sext_constants_after

theorem lshrugt_03_02_proof : lshrugt_03_02_before ⊑ lshrugt_03_02_after

theorem ashrsgt_01_09_exact_thm (e : IntW 4) :
  icmp IntPred.sgt (ashr e (const? 4 1) { «exact» := true }) (const? 4 (-7)) ⊑ const? 1 1

theorem e_361 :
     - 2 *  ~~~x - 11 *  ~~~(x &&&  ~~~x) + 3 *  ~~~(x ^^^ y) - 7 *  ~~~y - 1 *  ~~~(x &&& y) + 19 *  ~~~(x ||| y) + 14 *  ~~~(x |||  ~~~y) + 20 * (x &&&  ~~~y) = 1 * (x |||  ~~~y) - 9 * (x &&& y)

theorem e_2424 :
    1 * ( ~~~(d ||| e) |||  ~~~(d ^^^ (e ^^^ f))) + 11 * ((d &&& f) ^^^  ~~~(e &&&  ~~~f)) - 2 * (e ^^^  ~~~(d ||| (e &&& f))) + 2 * (e ^^^ (d &&& f)) - 1 * (f ^^^  ~~~( ~~~d &&& (e ||| f))) - 6 * ((d &&& f) ^^^  ~~~(d ^^^ ( ~~~e &&& f))) + 1 * (e ^^^ (d ||| (e ||| f))) + 3 * ( ~~~d &&& ( ~~~e ||| f)) + 5 * (e ^^^  ~~~( ~~~d ||| (e &&& f))) + 1 * ( ~~~d ||| ( ~~~e &&& f)) - 7 * (e ^^^ (d ||| f)) + 3 * ( ~~~(d ^^^ e) ||| (d ^^^ f)) - 5 * (f &&&  ~~~(d &&&  ~~~e)) - 11 * (f |||  ~~~(d ||| e)) + 5 * ((d &&& f) ||| (e &&&  ~~~f)) + 2 * ( ~~~f &&& (d ^^^ e)) + 7 *  ~~~(d ^^^ (e ||| f)) + 11 * ((d &&& e) ^^^  ~~~(d ^^^ (e &&& f))) - 11 * ((d &&&  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) + 1 * (e ^^^ ( ~~~d &&& (e ||| f))) + 1 *  ~~~( ~~~d &&& ( ~~~e ||| f)) + 3 * (d ||| (e ^^^ f)) + 11 * (e |||  ~~~(d |||  ~~~f)) + 7 * (f ^^^  ~~~(d ||| e)) + 1 * (d ||| ( ~~~e ||| f)) - 6 * (e ^^^  ~~~(d |||  ~~~f)) - 1 * (e ^^^ ( ~~~d ||| ( ~~~e ||| f))) - 3 * (e ^^^ ( ~~~d &&& (e ^^^ f))) - 1 * (e ||| (d ^^^ f)) + 7 *  ~~~(d &&& e) - 6 * ((d &&& e) |||  ~~~(d ^^^ (e ^^^ f))) - 3 * (e ^^^  ~~~( ~~~d ||| ( ~~~e &&& f))) - 6 *  ~~~(d &&& f) - 7 * (d ^^^ e) - 1 * (d ||| f) - 1 *  ~~~(d &&& (e ^^^ f)) - 1 * ( ~~~f &&&  ~~~(d ^^^ e)) + 7 * (d |||  ~~~f) - 2 * (f ||| (d ^^^ e)) - 1 * (f ^^^ (d ||| (e &&& f))) + 4 * ( ~~~e &&&  ~~~(d ^^^ f)) - 2 *  ~~~( ~~~d ||| (e &&& f)) - 1 * (e |||  ~~~(d ^^^ f)) - 5 *  ~~~(d ^^^ (e ^^^ f)) - 5 * (f ^^^ (d |||  ~~~e)) + 1 * (d ||| e) - 2 * ((e &&&  ~~~f) ^^^ (d ||| (e ^^^ f))) + 5 * (e ^^^ f) + 1 * ((d &&& f) ^^^ (d ^^^ ( ~~~e &&& f))) - 3 * (e ^^^  ~~~( ~~~d &&& ( ~~~e ||| f))) + 5 * ((d &&& e) |||  ~~~(e |||  ~~~f)) + 4 * (f &&& (d ||| e)) + 1 * ( ~~~f ||| (d ^^^ e)) - 1 * (f ^^^  ~~~( ~~~d ||| ( ~~~e &&& f))) + 2 * ((e &&& f) ^^^  ~~~( ~~~d &&& (e ^^^ f))) + 1 * ( ~~~d ||| (e ||| f)) + 3 * (e ^^^  ~~~( ~~~d &&& (e &&& f))) + 4 *  ~~~(d &&& (e ||| f)) + 1 *  ~~~( ~~~d &&& ( ~~~e &&& f)) + 11 * (e ^^^  ~~~( ~~~d ||| (e ^^^ f))) - 5 * (d &&& e) + 2 * ( ~~~e ||| (d ^^^ f)) + 4 * ((d ||| e) &&&  ~~~(d ^^^ (e ^^^ f))) - 11 * (e ^^^ (d ||| (e ^^^ f))) - 7 *  ~~~(d |||  ~~~f) - 2 * ( ~~~(d |||  ~~~e) ||| (e ^^^ f)) - 5 * ( ~~~(d &&& e) &&& (d ^^^ (e ^^^ f))) + 7 * ( ~~~(d ^^^ e) &&& (d ^^^ f)) - 13 *  ~~~(d ||| (e ||| f)) - 25 *  ~~~(d ||| ( ~~~e ||| f)) + 11 *  ~~~( ~~~d ||| (e ||| f)) - 26 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 1 * ( ~~~d &&& ( ~~~e &&& f)) - 2 * (d &&& ( ~~~e &&& f)) - 11 * (d &&& (e &&& f)) =  - 24 * ( ~~~d &&& (e &&& f)) + 7 *  ~~~(d &&& (e &&& f))

theorem e_19 :
    1 * x + 5 * (x ^^^ y) - 2 *  ~~~(x |||  ~~~y) - 3 * (x &&&  ~~~y) - 1 * (x &&& y) = 3 *  ~~~(x &&& y) - 3 *  ~~~(x ||| y)

theorem lowmask_add_zext_commute_thm (e : IntW 16) (e_1 : IntW 32) :
  LLVM.and (add (mul e_1 e_1) (zext 32 e)) (const? 32 65535) ⊑ zext 32 (add e (trunc 16 (mul e_1 e_1)))

theorem rev8_mul_and_lshr_thm (e : IntW 8) :
  trunc 8
      (lshr
        (mul
          (LLVM.or (LLVM.and (mul (zext 64 e) (const? 64 2050) { «nsw» := true, «nuw» := true }) (const? 64 139536))
            (LLVM.and (mul (zext 64 e) (const? 64 32800) { «nsw» := true, «nuw» := true }) (const? 64 558144)))
          (const? 64 65793) { «nsw» := true, «nuw» := true })
        (const? 64 16)) ⊑
    trunc 8
      (lshr
        (mul
          (LLVM.or (LLVM.and (mul (zext 64 e) (const? 64 2050) { «nsw» := true, «nuw» := true }) (const? 64 139536))
            (LLVM.and (mul (zext 64 e) (const? 64 32800) { «nsw» := true, «nuw» := true }) (const? 64 558144))
            { «disjoint» := true })
          (const? 64 65793) { «nsw» := true, «nuw» := true })
        (const? 64 16))

theorem t0_commutative_thm.extracted_1._8 : ∀ (x : BitVec 8) (x_1 : BitVec 1) (x_2 x_3 : BitVec 8),
  ofBool (x_3 == x_2) = 1#1 → ¬ofBool (x_3 != x_2) = 1#1 → ¬x_1 ^^^ 1#1 = 1#1 → ¬x_1 = 1#1 → False

theorem ashrsgt_03_01_exact_proof : ashrsgt_03_01_exact_before ⊑ ashrsgt_03_01_exact_after

theorem test_and_ne_a_b_thm (e e_1 : IntW 8) (e_2 : IntW 1) :
  select (LLVM.and e_2 (icmp IntPred.ne e_1 e)) e_1 e ⊑ select e_2 e_1 e

theorem demo2 (x : BitVec 64) : BitVec.zeroExtend 64 (BitVec.truncate 32 x) = x &&& 4294967295#64

theorem two_signed_truncation_checks_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x + 512#32 <ᵤ 1024#32) &&& ofBool (x + 128#32 <ᵤ 256#32) = ofBool (x + 128#32 <ᵤ 256#32)

theorem p13_commutativity0_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ofBool (x_1 <ᵤ 65536#32) = 1#1 → ofBool (65535#32 <ᵤ x_1) = 1#1 → 65535#32 = x

theorem e_1033 :
     - 1 * t + 11 *  ~~~(z &&&  ~~~z) + 2 *  ~~~(z ^^^ t) + 3 * (z |||  ~~~t) - 1 *  ~~~t - 15 *  ~~~(z ||| t) - 10 *  ~~~(z |||  ~~~t) = 15 * (z &&& t) + 13 * (z &&&  ~~~t)

theorem a_true_implies_b_true2_comm_thm.extracted_1._2 : ∀ (x : BitVec 1) (x_1 : BitVec 8),
  ofBool (10#8 <ᵤ x_1) = 1#1 → ¬ofBool (20#8 <ᵤ x_1) = 1#1 → x &&& ofBool (20#8 <ᵤ x_1) = 0#1

theorem e_2177 :
    5 * ( ~~~(d ||| e) |||  ~~~(e ^^^ f)) - 3 * (e ^^^ (d &&&  ~~~f)) - 11 * (e ^^^ ( ~~~d ||| ( ~~~e &&& f))) - 1 * ((d |||  ~~~e) &&& (e ^^^ f)) + 1 * (d |||  ~~~e) + 2 * (f ^^^ ( ~~~d ||| ( ~~~e ||| f))) - 1 * (f ^^^ (d ||| (e &&& f))) + 7 * ((d &&&  ~~~e) ||| (e ^^^ f)) + 1 *  ~~~( ~~~d &&& (e ||| f)) + 1 * ( ~~~(d |||  ~~~e) |||  ~~~(e ^^^ f)) - 3 *  ~~~d + 1 * (e ^^^  ~~~( ~~~d &&& ( ~~~e &&& f))) + 1 * ( ~~~d &&& (e ^^^ f)) + 5 * ((d &&& f) |||  ~~~(e ||| f)) + 4 * (f ^^^  ~~~( ~~~d ||| (e &&& f))) + 11 * (f ^^^ ( ~~~d &&& ( ~~~e ||| f))) - 1 * ( ~~~e |||  ~~~(d ^^^ f)) - 7 * (e ^^^ ( ~~~d &&& (e ||| f))) + 1 *  ~~~(d ^^^ e) - 6 * (f ^^^  ~~~(d ||| e)) - 2 * (e ^^^  ~~~(d ||| ( ~~~e &&& f))) - 7 * (f &&& (d |||  ~~~e)) + 2 * (f |||  ~~~(d ||| e)) - 3 *  ~~~(d ||| (e &&& f)) - 2 * (e ^^^ (d &&& (e ||| f))) - 2 *  ~~~(d ^^^ (e ||| f)) + 11 * (f ^^^  ~~~(d &&& (e &&& f))) + 2 * ( ~~~(d |||  ~~~e) ||| (d ^^^ (e ^^^ f))) - 2 * ((d &&& e) ^^^  ~~~(d ^^^ (e &&& f))) - 1 *  ~~~(d &&& ( ~~~e &&& f)) + 2 *  ~~~f + 3 * ((d &&& f) ^^^ (d ^^^ ( ~~~e &&& f))) + 2 * ( ~~~(d ||| e) ||| (e ^^^ f)) + 3 * (e ^^^ (d &&& ( ~~~e ||| f))) + 2 * (e |||  ~~~(d ||| f)) - 5 * ((d |||  ~~~e) &&&  ~~~(d ^^^ (e ^^^ f))) - 11 * (e ^^^  ~~~(d &&& f)) + 1 * (e ^^^  ~~~(d &&& ( ~~~e &&& f))) - 6 * (d ^^^ e) - 7 * (d &&& f) + 11 * ((d ^^^ e) &&&  ~~~(d ^^^ f)) + 3 * (d ^^^ (e ^^^ f)) - 1 *  ~~~(d ||| f) - 6 * d - 25 *  ~~~(d ||| ( ~~~e ||| f)) + 1 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 16 * ( ~~~d &&& ( ~~~e &&& f)) + 2 * ( ~~~d &&& (e &&& f)) + 7 * (d &&& ( ~~~e &&& f)) + 15 * (d &&& (e &&& f)) = 23 *  ~~~( ~~~d ||| (e ||| f))

theorem lshr_lshr_pow2_const_negative_nopow2_1_thm (e : IntW 16) :
  LLVM.and (lshr (lshr (const? 16 2047) e) (const? 16 6)) (const? 16 4) ⊑
    LLVM.and (lshr (const? 16 31) e) (const? 16 4)

theorem lshrult_02_09_exact_thm.extracted_1._1 : ∀ (x : BitVec 4),
  ¬(True ∧ x >>> 2#4 <<< 2#4 ≠ x ∨ 2#4 ≥ ↑4) → ofBool (x >>> 2#4 <ᵤ BitVec.ofInt 4 (-7)) = 1#1

theorem bools_multi_uses1_thm.extracted_1._1 : ∀ (x x_1 x_2 : BitVec 1),
  x_2 = 1#1 → ((x_2 ^^^ 1#1) &&& x_1 ||| x_2 &&& x) ^^^ (x_2 ^^^ 1#1) &&& x_1 = x ^^^ x_1 &&& (x_2 ^^^ 1#1)

theorem test3_proof : test3_before ⊑ test3_after

theorem p_commutative4_proof : p_commutative4_before ⊑ p_commutative4_after

theorem ult_swap_and_max_proof : ult_swap_and_max_before ⊑ ult_swap_and_max_after

theorem scalar_i8_signbit_lshr_and_eq_proof : scalar_i8_signbit_lshr_and_eq_before ⊑ scalar_i8_signbit_lshr_and_eq_after

theorem test_add_nuw__nsw_is_safe_thm.extracted_1._3 : ∀ (x : BitVec 32),
  ¬ofBool (x ||| BitVec.ofInt 32 (-2147483648) == -1#32) = 1#1 →
    ¬(True ∧ (x ||| BitVec.ofInt 32 (-2147483648)).uaddOverflow 1#32 = true) →
      True ∧ (x ||| BitVec.ofInt 32 (-2147483648)).saddOverflow 1#32 = true → False

theorem e_91 :
     - 5 * (x |||  ~~~y) - 5 *  ~~~(x &&& y) + 11 *  ~~~(x ||| y) + 10 * (x &&&  ~~~y) + 6 * (x &&& y) = 1 *  ~~~(x &&&  ~~~y) - 6 *  ~~~(x |||  ~~~y)

theorem select_of_symmetric_selects_negative1_thm.extracted_1._1 : ∀ (x : BitVec 32) (x_1 : BitVec 1),
  ¬(x_1 = 1#1 ∨ x_1 = 1#1) → x_1 = 1#1 → False

theorem demorgan_nor_use2bc_proof : demorgan_nor_use2bc_before ⊑ demorgan_nor_use2bc_after

@[symm] theorem Bisim.symm {a b : Stream α} : a ~ b → b ~ a

theorem bv_229 :
    ∀ (e e_1 e_2 : LLVM.IntW w), LLVM.mul (LLVM.add e e_1) e_2 ⊑ LLVM.add (LLVM.mul e e_2) (LLVM.mul e_1 e_2)

theorem test4_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ¬31#32 ≥ ↑32 → (x_1 ||| x >>> 31#32) &&& 2#32 = x_1 &&& 2#32

theorem trunc_shl_zext_64_thm (e : IntW 64) :
  zext 64 (shl (trunc 8 e) (const? 8 7)) ⊑ LLVM.and (shl e (const? 64 7)) (const? 64 128)

theorem icmp_select_implied_cond_swapped_select_proof : icmp_select_implied_cond_swapped_select_before ⊑ icmp_select_implied_cond_swapped_select_after

theorem OrZextOr_thm.extracted_1._1 : ∀ (x : BitVec 3), zeroExtend 5 (x ||| 3#3) ||

theorem e_1382 :
     - 1 * t + 2 *  ~~~(z ^^^ t) + 3 * (z ||| t) - 2 *  ~~~(z &&&  ~~~t) + 11 * (z |||  ~~~t) - 1 *  ~~~(z &&& t) + 5 * z - 10 *  ~~~(z ||| t) - 19 * (z &&&  ~~~t) - 18 * (z &&& t) =  - 1 * (z ^^^ t)

theorem bitwise_or_logical_or_icmps_comm1_proof : bitwise_or_logical_or_icmps_comm1_before ⊑ bitwise_or_logical_or_icmps_comm1_after

theorem lshr_mul_times_3_div_2_proof : lshr_mul_times_3_div_2_before ⊑ lshr_mul_times_3_div_2_after

theorem sge_swap_or_not_max_commute_proof : sge_swap_or_not_max_commute_before ⊑ sge_swap_or_not_max_commute_after

theorem logic_or_logic_and_4_thm.extracted_1._6 : ∀ (x x_1 x_2 : BitVec 1),
  ¬x_2 = 1#1 → ¬x = 1#1 → x_1 = 1#1 → x_2 = x

theorem and_not_or_commute4_proof : and_not_or_commute4_before ⊑ and_not_or_commute4_after

theorem test_implied_true_falseval_proof : test_implied_true_falseval_before ⊑ test_implied_true_falseval_after

@[simp]
lemma product_eval {M : NFA α σ} {N : NFA α ς} {w} :
  (M.product accept? N).eval w = M.eval w ×ˢ N.eval w

theorem lshr_add_and_shl_proof : lshr_add_and_shl_before ⊑ lshr_add_and_shl_after

@[simp]
theorem and_add_xor_eq_or {a b : BitVec w} : (a &&& b) + (a ^^^ b) = a ||

theorem trunc_shl_16_i32_i64_proof : trunc_shl_16_i32_i64_before ⊑ trunc_shl_16_i32_i64_after

theorem neg_nsw_sgt_0_proof : neg_nsw_sgt_0_before ⊑ neg_nsw_sgt_0_after

theorem test_or3_logical_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ¬ofBool (x_1 &&& 2147483647#32 ≤ₛ x) = 1#1 → ofBool (x <ₛ 0#32) = ofBool (x_1 &&& 2147483647#32 ≤ᵤ x)

theorem pr51551_proof : pr51551_before ⊑ pr51551_after

theorem shl_or_thm.extracted_1._2 : ∀ (x x_1 : BitVec 16),
  ¬((42#16 == 0 || 16 != 1 && x_1 == intMin 16 && 42#16 == -1) = true ∨ 5#16 ≥ ↑16 ∨ 7#16 ≥ ↑16) →
    ¬(12#16 ≥ ↑16 ∨
          (42#16 == 0 || 16 != 1 && x_1 == intMin 16 && 42#16 == -1) = true ∨
            True ∧ (x_1.srem 42#16 <<< 7#16).sshiftRight' 7#16 ≠ x_1.srem 42#16 ∨ 7#16 ≥ ↑16) →
      (x_1.srem 42#16 ||| x <<< 5#16) <<< 7#16 = x <<< 12#16 ||

theorem test3_thm (e e_1 : IntW 32) :
  LLVM.xor (LLVM.and (LLVM.xor e_1 (const? 32 (-1))) (LLVM.xor e (const? 32 (-1)))) (const? 32 (-1)) ⊑
    LLVM.or e_1 e

theorem t0_ult_slt_65536_thm (e e_1 e_2 : IntW 32) :
  select (icmp IntPred.ult e_2 (const? 32 65536)) e_2
      (select (icmp IntPred.slt e_2 (const? 32 65536)) e_1 e) ⊑
    select (icmp IntPred.sgt e_2 (const? 32 65535)) e
      (select (icmp IntPred.slt e_2 (const? 32 0)) e_1 e_2)

theorem lshrugt_02_14_proof : lshrugt_02_14_before ⊑ lshrugt_02_14_after

theorem substitute_constant_and_eq_eq_proof : substitute_constant_and_eq_eq_before ⊑ substitute_constant_and_eq_eq_after

@[trans]
theorem equal_up_to_trans (e1 : a ≈ʷ b) (e2 : b ≈ʷ c) : a ≈ʷ c

theorem ashrslt_03_07_exact_thm (e : IntW 4) :
  icmp IntPred.slt (ashr e (const? 4 3) { «exact» := true }) (const? 4 7) ⊑ const? 1 1

theorem n15_wrong_comparison_predicate_and_constant_thm.extracted_1._3 : ∀ (x : BitVec 8),
  ¬ofBool (x &&& 15#8 <ᵤ 2#8) = 1#1 →
    ¬ofBool (x &&& 14#8 == 0#8) = 1#1 → x + 16#8 &&& BitVec.ofInt 8 (-16) = (x &&& BitVec.ofInt 8 (-16)) + 16#8

theorem or_xor_tree_0111_thm (e e_1 e_2 : IntW 32) :
  LLVM.or (LLVM.xor (mul e_2 (const? 32 42)) (mul e_1 (const? 32 42)))
      (LLVM.xor (mul e_1 (const? 32 42)) (LLVM.xor (mul e (const? 32 42)) (mul e_2 (const? 32 42)))) ⊑
    LLVM.or (LLVM.xor (mul e_2 (const? 32 42)) (mul e_1 (const? 32 42))) (mul e (const? 32 42))

theorem test6_thm.extracted_1._2 : ∀ (x : BitVec 64),
  ¬32#128 ≥ ↑128 →
    ¬(32#64 ≥ ↑64 ∨ True ∧ zeroExtend 64 (truncate 32 (x >>> 32#64)) ≠ x >>> 32#64) →
      truncate 32 (zeroExtend 128 x >>> 32#128) = truncate 32 (x >>> 32#64)

theorem scalar_i32_lshr_and_signbit_eq_X_is_constant1_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬x ≥ ↑32 → ofBool (12345#32 >>> x &&& BitVec.ofInt 32 (-2147483648) == 0#32) = 1#1

theorem main11_thm (e : IntW 32) :
  select
      (LLVM.or (icmp IntPred.eq (LLVM.and e (const? 32 64)) (const? 32 0))
        (icmp IntPred.sge (trunc 8 e) (const? 8 0)))
      (const? 32 2) (const? 32 1) ⊑
    select (icmp IntPred.eq (LLVM.and e (const? 32 192)) (const? 32 192)) (const? 32 1) (const? 32 2)

theorem and_or1_wrong_operand_proof : and_or1_wrong_operand_before ⊑ and_or1_wrong_operand_after

theorem test_lshr__exact_is_unsafe_proof : test_lshr__exact_is_unsafe_before ⊑ test_lshr__exact_is_unsafe_after

theorem sge_or_not_max_logical_proof : sge_or_not_max_logical_before ⊑ sge_or_not_max_logical_after

theorem PR42691_6_proof : PR42691_6_before ⊑ PR42691_6_after

theorem t1_ult_slt_0_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x + 16#32 <ᵤ 144#32) = 1#1 → ofBool (127#32 <ₛ x) = 1#1 ∨ ofBool (x <ₛ BitVec.ofInt 32 (-16)) = 1#1 → False

theorem src_is_notmask_ashr_thm.extracted_1._1 : ∀ (x : BitVec 16) (x_1 : BitVec 8) (x_2 : BitVec 16),
  ¬(x_1 ≥ ↑8 ∨ x ≥ ↑16) →
    ofBool
        (x_2 ^^^ 123#16 ==
          (x_2 ^^^ 123#16) &&& ((signExtend 16 (BitVec.ofInt 8 (-32) <<< x_1)).sshiftRight' x ^^^ -1#16)) =
      ofBool ((signExtend 16 (BitVec.ofInt 8 (-32) <<< x_1)).sshiftRight' x ≤ᵤ x_2 ^^^ BitVec.ofInt 16 (-124))

theorem shl_add_nsw_proof : shl_add_nsw_before ⊑ shl_add_nsw_after

theorem test_sub_nuw__nuw_is_safe_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x &&& 2147483647#32 == 1073741824#32) = 1#1 →
    True ∧ (BitVec.ofInt 32 (-2147483648)).usubOverflow (x &&& 2147483647#32) = true → False

theorem alive_290__292  (w : Nat)   : alive_290__292_src w  ⊑ alive_290__292_tgt w

theorem n2_badmask_proof : n2_badmask_before ⊑ n2_badmask_after

theorem smear_sign_and_widen_thm.extracted_1._2 : ∀ (x : BitVec 8),
  ¬24#32 ≥ ↑32 → ¬7#8 ≥ ↑8 → signExtend 32 x >>> 24#32 = zeroExtend 32 (x.sshiftRight' 7#8)

theorem test6_thm (e : IntW 64) :
  trunc 32 (lshr (zext 128 e) (const? 128 32)) ⊑
    trunc 32 (lshr e (const? 64 32)) { «nsw» := false, «nuw» := true }

theorem different_size_zext_zext_ne_commute_thm.extracted_1._1 : ∀ (x : BitVec 4) (x_1 : BitVec 7),
  ofBool (zeroExtend 25 x_1 != zeroExtend 25 x) = ofBool (x_1 != zeroExtend 7 x)

theorem or_and_or_pat6_proof : or_and_or_pat6_before ⊑ or_and_or_pat6_after

theorem trunc_shl_shl_infloop_thm.extracted_1._2 : ∀ (x : BitVec 64),
  ¬(1#64 ≥ ↑64 ∨ 2#64 ≥ ↑64) → ¬3#32 ≥ ↑32 → truncate 32 (x <<< 1#64 <<< 2#64) = truncate 32 x <<< 3#32

theorem bor_land_right2_thm.extracted_1._2 : ∀ (x x_1 : BitVec 1), x_1 = 1#1 → x ||

theorem test69_thm.extracted_1._3 : ∀ (x x_1 : BitVec 32),
  ¬ofBool (x_1 &&& 128#32 != 0#32) = 1#1 → 6#32 ≥ ↑32 → False

theorem bools_logical_commute1_and2_thm.extracted_1._3 : ∀ (x x_1 : BitVec 1),
  x_1 = 1#1 → ¬x = 1#1 → x ^^^ 1#1 = 1#1 → 1#1 = x_1

theorem test85_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬(True ∧ x.uaddOverflow (BitVec.ofInt 32 (-16777216)) = true ∨
        True ∧ (x + BitVec.ofInt 32 (-16777216)) >>> 23#32 <<< 23#32 ≠ x + BitVec.ofInt 32 (-16777216) ∨ 23#32 ≥ ↑32) →
    23#32 ≥ ↑32 → False

theorem e_2039 :
    11 * ((d ^^^ e) ||| (d ^^^ f)) + 1 * (f ^^^  ~~~(d |||  ~~~e)) - 6 * ((d &&& e) ^^^  ~~~(d ^^^ ( ~~~e ||| f))) - 2 * (e ^^^  ~~~(d &&& ( ~~~e ||| f))) + 1 * (e ^^^  ~~~(d &&& f)) + 2 * ( ~~~(d ||| e) |||  ~~~(d ^^^ (e ^^^ f))) - 1 * ( ~~~d &&& (e ^^^ f)) - 2 * ((d ||| e) &&& (e ^^^ f)) - 1 * ( ~~~e |||  ~~~(d ^^^ f)) - 1 *  ~~~( ~~~d &&& (e &&& f)) - 1 *  ~~~(d &&& (e &&& f)) + 11 * (e ^^^  ~~~(d &&& (e ||| f))) - 2 * (e ^^^ (d ||| f)) + 5 * ((e &&& f) ||| (d &&& (e ||| f))) + 3 * ( ~~~(d |||  ~~~e) ||| (d ^^^ (e ^^^ f))) + 4 * ((d &&& f) ^^^  ~~~(d ^^^ ( ~~~e &&& f))) + 2 * (f ^^^  ~~~(d &&& (e &&& f))) - 1 *  ~~~(d &&& (e ||| f)) - 5 * ((e &&& f) ^^^  ~~~(d &&& (e ^^^ f))) - 1 * (e ^^^  ~~~(d |||  ~~~f)) - 1 * ((d &&&  ~~~e) ||| (d ^^^ (e ^^^ f))) - 1 *  ~~~(d &&& ( ~~~e ||| f)) - 5 * (d ^^^ ( ~~~e &&& f)) + 1 * (f &&&  ~~~(d ^^^ e)) - 3 *  ~~~( ~~~d ||| ( ~~~e &&& f)) + 1 * ((d &&& e) |||  ~~~(d ^^^ (e ^^^ f))) - 1 * ((d &&& e) ^^^  ~~~(d ^^^ (e &&& f))) - 2 * (f |||  ~~~(d ||| e)) - 3 *  ~~~(d ||| (e ||| f)) + 3 *  ~~~(d ||| ( ~~~e ||| f)) + 1 *  ~~~( ~~~d ||| (e ||| f)) - 8 *  ~~~( ~~~d ||| ( ~~~e ||| f)) - 2 * ( ~~~d &&& ( ~~~e &&& f)) - 21 * ( ~~~d &&& (e &&& f)) - 1 * (d &&& ( ~~~e &&& f)) - 10 * (d &&& (e &&& f)) = 3 * (d |||  ~~~e)

theorem poison_ne_value (a : α) :
    @Ne (no_index _) poison (value a)

theorem const_sub_const_sub_thm (e : IntW 32) : sub (const? 32 2) (sub (const? 32 8) e) ⊑ add e (const? 32 (-6))

theorem e_1523 :
    2 * (b ^^^  ~~~( ~~~a &&& (b &&& c))) + 1 * (b ^^^  ~~~( ~~~a &&& ( ~~~b &&& c))) + 2 * (b |||  ~~~(a |||  ~~~c)) - 1 * ((a &&& c) ||| (b &&&  ~~~c)) - 3 *  ~~~(a ||| (b ||| c)) - 1 *  ~~~(a ||| ( ~~~b ||| c)) - 3 *  ~~~( ~~~a ||| (b ||| c)) - 1 *  ~~~( ~~~a ||| ( ~~~b ||| c)) - 4 * ( ~~~a &&& (b &&& c)) - 2 * (a &&& ( ~~~b &&& c)) - 1 * (a &&& (b &&& c)) = 4 * ( ~~~a &&& ( ~~~b &&& c))

theorem signbit_splat_mask_thm.extracted_1._2 : ∀ (x : BitVec 16) (x_1 : BitVec 8),
  ¬7#8 ≥ ↑8 → ¬ofBool (x_1 <ₛ 0#8) = 1#1 → signExtend 16 (x_1.sshiftRight' 7#8) &&& x = 0#16

theorem test_mul_nsw__none_are_safe_proof : test_mul_nsw__none_are_safe_before ⊑ test_mul_nsw__none_are_safe_after

theorem select_icmp_x_and_8_ne_0_y_xor_8_thm.extracted_1._2 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ofBool (x_1 &&& 8#32 == 0#32) = 1#1 →
    ¬(True ∧ (x_1 &&& 8#32 ^^^ 8#32).msb = true) → x ^^^ 8#64 = x ^^^ zeroExtend 64 (x_1 &&& 8#32 ^^^ 8#32)

theorem must_drop_poison_proof : must_drop_poison_before ⊑ must_drop_poison_after

theorem test_cast_select_proof : test_cast_select_before ⊑ test_cast_select_after

theorem multiuse2_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬(True ∧ ((x &&& 96#32) <<< 8#32).sshiftRight' 8#32 ≠ x &&& 96#32 ∨
        True ∧ (x &&& 96#32) <<< 8#32 >>> 8#32 ≠ x &&& 96#32 ∨
          8#32 ≥ ↑32 ∨
            True ∧ ((x &&& 6#32) <<< 8#32).sshiftRight' 8#32 ≠ x &&& 6#32 ∨
              True ∧ (x &&& 6#32) <<< 8#32 >>> 8#32 ≠ x &&& 6#32 ∨
                8#32 ≥ ↑32 ∨
                  True ∧ ((x &&& 24#32) <<< 8#32).sshiftRight' 8#32 ≠ x &&& 24#32 ∨
                    True ∧ (x &&& 24#32) <<< 8#32 >>> 8#32 ≠ x &&& 24#32 ∨
                      8#32 ≥ ↑32 ∨
                        True ∧ ((x &&& 6#32) <<< 1#32).sshiftRight' 1#32 ≠ x &&& 6#32 ∨
                          True ∧ (x &&& 6#32) <<< 1#32 >>> 1#32 ≠ x &&& 6#32 ∨
                            1#32 ≥ ↑32 ∨
                              True ∧ ((x &&& 96#32) <<< 1#32).sshiftRight' 1#32 ≠ x &&& 96#32 ∨
                                True ∧ (x &&& 96#32) <<< 1#32 >>> 1#32 ≠ x &&& 96#32 ∨
                                  1#32 ≥ ↑32 ∨
                                    True ∧ ((x &&& 24#32) <<< 1#32).sshiftRight' 1#32 ≠ x &&& 24#32 ∨
                                      True ∧ (x &&& 24#32) <<< 1#32 >>> 1#32 ≠ x &&& 24#32 ∨ 1#32 ≥ ↑32) →
    ¬(8#32 ≥ ↑32 ∨
          1#32 ≥ ↑32 ∨
            1#32 ≥ ↑32 ∨
              1#32 ≥ ↑32 ∨
                True ∧ (x <<< 1#32 &&& 192#32 &&& (x <<< 1#32 &&& 48#32) != 0) = true ∨
                  True ∧ (x <<< 1#32 &&& 12#32 &&& (x <<< 1#32 &&& 192#32 ||| x <<< 1#32 &&& 48#32) != 0) = true ∨
                    True ∧
                      (x <<< 8#32 &&& 32256#32 &&&
                            (x <<< 1#32 &&& 12#32 ||| (x <<< 1#32 &&& 192#32 ||| x <<< 1#32 &&& 48#32)) !=
                          0) =
                        true) →
      (x &&& 96#32) <<< 8#32 ||

theorem lshrult_01_07_thm.extracted_1._1 : ∀ (x : BitVec 4),
  ¬1#4 ≥ ↑4 → ofBool (x >>> 1#4 <ᵤ 7#4) = ofBool (x <ᵤ BitVec.ofInt 4 (-2))

theorem ugt_or_not_min_commute_logical_thm.extracted_1._1 : ∀ (x : BitVec 8),
  ofBool (x != 0#8) = 1#1 → 1#1 = ofBool (x != 0#8)

theorem negtest_near_pow2_cmpval_ashr_wrong_cmp_pred_proof : negtest_near_pow2_cmpval_ashr_wrong_cmp_pred_before ⊑ negtest_near_pow2_cmpval_ashr_wrong_cmp_pred_after

theorem e_796 :
    1 * (z ^^^ t) + 1 *  ~~~(z ^^^ t) - 1 *  ~~~(z ||| t) - 1 * (z &&&  ~~~t) + 10 * (z &&& t) =  - 10 *  ~~~(z |||  ~~~t) + 11 * t

@[bv_multi_width_normalize] theorem eq_false_eq (p : Prop) : (p = False) = ¬p

theorem test3_logical_thm (e e_1 : IntW 32) :
  select (icmp IntPred.eq (sub e_1 e { «nsw» := true, «nuw» := false }) (const? 32 0)) (const? 1 1)
      (icmp IntPred.eq (sub e_1 e { «nsw» := true, «nuw» := false }) (const? 32 31)) ⊑
    select (icmp IntPred.eq e_1 e) (const? 1 1)
      (icmp IntPred.eq (sub e_1 e { «nsw» := true, «nuw» := false }) (const? 32 31))

theorem e_2358 :
     - 2 * ((d ^^^ e) &&& (d ^^^ f)) + 4 *  ~~~(d ^^^ (e ||| f)) - 5 * ( ~~~(d |||  ~~~e) |||  ~~~(e ^^^ f)) + 2 * e - 11 * ((d &&& e) ^^^ (e |||  ~~~f)) + 1 *  ~~~(e &&&  ~~~f) - 7 * ((d &&&  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) - 1 * ((d &&& e) ^^^  ~~~(d ^^^ ( ~~~e ||| f))) + 1 * (e ^^^ (d ||| ( ~~~e &&& f))) + 2 * (e ^^^ ( ~~~d ||| ( ~~~e &&& f))) - 3 * (d |||  ~~~e) - 1 *  ~~~(d |||  ~~~f) + 3 *  ~~~(d &&& ( ~~~e &&& f)) - 1 * (e &&&  ~~~(d &&&  ~~~f)) - 3 * (e ||| (d &&& f)) - 2 * (d ||| ( ~~~e &&& f)) - 6 * ( ~~~d &&& (e ^^^ f)) + 2 * ((d |||  ~~~e) &&& (d ^^^ (e ^^^ f))) - 1 * ( ~~~(d &&& e) &&&  ~~~(e ^^^ f)) + 1 *  ~~~(d &&&  ~~~d) - 11 * (e ^^^  ~~~(d ||| ( ~~~e &&& f))) - 1 * ( ~~~d ||| (e &&& f)) - 2 * (e ^^^  ~~~(d &&& ( ~~~e ||| f))) + 11 * (f ^^^  ~~~(d &&& e)) - 5 * ((d &&& e) |||  ~~~(e |||  ~~~f)) + 3 * ((e &&& f) ^^^  ~~~( ~~~d &&& (e ^^^ f))) - 1 * (d ||| (e &&& f)) - 3 * ( ~~~(d &&& e) &&& (e ^^^ f)) - 3 * ((d &&& e) |||  ~~~(d ^^^ (e ^^^ f))) - 5 * ((d &&& f) ^^^  ~~~(d ^^^ (e &&& f))) + 11 *  ~~~( ~~~d &&& (e ^^^ f)) + 1 * (f ^^^  ~~~(d &&&  ~~~e)) + 5 *  ~~~(d ||| ( ~~~e &&& f)) - 11 * ((d ||| e) &&&  ~~~(e ^^^ f)) + 1 * ((e &&&  ~~~f) |||  ~~~( ~~~d ||| ( ~~~e &&& f))) + 5 *  ~~~( ~~~d ||| (e &&& f)) - 3 * (f &&&  ~~~(d &&&  ~~~e)) + 3 * ((d &&& f) ^^^  ~~~(d ^^^ ( ~~~e &&& f))) + 1 * (f &&& (d ^^^ e)) + 2 * ( ~~~f &&& (d ^^^ e)) + 3 *  ~~~(d ^^^ ( ~~~e &&& f)) - 2 * (e ^^^  ~~~(d &&& f)) - 5 * (e &&&  ~~~(d ^^^ f)) + 5 *  ~~~f - 11 * (f ||| (d &&&  ~~~e)) - 1 * (e &&& f) + 4 * (d &&&  ~~~f) - 6 * (f ^^^ ( ~~~d ||| (e &&& f))) - 6 * (e &&&  ~~~f) - 2 * (d ^^^ (e ||| f)) + 2 * ((e &&& f) ||| (d &&& (e ||| f))) + 4 *  ~~~(d &&&  ~~~e) - 6 * ( ~~~(d ^^^ e) |||  ~~~(d ^^^ f)) + 1 * (e ^^^ (d &&&  ~~~f)) + 11 * (d ^^^ (e &&& f)) + 7 * (f ^^^ (d ||| ( ~~~e &&& f))) + 5 *  ~~~(e |||  ~~~f) - 1 * (e ^^^ ( ~~~d &&& ( ~~~e ||| f))) - 11 * (f &&&  ~~~(d &&& e)) + 4 * ((e &&&  ~~~f) ^^^ ( ~~~d ||| (e ^^^ f))) + 3 *  ~~~(d ||| (e ||| f)) + 17 *  ~~~(d ||| ( ~~~e ||| f)) - 10 *  ~~~( ~~~d ||| (e ||| f)) - 17 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 41 * ( ~~~d &&& ( ~~~e &&& f)) + 13 * ( ~~~d &&& (e &&& f)) + 10 * (d &&& ( ~~~e &&& f)) + 29 * (d &&& (e &&& f)) =  - 2 * (e ^^^ (d &&& (e ||| f)))

theorem test20_thm (e : IntW 8) : LLVM.and (lshr e (const? 8 7)) (const? 8 1) ⊑ lshr e (const? 8 7)

theorem test11_proof : test11_before ⊑ test11_after

theorem not_xor_to_or_not4_thm (e e_1 e_2 : IntW 3) :
  LLVM.xor (LLVM.xor (LLVM.and e_2 e_1) (LLVM.or e e_2)) (const? 3 (-1)) ⊑
    LLVM.or (LLVM.and e_2 e_1) (LLVM.xor (LLVM.or e e_2) (const? 3 (-1)))

theorem icmp_slt_0_and_icmp_sge_neg1_i64_fail_proof : icmp_slt_0_and_icmp_sge_neg1_i64_fail_before ⊑ icmp_slt_0_and_icmp_sge_neg1_i64_fail_after

theorem ashr_ult_9_proof : ashr_ult_9_before ⊑ ashr_ult_9_after

theorem smear_set_bit_thm (e : IntW 32) :
  sext 32 (ashr (trunc 8 e) (const? 8 7)) ⊑ ashr (shl e (const? 32 24)) (const? 32 31)

theorem main5c_like_logical_thm.extracted_1._8 : ∀ (x x_1 : BitVec 32),
  ofBool (x_1 &&& 7#32 != 7#32) = 1#1 → ¬ofBool (x_1 &&& 7#32 == 7#32) = 1#1 → ¬True → 0#32 = zeroExtend 32 0#1

@[grind =, simp]
lemma addInitial_stateMax {m : RawCNFA A} : (m.addInitial s).stateMax = m.stateMax

theorem PR39793_bswap_u32_as_u16_trunc_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬(8#32 ≥ ↑32 ∨ 8#32 ≥ ↑32) → 8#32 ≥ ↑32 → False

theorem t0_proof : t0_before ⊑ t0_after

theorem PR2539_A_thm (e : IntW 1) : icmp IntPred.slt (zext 32 e) (const? 32 1) ⊑ LLVM.xor e (const? 1 1)

theorem and_congr (e1 : a ≈ʷ b) (e2 : c ≈ʷ d) : (a &&& c) ≈ʷ (b &&& d)

theorem and_xor_commute2_thm (e e_1 : IntW 32) :
  LLVM.xor (LLVM.and (LLVM.udiv (const? 32 42) e_1) (LLVM.udiv (const? 32 42) e)) (LLVM.udiv (const? 32 42) e) ⊑
    LLVM.and (LLVM.udiv (const? 32 42) e) (LLVM.xor (LLVM.udiv (const? 32 42) e_1) (const? 32 (-1)))

theorem alive_275   : alive_275_src ⊑ alive_275_tgt

theorem fold_sext_to_and_wrong2_proof : fold_sext_to_and_wrong2_before ⊑ fold_sext_to_and_wrong2_after

theorem ashr_mul_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ¬8#20 ≥ ↑20 → True ∧ (signExtend 16 x_1).smulOverflow (signExtend 16 x) = true ∨ 8#16 ≥ ↑16 → False

theorem eq_21_proof : eq_21_before ⊑ eq_21_after

theorem lor_land_right1_thm (e e_1 : IntW 1) : select e_1 (select e_1 (const? 1 1) e) (const? 1 0) ⊑ e_1

theorem tctx_at_1 : tctx ⟨1, by omega⟩ = WidthExpr.var ⟨0, by omega⟩

theorem f_var1_proof : f_var1_before ⊑ f_var1_after

theorem exactly_one_set_signbit_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ¬7#8 ≥ ↑8 → ofBool (x_1 >>> 7#8 == zeroExtend 8 (ofBool (-1#8 <ₛ x))) = ofBool (x_1 ^^^ x <ₛ 0#8)

theorem lshr_xor_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ¬(3#8 ≥ ↑8 ∨ (42#8 == 0 || 8 != 1 && x == intMin 8 && 42#8 == -1) = true ∨ 3#8 ≥ ↑8) →
    (42#8 == 0 || 8 != 1 && x == intMin 8 && 42#8 == -1) = true ∨ 3#8 ≥ ↑8 → False

theorem lshrult_01_10_exact_proof : lshrult_01_10_exact_before ⊑ lshrult_01_10_exact_after

lemma formula_predicate_match {p : Predicate} :
    p.denote w vars ↔ (formula_of_predicate p).sat' (vars[·]!)

theorem positive_samevar_shlnsw_lshrexact_thm (e e_1 : IntW 8) :
  shl (lshr e_1 e { «exact» := true }) e { «nsw» := true, «nuw» := false } ⊑ e_1

theorem uge_umin3_proof : uge_umin3_before ⊑ uge_umin3_after

theorem icmp_power2_and_icmp_shifted_mask_swapped_2147483648_1610612736_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x &&& 1610612736#32 != 1610612736#32) &&& ofBool (x <ᵤ BitVec.ofInt 32 (-2147483648)) =
    ofBool (x <ᵤ 1610612736#32)

theorem ule_umax4_proof : ule_umax4_before ⊑ ule_umax4_after

theorem ashrsgt_02_12_exact_proof : ashrsgt_02_12_exact_before ⊑ ashrsgt_02_12_exact_after

theorem select_xor_icmp2_proof : select_xor_icmp2_before ⊑ select_xor_icmp2_after

theorem and_two_ranges_to_mask_and_range_no_add_on_one_range_proof : and_two_ranges_to_mask_and_range_no_add_on_one_range_before ⊑ and_two_ranges_to_mask_and_range_no_add_on_one_range_after

theorem trunc_ashr_proof : trunc_ashr_before ⊑ trunc_ashr_after

theorem select_2_proof : select_2_before ⊑ select_2_after

theorem select_icmp_eq_and_1_0_lshr_fv_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ofBool (x_1 &&& 1#8 == 0#8) = 1#1 → 1#8 ≥ ↑8 ∨ x_1 <<< 1#8 &&& 2#8 ≥ ↑8 → False

theorem e_356 :
     - 1 *  ~~~y + 2 *  ~~~(x &&& y) - 2 * (x |||  ~~~y) + 1 *  ~~~x + 1 *  ~~~(x &&&  ~~~x) - 3 *  ~~~(x ||| y) - 1 *  ~~~(x |||  ~~~y) - 1 * (x &&& y) =  - 5 *  ~~~(x ^^^ y) + 3 *  ~~~(x &&&  ~~~y)

theorem t3_exact_thm.extracted_1._1 : ∀ (x : BitVec 64),
  ¬(True ∧ x >>> 63#64 <<< 63#64 ≠ x ∨ 63#64 ≥ ↑64) → 0#64 - x.sshiftRight' 63#64 = x >>> 63#64

theorem ashr_mul_sign_bits_thm.extracted_1._2 : ∀ (x x_1 : BitVec 8),
  ¬3#32 ≥ ↑32 →
    ¬(True ∧ (signExtend 16 x_1).smulOverflow (signExtend 16 x) = true ∨ 3#16 ≥ ↑16) →
      truncate 16 ((signExtend 32 x_1 * signExtend 32 x).sshiftRight' 3#32) =
        (signExtend 16 x_1 * signExtend 16 x).sshiftRight' 3#16

private theorem not_gt_eq_le (A B : BitVec w) : (¬ (A >ₛ B)) = (A ≤ₛ B)

theorem bools_logical_commute0_thm.extracted_1._9 : ∀ (x x_1 : BitVec 1),
  ¬x_1 ^^^ 1#1 = 1#1 → ¬x_1 = 1#1 → ¬0#1 = 1#1 → 0#1 = x

theorem shl_add_log_may_cause_poison_pr62175_with_nsw_proof : shl_add_log_may_cause_poison_pr62175_with_nsw_before ⊑ shl_add_log_may_cause_poison_pr62175_with_nsw_after

theorem ult_umin1_proof : ult_umin1_before ⊑ ult_umin1_after

theorem icmp_eq_zext_eq_non_boolean_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (zeroExtend 32 (ofBool (x == 2#32)) == x) = ofBool (x == 0#32)

theorem test3_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ¬(True ∧ x_1.ssubOverflow x = true ∨ True ∧ x_1.ssubOverflow x = true) → True ∧ x_1.ssubOverflow x = true → False

@[simp] theorem getElem_map (xs : HVector A as) (v : Var ⟨as⟩ a) :
    (xs.map f)[v] = f _ xs[v]

theorem main6b_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬ofBool (x &&& 7#32 == 3#32) &&& ofBool (x &&& 16#32 != 0#32) = 1#1 →
    1#32 = zeroExtend 32 (ofBool (x &&& 23#32 != 19#32))

theorem test15_proof : test15_before ⊑ test15_after

theorem test9_proof : test9_before ⊑ test9_after

theorem trunc_equality_nsw_zext_proof : trunc_equality_nsw_zext_before ⊑ trunc_equality_nsw_zext_after

theorem lshrugt_02_12_thm (e : IntW 4) : icmp IntPred.ugt (lshr e (const? 4 2)) (const? 4 (-4)) ⊑ const? 1 0

theorem sdiv_exact_ne_1_thm (e e_1 : IntW 8) :
  icmp IntPred.eq (LLVM.sdiv e_1 e { «exact» := true }) (const? 8 0) ⊑
    icmp IntPred.eq e_1 (const? 8 0)

theorem trunc_ashr_trunc_outofrange_proof : trunc_ashr_trunc_outofrange_before ⊑ trunc_ashr_trunc_outofrange_after

theorem logical_and_logical_and_icmps_comm3_proof : logical_and_logical_and_icmps_comm3_before ⊑ logical_and_logical_and_icmps_comm3_after

theorem icmp_eq_and_pow2_lshr_pow2_case2_proof : icmp_eq_and_pow2_lshr_pow2_case2_before ⊑ icmp_eq_and_pow2_lshr_pow2_case2_after

theorem trunc_lshr_big_mask_proof : trunc_lshr_big_mask_before ⊑ trunc_lshr_big_mask_after

theorem ofBitVecZextMsb_EqualUpTo_ofBitVecSext
  (x : BitVec w) :
  EqualUpTo (w + 1)
    (BitStream.ofBitVecZextMsb x)
    (BitStream.concat false (BitStream.ofBitVecSext x))

theorem band_land_left2_thm.extracted_1._2 : ∀ (x x_1 : BitVec 1), ¬x_1 &&& x = 1#1 → 0#1 = x_1 &&& x

theorem e_1263 :
    4 * z + 3 * (z ||| t) - 1 *  ~~~(z &&&  ~~~z) + 5 *  ~~~(z &&&  ~~~t) - 11 * (z ^^^ t) + 3 *  ~~~(z ||| t) + 4 *  ~~~(z |||  ~~~t) + 12 * (z &&&  ~~~t) - 11 * (z &&& t) = 7 *  ~~~t

theorem select_zext_different_condition_thm.extracted_1._2 : ∀ (x x_1 : BitVec 1),
  ¬x_1 = 1#1 →
    True ∧ (1#64).saddOverflow (zeroExtend 64 x) = true ∨ True ∧ (1#64).uaddOverflow (zeroExtend 64 x) = true → False

theorem not_mul_of_bool_commute_thm (e e_1 : IntW 32) :
  icmp IntPred.ugt (mul (LLVM.and e_1 (const? 32 255)) (lshr e (const? 32 30))) (const? 32 255) ⊑
    icmp IntPred.ugt (mul (LLVM.and e_1 (const? 32 255)) (lshr e (const? 32 30)) { «nsw» := true, «nuw» := true })
      (const? 32 255)

theorem e_2204 :
    4 * (e ^^^ (d ||| (e &&& f))) + 4 * (e ^^^  ~~~(d ||| (e ^^^ f))) - 11 * (e ^^^  ~~~( ~~~d &&& (e &&& f))) - 3 *  ~~~(d |||  ~~~e) - 2 * (d |||  ~~~e) - 7 * ((d ^^^ e) &&& (d ^^^ f)) - 1 *  ~~~(d &&&  ~~~d) + 5 * (e ^^^  ~~~(d &&& (e &&& f))) - 1 * (e ^^^ ( ~~~d ||| (e &&& f))) + 1 * ((d ||| e) &&&  ~~~(e ^^^ f)) - 6 *  ~~~(d ^^^ ( ~~~e ||| f)) - 2 * (f ^^^ (d &&& ( ~~~e ||| f))) + 5 * (f ^^^  ~~~(d &&& ( ~~~e &&& f))) + 5 * ((d &&& e) |||  ~~~(d ^^^ (e ^^^ f))) - 11 * (e ^^^  ~~~( ~~~d &&& ( ~~~e ||| f))) - 6 * (e ^^^  ~~~(d ||| (e &&& f))) - 1 * ((d &&& e) |||  ~~~(e ||| f)) + 5 *  ~~~(d |||  ~~~f) - 11 *  ~~~(d ^^^ (e ||| f)) + 1 * (e |||  ~~~(d ^^^ f)) + 11 * (e &&&  ~~~f) - 6 * ( ~~~(d ||| e) ||| (d ^^^ (e ^^^ f))) - 3 * ( ~~~(d &&& e) &&& (e ^^^ f)) + 2 * (f ^^^  ~~~(d &&& (e ||| f))) + 1 *  ~~~( ~~~d ||| ( ~~~e &&& f)) - 1 * (e ^^^ ( ~~~d &&& ( ~~~e ||| f))) - 6 * (d &&& (e ||| f)) + 7 * ( ~~~e |||  ~~~(d ^^^ f)) - 1 * ((e &&& f) ^^^  ~~~( ~~~d &&& (e ^^^ f))) + 4 *  ~~~(d ^^^ (e ^^^ f)) + 1 * (e ^^^ (d |||  ~~~f)) - 2 * ((d &&& f) ||| (e &&&  ~~~f)) + 5 * ((d ^^^ e) &&&  ~~~(d ^^^ f)) + 11 * (f ^^^  ~~~(d &&& (e &&& f))) - 5 * (e ^^^  ~~~( ~~~d &&& ( ~~~e &&& f))) + 7 *  ~~~(d &&& e) - 7 * (d &&& f) - 1 * (e ^^^  ~~~(d &&& f)) + 2 * ( ~~~(d &&& e) &&& (d ^^^ (e ^^^ f))) - 1 * (d &&&  ~~~e) - 1 * ((e &&&  ~~~f) |||  ~~~( ~~~d ||| ( ~~~e &&& f))) + 2 *  ~~~(e ||| f) + 2 * ( ~~~(d ||| e) ||| (e ^^^ f)) + 2 *  ~~~(d &&& ( ~~~e ||| f)) - 11 *  ~~~(d ||| (e ||| f)) - 40 *  ~~~(d ||| ( ~~~e ||| f)) + 11 *  ~~~( ~~~d ||| (e ||| f)) - 11 *  ~~~( ~~~d ||| ( ~~~e ||| f)) + 6 * ( ~~~d &&& ( ~~~e &&& f)) + 15 * ( ~~~d &&& (e &&& f)) + 21 * (d &&& ( ~~~e &&& f)) + 17 * (d &&& (e &&& f)) = 3 * (d ||| ( ~~~e &&& f)) - 1 * ((d |||  ~~~e) &&& (e ^^^ f))

theorem sub_to_xor_or_commuted_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  (x_1 &&& x) - (x ||| x_1) = 0#32 - (x_1 ^^^ x)

lemma RawCNFA.autMsbSet_wf : autMsbSet.WF

theorem lshr_exact_thm.extracted_1._1 : ∀ (x : BitVec 8),
  ¬(2#8 ≥ ↑8 ∨ 2#8 ≥ ↑8) → (x <<< 2#8 + 4#8) >>> 2#8 = x + 1#8 &&& 63#8

theorem t0_proof : t0_before ⊑ t0_after

theorem test17_proof : test17_before ⊑ test17_after

theorem lshr_sext_i1_to_i128_thm (e : IntW 1) :
  lshr (sext 128 e) (const? 128 42) ⊑ select e (const? 128 77371252455336267181195263) (const? 128 0)

theorem ule_or_min_commute_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ofBool (x_1 == 0#8) ||

theorem main7e_logical_thm.extracted_1._1 : ∀ (x x_1 x_2 : BitVec 32),
  ¬ofBool (x_2 &&& x_1 &&& x == x_2 &&& x_1) = 1#1 →
    ofBool (x_2 &&& x_1 &&& x != x_2 &&& x_1) = 1#1 → 0#1 = 1#1 → 0#32 = zeroExtend 32 1#1

theorem not_or_or_and_not_and_and_commute4_proof : not_or_or_and_not_and_and_commute4_before ⊑ not_or_or_and_not_and_and_commute4_after

theorem test_invert_demorgan_or2_proof : test_invert_demorgan_or2_before ⊑ test_invert_demorgan_or2_after

theorem e_338 :
     - 6 *  ~~~y + 1 * (x ^^^ y) + 2 * y + 1 *  ~~~(x &&& y) + 1 * x + 12 *  ~~~(x ||| y) + 3 *  ~~~(x |||  ~~~y) + 4 * (x &&& y) =  - 10 * (x &&&  ~~~y) + 7 *  ~~~(x &&&  ~~~x)

theorem e_1081 :
     - 1 *  ~~~(z ^^^ t) + 4 *  ~~~(z &&& t) - 2 *  ~~~(z &&&  ~~~t) - 3 * t + 1 *  ~~~(z ||| t) + 3 *  ~~~(z |||  ~~~t) - 4 * (z &&&  ~~~t) + 6 * (z &&& t) = 2 *  ~~~(z &&&  ~~~z) - 2 * z

theorem test11_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ¬zeroExtend 128 x &&& 31#128 ≥ ↑128 →
    True ∧ (x &&& 31#32).msb = true ∨
        True ∧
            (zeroExtend 64 x_1 <<< zeroExtend 64 (x &&& 31#32)).sshiftRight' (zeroExtend 64 (x &&& 31#32)) ≠
              zeroExtend 64 x_1 ∨
          True ∧ zeroExtend 64 x_1 <<< zeroExtend 64 (x &&& 31#32) >>> zeroExtend 64 (x &&& 31#32) ≠ zeroExtend 64 x_1 ∨
            zeroExtend 64 (x &&& 31#32) ≥ ↑64 →
      False

theorem bools2_logical_commute0_thm.extracted_1._6 : ∀ (x x_1 : BitVec 1),
  x_1 = 1#1 → ¬x_1 ^^^ 1#1 = 1#1 → ¬x = 1#1 → 0#1 = x

theorem rawspeed_signbit_proof : rawspeed_signbit_before ⊑ rawspeed_signbit_after

theorem ugt_swap_or_not_min_commute_logical_thm.extracted_1._3 : ∀ (x x_1 : BitVec 823),
  ¬ofBool (x_1 != 0#823) = 1#1 → ofBool (x <ᵤ x_1) = ofBool (x_1 != 0#823)

theorem not_cmp_constant_thm (e : IntW 32) :
  icmp IntPred.ugt (LLVM.xor e (const? 32 (-1))) (const? 32 42) ⊑
    icmp IntPred.ult e (const? 32 (-43))

theorem ashr_shl_constants_proof : ashr_shl_constants_before ⊑ ashr_shl_constants_after

theorem test11e_proof : test11e_before ⊑ test11e_after

theorem test16_proof : test16_before ⊑ test16_after

theorem sgt_smin1_proof : sgt_smin1_before ⊑ sgt_smin1_after

theorem widget_proof : widget_before ⊑ widget_after

theorem select_icmp_ne_0_and_1073741824_or_8_proof : select_icmp_ne_0_and_1073741824_or_8_before ⊑ select_icmp_ne_0_and_1073741824_or_8_after

theorem negate_sdiv_thm (e e_1 : IntW 8) :
  sub e_1 (LLVM.sdiv e (const? 8 42)) ⊑ add (LLVM.sdiv e (const? 8 (-42))) e_1

theorem select_lshr_icmp_const_reordered_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ofBool (x <ᵤ 32#32) = 1#1 → ¬5#32 ≥ ↑32 → 0#32 = x >>> 5#32

theorem n11_uge_slt_thm (e e_1 e_2 : IntW 32) :
  select (icmp IntPred.ult e_2 (const? 32 129)) (select (icmp IntPred.slt e_2 (const? 32 0)) e_1 e) e_2 ⊑
    select (icmp IntPred.ult e_2 (const? 32 129)) e e_2

theorem t1_otherbitwidth_proof : t1_otherbitwidth_before ⊑ t1_otherbitwidth_after

theorem lshrult_01_11_proof : lshrult_01_11_before ⊑ lshrult_01_11_after

theorem ne_10_thm (e e_1 : IntW 32) :
  LLVM.or (icmp IntPred.ne (trunc 8 e_1) (trunc 8 e))
      (icmp IntPred.ne (trunc 8 (lshr e_1 (const? 32 8))) (trunc 8 (lshr e (const? 32 8)))) ⊑
    icmp IntPred.ne (trunc 16 e_1) (trunc 16 e)

theorem add_select_sext_thm (e : IntW 1) :
  add (select e (const? 64 64) (const? 64 1)) (sext 64 e) ⊑ select e (const? 64 63) (const? 64 1)

theorem t3_ult_sgt_neg1_thm.extracted_1._3 : ∀ (x x_1 : BitVec 32),
  ofBool (x_1 <ᵤ 65536#32) = 1#1 → ¬ofBool (65535#32 <ₛ x_1) = 1#1 → ofBool (x_1 <ₛ 0#32) = 1#1 → False

theorem positive_with_icmp_logical_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x <ᵤ 512#32) = 1#1 → ofBool (x + 128#32 <ᵤ 256#32) = ofBool (x <ᵤ 128#32)

@[simp]
theorem Factor.denote_width_zero  (f : Factor) (env : Env 0) : f.denote env = 0

theorem e_2397 :
     - 11 * (e ^^^  ~~~(d &&& ( ~~~e &&& f))) - 2 * ((d &&& f) ^^^ (d ^^^ (e &&& f))) - 3 * ( ~~~(d |||  ~~~e) |||  ~~~(e ^^^ f)) - 3 * (e ^^^  ~~~( ~~~d &&& (e ||| f))) + 3 * (d ||| (e &&& f)) + 2 * ((d ||| e) &&& (e ^^^ f)) - 2 * (f ^^^  ~~~(d &&& (e ||| f))) - 1 * (f ^^^ ( ~~~d ||| ( ~~~e &&& f))) - 5 *  ~~~( ~~~d &&& ( ~~~e ||| f)) - 1 * (f ^^^ (d ||| ( ~~~e ||| f))) + 11 * ((d &&& e) ^^^  ~~~(d ^^^ (e &&& f))) + 5 * ((d &&&  ~~~e) ||| (e ^^^ f)) - 2 * (f &&& (d ||| e)) - 6 * ( ~~~(d ||| e) |||  ~~~(d ^^^ (e ^^^ f))) - 5 * (e ^^^  ~~~( ~~~d &&& (e ^^^ f))) - 1 *  ~~~(d &&& ( ~~~e &&& f)) + 3 * (e &&& (d ^^^ f)) + 1 * (f |||  ~~~(d |||  ~~~e)) - 1 * (f ^^^ (d &&& (e ||| f))) - 7 * (e ^^^ (d &&&  ~~~f)) + 2 * (d ^^^ (e ||| f)) + 1 * (f ^^^ ( ~~~d &&& (e ||| f))) - 1 * (d &&&  ~~~e) + 1 *  ~~~(d ^^^ ( ~~~e ||| f)) - 5 * (d |||  ~~~e) + 7 * (f ^^^  ~~~(d &&& (e &&& f))) - 2 * (d &&& ( ~~~e ||| f)) - 1 * ((d |||  ~~~e) &&& (d ^^^ (e ^^^ f))) + 2 * ( ~~~d ||| ( ~~~e &&& f)) - 6 * ( ~~~e &&& (d ^^^ f)) - 1 *  ~~~e - 6 * ((d &&&  ~~~e) |||  ~~~(d ^^^ (e ^^^ f))) + 5 * (f ^^^ (d &&& ( ~~~e ||| f))) + 1 * ( ~~~(d &&&  ~~~e) &&& (d ^^^ (e ^^^ f))) + 2 * ((d &&& f) ^^^ (e ||| f)) - 2 *  ~~~(d &&& (e ||| f)) + 2 * (e ^^^ ( ~~~d ||| ( ~~~e ||| f))) - 1 * (d ^^^ ( ~~~e ||| f)) + 2 * ( ~~~(d &&& e) &&&  ~~~(d ^^^ (e ^^^ f))) + 3 * ( ~~~e |||  ~~~(d ^^^ f)) - 7 * (f ^^^ (d |||  ~~~e)) - 5 * (f ^^^ (d ||| ( ~~~e &&& f))) + 7 * ( ~~~(d |||  ~~~e) ||| (e ^^^ f)) + 1 * ((d &&& e) |||  ~~~(e ||| f)) + 11 * (e ||| (d ^^^ f)) + 1 * (f ^^^ (d &&& e)) - 6 *  ~~~(d &&&  ~~~d) + 7 * (f &&&  ~~~(d &&&  ~~~e)) - 2 * (f ^^^ (d ||| (e &&& f))) - 6 *  ~~~(d ^^^ ( ~~~e &&& f)) + 1 * ((d ^^^ e) ||| (d ^^^ f)) + 2 * ( ~~~(d ||| e) |||  ~~~(e ^^^ f)) - 1 * ( ~~~f &&&  ~~~(d ^^^ e)) + 4 * ( ~~~(d ||| e) ||| (d ^^^ (e ^^^ f))) + 3 * ((d &&& f) ^^^ (d ^^^ ( ~~~e &&& f))) - 7 * ((e &&& f) ||| ( ~~~d &&& (e ||| f))) - 1 * (e ^^^ f) + 7 * (e ^^^  ~~~(d ||| ( ~~~e &&& f))) + 1 * ((d &&& f) ||| (e &&&  ~~~f)) - 2 * ( ~~~(d ^^^ e) |||  ~~~(d ^^^ f)) + 4 * ((d &&& f) ^^^  ~~~(e &&&  ~~~f)) + 7 * (e ^^^ (d &&& (e ||| f))) - 1 * ( ~~~e &&&  ~~~(d ^^^ f)) + 4 * (e ||| (d &&&  ~~~f)) + 33 *  ~~~(d ||| (e ||| f)) - 15 *  ~~~(d ||| ( ~~~e ||| f)) + 33 *  ~~~( ~~~d ||| (e ||| f)) - 19 *  ~~~( ~~~d ||| ( ~~~e ||| f)) - 21 * ( ~~~d &&& ( ~~~e &&& f)) + 1 * ( ~~~d &&& (e &&& f)) + 12 * (d &&& ( ~~~e &&& f)) - 1 * (d &&& (e &&& f)) = 7 * (f ^^^  ~~~(d &&& e))

theorem sdiv4_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬(True ∧ x.smod 3#32 ≠ 0 ∨ (3#32 == 0 || 32 != 1 && x == intMin 32 && 3#32 == -1) = true) → x.sdiv 3#32 * 3#32 = x

@[simp]
theorem Std.HashSet.isEmpty_union_iff_isEmpty [BEq α] [Hashable α] [LawfulBEq α] {m₁ m₂ : HashSet α} :
    (m₁.union m₂).isEmpty ↔ m₁.isEmpty ∧ m₂.isEmpty

theorem test_sub_nsw__nsw_is_safe_proof : test_sub_nsw__nsw_is_safe_before ⊑ test_sub_nsw__nsw_is_safe_after

theorem nonexact_lshr_eq_exactdiv_proof : nonexact_lshr_eq_exactdiv_before ⊑ nonexact_lshr_eq_exactdiv_after

theorem trunc_ashr_trunc_thm.extracted_1._1 : ∀ (x : BitVec 64), ¬8#32 ≥ ↑32 → 8#64 ≥ ↑64 → False

theorem negate_add_with_single_negatible_operand_depth2_thm (e e_1 : IntW 8) :
  sub (const? 8 0) (mul (add e_1 (const? 8 21)) e) ⊑ mul (sub (const? 8 (-21)) e_1) e

theorem test4_proof : test4_before ⊑ test4_after

theorem sge_or_not_max_commute_logical_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ¬ofBool (x_1 != 127#8) = 1#1 → ofBool (x ≤ₛ x_1) = 1#1

theorem xor_lshr_thm.extracted_1._2 : ∀ (x x_1 x_2 x_3 : BitVec 8),
  ¬(x_2 ≥ ↑8 ∨ x_2 ≥ ↑8) → ¬x_2 ≥ ↑8 → x_3 >>> x_2 ^^^ x_1 ^^^ x >>> x_2 = (x_3 ^^^ x) >>> x_2 ^^^ x_1

theorem t9_lshr_proof : t9_lshr_before ⊑ t9_lshr_after

theorem appendInl_toCons {v : Var Γ t} :
    v.toCons (t':=t').appendInl (Δ := Δ) = v.appendInl.toCons

theorem shl_add_add_no_const_thm (e e_1 e_2 e_3 : IntW 8) :
  add (shl e_3 e_2) (add (shl e_1 e_2) e) ⊑ add (shl (add e_1 e_3) e_2) e

theorem no_shift_no_xor_multiuse_cmp_or_thm.extracted_1._2 : ∀ (x x_1 x_2 : BitVec 32),
  ¬ofBool (x_2 &&& 4096#32 == 0#32) = 1#1 →
    (x_1 ||| 4096#32) * x * (x_1 ||| 4096#32) = (x_1 ||| x_2 &&& 4096#32) * x * (x_1 ||| 4096#32)

theorem bools2_logical_commute1_thm.extracted_1._16 : ∀ (x x_1 x_2 : BitVec 1),
  ¬x_2 = 1#1 → x_1 ^^^ 1#1 = 1#1 → x_1 = 1#1 → ¬0#1 = 1#1 → x = x_2

theorem and_or2_commuted_thm.extracted_1._2 : ∀ (x x_1 : BitVec 1),
  ¬x_1 &&& (x ^^^ 1#1) = 1#1 → x_1 = 1#1 → ¬x = 1#1 → False

theorem bools2_logical_commute3_and1_thm.extracted_1._5 : ∀ (x x_1 x_2 : BitVec 1),
  ¬x_2 &&& x_1 = 1#1 → x = 1#1 → x_1 = 1#1 → x_1 ^^^ 1#1 = x_2

theorem sle_smax2_proof : sle_smax2_before ⊑ sle_smax2_after

theorem PR2539_A_proof : PR2539_A_before ⊑ PR2539_A_after

theorem urem_illegal_type_c_thm (e : IntW 9) :
  urem (zext 32 e) (const? 32 10) ⊑ zext 32 (urem e (const? 9 10)) { «nneg» := true }

theorem main6d_logical_thm.extracted_1._3 : ∀ (x : BitVec 32),
  ¬ofBool (x &&& 7#32 != 3#32) = 1#1 →
    ofBool (x &&& 16#32 == 0#32) = 1#1 → 0#32 = zeroExtend 32 (ofBool (x &&& 23#32 == 19#32))

theorem e_1196 :
     - 6 * t + 4 * (z ||| t) - 5 *  ~~~t + 7 *  ~~~(z ^^^ t) + 4 *  ~~~z - 3 *  ~~~(z ||| t) - 2 *  ~~~(z |||  ~~~t) + 4 * (z &&&  ~~~t) = 2 * (z &&& t) + 3 * (z |||  ~~~t)

theorem test_shl_nuw__nuw_is_safe_thm.extracted_1._1 : ∀ (x : BitVec 64) (x_1 : BitVec 32),
  ofBool (x_1 &&& 1073741822#32 == 0#32) = 1#1 →
    2#32 ≥ ↑32 ∨
        True ∧ (x_1 <<< 2#32 &&& BitVec.ofInt 32 (-8)).msb = true ∨
          zeroExtend 64 (x_1 <<< 2#32 &&& BitVec.ofInt 32 (-8)) ≥ ↑64 →
      False

theorem lshrult_03_01_exact_proof : lshrult_03_01_exact_before ⊑ lshrult_03_01_exact_after

theorem lshrult_01_15_exact_proof : lshrult_01_15_exact_before ⊑ lshrult_01_15_exact_after

theorem xor_or_proof : xor_or_before ⊑ xor_or_after

theorem shl_nuw_add_nuw_thm (e : IntW 32) :
  shl (const? 32 1) (add e (const? 32 1) { «nsw» := false, «nuw» := true }) { «nsw» := false, «nuw» := true } ⊑
    shl (const? 32 2) e { «nsw» := false, «nuw» := true }

theorem shl_lshr_pow2_not_const_case2_thm (e : IntW 16) :
  LLVM.xor (LLVM.and (lshr (shl (const? 16 16) e) (const? 16 3)) (const? 16 8)) (const? 16 8) ⊑
    select (icmp IntPred.eq e (const? 16 2)) (const? 16 0) (const? 16 8)

theorem eval_sext_multi_use_in_one_inst_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ¬(True ∧ (truncate 16 x &&& 14#16).smulOverflow (truncate 16 x &&& 14#16) = true ∨
        True ∧ (truncate 16 x &&& 14#16).umulOverflow (truncate 16 x &&& 14#16) = true) →
    True ∧ (truncate 16 x &&& 14#16).smulOverflow (truncate 16 x &&& 14#16) = true ∨
        True ∧ (truncate 16 x &&& 14#16).umulOverflow (truncate 16 x &&& 14#16) = true ∨
          True ∧ ((truncate 16 x &&& 14#16) * (truncate 16 x &&& 14#16) &&& BitVec.ofInt 16 (-32768) != 0) = true →
      False

theorem lshrult_03_15_exact_proof : lshrult_03_15_exact_before ⊑ lshrult_03_15_exact_after

theorem sge_swap_and_max_logical_proof : sge_swap_and_max_logical_before ⊑ sge_swap_and_max_logical_after

theorem test10_proof : test10_before ⊑ test10_after

theorem sext_zext_nneg_slt_thm.extracted_1._1 : ∀ (x x_1 : BitVec 8),
  ¬(True ∧ x.msb = true) → ofBool (signExtend 32 x_1 <ₛ zeroExtend 32 x) = ofBool (x_1 <ₛ x)

theorem select_constants_and_icmp_eq0_proof : select_constants_and_icmp_eq0_before ⊑ select_constants_and_icmp_eq0_after

theorem icmp_sle11_thm (e : IntW 8) :
  icmp IntPred.sle (shl e (const? 8 7) { «nsw» := true, «nuw» := false }) (const? 8 (-2)) ⊑
    icmp IntPred.slt e (const? 8 0)

@[simp] theorem liftEffect_impure [Pure m] {e} (hle : e ≤ impure) :
    liftEffect hle (α := α) (m := m) = match e with

theorem masked_icmps_mask_notallzeros_bmask_mixed_swapped_2_thm (e : IntW 32) :
  LLVM.and (icmp IntPred.eq (LLVM.and e (const? 32 7)) (const? 32 0))
      (icmp IntPred.ne (LLVM.and e (const? 32 3)) (const? 32 0)) ⊑
    const? 1 0

theorem e_1553 :
     - 6 *  ~~~(a ^^^ c) - 1 * (b ^^^  ~~~( ~~~a &&& ( ~~~b ||| c))) - 5 * (b ^^^  ~~~(a &&& ( ~~~b &&& c))) - 1 * (b ||| (a ^^^ c)) - 1 *  ~~~( ~~~a &&& ( ~~~b ||| c)) + 5 * ( ~~~a &&& (b ||| c)) - 5 * ((a &&& c) ||| (b &&&  ~~~c)) + 12 *  ~~~(a ||| (b ||| c)) + 8 *  ~~~(a ||| ( ~~~b ||| c)) + 8 *  ~~~( ~~~a ||| (b ||| c)) + 8 *  ~~~( ~~~a ||| ( ~~~b ||| c)) - 3 * ( ~~~a &&& (b &&& c)) + 13 * (a &&& ( ~~~b &&& c)) + 14 * (a &&& (b &&& c)) =  - 2 * ( ~~~a &&& ( ~~~b &&& c)) + 1 *  ~~~(a ^^^ b)

theorem set_to_set_decomposebittest_thm (e : IntW 8) :
  select (icmp IntPred.slt e (const? 8 0)) (const? 8 (-125)) (const? 8 3) ⊑
    LLVM.or (LLVM.and e (const? 8 (-128))) (const? 8 3) { «disjoint» := true }

theorem add_right_shift (hq : q >= t) (hs : s >= p + (2 ^ u - 1)) (hv_s : v > s) (hv_t : v > t) :
  (bw r (addMax (bw p a) (bw q (shrMax (bw t b) (bw u c)))))  =
  (bw r (shrMax (bw v (addMax (bw s (shlMax (bw p a) (bw u c))) (bw t b))) (bw u c)))

theorem or_and3_thm.extracted_1._6 : ∀ (x : BitVec 1) (x_1 x_2 : BitVec 32) (x_3 : BitVec 1),
  x_3 ||

theorem src_srem_shl_demand_max_signbit_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬((2#32 == 0 || 32 != 1 && x == intMin 32 && 2#32 == -1) = true ∨ 30#32 ≥ ↑32) →
    ¬(2#32 == 0 || 32 != 1 && x == intMin 32 && 2#32 == -1) = true →
      x.srem 2#32 <<< 30#32 &&& BitVec.ofInt 32 (-2147483648) = x.srem 2#32 &&& BitVec.ofInt 32 (-2147483648)

theorem sext_sub_const_proof : sext_sub_const_before ⊑ sext_sub_const_after

theorem and_ne_with_one_bit_diff_constants1_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x != 51#32) &&& ofBool (x != 50#32) = ofBool (x + BitVec.ofInt 32 (-52) <ᵤ BitVec.ofInt 32 (-2))

theorem tryFactorization_xor_ashr_lshr_thm.extracted_1._1 : ∀ (x : BitVec 32), ¬(x ≥ ↑32 ∨ x ≥ ↑32) → x ≥ ↑32 → False

theorem and_xor_or7_thm.extracted_1._2 : ∀ (x x_1 x_2 : BitVec 64),
  ¬(x_2 = 0 ∨ x_1 = 0 ∨ x = 0 ∨ x_2 = 0) →
    ¬(x_2 = 0 ∨ x_1 = 0) → 42#64 / x_2 ||

@[simp_llvm_option]
theorem LLVM.IntW.value_isRefinedBy_iff (a : BitVec w) (b? : PoisonOr (BitVec w)) :
    value a ⊑ b? ↔ b? = value a

theorem udiv_i80_thm (e : IntW 80) :
  LLVM.udiv (lshr e (const? 80 2)) (const? 80 100) ⊑ LLVM.udiv e (const? 80 400)

theorem shl_trunc_smaller_ashr_thm.extracted_1._2 : ∀ (x : BitVec 32),
  ¬(10#32 ≥ ↑32 ∨ 13#24 ≥ ↑24) →
    ¬3#24 ≥ ↑24 → truncate 24 (x.sshiftRight' 10#32) <<< 13#24 = truncate 24 x <<< 3#24 &&& BitVec.ofInt 24 (-8192)

@[simp] theorem map_append (f : Ty₁ → Ty₂) (Γ Δ : Ctxt Ty₁) :
    (Γ ++ Δ).map f = Γ.map f ++ Δ.map f

theorem alive_Select_1078 : forall (w : Nat) (X c Z W : Bitvec 1)
, TSSA.eval
  (Op := Op) (e := e)
  (i := TSSAIndex.STMT (UserType.base (BaseType.bitvec 1)))
  [dsl_bb|
  ^bb
  %v0 := unit: ;
  %v1 := op:const (c) %v0;
  %v2 := op:const (W) %v0;
  %v3 := op:const (Z) %v0;
  %v4 := triple:%v1 %v2 %v3;
  %v5 := op:select w %v4;
  %v6 := op:const (X) %v0;
  %v7 := triple:%v1 %v6 %v5;
  %v8 := op:select w %v7
  dsl_ret %v8
  ]  ⊑
  TSSA.eval
  (Op := Op) (e := e)
  (i := TSSAIndex.STMT (UserType.base (BaseType.bitvec 1)))
  [dsl_bb|
  ^bb
  %v0 := unit: ;
  %v1 := op:const (c) %v0;
  %v2 := op:const (W) %v0;
  %v3 := op:const (Z) %v0;
  %v4 := triple:%v1 %v2 %v3;
  %v5 := op:select 1 %v4;
  %v6 := op:const (X) %v0;
  %v7 := triple:%v1 %v6 %v3;
  %v8 := op:select 1 %v7
  dsl_ret %v8
  ]

theorem test4_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ofBool (-1#32 <ₛ x_1) &&& ofBool (-1#32 <ₛ x) = ofBool (-1#32 <ₛ x_1 ||| x)

theorem ashrslt_02_08_exact_thm.extracted_1._1 : ∀ (x : BitVec 4),
  ¬(True ∧ x >>> 2#4 <<< 2#4 ≠ x ∨ 2#4 ≥ ↑4) → ofBool (x.sshiftRight' 2#4 <ₛ BitVec.ofInt 4 (-8)) = 0#1

theorem e_1099 :
    11 *  ~~~z - 6 *  ~~~(z ^^^ t) - 5 * z + 1 *  ~~~(z &&&  ~~~z) + 7 * t + 4 * (z ^^^ t) - 6 *  ~~~(z ||| t) + 3 * (z &&& t) = 23 *  ~~~(z |||  ~~~t)

theorem ashr_lshr_no_lshr_thm.extracted_1._2 : ∀ (x x_1 : BitVec 32),
  ofBool (0#32 ≤ₛ x_1) = 1#1 → ofBool (x_1 <ₛ 0#32) = 1#1 → ¬x ≥ ↑32 → x_1 + x = x_1.sshiftRight' x

theorem e_2235 :
     - 2 *  ~~~(d &&& e) + 1 *  ~~~( ~~~d ||| ( ~~~e &&& f)) - 5 * ((d ^^^ e) ||| (d ^^^ f)) - 3 * (f ||| (d &&&  ~~~e)) - 1 * ( ~~~d ||| (e ||| f)) + 4 *  ~~~(d ^^^ ( ~~~e &&& f)) - 6 * (e ^^^ ( ~~~d ||| (e ^^^ f))) + 1 * (e ^^^ (d ||| (e &&& f))) + 1 * ( ~~~(d ||| e) ||| (e ^^^ f)) - 2 * (e ||| f) + 5 *  ~~~(d &&& (e ||| f)) - 2 * (f ^^^  ~~~(d &&& (e ||| f))) + 1 * (f ^^^ (d &&& e)) + 3 *  ~~~(d &&&  ~~~e) - 2 * (e ^^^  ~~~(d &&& ( ~~~e &&& f))) - 2 * (e ^^^  ~~~(d ||| (e ^^^ f))) - 3 * ((d ^^^ e) &&& (d ^^^ f)) + 1 *  ~~~(d |||  ~~~f) + 2 * ((d ^^^ e) &&&  ~~~(d ^^^ f)) - 1 * (e ^^^ ( ~~~d &&& ( ~~~e ||| f))) - 1 * (e &&& (d ^^^ f)) + 5 * (f ^^^ ( ~~~d &&& (e ||| f))) + 1 * f - 2 * (e ^^^ ( ~~~d ||| ( ~~~e &&& f))) - 1 * (d &&& ( ~~~e ||| f)) - 3 * ((d &&& f) ^^^ (d ^^^ (e &&& f))) - 2 * ( ~~~(d ||| e) |||  ~~~(d ^^^ (e ^^^ f))) + 5 * (e |||  ~~~(d ^^^ f)) - 6 * ( ~~~f &&& (d ^^^ e)) - 1 *  ~~~(d &&&  ~~~d) + 3 * (e ^^^ (d ||| ( ~~~e ||| f))) + 5 * ( ~~~d ||| ( ~~~e ||| f)) + 5 *  ~~~(d &&& (e ^^^ f)) - 1 *  ~~~(d ^^^ (e ||| f)) - 11 *  ~~~(d &&& (e &&& f)) + 2 * ( ~~~(d ^^^ e) &&&  ~~~(d ^^^ f)) - 5 * (e ^^^  ~~~( ~~~d &&& ( ~~~e ||| f))) - 1 *  ~~~(d ||| ( ~~~e &&& f)) + 2 * ( ~~~d &&& ( ~~~e ||| f)) - 1 * e + 2 * (f &&&  ~~~(d &&&  ~~~e)) - 2 * (d ||| (e ^^^ f)) + 7 * ((e &&& f) ||| (d &&& (e ||| f))) + 11 * (e ^^^  ~~~(d &&& (e ^^^ f))) + 2 * ((d &&& e) ^^^ (d ^^^ ( ~~~e ||| f))) + 7 * (f ^^^ (d ||| ( ~~~e &&& f))) - 11 * (f ^^^  ~~~(d &&& (e &&& f))) + 2 * ((d &&& e) ^^^  ~~~(d ^^^ (e &&& f))) - 5 *  ~~~(d ||| (e ||| f)) + 7 *  ~~~(d ||| ( ~~~e ||| f)) + 19 *  ~~~( ~~~d ||| (e ||| f)) + 8 *  ~~~( ~~~d ||| ( ~~~e ||| f)) - 4 * ( ~~~d &&& ( ~~~e &&& f)) - 9 * ( ~~~d &&& (e &&& f)) + 11 * (d &&& ( ~~~e &&& f)) =  - 1 * (d &&& (e &&& f))

theorem p_constmask2_thm (e e_1 : IntW 32) :
  add (LLVM.and e_1 (const? 32 61440)) (LLVM.and e (const? 32 (-65281))) ⊑
    LLVM.or (LLVM.and e_1 (const? 32 61440)) (LLVM.and e (const? 32 (-65281))) { «disjoint» := true }

theorem positive_sameconst_shlnsw_thm (e : IntW 8) :
  shl (ashr e (const? 8 3)) (const? 8 3) { «nsw» := true, «nuw» := false } ⊑ LLVM.and e (const? 8 (-8))

theorem neg_mask_proof : neg_mask_before ⊑ neg_mask_after

theorem positive_sameconst_proof : positive_sameconst_before ⊑ positive_sameconst_after

theorem unsigned_sign_bit_extract_with_trunc_proof : unsigned_sign_bit_extract_with_trunc_before ⊑ unsigned_sign_bit_extract_with_trunc_after

theorem trunc_equality_nsw_zext_proof : trunc_equality_nsw_zext_before ⊑ trunc_equality_nsw_zext_after

theorem select_of_symmetric_selects_thm.extracted_1._6 : ∀ (x x_1 : BitVec 32) (x_2 x_3 : BitVec 1),
  x_3 = 1#1 → ¬x_2 = 1#1 → ¬x_2 ^^^ x_3 = 1#1 → x = x_1

theorem p_proof : p_before ⊑ p_after

theorem test_zext4_thm (e e_1 : IntW 1) :
  select e_1 (zext 32 e) (const? 32 1) ⊑ zext 32 (select (LLVM.xor e_1 (const? 1 1)) (const? 1 1) e)

theorem urem_i32_c_proof : urem_i32_c_before ⊑ urem_i32_c_after

theorem test4_thm.extracted_1._1 : ∀ (x x_1 : BitVec 67),
  ¬66#67 ≥ ↑67 → (x_1 ||| x >>> 66#67) &&& 2#67 = x_1 &&& 2#67

theorem test19_thm (e e_1 : IntW 32) :
  LLVM.xor (LLVM.or e_1 e) (LLVM.or (LLVM.xor e_1 (const? 32 (-1))) (LLVM.xor e (const? 32 (-1)))) ⊑
    LLVM.xor (LLVM.xor e_1 e) (const? 32 (-1))

theorem test1_thm.extracted_1._1 : ∀ (x : BitVec 61), zeroExtend 61 (truncate 41 x) = x &&& 2199023255551#61

theorem lshrult_01_06_proof : lshrult_01_06_before ⊑ lshrult_01_06_after

theorem main_proof : main_before ⊑ main_after

theorem sle_smax1_thm (e e_1 : IntW 32) :
  icmp IntPred.sle (select (icmp IntPred.sgt e_1 e) e_1 e) e_1 ⊑ icmp IntPred.sle e e_1

theorem eq_umax4_thm.extracted_1._1 : ∀ (x x_1 : BitVec 32),
  ofBool (x_1 + 3#32 <ᵤ x) = 1#1 → ofBool (x_1 + 3#32 == x) = ofBool (x ≤ᵤ x_1 + 3#32)

theorem test2_thm.extracted_1._1 : ∀ (x x_1 x_2 : BitVec 49), ¬(x_1 ≥ ↑49 ∨ x_1 ≥ ↑49) → x_1 ≥ ↑49 → False

theorem rev8_mul_and_lshr_thm.extracted_1._1 : ∀ (x : BitVec 8),
  ¬(True ∧ (zeroExtend 64 x).smulOverflow 2050#64 = true ∨
        True ∧ (zeroExtend 64 x).umulOverflow 2050#64 = true ∨
          True ∧ (zeroExtend 64 x).smulOverflow 32800#64 = true ∨
            True ∧ (zeroExtend 64 x).umulOverflow 32800#64 = true ∨
              True ∧
                  (zeroExtend 64 x * 2050#64 &&& 139536#64 ||| zeroExtend 64 x * 32800#64 &&& 558144#64).smulOverflow
                      65793#64 =
                    true ∨
                True ∧
                    (zeroExtend 64 x * 2050#64 &&& 139536#64 ||| zeroExtend 64 x * 32800#64 &&& 558144#64).umulOverflow
                        65793#64 =
                      true ∨
                  16#64 ≥ ↑64) →
    True ∧ (zeroExtend 64 x).smulOverflow 2050#64 = true ∨
        True ∧ (zeroExtend 64 x).umulOverflow 2050#64 = true ∨
          True ∧ (zeroExtend 64 x).smulOverflow 32800#64 = true ∨
            True ∧ (zeroExtend 64 x).umulOverflow 32800#64 = true ∨
              True ∧
                  (zeroExtend 64 x * 2050#64 &&& 139536#64 &&& (zeroExtend 64 x * 32800#64 &&& 558144#64) != 0) = true ∨
                True ∧
                    (zeroExtend 64 x * 2050#64 &&& 139536#64 ||| zeroExtend 64 x * 32800#64 &&& 558144#64).smulOverflow
                        65793#64 =
                      true ∨
                  True ∧
                      (zeroExtend 64 x * 2050#64 &&& 139536#64 |||
                              zeroExtend 64 x * 32800#64 &&& 558144#64).umulOverflow
                          65793#64 =
                        true ∨
                    16#64 ≥ ↑64 →
      False

theorem sdiv_x_by_const_cmp_x_thm (e : IntW 32) :
  icmp IntPred.eq (LLVM.sdiv e (const? 32 13)) e ⊑ icmp IntPred.eq e (const? 32 0)

theorem logical_or_logical_or_icmps_comm1_thm.extracted_1._5 : ∀ (x x_1 x_2 : BitVec 8),
  ¬x_1 ≥ ↑8 →
    ¬(ofBool (x_2 &&& 1#8 <<< x_1 == 0#8) = 1#1 ∨ ofBool (x == 42#8) = 1#1) →
      ¬(True ∧ 1#8 <<< x_1 >>> x_1 ≠ 1#8 ∨ x_1 ≥ ↑8) →
        ofBool (x_2 &&& 1#8 <<< x_1 == 0#8) = 1#1 → True → ofBool (x_2 &&& 1#8 == 0#8) = 1#1

theorem ashrsgt_03_11_exact_thm.extracted_1._1 : ∀ (x : BitVec 4),
  ¬(True ∧ x >>> 3#4 <<< 3#4 ≠ x ∨ 3#4 ≥ ↑4) → ofBool (BitVec.ofInt 4 (-5) <ₛ x.sshiftRight' 3#4) = 1#1

theorem main4c_logical_thm.extracted_1._3 : ∀ (x : BitVec 32),
  ¬ofBool (x &&& 7#32 != 7#32) = 1#1 →
    ofBool (x &&& 48#32 != 48#32) = 1#1 → 0#32 = zeroExtend 32 (ofBool (x &&& 55#32 == 55#32))

theorem ashr_lshr2_proof : ashr_lshr2_before ⊑ ashr_lshr2_after

theorem e_1886 :
     - 1 * ((a &&&  ~~~b) |||  ~~~(b ^^^ c)) - 1 * (c ^^^  ~~~(a &&& b)) - 6 * (c &&& (a ||| b)) - 11 * (c ^^^ ( ~~~a ||| ( ~~~b ||| c))) - 1 * (b ^^^  ~~~(a ||| (b ^^^ c))) - 3 * (b ^^^  ~~~(a &&& ( ~~~b ||| c))) - 1 * (b &&&  ~~~c) - 2 * (c ^^^  ~~~(a &&& (b &&& c))) + 5 * ((b &&&  ~~~c) |||  ~~~(a ||| ( ~~~b &&& c))) - 6 * ((b &&& c) ||| ( ~~~a &&& (b ||| c))) + 11 * (b ^^^ (a ||| c)) + 4 * ( ~~~(a &&&  ~~~b) &&&  ~~~(b ^^^ c)) - 7 * ((b &&& c) ||| (a &&& (b ||| c))) - 1 * (a ||| (b ||| c)) + 7 * (a ^^^ b) + 7 * ((a &&& b) ||| (a ^^^ (b ^^^ c))) - 1 * (a ||| (b &&& c)) + 3 *  ~~~(a |||  ~~~c) + 4 * (c ^^^ (a |||  ~~~b)) - 1 * (b ^^^ (a ||| ( ~~~b &&& c))) + 7 * ((a &&& b) ^^^ (b |||  ~~~c)) + 11 * (c ^^^  ~~~(a ||| (b &&& c))) + 3 * ( ~~~(a ^^^ b) &&&  ~~~(a ^^^ c)) + 1 * (b &&& (a ^^^ c)) - 7 * ( ~~~(a &&& b) &&& (b ^^^ c)) - 6 * ((b &&&  ~~~c) ^^^ (a ||| (b ^^^ c))) + 2 * ( ~~~b &&& (a ^^^ c)) + 2 * (c &&&  ~~~(a &&& b)) - 2 * ((a &&&  ~~~b) ||| (b ^^^ c)) + 1 * ((a &&& c) ^^^  ~~~(b &&&  ~~~c)) - 7 * (c ^^^ (a ||| b)) - 1 * (b ^^^  ~~~( ~~~a &&& ( ~~~b &&& c))) + 3 * ( ~~~a ||| (b &&& c)) + 2 * ((a ||| b) &&&  ~~~(a ^^^ (b ^^^ c))) + 1 * ( ~~~a &&& (b ||| c)) - 11 * (b ^^^  ~~~( ~~~a ||| (b &&& c))) - 6 * (c ^^^  ~~~(a ||| ( ~~~b &&& c))) + 2 * ((a &&& b) ^^^ (a ^^^ (b &&& c))) - 7 * ( ~~~a &&& ( ~~~b ||| c)) - 3 * (c ^^^ (a &&& b)) - 2 *  ~~~(a &&&  ~~~c) - 7 *  ~~~(a ||| (b ||| c)) + 3 *  ~~~(a ||| ( ~~~b ||| c)) + 6 *  ~~~( ~~~a ||| ( ~~~b ||| c)) + 17 * ( ~~~a &&& ( ~~~b &&& c)) - 11 * ( ~~~a &&& (b &&& c)) + 20 * (a &&& ( ~~~b &&& c)) + 24 * (a &&& (b &&& c)) =  - 4 *  ~~~(a &&& (b ||| c))

theorem masked_icmps_mask_notallzeros_bmask_mixed_negated_swapped_1_proof : masked_icmps_mask_notallzeros_bmask_mixed_negated_swapped_1_before ⊑ masked_icmps_mask_notallzeros_bmask_mixed_negated_swapped_1_after

theorem uadd_sat_flipped_wrong_bounds7_thm.extracted_1._1 : ∀ (x : BitVec 32),
  ofBool (x ≤ᵤ BitVec.ofInt 32 (-12)) = 1#1 → ¬ofBool (x <ᵤ BitVec.ofInt 32 (-11)) = 1#1 → x + 9#32 = -1#32

theorem ashr_mul_proof : ashr_mul_before ⊑ ashr_mul_after

theorem shl_lshr_demand1_thm.extracted_1._2 : ∀ (x : BitVec 8),
  ¬(x ≥ ↑8 ∨ 3#8 ≥ ↑8) → ¬x ≥ ↑8 → 40#8 <<< x >>> 3#8 ||

theorem or_signbit_shl_thm (e : IntW 32) :
  shl (LLVM.or e (const? 32 (-65536))) (const? 32 8) ⊑ LLVM.or (shl e (const? 32 8)) (const? 32 (-16777216))

theorem mul_constant_eq_proof : mul_constant_eq_before ⊑ mul_constant_eq_after

theorem or_xor_commute4_thm (e e_1 : IntW 32) :
  LLVM.xor (LLVM.udiv (const? 32 42) e_1) (LLVM.or (LLVM.udiv (const? 32 42) e) (LLVM.udiv (const? 32 42) e_1)) ⊑
    LLVM.and (LLVM.udiv (const? 32 42) e) (LLVM.xor (LLVM.udiv (const? 32 42) e_1) (const? 32 (-1)))

theorem test1_proof : test1_before ⊑ test1_after

theorem srem_i1_is_zero_proof : srem_i1_is_zero_before ⊑ srem_i1_is_zero_after

theorem positive_sameconst_shlnuw_proof : positive_sameconst_shlnuw_before ⊑ positive_sameconst_shlnuw_after

theorem bitwise_or_logical_or_icmps_comm3_proof : bitwise_or_logical_or_icmps_comm3_before ⊑ bitwise_or_logical_or_icmps_comm3_after

theorem test12_thm (e e_1 : IntW 32) :
  trunc 64 (lshr (zext 128 e_1) (LLVM.and (zext 128 e) (const? 128 31))) ⊑
    lshr (zext 64 e_1) (zext 64 (LLVM.and e (const? 32 31)) { «nneg» := true })

@[simp]
theorem Factor.reflect_zero_of_denote_zero {w : Nat} {f : Factor} {xs : Env w} (h : f.denote xs = 0) :
    f.reflect xs = 0#w

theorem or_xor_tree_1110_thm.extracted_1._1 : ∀ (x x_1 x_2 : BitVec 32),
  x_2 * 42#32 ^^^ (x_1 * 42#32 ^^^ x * 42#32) ||

theorem and_signbit_ashr_proof : and_signbit_ashr_before ⊑ and_signbit_ashr_after

theorem test10b_proof : test10b_before ⊑ test10b_after

theorem e_1557 :
     - 7 * (c ^^^ ( ~~~a ||| ( ~~~b &&& c))) - 5 * (c ^^^ (a &&& b)) + 5 * (c ^^^  ~~~(a &&& (b ||| c))) + 2 * (b ^^^ ( ~~~a ||| (b &&& c))) - 5 * ( ~~~(a ||| b) |||  ~~~(a ^^^ (b ^^^ c))) - 3 * (b ||| (a ^^^ c)) - 1 * (b ^^^  ~~~( ~~~a &&& (b ||| c))) + 7 *  ~~~(a ||| (b ||| c)) + 7 *  ~~~(a ||| ( ~~~b ||| c)) - 1 *  ~~~( ~~~a ||| (b ||| c)) + 12 *  ~~~( ~~~a ||| ( ~~~b ||| c)) + 12 * ( ~~~a &&& ( ~~~b &&& c)) + 15 * ( ~~~a &&& (b &&& c)) + 6 * (a &&& ( ~~~b &&& c)) = 1 *  ~~~(a &&& ( ~~~b ||| c)) - 5 * (a &&& (b &&& c))

theorem EqualUpTo_ofBitVecZextMsb_add (a b : BitVec w) :
    EqualUpTo (w + 1)
    (BitStream.ofBitVecZextMsb a + BitStream.ofBitVecZextMsb b)
    (BitStream.ofBitVecZextMsb (a + b))

theorem positive_biggershl_shlnsw_proof : positive_biggershl_shlnsw_before ⊑ positive_biggershl_shlnsw_after

theorem xor_sext_sext_thm.extracted_1._1 : ∀ (x : BitVec 4) (x_1 : BitVec 8),
  signExtend 16 x_1 ^^^ signExtend 16 x = signExtend 16 (x_1 ^^^ signExtend 8 x)

theorem logic_or_logic_and_4_proof : logic_or_logic_and_4_before ⊑ logic_or_logic_and_4_after
</all_available_lemmas>

<local_ctx>
import Batteries.Data.Fin.Basic

import Batteries.Data.Fin.Lemmas

import Blase.SingleWidth.Defs

import Blase.AutoStructs.Constructions

import Blase.AutoStructs.Defs

import Blase.AutoStructs.FiniteStateMachine

import Mathlib.Tactic.Ring

import Mathlib.Data.Nat.Size -- TODO: remove and get rid of shiftLeft_eq_mul_pow use

import Mathlib.Data.BitVec

import Mathlib.Tactic.FinCases

open Fin.NatCast

open Mathlib

def NFA.sa (_ : NFA α σ) := σ → Language α

structure NFA.correct (M : NFA α σ) (ζ : M.sa) (L : Language α) where
  cond1 : ∀ w, (w ∈ L ↔ ∃ q ∈ M.accept, w ∈ ζ q)
  cond2 : ∀ w q, q ∈ M.eval w ↔ w ∈ ζ q

abbrev BVRel := ∀ ⦃w⦄, BitVec w → BitVec w → Prop

abbrev BVNRel n := ∀ ⦃w⦄, List.Vector (BitVec w) n → Prop

def NFA'.sa (M : NFA' n) := M.σ → BVNRel n

def NFA'.sa2 (M : NFA' 2) := M.σ → BVRel

def langRel (R : BVNRel n) : Set (BitVecs n) :=
  { bvs | R bvs.bvs }

def langRel2 (R : BVRel) : Set (BitVecs 2) :=
  { bvs | R (bvs.bvs.get 0) (bvs.bvs.get 1) }

structure NFA'.correct (M : NFA' n) (ζ : M.sa) (L : BVNRel n) where
  cond1 : ∀ ⦃w⦄ (bvn : List.Vector (BitVec w) n), (L bvn ↔ ∃ q ∈ M.M.accept, ζ q bvn)
  cond2 q : q ∈ M.M.start ↔ ζ q (List.Vector.replicate n .nil)
  cond3 q a {w} (bvn : List.Vector (BitVec w) n) : q ∈ M.M.stepSet { q | ζ q bvn } a ↔
              ζ q (List.Vector.ofFn fun k => BitVec.cons (a.getLsbD k) (bvn.get k))

structure NFA'.correct2 (M : NFA' 2) (ζ : M.sa2) (L : BVRel) where
  cond1 : ∀ (bv1 bv2 : BitVec w), (L bv1 bv2 ↔ ∃ q ∈ M.M.accept, ζ q bv1 bv2)
  cond2 q : q ∈ M.M.start ↔ ζ q .nil .nil
  cond3 q a w (bv1 bv2 : BitVec w) : q ∈ M.M.stepSet { q | ζ q bv1 bv2 } a ↔
              ζ q (BitVec.cons (a.getLsbD 0) bv1) (BitVec.cons (a.getLsbD 1) bv2)

section fsm

variable {arity : Type} [FinEnum arity]

open BitStream in

end fsm

section nfas_relations

def NFA.autEq : NFA (BitVec 2) Unit :=
  { start := ⊤, accept := ⊤, step _ a := { _s' | if a = 0 ∨ a = 3 then true else false }}

def NFA'.autEq : NFA' 2 :=
  ⟨Unit, NFA.autEq⟩

def NFA'.eqRel : BVRel := fun _ x y => x = y

inductive NFA.unsignedCmpState : Type where
| eq | gt | lt
deriving Fintype, DecidableEq

def NFA.unsignedCmpStep (q : NFA.unsignedCmpState) (a : BitVec 2) : List NFA.unsignedCmpState :=
  match q, a with
  | .eq, 0 => [ .eq ] | .eq, 3 => [ .eq ] | .eq, 1 => [ .gt ] | .eq, 2 => [ .lt ]
  | .gt, 0 => [ .gt ] | .gt, 1 => [ .gt ] | .gt, 3 => [ .gt ] | .gt, 2 => [ .lt ]
  | .lt, 0 => [ .lt ] | .lt, 1 => [ .gt ] | .lt, 2 => [ .lt ] | .lt, 3 => [ .lt ]

def NFA.autUnsignedCmp (cmp: RelationOrdering) : NFA (BitVec 2) unsignedCmpState where
  step s a := { s' | s' ∈ unsignedCmpStep s a }
  start := {s | s = .eq }
  accept := { s | s ∈ match cmp with | .lt => [unsignedCmpState.lt] | .le => [.lt, .eq] | .gt => [.gt] | .ge => [.gt, .eq] }

def NFA'.autUnsignedCmp (cmp: RelationOrdering) : NFA' 2 :=
  ⟨_, NFA.autUnsignedCmp cmp⟩

def RelationOrdering.urel (cmp : RelationOrdering) : BVRel :=
  match cmp with
  | .lt => fun _ bv1 bv2 => bv1.ult bv2
  | .le => fun _ bv1 bv2 => bv1.ule bv2
  | .gt => fun _ bv1 bv2 => bv2.ult bv1
  | .ge => fun _ bv1 bv2 => bv2.ule bv1

def NFA'.autUnsignedCmpSA (q : NFA.unsignedCmpState) : BVRel :=
  match q with
  | .eq => fun _ bv1 bv2 => bv1 = bv2
  | .lt => fun _ bv1 bv2 => bv1.ult bv2
  | .gt => fun _ bv1 bv2 => bv2.ult bv1

inductive NFA.signedCmpState : Type where
| eq | gt | lt | ltfin | gtfin
deriving DecidableEq, Fintype

def NFA.signedCmpStep (q : NFA.signedCmpState) (a : BitVec 2) : List NFA.signedCmpState :=
  match q, a with
  | .eq, 0 => [ .eq ] | .eq, 3 => [.eq] | .eq, 1 => [.gt, .ltfin] | .eq, 2 => [ .lt, .gtfin ]
  | .gt, 0 => [ .gt, .gtfin ] | .gt, 1 => [ .gt, .ltfin ] | .gt, 3 => [ .gt, .gtfin ] | .gt, 2 => [ .lt, .gtfin ]
  | .lt, 0 => [ .lt, .ltfin ] | .lt, 1 => [ .gt, .ltfin ] | .lt, 2 => [ .lt, .gtfin ] | .lt, 3 => [ .lt, .ltfin ]
  | .gtfin, _ => ∅
  | .ltfin, _ => ∅

def NFA.autSignedCmp (cmp: RelationOrdering) : NFA (BitVec 2) signedCmpState where
  step s a := { s' | s' ∈ signedCmpStep s a }
  start := { s | s = signedCmpState.eq }
  accept := { s | s ∈ match cmp with | .lt => [NFA.signedCmpState.ltfin] | .le => [.ltfin, .eq] | .gt => [.gtfin] | .ge => [.gtfin, .eq] }

def NFA'.autSignedCmp (cmp: RelationOrdering) : NFA' 2 :=
  ⟨_, NFA.autSignedCmp cmp⟩

def RelationOrdering.srel (cmp : RelationOrdering) : BVRel :=
  match cmp with
  | .lt => fun _ bv1 bv2 => bv1.slt bv2
  | .le => fun _ bv1 bv2 => bv1.sle bv2
  | .gt => fun _ bv1 bv2 => bv2.slt bv1
  | .ge => fun _ bv1 bv2 => bv2.sle bv1

def NFA'.autSignedCmpSA (q : NFA.signedCmpState) : BVRel :=
  match q with
  | .eq => fun _ bv1 bv2 => bv1 = bv2
  | .lt => fun _ bv1 bv2 => bv1.ult bv2
  | .gt => fun _ bv1 bv2 => bv2.ult bv1
  | .ltfin => fun _ bv1 bv2 => bv1.slt bv2
  | .gtfin => fun _ bv1 bv2 => bv2.slt bv1

end nfas_relations

def Relation.absAutOfRelation (rel : Relation) : NFA' 2 :=
  match rel with
  | .eq => NFA'.autEq
  | .unsigned cmp => NFA'.autUnsignedCmp cmp
  | .signed cmp => NFA'.autSignedCmp cmp
</local_ctx>

<target_theorem>
@[simp]
lemma autOfRelation_accepts (r : Relation) :
    r.absAutOfRelation.accepts = r.language :=
</target_theorem>

