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

; 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_info = type { ptr, ptr, i32, i32, i32, i32 }
%struct.bignum256 = type { [9 x i32] }
%struct._HMAC_SHA512_CTX = type { [128 x i8], %struct._SHA512_CTX }
%struct._SHA512_CTX = type { [8 x i64], [2 x i64], [16 x i64] }
%struct.HDNode = type { i32, i32, [32 x i8], [32 x i8], [32 x i8], [33 x i8], ptr }
%struct.ecdsa_curve = type { %struct.bignum256, %struct.curve_point, %struct.bignum256, %struct.bignum256, i32, %struct.bignum256, [64 x [8 x %struct.curve_point]] }
%struct.curve_point = type { %struct.bignum256, %struct.bignum256 }

@ed25519_cardano_info = external constant %struct.curve_info, align 8

; 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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

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

declare i32 @bn_is_zero(ptr noundef) #2

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

declare void @hmac_sha512_Init(ptr noundef, ptr noundef, i32 noundef) #2

declare void @hmac_sha512_Update(ptr noundef, ptr noundef, i32 noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @hdnode_private_ckd_bip32(ptr noundef %0, i32 noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [37 x i8], align 16
  %7 = alloca [64 x i8], align 16
  %8 = alloca %struct.bignum256, align 4
  %9 = alloca %struct.bignum256, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct._HMAC_SHA512_CTX, align 8
  %12 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 37, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 64, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 36, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 36, ptr %9) #5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.HDNode, ptr %13, i32 0, i32 6
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp eq ptr %15, @ed25519_cardano_info
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %134

18:                                               ; preds = %2
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = and i32 %19, -2147483648
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %29

22:                                               ; preds = %18
  %23 = getelementptr inbounds [37 x i8], ptr %6, i64 0, i64 0
  store i8 0, ptr %23, align 16, !tbaa !13
  %24 = getelementptr inbounds [37 x i8], ptr %6, i64 0, i64 0
  %25 = getelementptr inbounds i8, ptr %24, i64 1
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.HDNode, ptr %26, i32 0, i32 3
  %28 = getelementptr inbounds [32 x i8], ptr %27, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 8 %28, i64 32, i1 false)
  br label %47

29:                                               ; preds = %18
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.HDNode, ptr %30, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds %struct.curve_info, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = icmp ne ptr %34, null
  br i1 %35, label %37, label %36

36:                                               ; preds = %29
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %134

37:                                               ; preds = %29
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call i32 @hdnode_fill_public_key(ptr noundef %38)
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %37
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %134

42:                                               ; preds = %37
  %43 = getelementptr inbounds [37 x i8], ptr %6, i64 0, i64 0
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.HDNode, ptr %44, i32 0, i32 5
  %46 = getelementptr inbounds [33 x i8], ptr %45, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %43, ptr align 8 %46, i64 33, i1 false)
  br label %47

47:                                               ; preds = %42, %22
  %48 = getelementptr inbounds [37 x i8], ptr %6, i64 0, i64 0
  %49 = getelementptr inbounds i8, ptr %48, i64 33
  %50 = load i32, ptr %5, align 4, !tbaa !9
  call void @write_be(ptr noundef %49, i32 noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.HDNode, ptr %51, i32 0, i32 3
  %53 = getelementptr inbounds [32 x i8], ptr %52, i64 0, i64 0
  call void @bn_read_be(ptr noundef %53, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 336, ptr %11) #5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.HDNode, ptr %54, i32 0, i32 2
  %56 = getelementptr inbounds [32 x i8], ptr %55, i64 0, i64 0
  call void @hmac_sha512_Init(ptr noundef %11, ptr noundef %56, i32 noundef 32)
  %57 = getelementptr inbounds [37 x i8], ptr %6, i64 0, i64 0
  call void @hmac_sha512_Update(ptr noundef %11, ptr noundef %57, i32 noundef 37)
  %58 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  call void @hmac_sha512_Final(ptr noundef %11, ptr noundef %58)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.HDNode, ptr %59, i32 0, i32 6
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = getelementptr inbounds %struct.curve_info, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %111

65:                                               ; preds = %47
  br label %66

66:                                               ; preds = %109, %65
  br label %67

67:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #5
  store i8 0, ptr %12, align 1, !tbaa !16
  %68 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  call void @bn_read_be(ptr noundef %68, ptr noundef %9)
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.HDNode, ptr %69, i32 0, i32 6
  %71 = load ptr, ptr %70, align 8, !tbaa !11
  %72 = getelementptr inbounds %struct.curve_info, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !14
  %74 = getelementptr inbounds %struct.ecdsa_curve, ptr %73, i32 0, i32 2
  %75 = call i32 @bn_is_less(ptr noundef %9, ptr noundef %74)
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %78, label %77

77:                                               ; preds = %67
  store i8 1, ptr %12, align 1, !tbaa !16
  br label %89

78:                                               ; preds = %67
  call void @bn_add(ptr noundef %9, ptr noundef %8)
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.HDNode, ptr %79, i32 0, i32 6
  %81 = load ptr, ptr %80, align 8, !tbaa !11
  %82 = getelementptr inbounds %struct.curve_info, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %82, align 8, !tbaa !14
  %84 = getelementptr inbounds %struct.ecdsa_curve, ptr %83, i32 0, i32 2
  call void @bn_mod(ptr noundef %9, ptr noundef %84)
  %85 = call i32 @bn_is_zero(ptr noundef %9)
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %88

87:                                               ; preds = %78
  store i8 1, ptr %12, align 1, !tbaa !16
  br label %88

88:                                               ; preds = %87, %78
  br label %89

89:                                               ; preds = %88, %77
  %90 = load i8, ptr %12, align 1, !tbaa !16, !range !18, !noundef !19
  %91 = trunc i8 %90 to i1
  br i1 %91, label %96, label %92

92:                                               ; preds = %89
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.HDNode, ptr %93, i32 0, i32 3
  %95 = getelementptr inbounds [32 x i8], ptr %94, i64 0, i64 0
  call void @bn_write_be(ptr noundef %9, ptr noundef %95)
  store i32 3, ptr %10, align 4
  br label %107

96:                                               ; preds = %89
  %97 = getelementptr inbounds [37 x i8], ptr %6, i64 0, i64 0
  store i8 1, ptr %97, align 16, !tbaa !13
  %98 = getelementptr inbounds [37 x i8], ptr %6, i64 0, i64 0
  %99 = getelementptr inbounds i8, ptr %98, i64 1
  %100 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %101 = getelementptr inbounds i8, ptr %100, i64 32
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %99, ptr align 1 %101, i64 32, i1 false)
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.HDNode, ptr %102, i32 0, i32 2
  %104 = getelementptr inbounds [32 x i8], ptr %103, i64 0, i64 0
  call void @hmac_sha512_Init(ptr noundef %11, ptr noundef %104, i32 noundef 32)
  %105 = getelementptr inbounds [37 x i8], ptr %6, i64 0, i64 0
  call void @hmac_sha512_Update(ptr noundef %11, ptr noundef %105, i32 noundef 37)
  %106 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  call void @hmac_sha512_Final(ptr noundef %11, ptr noundef %106)
  store i32 0, ptr %10, align 4
  br label %107

107:                                              ; preds = %96, %92
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #5
  %108 = load i32, ptr %10, align 4
  switch i32 %108, label %136 [
    i32 0, label %109
    i32 3, label %110
  ]

109:                                              ; preds = %107
  br label %66

110:                                              ; preds = %107
  br label %116

111:                                              ; preds = %47
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.HDNode, ptr %112, i32 0, i32 3
  %114 = getelementptr inbounds [32 x i8], ptr %113, i64 0, i64 0
  %115 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %114, ptr align 16 %115, i64 32, i1 false)
  br label %116

116:                                              ; preds = %111, %110
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.HDNode, ptr %117, i32 0, i32 2
  %119 = getelementptr inbounds [32 x i8], ptr %118, i64 0, i64 0
  %120 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %121 = getelementptr inbounds i8, ptr %120, i64 32
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %119, ptr align 1 %121, i64 32, i1 false)
  %122 = load ptr, ptr %4, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.HDNode, ptr %122, i32 0, i32 0
  %124 = load i32, ptr %123, align 8, !tbaa !20
  %125 = add i32 %124, 1
  store i32 %125, ptr %123, align 8, !tbaa !20
  %126 = load i32, ptr %5, align 4, !tbaa !9
  %127 = load ptr, ptr %4, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.HDNode, ptr %127, i32 0, i32 1
  store i32 %126, ptr %128, align 4, !tbaa !21
  %129 = load ptr, ptr %4, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.HDNode, ptr %129, i32 0, i32 5
  %131 = getelementptr inbounds [33 x i8], ptr %130, i64 0, i64 0
  call void @memzero(ptr noundef %131, i64 noundef 33)
  call void @memzero(ptr noundef %8, i64 noundef 36)
  call void @memzero(ptr noundef %9, i64 noundef 36)
  %132 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  call void @memzero(ptr noundef %132, i64 noundef 64)
  %133 = getelementptr inbounds [37 x i8], ptr %6, i64 0, i64 0
  call void @memzero(ptr noundef %133, i64 noundef 37)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 336, ptr %11) #5
  br label %134

134:                                              ; preds = %116, %41, %36, %17
  call void @llvm.lifetime.end.p0(i64 36, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 37, ptr %6) #5
  %135 = load i32, ptr %3, align 4
  ret i32 %135

136:                                              ; preds = %107
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @write_be(ptr noundef, i32 noundef) #4

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #5 = { 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 = !{!12, !6, i64 144}
!12 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 40, !7, i64 72, !7, i64 104, !6, i64 144}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!16 = !{!17, !17, i64 0}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!12, !10, i64 0}
!21 = !{!12, !10, i64 4}


; 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_info = type { ptr, ptr, i32, i32, i32, i32 }
%struct.bignum256 = type { [9 x i32] }
%struct._HMAC_SHA512_CTX = type { [128 x i8], %struct._SHA512_CTX }
%struct._SHA512_CTX = type { [8 x i64], [2 x i64], [16 x i64] }

@ed25519_cardano_info = external constant %struct.curve_info, align 8

; 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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare void @memzero(ptr noundef, i64 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 void @bn_read_be(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @bn_is_zero(ptr noundef) local_unnamed_addr #2

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

declare void @hmac_sha512_Init(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @hmac_sha512_Update(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @hdnode_private_ckd_bip32(ptr noundef %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = alloca [37 x i8], align 16
  %4 = alloca [64 x i8], align 16
  %5 = alloca %struct.bignum256, align 4
  %6 = alloca %struct.bignum256, align 4
  %7 = alloca %struct._HMAC_SHA512_CTX, align 8
  call void @llvm.lifetime.start.p0(i64 37, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %6) #5
  %8 = getelementptr inbounds i8, ptr %0, i64 144
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp eq ptr %9, @ed25519_cardano_info
  br i1 %10, label %51, label %11

11:                                               ; preds = %2
  %.not = icmp sgt i32 %1, -1
  br i1 %.not, label %15, label %12

12:                                               ; preds = %11
  store i8 0, ptr %3, align 16, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %3, i64 1
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %13, ptr noundef nonnull align 8 dereferenceable(32) %14, i64 32, i1 false)
  br label %22

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %9, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %.not25 = icmp eq ptr %17, null
  br i1 %.not25, label %51, label %18

18:                                               ; preds = %15
  %19 = tail call i32 @hdnode_fill_public_key(ptr noundef nonnull %0)
  %.not26 = icmp eq i32 %19, 0
  br i1 %.not26, label %20, label %51

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %0, i64 104
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(33) %3, ptr noundef nonnull align 8 dereferenceable(33) %21, i64 33, i1 false)
  br label %22

22:                                               ; preds = %20, %12
  %23 = getelementptr inbounds i8, ptr %3, i64 33
  call void @write_be(ptr noundef nonnull %23, i32 noundef %1)
  %24 = getelementptr inbounds i8, ptr %0, i64 40
  call void @bn_read_be(ptr noundef nonnull %24, ptr noundef nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 336, ptr nonnull %7) #5
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  call void @hmac_sha512_Init(ptr noundef nonnull %7, ptr noundef nonnull %25, i32 noundef 32) #5
  call void @hmac_sha512_Update(ptr noundef nonnull %7, ptr noundef nonnull %3, i32 noundef 37) #5
  call void @hmac_sha512_Final(ptr noundef nonnull %7, ptr noundef nonnull %4) #5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %.not27 = icmp eq ptr %28, null
  br i1 %.not27, label %44, label %.preheader

.preheader:                                       ; preds = %22
  %29 = getelementptr inbounds i8, ptr %3, i64 1
  %30 = getelementptr inbounds i8, ptr %4, i64 32
  br label %31

31:                                               ; preds = %.preheader, %43
  call void @bn_read_be(ptr noundef nonnull %4, ptr noundef nonnull %6) #5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %35 = getelementptr inbounds i8, ptr %34, i64 108
  %36 = call i32 @bn_is_less(ptr noundef nonnull %6, ptr noundef nonnull %35) #5
  %.not28 = icmp eq i32 %36, 0
  br i1 %.not28, label %43, label %37

37:                                               ; preds = %31
  call void @bn_add(ptr noundef nonnull %6, ptr noundef nonnull %5) #5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 8
  %40 = load ptr, ptr %39, align 8, !tbaa !12
  %41 = getelementptr inbounds i8, ptr %40, i64 108
  call void @bn_mod(ptr noundef nonnull %6, ptr noundef nonnull %41) #5
  %42 = call i32 @bn_is_zero(ptr noundef nonnull %6) #5
  %.not29.not = icmp eq i32 %42, 0
  br i1 %.not29.not, label %.thread, label %43

.thread:                                          ; preds = %37
  call void @bn_write_be(ptr noundef nonnull %6, ptr noundef nonnull %24) #5
  br label %45

43:                                               ; preds = %37, %31
  store i8 1, ptr %3, align 16, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %29, ptr noundef nonnull align 16 dereferenceable(32) %30, i64 32, i1 false)
  call void @hmac_sha512_Init(ptr noundef nonnull %7, ptr noundef nonnull %25, i32 noundef 32) #5
  call void @hmac_sha512_Update(ptr noundef nonnull %7, ptr noundef nonnull %3, i32 noundef 37) #5
  call void @hmac_sha512_Final(ptr noundef nonnull %7, ptr noundef nonnull %4) #5
  br label %31

44:                                               ; preds = %22
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %24, ptr noundef nonnull align 16 dereferenceable(32) %4, i64 32, i1 false)
  br label %45

45:                                               ; preds = %.thread, %44
  %46 = getelementptr inbounds i8, ptr %4, i64 32
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %25, ptr noundef nonnull align 16 dereferenceable(32) %46, i64 32, i1 false)
  %47 = load i32, ptr %0, align 8, !tbaa !14
  %48 = add i32 %47, 1
  store i32 %48, ptr %0, align 8, !tbaa !14
  %49 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %1, ptr %49, align 4, !tbaa !15
  %50 = getelementptr inbounds i8, ptr %0, i64 104
  call void @memzero(ptr noundef nonnull %50, i64 noundef 33) #5
  call void @memzero(ptr noundef nonnull %5, i64 noundef 36) #5
  call void @memzero(ptr noundef nonnull %6, i64 noundef 36) #5
  call void @memzero(ptr noundef nonnull %4, i64 noundef 64) #5
  call void @memzero(ptr noundef nonnull %3, i64 noundef 37) #5
  call void @llvm.lifetime.end.p0(i64 336, ptr nonnull %7) #5
  br label %51

51:                                               ; preds = %18, %15, %2, %45
  %.023 = phi i32 [ 1, %45 ], [ 0, %2 ], [ 0, %15 ], [ 0, %18 ]
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 37, ptr nonnull %3) #5
  ret i32 %.023
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @write_be(ptr noundef, i32 noundef) local_unnamed_addr #4

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

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

declare void @bn_write_be(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: readwrite) }
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 = { inlinehint 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 #5 = { 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, !10, i64 144}
!6 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8, !8, i64 40, !8, i64 72, !8, i64 104, !10, i64 144}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !10, i64 8}
!13 = !{!"", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !7, i64 4}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass