; LLVM IR from square/subzero :: core/trezor-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"

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @xmr_base58_decode(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

declare void @hasher_Raw(i32 noundef, ptr noundef, i64 noundef, ptr noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @xmr_base58_addr_decode_check(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca [32 x i8], align 16
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  store i64 69, ptr %12, align 8, !tbaa !9
  %18 = load i64, ptr %12, align 8, !tbaa !9
  %19 = call ptr @llvm.stacksave.p0()
  store ptr %19, ptr %13, align 8
  %20 = alloca i8, i64 %18, align 16
  store i64 %18, ptr %14, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr %15) #6
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = call zeroext i1 @xmr_base58_decode(ptr noundef %21, i64 noundef %22, ptr noundef %20, ptr noundef %12)
  br i1 %23, label %25, label %24

24:                                               ; preds = %5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %64

25:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  %26 = load i64, ptr %12, align 8, !tbaa !9
  %27 = sub i64 %26, 4
  %28 = sub i64 %27, 1
  store i64 %28, ptr %17, align 8, !tbaa !9
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = load i64, ptr %17, align 8, !tbaa !9
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %63

33:                                               ; preds = %25
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = icmp ule i64 %34, 5
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %63

37:                                               ; preds = %33
  %38 = load i64, ptr %12, align 8, !tbaa !9
  %39 = sub i64 %38, 4
  %40 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  call void @hasher_Raw(i32 noundef 4, ptr noundef %20, i64 noundef %39, ptr noundef %40)
  %41 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  %42 = load i64, ptr %12, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %20, i64 %42
  %44 = getelementptr inbounds i8, ptr %43, i64 -4
  %45 = call i32 @memcmp(ptr noundef %41, ptr noundef %44, i64 noundef 4) #7
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %37
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %63

48:                                               ; preds = %37
  %49 = getelementptr inbounds i8, ptr %20, i64 0
  %50 = load i8, ptr %49, align 16, !tbaa !11
  %51 = zext i8 %50 to i64
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %51, ptr %52, align 8, !tbaa !9
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = icmp ugt i64 %54, 127
  br i1 %55, label %56, label %57

56:                                               ; preds = %48
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %63

57:                                               ; preds = %48
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %20, i64 1
  %60 = load i64, ptr %17, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %58, ptr align 1 %59, i64 %60, i1 false)
  %61 = load i64, ptr %17, align 8, !tbaa !9
  %62 = trunc i64 %61 to i32
  store i32 %62, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %63

63:                                               ; preds = %57, %56, %47, %36, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  br label %64

64:                                               ; preds = %63, %24
  call void @llvm.lifetime.end.p0(i64 32, ptr %15) #6
  %65 = load ptr, ptr %13, align 8
  call void @llvm.stackrestore.p0(ptr %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  %66 = load i32, ptr %6, align 4
  ret i32 %66
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { nocallback nofree nosync nounwind willreturn }
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 willreturn memory(read) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!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: 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @xmr_base58_decode(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

declare void @hasher_Raw(i32 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @xmr_base58_addr_decode_check(ptr noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3, i64 noundef %4) local_unnamed_addr #2 {
  %6 = alloca i64, align 8
  %7 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #6
  store i64 69, ptr %6, align 8, !tbaa !5
  %8 = tail call ptr @llvm.stacksave.p0()
  %9 = alloca [69 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #6
  %10 = call zeroext i1 @xmr_base58_decode(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %9, ptr noundef nonnull %6)
  br i1 %10, label %11, label %28

11:                                               ; preds = %5
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = add i64 %12, -5
  %14 = icmp ugt i64 %13, %4
  %15 = icmp ult i64 %12, 6
  %or.cond = or i1 %15, %14
  br i1 %or.cond, label %28, label %16

16:                                               ; preds = %11
  %17 = add i64 %12, -4
  call void @hasher_Raw(i32 noundef 4, ptr noundef nonnull %9, i64 noundef %17, ptr noundef nonnull %7) #6
  %18 = load i64, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %9, i64 %18
  %20 = getelementptr inbounds i8, ptr %19, i64 -4
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(4) %7, ptr noundef nonnull dereferenceable(4) %20, i64 4)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %21, label %28

21:                                               ; preds = %16
  %22 = load i8, ptr %9, align 16, !tbaa !9
  %23 = zext i8 %22 to i64
  store i64 %23, ptr %2, align 8, !tbaa !5
  %24 = icmp slt i8 %22, 0
  br i1 %24, label %28, label %25

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %9, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr nonnull align 1 %26, i64 %13, i1 false)
  %27 = trunc i64 %13 to i32
  br label %28

28:                                               ; preds = %25, %11, %16, %21, %5
  %.1 = phi i32 [ 0, %5 ], [ %27, %25 ], [ 0, %11 ], [ 0, %16 ], [ 0, %21 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #6
  call void @llvm.stackrestore.p0(ptr %8)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #6
  ret i32 %.1
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #5

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass