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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @script_output_to_address(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca [35 x i8], align 16
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 35, ptr %10) #5
  call void @llvm.memset.p0.i64(ptr align 16 %10, i8 0, i64 35, i1 false)
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 25
  br i1 %13, label %14, label %54

14:                                               ; preds = %4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 0
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = icmp eq i32 %18, 118
  br i1 %19, label %20, label %54

20:                                               ; preds = %14
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 1
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = icmp eq i32 %24, 169
  br i1 %25, label %26, label %54

26:                                               ; preds = %20
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 2
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = icmp eq i32 %30, 20
  br i1 %31, label %32, label %54

32:                                               ; preds = %26
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 23
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = icmp eq i32 %36, 136
  br i1 %37, label %38, label %54

38:                                               ; preds = %32
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 24
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = zext i8 %41 to i32
  %43 = icmp eq i32 %42, 172
  br i1 %43, label %44, label %54

44:                                               ; preds = %38
  %45 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  store i8 0, ptr %45, align 16, !tbaa !11
  %46 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  %47 = getelementptr inbounds i8, ptr %46, i64 1
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i64 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %47, ptr align 1 %49, i64 20, i1 false)
  %50 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = call i32 @base58_encode_check(ptr noundef %50, i32 noundef 21, i32 noundef 1, ptr noundef %51, i32 noundef %52)
  store i32 %53, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %140

54:                                               ; preds = %38, %32, %26, %20, %14, %4
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 23
  br i1 %56, label %57, label %85

57:                                               ; preds = %54
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 0
  %60 = load i8, ptr %59, align 1, !tbaa !11
  %61 = zext i8 %60 to i32
  %62 = icmp eq i32 %61, 169
  br i1 %62, label %63, label %85

63:                                               ; preds = %57
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 1
  %66 = load i8, ptr %65, align 1, !tbaa !11
  %67 = zext i8 %66 to i32
  %68 = icmp eq i32 %67, 20
  br i1 %68, label %69, label %85

69:                                               ; preds = %63
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 22
  %72 = load i8, ptr %71, align 1, !tbaa !11
  %73 = zext i8 %72 to i32
  %74 = icmp eq i32 %73, 135
  br i1 %74, label %75, label %85

75:                                               ; preds = %69
  %76 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  store i8 5, ptr %76, align 16, !tbaa !11
  %77 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  %78 = getelementptr inbounds i8, ptr %77, i64 1
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds i8, ptr %79, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %78, ptr align 1 %80, i64 20, i1 false)
  %81 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = call i32 @base58_encode_check(ptr noundef %81, i32 noundef 21, i32 noundef 1, ptr noundef %82, i32 noundef %83)
  store i32 %84, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %140

85:                                               ; preds = %69, %63, %57, %54
  %86 = load i32, ptr %7, align 4, !tbaa !9
  %87 = icmp eq i32 %86, 22
  br i1 %87, label %88, label %112

88:                                               ; preds = %85
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i64 0
  %91 = load i8, ptr %90, align 1, !tbaa !11
  %92 = zext i8 %91 to i32
  %93 = icmp eq i32 %92, 0
  br i1 %93, label %94, label %112

94:                                               ; preds = %88
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds i8, ptr %95, i64 1
  %97 = load i8, ptr %96, align 1, !tbaa !11
  %98 = zext i8 %97 to i32
  %99 = icmp eq i32 %98, 20
  br i1 %99, label %100, label %112

100:                                              ; preds = %94
  %101 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  store i8 6, ptr %101, align 16, !tbaa !11
  %102 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 1
  store i8 0, ptr %102, align 1, !tbaa !11
  %103 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 2
  store i8 0, ptr %103, align 2, !tbaa !11
  %104 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  %105 = getelementptr inbounds i8, ptr %104, i64 3
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  %107 = getelementptr inbounds i8, ptr %106, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %105, ptr align 1 %107, i64 20, i1 false)
  %108 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = load i32, ptr %9, align 4, !tbaa !9
  %111 = call i32 @base58_encode_check(ptr noundef %108, i32 noundef 23, i32 noundef 1, ptr noundef %109, i32 noundef %110)
  store i32 %111, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %140

112:                                              ; preds = %94, %88, %85
  %113 = load i32, ptr %7, align 4, !tbaa !9
  %114 = icmp eq i32 %113, 34
  br i1 %114, label %115, label %139

115:                                              ; preds = %112
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  %117 = getelementptr inbounds i8, ptr %116, i64 0
  %118 = load i8, ptr %117, align 1, !tbaa !11
  %119 = zext i8 %118 to i32
  %120 = icmp eq i32 %119, 0
  br i1 %120, label %121, label %139

121:                                              ; preds = %115
  %122 = load ptr, ptr %6, align 8, !tbaa !5
  %123 = getelementptr inbounds i8, ptr %122, i64 1
  %124 = load i8, ptr %123, align 1, !tbaa !11
  %125 = zext i8 %124 to i32
  %126 = icmp eq i32 %125, 32
  br i1 %126, label %127, label %139

127:                                              ; preds = %121
  %128 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  store i8 10, ptr %128, align 16, !tbaa !11
  %129 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 1
  store i8 0, ptr %129, align 1, !tbaa !11
  %130 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 2
  store i8 0, ptr %130, align 2, !tbaa !11
  %131 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  %132 = getelementptr inbounds i8, ptr %131, i64 3
  %133 = load ptr, ptr %6, align 8, !tbaa !5
  %134 = getelementptr inbounds i8, ptr %133, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %132, ptr align 1 %134, i64 32, i1 false)
  %135 = getelementptr inbounds [35 x i8], ptr %10, i64 0, i64 0
  %136 = load ptr, ptr %8, align 8, !tbaa !5
  %137 = load i32, ptr %9, align 4, !tbaa !9
  %138 = call i32 @base58_encode_check(ptr noundef %135, i32 noundef 35, i32 noundef 1, ptr noundef %136, i32 noundef %137)
  store i32 %138, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %140

139:                                              ; preds = %121, %115, %112
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %140

140:                                              ; preds = %139, %127, %100, %75, %44
  call void @llvm.lifetime.end.p0(i64 35, ptr %10) #5
  %141 = load i32, ptr %5, align 4
  ret i32 %141
}

; 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

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

declare i32 @base58_encode_check(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 = !{!7, !7, i64 0}


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

; Function Attrs: nounwind uwtable
define dso_local i32 @script_output_to_address(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [35 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 35, ptr nonnull %5) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(35) %5, i8 0, i64 35, i1 false)
  switch i32 %1, label %65 [
    i32 25, label %6
    i32 23, label %28
    i32 22, label %42
    i32 34, label %53
  ]

6:                                                ; preds = %4
  %7 = load i8, ptr %0, align 1, !tbaa !5
  %8 = icmp eq i8 %7, 118
  br i1 %8, label %9, label %65

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 1
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = icmp eq i8 %11, -87
  br i1 %12, label %13, label %65

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 2
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = icmp eq i8 %15, 20
  br i1 %16, label %17, label %65

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %0, i64 23
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = icmp eq i8 %19, -120
  br i1 %20, label %21, label %65

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = icmp eq i8 %23, -84
  br i1 %24, label %25, label %65

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %5, i64 1
  %27 = getelementptr inbounds i8, ptr %0, i64 3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(20) %26, ptr noundef nonnull align 1 dereferenceable(20) %27, i64 20, i1 false)
  br label %.sink.split

28:                                               ; preds = %4
  %29 = load i8, ptr %0, align 1, !tbaa !5
  %30 = icmp eq i8 %29, -87
  br i1 %30, label %31, label %65

31:                                               ; preds = %28
  %32 = getelementptr inbounds i8, ptr %0, i64 1
  %33 = load i8, ptr %32, align 1, !tbaa !5
  %34 = icmp eq i8 %33, 20
  br i1 %34, label %35, label %65

35:                                               ; preds = %31
  %36 = getelementptr inbounds i8, ptr %0, i64 22
  %37 = load i8, ptr %36, align 1, !tbaa !5
  %38 = icmp eq i8 %37, -121
  br i1 %38, label %39, label %65

39:                                               ; preds = %35
  store i8 5, ptr %5, align 16, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %5, i64 1
  %41 = getelementptr inbounds i8, ptr %0, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(20) %40, ptr noundef nonnull align 1 dereferenceable(20) %41, i64 20, i1 false)
  br label %.sink.split

42:                                               ; preds = %4
  %43 = load i8, ptr %0, align 1, !tbaa !5
  %44 = icmp eq i8 %43, 0
  br i1 %44, label %45, label %65

45:                                               ; preds = %42
  %46 = getelementptr inbounds i8, ptr %0, i64 1
  %47 = load i8, ptr %46, align 1, !tbaa !5
  %48 = icmp eq i8 %47, 20
  br i1 %48, label %49, label %65

49:                                               ; preds = %45
  store i8 6, ptr %5, align 16, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %5, i64 2
  store i8 0, ptr %50, align 2, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %5, i64 3
  %52 = getelementptr inbounds i8, ptr %0, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(20) %51, ptr noundef nonnull align 1 dereferenceable(20) %52, i64 20, i1 false)
  br label %.sink.split

53:                                               ; preds = %4
  %54 = load i8, ptr %0, align 1, !tbaa !5
  %55 = icmp eq i8 %54, 0
  br i1 %55, label %56, label %65

56:                                               ; preds = %53
  %57 = getelementptr inbounds i8, ptr %0, i64 1
  %58 = load i8, ptr %57, align 1, !tbaa !5
  %59 = icmp eq i8 %58, 32
  br i1 %59, label %60, label %65

60:                                               ; preds = %56
  store i8 10, ptr %5, align 16, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %5, i64 2
  store i8 0, ptr %61, align 2, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %5, i64 3
  %63 = getelementptr inbounds i8, ptr %0, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %62, ptr noundef nonnull align 1 dereferenceable(32) %63, i64 32, i1 false)
  br label %.sink.split

.sink.split:                                      ; preds = %25, %39, %49, %60
  %.sink = phi i32 [ 35, %60 ], [ 23, %49 ], [ 21, %39 ], [ 21, %25 ]
  %64 = call i32 @base58_encode_check(ptr noundef nonnull %5, i32 noundef %.sink, i32 noundef 1, ptr noundef %2, i32 noundef %3) #5
  br label %65

65:                                               ; preds = %.sink.split, %42, %45, %28, %31, %35, %6, %9, %13, %17, %21, %53, %56, %4
  %.0 = phi i32 [ 0, %4 ], [ 0, %56 ], [ 0, %53 ], [ 0, %21 ], [ 0, %17 ], [ 0, %13 ], [ 0, %9 ], [ 0, %6 ], [ 0, %35 ], [ 0, %31 ], [ 0, %28 ], [ 0, %45 ], [ 0, %42 ], [ %64, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 35, ptr nonnull %5) #5
  ret i32 %.0
}

; 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

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

declare i32 @base58_encode_check(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass