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

; 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.curve_point = type { %struct.bignum256, %struct.bignum256 }
%struct.bignum256 = type { [9 x i32] }
%struct._HMAC_DRBG_CTX = type { [8 x i32], [8 x i32], [16 x i32] }
%struct.ecdsa_curve = type { %struct.bignum256, %struct.curve_point, %struct.bignum256, %struct.bignum256, i32, %struct.bignum256, [64 x [8 x %struct.curve_point]] }

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare void @bn_inverse(ptr noundef, ptr noundef) #2

declare void @bn_multiply(ptr noundef, ptr noundef, ptr noundef) #2

declare void @bn_mod(ptr noundef, ptr noundef) #2

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

declare i32 @bn_is_zero(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @generate_k_random(ptr noundef, ptr noundef) #3

declare void @bn_add(ptr noundef, ptr noundef) #2

declare i32 @bn_is_less(ptr noundef, ptr noundef) #2

declare void @memzero(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @scalar_multiply(ptr noundef, ptr noundef, ptr noundef) #3

declare void @bn_read_be(ptr noundef, ptr noundef) #2

declare void @bn_write_be(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ecdsa_sign_digest(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca %struct.curve_point, align 4
  %16 = alloca %struct.bignum256, align 4
  %17 = alloca %struct.bignum256, align 4
  %18 = alloca %struct.bignum256, align 4
  %19 = alloca ptr, align 8
  %20 = alloca i8, align 1
  %21 = alloca %struct._HMAC_DRBG_CTX, align 4
  %22 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 72, ptr %15) #4
  call void @llvm.memset.p0.i64(ptr align 4 %15, i8 0, i64 72, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %16) #4
  call void @llvm.memset.p0.i64(ptr align 4 %16, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %17) #4
  call void @llvm.memset.p0.i64(ptr align 4 %17, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %18) #4
  call void @llvm.memset.p0.i64(ptr align 4 %18, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %23 = getelementptr inbounds %struct.curve_point, ptr %15, i32 0, i32 1
  store ptr %23, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %20) #4
  call void @llvm.lifetime.start.p0(i64 128, ptr %21) #4
  call void @llvm.memset.p0.i64(ptr align 4 %21, i8 0, i64 128, i1 false)
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  call void @init_rfc6979(ptr noundef %24, ptr noundef %25, ptr noundef %26, ptr noundef %21)
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  call void @bn_read_be(ptr noundef %27, ptr noundef %17)
  %28 = call i32 @bn_is_zero(ptr noundef %17)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %6
  store i32 1, ptr %7, align 4
  store i32 1, ptr %22, align 4
  br label %151

31:                                               ; preds = %6
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %147, %31
  %33 = load i32, ptr %14, align 4, !tbaa !9
  %34 = icmp slt i32 %33, 10000
  br i1 %34, label %35, label %150

35:                                               ; preds = %32
  call void @generate_k_rfc6979(ptr noundef %16, ptr noundef %21)
  %36 = call i32 @bn_is_zero(ptr noundef %16)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %43, label %38

38:                                               ; preds = %35
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ecdsa_curve, ptr %39, i32 0, i32 2
  %41 = call i32 @bn_is_less(ptr noundef %16, ptr noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %38, %35
  br label %147

44:                                               ; preds = %38
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = call i32 @scalar_multiply(ptr noundef %45, ptr noundef %16, ptr noundef %15)
  %47 = getelementptr inbounds %struct.curve_point, ptr %15, i32 0, i32 1
  %48 = getelementptr inbounds %struct.bignum256, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds [9 x i32], ptr %48, i64 0, i64 0
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = and i32 %50, 1
  %52 = trunc i32 %51 to i8
  store i8 %52, ptr %20, align 1, !tbaa !11
  %53 = getelementptr inbounds %struct.curve_point, ptr %15, i32 0, i32 0
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ecdsa_curve, ptr %54, i32 0, i32 2
  %56 = call i32 @bn_is_less(ptr noundef %53, ptr noundef %55)
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %67, label %58

58:                                               ; preds = %44
  %59 = getelementptr inbounds %struct.curve_point, ptr %15, i32 0, i32 0
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ecdsa_curve, ptr %60, i32 0, i32 2
  %62 = getelementptr inbounds %struct.curve_point, ptr %15, i32 0, i32 0
  call void @bn_subtract(ptr noundef %59, ptr noundef %61, ptr noundef %62)
  %63 = load i8, ptr %20, align 1, !tbaa !11
  %64 = zext i8 %63 to i32
  %65 = or i32 %64, 2
  %66 = trunc i32 %65 to i8
  store i8 %66, ptr %20, align 1, !tbaa !11
  br label %67

67:                                               ; preds = %58, %44
  %68 = getelementptr inbounds %struct.curve_point, ptr %15, i32 0, i32 0
  %69 = call i32 @bn_is_zero(ptr noundef %68)
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %67
  br label %147

72:                                               ; preds = %67
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load ptr, ptr %19, align 8, !tbaa !5
  call void @bn_read_be(ptr noundef %73, ptr noundef %74)
  %75 = load ptr, ptr %19, align 8, !tbaa !5
  %76 = call i32 @bn_is_zero(ptr noundef %75)
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %84, label %78

78:                                               ; preds = %72
  %79 = load ptr, ptr %19, align 8, !tbaa !5
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.ecdsa_curve, ptr %80, i32 0, i32 2
  %82 = call i32 @bn_is_less(ptr noundef %79, ptr noundef %81)
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %85, label %84

84:                                               ; preds = %78, %72
  store i32 2, ptr %7, align 4
  store i32 1, ptr %22, align 4
  br label %151

85:                                               ; preds = %78
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.ecdsa_curve, ptr %86, i32 0, i32 2
  call void @generate_k_random(ptr noundef %18, ptr noundef %87)
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.ecdsa_curve, ptr %88, i32 0, i32 2
  call void @bn_multiply(ptr noundef %18, ptr noundef %16, ptr noundef %89)
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.ecdsa_curve, ptr %90, i32 0, i32 2
  call void @bn_inverse(ptr noundef %16, ptr noundef %91)
  %92 = getelementptr inbounds %struct.curve_point, ptr %15, i32 0, i32 0
  %93 = load ptr, ptr %19, align 8, !tbaa !5
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.ecdsa_curve, ptr %94, i32 0, i32 2
  call void @bn_multiply(ptr noundef %92, ptr noundef %93, ptr noundef %95)
  %96 = load ptr, ptr %19, align 8, !tbaa !5
  call void @bn_add(ptr noundef %96, ptr noundef %17)
  %97 = load ptr, ptr %19, align 8, !tbaa !5
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.ecdsa_curve, ptr %98, i32 0, i32 2
  call void @bn_multiply(ptr noundef %16, ptr noundef %97, ptr noundef %99)
  %100 = load ptr, ptr %19, align 8, !tbaa !5
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.ecdsa_curve, ptr %101, i32 0, i32 2
  call void @bn_multiply(ptr noundef %18, ptr noundef %100, ptr noundef %102)
  %103 = load ptr, ptr %19, align 8, !tbaa !5
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.ecdsa_curve, ptr %104, i32 0, i32 2
  call void @bn_mod(ptr noundef %103, ptr noundef %105)
  %106 = load ptr, ptr %19, align 8, !tbaa !5
  %107 = call i32 @bn_is_zero(ptr noundef %106)
  %108 = icmp ne i32 %107, 0
  br i1 %108, label %109, label %110

109:                                              ; preds = %85
  br label %147

110:                                              ; preds = %85
  %111 = load ptr, ptr %8, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.ecdsa_curve, ptr %111, i32 0, i32 3
  %113 = load ptr, ptr %19, align 8, !tbaa !5
  %114 = call i32 @bn_is_less(ptr noundef %112, ptr noundef %113)
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %116, label %125

116:                                              ; preds = %110
  %117 = load ptr, ptr %8, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.ecdsa_curve, ptr %117, i32 0, i32 2
  %119 = load ptr, ptr %19, align 8, !tbaa !5
  %120 = load ptr, ptr %19, align 8, !tbaa !5
  call void @bn_subtract(ptr noundef %118, ptr noundef %119, ptr noundef %120)
  %121 = load i8, ptr %20, align 1, !tbaa !11
  %122 = zext i8 %121 to i32
  %123 = xor i32 %122, 1
  %124 = trunc i32 %123 to i8
  store i8 %124, ptr %20, align 1, !tbaa !11
  br label %125

125:                                              ; preds = %116, %110
  %126 = getelementptr inbounds %struct.curve_point, ptr %15, i32 0, i32 0
  %127 = load ptr, ptr %11, align 8, !tbaa !5
  call void @bn_write_be(ptr noundef %126, ptr noundef %127)
  %128 = load ptr, ptr %19, align 8, !tbaa !5
  %129 = load ptr, ptr %11, align 8, !tbaa !5
  %130 = getelementptr inbounds i8, ptr %129, i64 32
  call void @bn_write_be(ptr noundef %128, ptr noundef %130)
  %131 = load ptr, ptr %13, align 8, !tbaa !5
  %132 = icmp ne ptr %131, null
  br i1 %132, label %133, label %140

133:                                              ; preds = %125
  %134 = load ptr, ptr %13, align 8, !tbaa !5
  %135 = load i8, ptr %20, align 1, !tbaa !11
  %136 = load ptr, ptr %11, align 8, !tbaa !5
  %137 = call i32 %134(i8 noundef zeroext %135, ptr noundef %136)
  %138 = icmp ne i32 %137, 0
  br i1 %138, label %140, label %139

139:                                              ; preds = %133
  br label %147

140:                                              ; preds = %133, %125
  %141 = load ptr, ptr %12, align 8, !tbaa !5
  %142 = icmp ne ptr %141, null
  br i1 %142, label %143, label %146

143:                                              ; preds = %140
  %144 = load i8, ptr %20, align 1, !tbaa !11
  %145 = load ptr, ptr %12, align 8, !tbaa !5
  store i8 %144, ptr %145, align 1, !tbaa !11
  br label %146

146:                                              ; preds = %143, %140
  call void @memzero(ptr noundef %16, i64 noundef 36)
  call void @memzero(ptr noundef %18, i64 noundef 36)
  call void @memzero(ptr noundef %21, i64 noundef 128)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %22, align 4
  br label %151

147:                                              ; preds = %139, %109, %71, %43
  %148 = load i32, ptr %14, align 4, !tbaa !9
  %149 = add nsw i32 %148, 1
  store i32 %149, ptr %14, align 4, !tbaa !9
  br label %32, !llvm.loop !12

150:                                              ; preds = %32
  call void @memzero(ptr noundef %16, i64 noundef 36)
  call void @memzero(ptr noundef %18, i64 noundef 36)
  call void @memzero(ptr noundef %21, i64 noundef 128)
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %22, align 4
  br label %151

151:                                              ; preds = %150, %146, %84, %30
  call void @llvm.lifetime.end.p0(i64 128, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %152 = load i32, ptr %7, align 4
  ret i32 %152
}

declare void @init_rfc6979(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare void @generate_k_rfc6979(ptr noundef, ptr noundef) #2

declare void @bn_subtract(ptr noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 = { 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 #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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%struct.curve_point = type { %struct.bignum256, %struct.bignum256 }
%struct.bignum256 = type { [9 x i32] }
%struct._HMAC_DRBG_CTX = type { [8 x i32], [8 x i32], [16 x i32] }

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare void @bn_inverse(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @bn_multiply(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @bn_mod(ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare i32 @bn_is_zero(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @generate_k_random(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @bn_add(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @bn_is_less(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @memzero(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @scalar_multiply(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @bn_read_be(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @bn_write_be(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 3) i32 @ecdsa_sign_digest(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef writeonly %4, ptr noundef readonly %5) local_unnamed_addr #3 {
  %7 = alloca %struct.curve_point, align 4
  %8 = alloca %struct.bignum256, align 4
  %9 = alloca %struct.bignum256, align 4
  %10 = alloca %struct.bignum256, align 4
  %11 = alloca %struct._HMAC_DRBG_CTX, align 4
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %7) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(72) %7, i8 0, i64 72, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %8) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %8, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %9) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %9, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %10) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %10, i8 0, i64 36, i1 false)
  %12 = getelementptr inbounds i8, ptr %7, i64 36
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %11) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(128) %11, i8 0, i64 128, i1 false)
  call void @init_rfc6979(ptr noundef %1, ptr noundef %2, ptr noundef %0, ptr noundef nonnull %11) #4
  call void @bn_read_be(ptr noundef %2, ptr noundef nonnull %9) #4
  %13 = call i32 @bn_is_zero(ptr noundef nonnull %9) #4
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %6
  %14 = getelementptr inbounds i8, ptr %0, i64 108
  %15 = getelementptr inbounds i8, ptr %0, i64 144
  %16 = getelementptr inbounds i8, ptr %3, i64 32
  %.not57 = icmp eq ptr %5, null
  br label %17

17:                                               ; preds = %.preheader, %46
  %.04660 = phi i32 [ 0, %.preheader ], [ %47, %46 ]
  call void @generate_k_rfc6979(ptr noundef nonnull %8, ptr noundef nonnull %11) #4
  %18 = call i32 @bn_is_zero(ptr noundef nonnull %8) #4
  %.not49 = icmp eq i32 %18, 0
  br i1 %.not49, label %19, label %46

19:                                               ; preds = %17
  %20 = call i32 @bn_is_less(ptr noundef nonnull %8, ptr noundef nonnull %14) #4
  %.not50 = icmp eq i32 %20, 0
  br i1 %.not50, label %46, label %21

21:                                               ; preds = %19
  %22 = call i32 @scalar_multiply(ptr noundef %0, ptr noundef nonnull %8, ptr noundef nonnull %7)
  %23 = load i32, ptr %12, align 4, !tbaa !5
  %24 = trunc i32 %23 to i8
  %25 = and i8 %24, 1
  %26 = call i32 @bn_is_less(ptr noundef nonnull %7, ptr noundef nonnull %14) #4
  %.not51 = icmp eq i32 %26, 0
  br i1 %.not51, label %27, label %29

27:                                               ; preds = %21
  call void @bn_subtract(ptr noundef nonnull %7, ptr noundef nonnull %14, ptr noundef nonnull %7) #4
  %28 = or disjoint i8 %25, 2
  br label %29

29:                                               ; preds = %27, %21
  %.0 = phi i8 [ %25, %21 ], [ %28, %27 ]
  %30 = call i32 @bn_is_zero(ptr noundef nonnull %7) #4
  %.not52 = icmp eq i32 %30, 0
  br i1 %.not52, label %31, label %46

31:                                               ; preds = %29
  call void @bn_read_be(ptr noundef %1, ptr noundef nonnull %12) #4
  %32 = call i32 @bn_is_zero(ptr noundef nonnull %12) #4
  %.not53 = icmp eq i32 %32, 0
  br i1 %.not53, label %33, label %.loopexit

33:                                               ; preds = %31
  %34 = call i32 @bn_is_less(ptr noundef nonnull %12, ptr noundef nonnull %14) #4
  %.not54 = icmp eq i32 %34, 0
  br i1 %.not54, label %.loopexit, label %35

35:                                               ; preds = %33
  call void @generate_k_random(ptr noundef nonnull %10, ptr noundef nonnull %14)
  call void @bn_multiply(ptr noundef nonnull %10, ptr noundef nonnull %8, ptr noundef nonnull %14) #4
  call void @bn_inverse(ptr noundef nonnull %8, ptr noundef nonnull %14) #4
  call void @bn_multiply(ptr noundef nonnull %7, ptr noundef nonnull %12, ptr noundef nonnull %14) #4
  call void @bn_add(ptr noundef nonnull %12, ptr noundef nonnull %9) #4
  call void @bn_multiply(ptr noundef nonnull %8, ptr noundef nonnull %12, ptr noundef nonnull %14) #4
  call void @bn_multiply(ptr noundef nonnull %10, ptr noundef nonnull %12, ptr noundef nonnull %14) #4
  call void @bn_mod(ptr noundef nonnull %12, ptr noundef nonnull %14) #4
  %36 = call i32 @bn_is_zero(ptr noundef nonnull %12) #4
  %.not55 = icmp eq i32 %36, 0
  br i1 %.not55, label %37, label %46

37:                                               ; preds = %35
  %38 = call i32 @bn_is_less(ptr noundef nonnull %15, ptr noundef nonnull %12) #4
  %.not56 = icmp eq i32 %38, 0
  br i1 %.not56, label %41, label %39

39:                                               ; preds = %37
  call void @bn_subtract(ptr noundef nonnull %14, ptr noundef nonnull %12, ptr noundef nonnull %12) #4
  %40 = xor i8 %.0, 1
  br label %41

41:                                               ; preds = %39, %37
  %.1 = phi i8 [ %40, %39 ], [ %.0, %37 ]
  call void @bn_write_be(ptr noundef nonnull %7, ptr noundef %3) #4
  call void @bn_write_be(ptr noundef nonnull %12, ptr noundef nonnull %16) #4
  br i1 %.not57, label %44, label %42

42:                                               ; preds = %41
  %43 = call i32 %5(i8 noundef zeroext %.1, ptr noundef %3) #4
  %.not58 = icmp eq i32 %43, 0
  br i1 %.not58, label %46, label %44

44:                                               ; preds = %42, %41
  %.not59 = icmp eq ptr %4, null
  br i1 %.not59, label %.loopexit.sink.split, label %45

45:                                               ; preds = %44
  store i8 %.1, ptr %4, align 1, !tbaa !9
  br label %.loopexit.sink.split

46:                                               ; preds = %42, %35, %29, %17, %19
  %47 = add nuw nsw i32 %.04660, 1
  %exitcond.not = icmp eq i32 %47, 10000
  br i1 %exitcond.not, label %.loopexit.sink.split, label %17, !llvm.loop !10

.loopexit.sink.split:                             ; preds = %46, %44, %45
  %.045.ph = phi i32 [ 0, %45 ], [ 0, %44 ], [ -1, %46 ]
  call void @memzero(ptr noundef nonnull %8, i64 noundef 36) #4
  call void @memzero(ptr noundef nonnull %10, i64 noundef 36) #4
  call void @memzero(ptr noundef nonnull %11, i64 noundef 128) #4
  br label %.loopexit

.loopexit:                                        ; preds = %31, %33, %.loopexit.sink.split, %6
  %.045 = phi i32 [ 1, %6 ], [ %.045.ph, %.loopexit.sink.split ], [ 2, %33 ], [ 2, %31 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %11) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %7) #4
  ret i32 %.045
}

declare void @init_rfc6979(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @generate_k_rfc6979(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @bn_subtract(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass