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

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

%union.nano_address_raw = type { [40 x i8] }
%struct.__blake2b_state = type { [8 x i64], [2 x i64], [2 x i64], [128 x i8], i64, i64, i8 }
%union.nano_address_encoded = type { [65 x i8] }
%struct.anon = type { [3 x i8], [32 x i8], [5 x i8] }
%struct.anon.0 = type { [4 x i8], [60 x i8], i8 }

@BASE32_ALPHABET_NANO = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @nano_get_address(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca %union.nano_address_raw, align 1
  %13 = alloca [5 x i8], align 1
  %14 = alloca %struct.__blake2b_state, align 8
  %15 = alloca i32, align 4
  %16 = alloca %union.nano_address_encoded, align 1
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  %20 = load i64, ptr %11, align 8, !tbaa !9
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = add i64 %21, 60
  %23 = add i64 %22, 1
  %24 = icmp ult i64 %20, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %5
  store i64 0, ptr %6, align 8
  br label %84

26:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 40, ptr %12) #5
  call void @llvm.memset.p0.i64(ptr align 1 %12, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 5, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 248, ptr %14) #5
  %27 = call i32 @tc_blake2b_Init(ptr noundef %14, i64 noundef 5)
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call i32 @tc_blake2b_Update(ptr noundef %14, ptr noundef %28, i64 noundef 32)
  %30 = getelementptr inbounds [5 x i8], ptr %13, i64 0, i64 0
  %31 = call i32 @tc_blake2b_Final(ptr noundef %14, ptr noundef %30, i64 noundef 5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 0, ptr %15, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %47, %26
  %33 = load i32, ptr %15, align 4, !tbaa !11
  %34 = icmp slt i32 %33, 5
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %50

36:                                               ; preds = %32
  %37 = load i32, ptr %15, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [5 x i8], ptr %13, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 2
  %42 = load i32, ptr %15, align 4, !tbaa !11
  %43 = add nsw i32 %42, 1
  %44 = sub nsw i32 5, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [5 x i8], ptr %41, i64 0, i64 %45
  store i8 %40, ptr %46, align 1, !tbaa !13
  br label %47

47:                                               ; preds = %36
  %48 = load i32, ptr %15, align 4, !tbaa !11
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %15, align 4, !tbaa !11
  br label %32, !llvm.loop !14

50:                                               ; preds = %35
  %51 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 1
  %52 = getelementptr inbounds [32 x i8], ptr %51, i64 0, i64 0
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %52, ptr align 1 %53, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 65, ptr %16) #5
  call void @llvm.memset.p0.i64(ptr align 1 %16, i8 0, i64 65, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %54 = getelementptr inbounds [40 x i8], ptr %12, i64 0, i64 0
  %55 = getelementptr inbounds [65 x i8], ptr %16, i64 0, i64 0
  %56 = load ptr, ptr @BASE32_ALPHABET_NANO, align 8, !tbaa !5
  %57 = call ptr @base32_encode(ptr noundef %54, i64 noundef 40, ptr noundef %55, i64 noundef 65, ptr noundef %56)
  store ptr %57, ptr %17, align 8, !tbaa !5
  %58 = load ptr, ptr %17, align 8, !tbaa !5
  %59 = icmp eq ptr %58, null
  br i1 %59, label %60, label %61

60:                                               ; preds = %50
  store i64 0, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %83

61:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  store i64 0, ptr %19, align 8, !tbaa !9
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load i64, ptr %19, align 8, !tbaa !9
  %64 = getelementptr inbounds i8, ptr %62, i64 %63
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %64, ptr align 1 %65, i64 %66, i1 false)
  %67 = load i64, ptr %9, align 8, !tbaa !9
  %68 = load i64, ptr %19, align 8, !tbaa !9
  %69 = add i64 %68, %67
  store i64 %69, ptr %19, align 8, !tbaa !9
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = load i64, ptr %19, align 8, !tbaa !9
  %72 = getelementptr inbounds i8, ptr %70, i64 %71
  %73 = getelementptr inbounds %struct.anon.0, ptr %16, i32 0, i32 1
  %74 = getelementptr inbounds [60 x i8], ptr %73, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %72, ptr align 1 %74, i64 60, i1 false)
  %75 = load i64, ptr %19, align 8, !tbaa !9
  %76 = add i64 %75, 60
  store i64 %76, ptr %19, align 8, !tbaa !9
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load i64, ptr %19, align 8, !tbaa !9
  %79 = getelementptr inbounds i8, ptr %77, i64 %78
  store i8 0, ptr %79, align 1, !tbaa !13
  %80 = load i64, ptr %19, align 8, !tbaa !9
  %81 = add i64 %80, 1
  store i64 %81, ptr %19, align 8, !tbaa !9
  %82 = load i64, ptr %19, align 8, !tbaa !9
  store i64 %82, ptr %6, align 8
  store i32 1, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  br label %83

83:                                               ; preds = %61, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 65, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 248, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 5, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %12) #5
  br label %84

84:                                               ; preds = %83, %25
  %85 = load i64, ptr %6, align 8
  ret i64 %85
}

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

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

declare i32 @tc_blake2b_Init(ptr noundef, i64 noundef) #3

declare i32 @tc_blake2b_Update(ptr noundef, ptr noundef, i64 noundef) #3

declare i32 @tc_blake2b_Final(ptr noundef, ptr noundef, i64 noundef) #3

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

; 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) #4

declare ptr @base32_encode(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #3

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

%union.nano_address_raw = type { [40 x i8] }
%struct.__blake2b_state = type { [8 x i64], [2 x i64], [2 x i64], [128 x i8], i64, i64, i8 }
%union.nano_address_encoded = type { [65 x i8] }

@BASE32_ALPHABET_NANO = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @nano_get_address(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef writeonly %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = alloca %union.nano_address_raw, align 1
  %7 = alloca [5 x i8], align 1
  %8 = alloca %struct.__blake2b_state, align 8
  %9 = alloca %union.nano_address_encoded, align 1
  %10 = add i64 %2, 61
  %11 = icmp ugt i64 %10, %4
  br i1 %11, label %31, label %12

12:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %6) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(40) %6, i8 0, i64 3, i1 false)
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %7) #5
  call void @llvm.lifetime.start.p0(i64 248, ptr nonnull %8) #5
  %13 = call i32 @tc_blake2b_Init(ptr noundef nonnull %8, i64 noundef 5) #5
  %14 = call i32 @tc_blake2b_Update(ptr noundef nonnull %8, ptr noundef %0, i64 noundef 32) #5
  %15 = call i32 @tc_blake2b_Final(ptr noundef nonnull %8, ptr noundef nonnull %7, i64 noundef 5) #5
  %16 = getelementptr inbounds i8, ptr %6, i64 35
  %17 = load i8, ptr %7, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %6, i64 39
  store i8 %17, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %7, i64 1
  %20 = load <4 x i8>, ptr %19, align 1, !tbaa !5
  %21 = shufflevector <4 x i8> %20, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i8> %21, ptr %16, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %6, i64 3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %22, ptr noundef nonnull align 1 dereferenceable(32) %0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 65, ptr nonnull %9) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(65) %9, i8 0, i64 65, i1 false)
  %23 = load ptr, ptr @BASE32_ALPHABET_NANO, align 8, !tbaa !8
  %24 = call ptr @base32_encode(ptr noundef nonnull %6, i64 noundef 40, ptr noundef nonnull %9, i64 noundef 65, ptr noundef %23) #5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %30, label %26

26:                                               ; preds = %12
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr align 1 %1, i64 %2, i1 false)
  %27 = getelementptr inbounds i8, ptr %3, i64 %2
  %28 = getelementptr inbounds i8, ptr %9, i64 4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(60) %27, ptr noundef nonnull align 1 dereferenceable(60) %28, i64 60, i1 false)
  %29 = getelementptr i8, ptr %27, i64 60
  store i8 0, ptr %29, align 1, !tbaa !5
  br label %30

30:                                               ; preds = %12, %26
  %.0 = phi i64 [ %10, %26 ], [ 0, %12 ]
  call void @llvm.lifetime.end.p0(i64 65, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 248, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %6) #5
  br label %31

31:                                               ; preds = %5, %30
  %.1 = phi i64 [ %.0, %30 ], [ 0, %5 ]
  ret i64 %.1
}

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

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

declare i32 @tc_blake2b_Init(ptr noundef, i64 noundef) local_unnamed_addr #3

declare i32 @tc_blake2b_Update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

declare i32 @tc_blake2b_Final(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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

; 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) #4

declare ptr @base32_encode(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass