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

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

@decoded_block_sizes = external dso_local constant [12 x i32], align 16
@.str.1 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [45 x i8], align 1
@__PRETTY_FUNCTION__.decode_block = external hidden unnamed_addr constant [49 x i8], align 1
@b58digits_map = external constant [0 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @uint_64_to_8be(i64 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @decode_block(ptr noundef %0, i64 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = icmp ule i64 1, %16
  br i1 %17, label %18, label %22

18:                                               ; preds = %3
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp ule i64 %19, 11
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  br label %23

22:                                               ; preds = %18, %3
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 94, ptr noundef @__PRETTY_FUNCTION__.decode_block) #4
  unreachable

23:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = getelementptr inbounds [12 x i32], ptr @decoded_block_sizes, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !11
  store i32 %26, ptr %8, align 4, !tbaa !11
  %27 = load i32, ptr %8, align 4, !tbaa !11
  %28 = icmp sle i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %23
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %105

30:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 1, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = sub i64 %31, 1
  store i64 %32, ptr %12, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %82, %30
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = icmp ult i64 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 2, ptr %9, align 4
  br label %85

38:                                               ; preds = %33
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %12, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = sext i8 %42 to i32
  %44 = and i32 %43, 128
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %38
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %85

47:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i64, ptr %12, align 8, !tbaa !9
  %50 = getelementptr inbounds i8, ptr %48, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !13
  %52 = sext i8 %51 to i32
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [0 x i8], ptr @b58digits_map, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !13
  %56 = sext i8 %55 to i32
  store i32 %56, ptr %13, align 4, !tbaa !11
  %57 = load i32, ptr %13, align 4, !tbaa !11
  %58 = icmp slt i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %47
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %79

60:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store i64 0, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %61 = load i64, ptr %10, align 8, !tbaa !9
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = load i32, ptr %13, align 4, !tbaa !11
  %64 = sext i32 %63 to i64
  %65 = call i64 @mul128(i64 noundef %62, i64 noundef %64, ptr noundef %14)
  %66 = add i64 %61, %65
  store i64 %66, ptr %15, align 8, !tbaa !9
  %67 = load i64, ptr %15, align 8, !tbaa !9
  %68 = load i64, ptr %10, align 8, !tbaa !9
  %69 = icmp ult i64 %67, %68
  br i1 %69, label %73, label %70

70:                                               ; preds = %60
  %71 = load i64, ptr %14, align 8, !tbaa !9
  %72 = icmp ne i64 0, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %70, %60
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %78

74:                                               ; preds = %70
  %75 = load i64, ptr %15, align 8, !tbaa !9
  store i64 %75, ptr %10, align 8, !tbaa !9
  %76 = load i64, ptr %11, align 8, !tbaa !9
  %77 = mul i64 %76, 58
  store i64 %77, ptr %11, align 8, !tbaa !9
  store i32 0, ptr %9, align 4
  br label %78

78:                                               ; preds = %74, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %79

79:                                               ; preds = %78, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  %80 = load i32, ptr %9, align 4
  switch i32 %80, label %85 [
    i32 0, label %81
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81
  %83 = load i64, ptr %12, align 8, !tbaa !9
  %84 = add i64 %83, -1
  store i64 %84, ptr %12, align 8, !tbaa !9
  br label %33, !llvm.loop !14

85:                                               ; preds = %79, %46, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %86 = load i32, ptr %9, align 4
  switch i32 %86, label %104 [
    i32 2, label %87
  ]

87:                                               ; preds = %85
  %88 = load i32, ptr %8, align 4, !tbaa !11
  %89 = sext i32 %88 to i64
  %90 = icmp ult i64 %89, 8
  br i1 %90, label %91, label %99

91:                                               ; preds = %87
  %92 = load i32, ptr %8, align 4, !tbaa !11
  %93 = mul nsw i32 8, %92
  %94 = zext i32 %93 to i64
  %95 = shl i64 1, %94
  %96 = load i64, ptr %10, align 8, !tbaa !9
  %97 = icmp ule i64 %95, %96
  br i1 %97, label %98, label %99

98:                                               ; preds = %91
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %104

99:                                               ; preds = %91, %87
  %100 = load i64, ptr %10, align 8, !tbaa !9
  %101 = load i32, ptr %8, align 4, !tbaa !11
  %102 = sext i32 %101 to i64
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  call void @uint_64_to_8be(i64 noundef %100, i64 noundef %102, ptr noundef %103)
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %104

104:                                              ; preds = %99, %98, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %105

105:                                              ; preds = %104, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %106 = load i1, ptr %4, align 1
  ret i1 %106
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @mul128(i64 noundef, i64 noundef, ptr noundef) #3

attributes #0 = { noreturn nounwind "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 = { 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 #3 = { 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 #4 = { noreturn nounwind }
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"

@decoded_block_sizes = external dso_local local_unnamed_addr constant [12 x i32], align 16
@.str.1 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [45 x i8], align 1
@__PRETTY_FUNCTION__.decode_block = external hidden unnamed_addr constant [49 x i8], align 1
@b58digits_map = external local_unnamed_addr constant [0 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @uint_64_to_8be(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @decode_block(ptr nocapture noundef readonly %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca i64, align 8
  %5 = add i64 %1, -1
  %or.cond = icmp ult i64 %5, 11
  br i1 %or.cond, label %7, label %6

6:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 94, ptr noundef nonnull @__PRETTY_FUNCTION__.decode_block) #4
  unreachable

7:                                                ; preds = %3
  %8 = getelementptr inbounds [12 x i32], ptr @decoded_block_sizes, i64 0, i64 %1
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 1
  br i1 %10, label %.thread54, label %.preheader

.preheader:                                       ; preds = %7, %19
  %.039 = phi i64 [ %22, %19 ], [ 0, %7 ]
  %.036 = phi i64 [ %26, %19 ], [ 1, %7 ]
  %.035.in = phi i64 [ %.035, %19 ], [ %1, %7 ]
  %.035 = add nsw i64 %.035.in, -1
  %.not47 = icmp ult i64 %.035, %1
  br i1 %.not47, label %11, label %27

11:                                               ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %0, i64 %.035
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %.not = icmp sgt i8 %13, -1
  br i1 %.not, label %14, label %.thread54

14:                                               ; preds = %11
  %15 = zext nneg i8 %13 to i64
  %16 = getelementptr inbounds [0 x i8], ptr @b58digits_map, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = icmp slt i8 %17, 0
  br i1 %18, label %.thread54, label %19

19:                                               ; preds = %14
  %20 = zext nneg i8 %17 to i64
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  store i64 0, ptr %4, align 8, !tbaa !10
  %21 = call i64 @mul128(i64 noundef %.036, i64 noundef %20, ptr noundef nonnull %4)
  %22 = add i64 %21, %.039
  %23 = icmp ult i64 %22, %.039
  %24 = load i64, ptr %4, align 8
  %25 = icmp ne i64 %24, 0
  %or.cond4 = select i1 %23, i1 true, i1 %25
  %26 = mul i64 %.036, 58
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  br i1 %or.cond4, label %.thread54, label %.preheader, !llvm.loop !12

27:                                               ; preds = %.preheader
  %28 = zext nneg i32 %9 to i64
  %29 = icmp ult i32 %9, 8
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = shl nuw nsw i32 %9, 3
  %32 = zext nneg i32 %31 to i64
  %.342.highbits = lshr i64 %.039, %32
  %.not48 = icmp eq i64 %.342.highbits, 0
  br i1 %.not48, label %33, label %.thread54

33:                                               ; preds = %30, %27
  call void @uint_64_to_8be(i64 noundef %.039, i64 noundef %28, ptr noundef %2)
  br label %.thread54

.thread54:                                        ; preds = %19, %14, %11, %33, %30, %7
  %.5 = phi i1 [ false, %7 ], [ true, %33 ], [ false, %30 ], [ false, %11 ], [ false, %14 ], [ false, %19 ]
  ret i1 %.5
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @mul128(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { noreturn nounwind "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 = { 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 #3 = { 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 #4 = { noreturn nounwind }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass