; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto (bignum)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.bignum256 = type { [9 x i32] }

@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.bn_cmov = external hidden unnamed_addr constant [83 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @bn_cmov(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store volatile i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load volatile i32, ptr %6, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 1
  %14 = zext i1 %13 to i32
  %15 = load volatile i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  %17 = zext i1 %16 to i32
  %18 = or i32 %14, %17
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %4
  br label %22

21:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 274, ptr noundef @__PRETTY_FUNCTION__.bn_cmov) #3
  unreachable

22:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %23 = load volatile i32, ptr %6, align 4, !tbaa !9
  %24 = sub i32 0, %23
  store i32 %24, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = xor i32 %25, -1
  store i32 %26, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %54, %22
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 9
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %57

31:                                               ; preds = %27
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.bignum256, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [9 x i32], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = and i32 %37, %38
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.bignum256, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [9 x i32], ptr %41, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = and i32 %45, %46
  %48 = or i32 %39, %47
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.bignum256, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [9 x i32], ptr %50, i64 0, i64 %52
  store i32 %48, ptr %53, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %31
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %11, align 4, !tbaa !9
  br label %27, !llvm.loop !11

57:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { noreturn nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { noreturn nounwind }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.bn_cmov = external hidden unnamed_addr constant [83 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @bn_cmov(ptr nocapture noundef writeonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  store volatile i32 %1, ptr %5, align 4, !tbaa !5
  %.0..0..0..0.9 = load volatile i32, ptr %5, align 4, !tbaa !5
  %6 = icmp eq i32 %.0..0..0..0.9, 1
  %.0..0..0..0.10 = load volatile i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %.0..0..0..0.10, 0
  %8 = or i1 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 274, ptr noundef nonnull @__PRETTY_FUNCTION__.bn_cmov) #2
  unreachable

10:                                               ; preds = %4
  %.0..0..0..0.11 = load volatile i32, ptr %5, align 4, !tbaa !5
  %11 = sub i32 0, %.0..0..0..0.11
  %12 = add i32 %.0..0..0..0.11, -1
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = and i32 %13, %11
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = and i32 %15, %12
  %17 = or i32 %16, %14
  store i32 %17, ptr %0, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %2, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = and i32 %19, %11
  %21 = getelementptr inbounds i8, ptr %3, i64 4
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = and i32 %22, %12
  %24 = or i32 %23, %20
  %25 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %24, ptr %25, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %2, i64 8
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = and i32 %27, %11
  %29 = getelementptr inbounds i8, ptr %3, i64 8
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = and i32 %30, %12
  %32 = or i32 %31, %28
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %32, ptr %33, align 4, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %2, i64 12
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = and i32 %35, %11
  %37 = getelementptr inbounds i8, ptr %3, i64 12
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = and i32 %38, %12
  %40 = or i32 %39, %36
  %41 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %40, ptr %41, align 4, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %2, i64 16
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = and i32 %43, %11
  %45 = getelementptr inbounds i8, ptr %3, i64 16
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = and i32 %46, %12
  %48 = or i32 %47, %44
  %49 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %48, ptr %49, align 4, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %2, i64 20
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = and i32 %51, %11
  %53 = getelementptr inbounds i8, ptr %3, i64 20
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = and i32 %54, %12
  %56 = or i32 %55, %52
  %57 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %56, ptr %57, align 4, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %2, i64 24
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = and i32 %59, %11
  %61 = getelementptr inbounds i8, ptr %3, i64 24
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = and i32 %62, %12
  %64 = or i32 %63, %60
  %65 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %64, ptr %65, align 4, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %2, i64 28
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = and i32 %67, %11
  %69 = getelementptr inbounds i8, ptr %3, i64 28
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = and i32 %70, %12
  %72 = or i32 %71, %68
  %73 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %72, ptr %73, align 4, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %2, i64 32
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = and i32 %75, %11
  %77 = getelementptr inbounds i8, ptr %3, i64 32
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = and i32 %78, %12
  %80 = or i32 %79, %76
  %81 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %80, ptr %81, align 4, !tbaa !5
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { noreturn nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { noreturn nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass