; 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.HDNode = type { i32, i32, [32 x i8], [32 x i8], [32 x i8], [33 x i8], ptr }

@ed25519_info = external dso_local constant %struct.curve_info, align 8
@ed25519_sha3_info = external dso_local constant %struct.curve_info, align 8
@ed25519_keccak_info = external dso_local constant %struct.curve_info, align 8
@curve25519_info = external dso_local constant %struct.curve_info, align 8
@ed25519_cardano_info = external constant %struct.curve_info, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @hdnode_fill_public_key(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.HDNode, ptr %4, i32 0, i32 5
  %6 = getelementptr inbounds [33 x i8], ptr %5, i64 0, i64 0
  %7 = load i8, ptr %6, align 8, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %11

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

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.HDNode, ptr %12, i32 0, i32 6
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  %15 = getelementptr inbounds %struct.curve_info, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %34

18:                                               ; preds = %11
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.HDNode, ptr %19, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !10
  %22 = getelementptr inbounds %struct.curve_info, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.HDNode, ptr %24, i32 0, i32 3
  %26 = getelementptr inbounds [32 x i8], ptr %25, i64 0, i64 0
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.HDNode, ptr %27, i32 0, i32 5
  %29 = getelementptr inbounds [33 x i8], ptr %28, i64 0, i64 0
  %30 = call i32 @ecdsa_get_public_key33(ptr noundef %23, ptr noundef %26, ptr noundef %29)
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %18
  store i32 1, ptr %2, align 4
  br label %108

33:                                               ; preds = %18
  br label %107

34:                                               ; preds = %11
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.HDNode, ptr %35, i32 0, i32 5
  %37 = getelementptr inbounds [33 x i8], ptr %36, i64 0, i64 0
  store i8 1, ptr %37, align 8, !tbaa !9
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.HDNode, ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !10
  %41 = icmp eq ptr %40, @ed25519_info
  br i1 %41, label %42, label %50

42:                                               ; preds = %34
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.HDNode, ptr %43, i32 0, i32 3
  %45 = getelementptr inbounds [32 x i8], ptr %44, i64 0, i64 0
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.HDNode, ptr %46, i32 0, i32 5
  %48 = getelementptr inbounds [33 x i8], ptr %47, i64 0, i64 0
  %49 = getelementptr inbounds i8, ptr %48, i64 1
  call void @ed25519_publickey(ptr noundef %45, ptr noundef %49)
  br label %106

50:                                               ; preds = %34
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.HDNode, ptr %51, i32 0, i32 6
  %53 = load ptr, ptr %52, align 8, !tbaa !10
  %54 = icmp eq ptr %53, @ed25519_sha3_info
  br i1 %54, label %55, label %63

55:                                               ; preds = %50
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.HDNode, ptr %56, i32 0, i32 3
  %58 = getelementptr inbounds [32 x i8], ptr %57, i64 0, i64 0
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.HDNode, ptr %59, i32 0, i32 5
  %61 = getelementptr inbounds [33 x i8], ptr %60, i64 0, i64 0
  %62 = getelementptr inbounds i8, ptr %61, i64 1
  call void @ed25519_publickey_sha3(ptr noundef %58, ptr noundef %62)
  br label %105

63:                                               ; preds = %50
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.HDNode, ptr %64, i32 0, i32 6
  %66 = load ptr, ptr %65, align 8, !tbaa !10
  %67 = icmp eq ptr %66, @ed25519_keccak_info
  br i1 %67, label %68, label %76

68:                                               ; preds = %63
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.HDNode, ptr %69, i32 0, i32 3
  %71 = getelementptr inbounds [32 x i8], ptr %70, i64 0, i64 0
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.HDNode, ptr %72, i32 0, i32 5
  %74 = getelementptr inbounds [33 x i8], ptr %73, i64 0, i64 0
  %75 = getelementptr inbounds i8, ptr %74, i64 1
  call void @ed25519_publickey_keccak(ptr noundef %71, ptr noundef %75)
  br label %104

76:                                               ; preds = %63
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.HDNode, ptr %77, i32 0, i32 6
  %79 = load ptr, ptr %78, align 8, !tbaa !10
  %80 = icmp eq ptr %79, @curve25519_info
  br i1 %80, label %81, label %89

81:                                               ; preds = %76
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.HDNode, ptr %82, i32 0, i32 5
  %84 = getelementptr inbounds [33 x i8], ptr %83, i64 0, i64 0
  %85 = getelementptr inbounds i8, ptr %84, i64 1
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.HDNode, ptr %86, i32 0, i32 3
  %88 = getelementptr inbounds [32 x i8], ptr %87, i64 0, i64 0
  call void @curve25519_scalarmult_basepoint(ptr noundef %85, ptr noundef %88)
  br label %103

89:                                               ; preds = %76
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.HDNode, ptr %90, i32 0, i32 6
  %92 = load ptr, ptr %91, align 8, !tbaa !10
  %93 = icmp eq ptr %92, @ed25519_cardano_info
  br i1 %93, label %94, label %102

94:                                               ; preds = %89
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.HDNode, ptr %95, i32 0, i32 3
  %97 = getelementptr inbounds [32 x i8], ptr %96, i64 0, i64 0
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.HDNode, ptr %98, i32 0, i32 5
  %100 = getelementptr inbounds [33 x i8], ptr %99, i64 0, i64 0
  %101 = getelementptr inbounds i8, ptr %100, i64 1
  call void @ed25519_publickey_ext(ptr noundef %97, ptr noundef %101)
  br label %102

102:                                              ; preds = %94, %89
  br label %103

103:                                              ; preds = %102, %81
  br label %104

104:                                              ; preds = %103, %68
  br label %105

105:                                              ; preds = %104, %55
  br label %106

106:                                              ; preds = %105, %42
  br label %107

107:                                              ; preds = %106, %33
  store i32 0, ptr %2, align 4
  br label %108

108:                                              ; preds = %107, %32, %10
  %109 = load i32, ptr %2, align 4
  ret i32 %109
}

declare i32 @ecdsa_get_public_key33(ptr noundef, ptr noundef, ptr noundef) #1

declare void @ed25519_publickey(ptr noundef, ptr noundef) #1

declare void @ed25519_publickey_sha3(ptr noundef, ptr noundef) #1

declare void @ed25519_publickey_keccak(ptr noundef, ptr noundef) #1

declare void @curve25519_scalarmult_basepoint(ptr noundef, ptr noundef) #1

declare void @ed25519_publickey_ext(ptr noundef, ptr noundef) #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 = { "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" }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 144}
!11 = !{!"", !12, i64 0, !12, i64 4, !7, i64 8, !7, i64 40, !7, i64 72, !7, i64 104, !6, i64 144}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28}


; 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 }

@ed25519_info = external dso_local constant %struct.curve_info, align 8
@ed25519_sha3_info = external dso_local constant %struct.curve_info, align 8
@ed25519_keccak_info = external dso_local constant %struct.curve_info, align 8
@curve25519_info = external dso_local constant %struct.curve_info, align 8
@ed25519_cardano_info = external constant %struct.curve_info, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @hdnode_fill_public_key(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 104
  %3 = load i8, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %4, label %38

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 144
  %6 = load ptr, ptr %5, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %.not23 = icmp eq ptr %8, null
  br i1 %.not23, label %12, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = tail call i32 @ecdsa_get_public_key33(ptr noundef nonnull %8, ptr noundef nonnull %10, ptr noundef nonnull %2) #2
  %.not24 = icmp eq i32 %11, 0
  br i1 %.not24, label %37, label %38

12:                                               ; preds = %4
  store i8 1, ptr %2, align 8, !tbaa !5
  %13 = icmp eq ptr %6, @ed25519_info
  br i1 %13, label %14, label %17

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = getelementptr inbounds i8, ptr %0, i64 105
  tail call void @ed25519_publickey(ptr noundef nonnull %15, ptr noundef nonnull %16) #2
  br label %37

17:                                               ; preds = %12
  %18 = icmp eq ptr %6, @ed25519_sha3_info
  br i1 %18, label %19, label %22

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %0, i64 40
  %21 = getelementptr inbounds i8, ptr %0, i64 105
  tail call void @ed25519_publickey_sha3(ptr noundef nonnull %20, ptr noundef nonnull %21) #2
  br label %37

22:                                               ; preds = %17
  %23 = icmp eq ptr %6, @ed25519_keccak_info
  br i1 %23, label %24, label %27

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = getelementptr inbounds i8, ptr %0, i64 105
  tail call void @ed25519_publickey_keccak(ptr noundef nonnull %25, ptr noundef nonnull %26) #2
  br label %37

27:                                               ; preds = %22
  %28 = icmp eq ptr %6, @curve25519_info
  br i1 %28, label %29, label %32

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %0, i64 105
  %31 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @curve25519_scalarmult_basepoint(ptr noundef nonnull %30, ptr noundef nonnull %31) #2
  br label %37

32:                                               ; preds = %27
  %33 = icmp eq ptr %6, @ed25519_cardano_info
  br i1 %33, label %34, label %37

34:                                               ; preds = %32
  %35 = getelementptr inbounds i8, ptr %0, i64 40
  %36 = getelementptr inbounds i8, ptr %0, i64 105
  tail call void @ed25519_publickey_ext(ptr noundef nonnull %35, ptr noundef nonnull %36) #2
  br label %37

37:                                               ; preds = %14, %24, %32, %34, %29, %19, %9
  br label %38

38:                                               ; preds = %9, %1, %37
  %.0 = phi i32 [ 0, %37 ], [ 0, %1 ], [ 1, %9 ]
  ret i32 %.0
}

declare i32 @ecdsa_get_public_key33(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ed25519_publickey(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ed25519_publickey_sha3(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ed25519_publickey_keccak(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @curve25519_scalarmult_basepoint(ptr noundef, ptr noundef) local_unnamed_addr #1

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass