; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/util.ll (ZN3qOS4util19hexStringToUnsignedEPKc)

; 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 i32 @_ZN3qOS4util19hexStringToUnsignedEPKc(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr null, %7
  br i1 %8, label %9, label %51

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  store i8 0, ptr %4, align 1, !tbaa !11
  br label %10

10:                                               ; preds = %49, %9
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = sext i8 %12 to i32
  %14 = icmp ne i32 0, %13
  br i1 %14, label %15, label %19

15:                                               ; preds = %10
  %16 = load i8, ptr %4, align 1, !tbaa !11
  %17 = zext i8 %16 to i32
  %18 = icmp ult i32 %17, 8
  br label %19

19:                                               ; preds = %15, %10
  %20 = phi i1 [ false, %10 ], [ %18, %15 ]
  br i1 %20, label %21, label %50

21:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i32 1
  store ptr %23, ptr %2, align 8, !tbaa !5
  %24 = load i8, ptr %22, align 1, !tbaa !11
  store i8 %24, ptr %5, align 1, !tbaa !11
  %25 = load i8, ptr %5, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = call i32 @isxdigit(i32 noundef %26) #4
  %28 = icmp ne i32 0, %27
  br i1 %28, label %29, label %38

29:                                               ; preds = %21
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = shl i32 %30, 4
  %32 = load i8, ptr %5, align 1, !tbaa !11
  %33 = call noundef zeroext i8 @_ZL17hexCharToUnsignedc(i8 noundef signext %32) #3
  %34 = zext i8 %33 to i32
  %35 = or i32 %31, %34
  store i32 %35, ptr %3, align 4, !tbaa !9
  %36 = load i8, ptr %4, align 1, !tbaa !11
  %37 = add i8 %36, 1
  store i8 %37, ptr %4, align 1, !tbaa !11
  br label %46

38:                                               ; preds = %21
  %39 = load i8, ptr %5, align 1, !tbaa !11
  %40 = sext i8 %39 to i32
  %41 = call i32 @isspace(i32 noundef %40) #4
  %42 = icmp ne i32 0, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %38
  br label %45

44:                                               ; preds = %38
  store i32 3, ptr %6, align 4
  br label %47

45:                                               ; preds = %43
  br label %46

46:                                               ; preds = %45, %29
  store i32 0, ptr %6, align 4
  br label %47

47:                                               ; preds = %46, %44
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  %48 = load i32, ptr %6, align 4
  switch i32 %48, label %53 [
    i32 0, label %49
    i32 3, label %50
  ]

49:                                               ; preds = %47
  br label %10, !llvm.loop !12

50:                                               ; preds = %47, %19
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  br label %51

51:                                               ; preds = %50, %1
  %52 = load i32, ptr %3, align 4, !tbaa !9
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %52

53:                                               ; preds = %47
  unreachable
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @isxdigit(i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i8 @_ZL17hexCharToUnsignedc(i8 noundef signext) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @isspace(i32 noundef) #2

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 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 nounwind uwtable
define dso_local noundef i32 @_ZN3qOS4util19hexStringToUnsignedEPKc(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.thread, label %.preheader

.preheader:                                       ; preds = %1
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %.not28 = icmp eq i8 %2, 0
  br i1 %.not28, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %15
  %3 = phi i8 [ %16, %15 ], [ %2, %.preheader ]
  %.01025 = phi ptr [ %5, %15 ], [ %0, %.preheader ]
  %.01124 = phi i8 [ %.2, %15 ], [ 0, %.preheader ]
  %.01223 = phi i32 [ %.214, %15 ], [ 0, %.preheader ]
  %4 = sext i8 %3 to i32
  %5 = getelementptr inbounds i8, ptr %.01025, i64 1
  %6 = tail call i32 @isxdigit(i32 noundef %4) #2
  %.not17 = icmp eq i32 %6, 0
  br i1 %.not17, label %13, label %7

7:                                                ; preds = %.lr.ph
  %8 = shl i32 %.01223, 4
  %9 = tail call noundef zeroext i8 @_ZL17hexCharToUnsignedc(i8 noundef signext %3) #3
  %10 = zext i8 %9 to i32
  %11 = or i32 %8, %10
  %12 = add nuw nsw i8 %.01124, 1
  br label %15

13:                                               ; preds = %.lr.ph
  %14 = tail call i32 @isspace(i32 noundef %4) #2
  %.not18 = icmp eq i32 %14, 0
  br i1 %.not18, label %.thread, label %15

15:                                               ; preds = %13, %7
  %.214 = phi i32 [ %11, %7 ], [ %.01223, %13 ]
  %.2 = phi i8 [ %12, %7 ], [ %.01124, %13 ]
  %16 = load i8, ptr %5, align 1, !tbaa !5
  %17 = icmp ne i8 %16, 0
  %18 = icmp ult i8 %.2, 8
  %19 = select i1 %17, i1 %18, i1 false
  br i1 %19, label %.lr.ph, label %.thread

.thread:                                          ; preds = %15, %13, %.preheader, %1
  %.4 = phi i32 [ 0, %1 ], [ 0, %.preheader ], [ %.214, %15 ], [ %.01223, %13 ]
  ret i32 %.4
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @isxdigit(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i8 @_ZL17hexCharToUnsignedc(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @isspace(i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { mustprogress nofree 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 #2 = { nounwind willreturn memory(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++ TBAA"}


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