; LLVM IR from albertobsd/keyhunt :: base58 (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: nounwind uwtable
define dso_local i32 @b58check(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca [32 x i8], align 16
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %14, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = icmp ult i64 %15, 4
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  store i32 -4, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %79

18:                                               ; preds = %4
  %19 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = sub i64 %21, 4
  %23 = call zeroext i1 @my_dblsha256(ptr noundef %19, ptr noundef %20, i64 noundef %22)
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  store i32 -2, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %79

25:                                               ; preds = %18
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = sub i64 %27, 4
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  %30 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %31 = call i32 @memcmp(ptr noundef %29, ptr noundef %30, i64 noundef 4) #4
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %25
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %79

34:                                               ; preds = %25
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %54, %34
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load i32, ptr %12, align 4, !tbaa !11
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %51

43:                                               ; preds = %35
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load i32, ptr %12, align 4, !tbaa !11
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !13
  %49 = sext i8 %48 to i32
  %50 = icmp eq i32 %49, 49
  br label %51

51:                                               ; preds = %43, %35
  %52 = phi i1 [ false, %35 ], [ %50, %43 ]
  br i1 %52, label %53, label %57

53:                                               ; preds = %51
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %12, align 4, !tbaa !11
  %56 = add i32 %55, 1
  store i32 %56, ptr %12, align 4, !tbaa !11
  br label %35, !llvm.loop !14

57:                                               ; preds = %51
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load i32, ptr %12, align 4, !tbaa !11
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !13
  %63 = zext i8 %62 to i32
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %73, label %65

65:                                               ; preds = %57
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = load i32, ptr %12, align 4, !tbaa !11
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds i8, ptr %66, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !13
  %71 = sext i8 %70 to i32
  %72 = icmp eq i32 %71, 49
  br i1 %72, label %73, label %74

73:                                               ; preds = %65, %57
  store i32 -3, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %79

74:                                               ; preds = %65
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds i8, ptr %75, i64 0
  %77 = load i8, ptr %76, align 1, !tbaa !13
  %78 = zext i8 %77 to i32
  store i32 %78, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %79

79:                                               ; preds = %74, %73, %33, %24, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #3
  %80 = load i32, ptr %5, align 4
  ret i32 %80
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @my_dblsha256(ptr noundef, ptr noundef, i64 noundef) #1

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

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

; 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: nounwind uwtable
define dso_local range(i32 -4, 256) i32 @b58check(ptr noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  %6 = icmp ult i64 %1, 4
  br i1 %6, label %.critedge.thread, label %7

7:                                                ; preds = %4
  %8 = add i64 %1, -4
  %9 = call zeroext i1 @my_dblsha256(ptr noundef nonnull %5, ptr noundef %0, i64 noundef %8)
  br i1 %9, label %10, label %.critedge.thread

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 %8
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(4) %11, ptr noundef nonnull dereferenceable(4) %5, i64 4)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %.preheader, label %.critedge.thread

.preheader:                                       ; preds = %10
  %12 = load i8, ptr %0, align 1, !tbaa !5
  %13 = icmp eq i8 %12, 0
  br i1 %13, label %.lr.ph, label %.critedge

14:                                               ; preds = %.lr.ph
  %15 = add i32 %.019, 1
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = icmp eq i8 %18, 0
  br i1 %19, label %.lr.ph, label %.critedge, !llvm.loop !8

.lr.ph:                                           ; preds = %.preheader, %14
  %20 = phi i64 [ %16, %14 ], [ 0, %.preheader ]
  %.019 = phi i32 [ %15, %14 ], [ 0, %.preheader ]
  %21 = getelementptr inbounds i8, ptr %2, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = icmp eq i8 %22, 49
  br i1 %23, label %14, label %.critedge.thread

.critedge:                                        ; preds = %14, %.preheader
  %.lcssa = phi i64 [ 0, %.preheader ], [ %16, %14 ]
  %24 = getelementptr inbounds i8, ptr %2, i64 %.lcssa
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = icmp eq i8 %25, 49
  %27 = zext i8 %12 to i32
  %spec.select = select i1 %26, i32 -3, i32 %27
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %.lr.ph, %.critedge, %10, %7, %4
  %.016 = phi i32 [ -4, %4 ], [ -2, %7 ], [ -1, %10 ], [ %spec.select, %.critedge ], [ -3, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  ret i32 %.016
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @my_dblsha256(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nofree nounwind willreturn memory(argmem: read) }
attributes #3 = { 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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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