; LLVM IR from Waqar144/simplecrypto-cxx :: simplecrypto-cxx/base58.ll (Z8b58checkPKhmPKc)

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

15:                                               ; preds = %3
  store i32 -4, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %76

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = sub i64 %18, 4
  %20 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  call void @_Z6sha256PKhmPh(ptr noundef %17, i64 noundef %19, ptr noundef %20)
  %21 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %22 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  call void @_Z6sha256PKhmPh(ptr noundef %21, i64 noundef 32, ptr noundef %22)
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = sub i64 %24, 4
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %28 = call i32 @memcmp(ptr noundef %26, ptr noundef %27, i64 noundef 4) #5
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %16
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %76

31:                                               ; preds = %16
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %51, %31
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !11
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = zext i8 %37 to i32
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %48

40:                                               ; preds = %32
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !11
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !13
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %46, 49
  br label %48

48:                                               ; preds = %40, %32
  %49 = phi i1 [ false, %32 ], [ %47, %40 ]
  br i1 %49, label %50, label %54

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %10, align 4, !tbaa !11
  %53 = add i32 %52, 1
  store i32 %53, ptr %10, align 4, !tbaa !11
  br label %32, !llvm.loop !14

54:                                               ; preds = %48
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load i32, ptr %10, align 4, !tbaa !11
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !13
  %60 = zext i8 %59 to i32
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %70, label %62

62:                                               ; preds = %54
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %10, align 4, !tbaa !11
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !13
  %68 = sext i8 %67 to i32
  %69 = icmp eq i32 %68, 49
  br i1 %69, label %70, label %71

70:                                               ; preds = %62, %54
  store i32 -3, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %76

71:                                               ; preds = %62
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i64 0
  %74 = load i8, ptr %73, align 1, !tbaa !13
  %75 = zext i8 %74 to i32
  store i32 %75, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %76

76:                                               ; preds = %71, %70, %30, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  %77 = load i32, ptr %4, align 4
  ret i32 %77
}

declare void @_Z6sha256PKhmPh(ptr noundef, i64 noundef, ptr noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 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 #4 = { nounwind }
attributes #5 = { 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++ 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: mustprogress uwtable
define dso_local noundef range(i32 -4, 256) i32 @_Z8b58checkPKhmPKc(ptr noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  %5 = icmp ult i64 %1, 4
  br i1 %5, label %.critedge.thread, label %6

6:                                                ; preds = %3
  %7 = add i64 %1, -4
  call void @_Z6sha256PKhmPh(ptr noundef %0, i64 noundef %7, ptr noundef nonnull %4)
  call void @_Z6sha256PKhmPh(ptr noundef nonnull %4, i64 noundef 32, ptr noundef nonnull %4)
  %8 = getelementptr inbounds i8, ptr %0, i64 %7
  %9 = call i32 @memcmp(ptr noundef nonnull dereferenceable(4) %8, ptr noundef nonnull dereferenceable(4) %4, i64 noundef 4) #5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.critedge.thread, label %.preheader

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

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

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

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

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

declare void @_Z6sha256PKhmPh(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @memcmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 nofree nounwind willreturn memory(argmem: 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple 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