; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/lzma465/CPP/Common (StringToInt)

; 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 nounwind uwtable
define dso_local noundef i64 @_Z24ConvertHexStringToUInt64PKcPS0_(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %71, %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i8, ptr %11, align 1, !tbaa !11
  store i8 %12, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %13 = load i8, ptr %7, align 1, !tbaa !11
  %14 = sext i8 %13 to i32
  %15 = icmp sge i32 %14, 48
  br i1 %15, label %16, label %24

16:                                               ; preds = %10
  %17 = load i8, ptr %7, align 1, !tbaa !11
  %18 = sext i8 %17 to i32
  %19 = icmp sle i32 %18, 57
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = load i8, ptr %7, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  %23 = sub nsw i32 %22, 48
  store i32 %23, ptr %8, align 4, !tbaa !12
  br label %60

24:                                               ; preds = %16, %10
  %25 = load i8, ptr %7, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = icmp sge i32 %26, 65
  br i1 %27, label %28, label %37

28:                                               ; preds = %24
  %29 = load i8, ptr %7, align 1, !tbaa !11
  %30 = sext i8 %29 to i32
  %31 = icmp sle i32 %30, 70
  br i1 %31, label %32, label %37

32:                                               ; preds = %28
  %33 = load i8, ptr %7, align 1, !tbaa !11
  %34 = sext i8 %33 to i32
  %35 = sub nsw i32 %34, 65
  %36 = add nsw i32 10, %35
  store i32 %36, ptr %8, align 4, !tbaa !12
  br label %59

37:                                               ; preds = %28, %24
  %38 = load i8, ptr %7, align 1, !tbaa !11
  %39 = sext i8 %38 to i32
  %40 = icmp sge i32 %39, 97
  br i1 %40, label %41, label %50

41:                                               ; preds = %37
  %42 = load i8, ptr %7, align 1, !tbaa !11
  %43 = sext i8 %42 to i32
  %44 = icmp sle i32 %43, 102
  br i1 %44, label %45, label %50

45:                                               ; preds = %41
  %46 = load i8, ptr %7, align 1, !tbaa !11
  %47 = sext i8 %46 to i32
  %48 = sub nsw i32 %47, 97
  %49 = add nsw i32 10, %48
  store i32 %49, ptr %8, align 4, !tbaa !12
  br label %58

50:                                               ; preds = %41, %37
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %56

53:                                               ; preds = %50
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %54, ptr %55, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %53, %50
  %57 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %57, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %69

58:                                               ; preds = %45
  br label %59

59:                                               ; preds = %58, %32
  br label %60

60:                                               ; preds = %59, %20
  %61 = load i64, ptr %6, align 8, !tbaa !9
  %62 = shl i64 %61, 4
  store i64 %62, ptr %6, align 8, !tbaa !9
  %63 = load i32, ptr %8, align 4, !tbaa !12
  %64 = zext i32 %63 to i64
  %65 = load i64, ptr %6, align 8, !tbaa !9
  %66 = or i64 %65, %64
  store i64 %66, ptr %6, align 8, !tbaa !9
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i32 1
  store ptr %68, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %9, align 4
  br label %69

69:                                               ; preds = %60, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  %70 = load i32, ptr %9, align 4
  switch i32 %70, label %72 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %10, !llvm.loop !14

72:                                               ; preds = %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %73 = load i64, ptr %3, align 8
  ret i64 %73
}

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

!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 long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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 nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z24ConvertHexStringToUInt64PKcPS0_(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %13, %2
  %.031 = phi ptr [ %0, %2 ], [ %18, %13 ]
  %.029 = phi i64 [ 0, %2 ], [ %17, %13 ]
  %4 = load i8, ptr %.031, align 1, !tbaa !5
  %5 = sext i8 %4 to i64
  %6 = add i8 %4, -48
  %or.cond = icmp ult i8 %6, 10
  br i1 %or.cond, label %13, label %7

7:                                                ; preds = %3
  %8 = add i8 %4, -65
  %or.cond5 = icmp ult i8 %8, 6
  br i1 %or.cond5, label %13, label %9

9:                                                ; preds = %7
  %10 = add i8 %4, -97
  %or.cond8 = icmp ult i8 %10, 6
  br i1 %or.cond8, label %13, label %11

11:                                               ; preds = %9
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %19, label %12

12:                                               ; preds = %11
  store ptr %.031, ptr %1, align 8, !tbaa !8
  br label %19

13:                                               ; preds = %9, %7, %3
  %.sink = phi i64 [ 4294967248, %3 ], [ 4294967241, %7 ], [ 4294967209, %9 ]
  %14 = add nsw i64 %.sink, %5
  %15 = shl i64 %.029, 4
  %16 = and i64 %14, 4294967295
  %17 = or i64 %15, %16
  %18 = getelementptr inbounds i8, ptr %.031, i64 1
  br label %3, !llvm.loop !10

19:                                               ; preds = %12, %11
  ret i64 %.029
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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