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

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS4util10printXDataEPFvPvcES1_mbS1_(ptr noundef %0, ptr noundef %1, i64 noundef %2, i1 noundef zeroext %3, ptr noundef %4) #2 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  %14 = zext i1 %3 to i8
  store i8 %14, ptr %9, align 1, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  store i8 0, ptr %11, align 1, !tbaa !11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr null, %15
  br i1 %16, label %17, label %67

17:                                               ; preds = %5
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = icmp ugt i64 %18, 0
  br i1 %19, label %20, label %67

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %21, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %53, %20
  %23 = load i64, ptr %13, align 8, !tbaa !9
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %56

27:                                               ; preds = %22
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = load i64, ptr %13, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %30, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !13
  %34 = zext i8 %33 to i32
  %35 = ashr i32 %34, 4
  %36 = trunc i32 %35 to i8
  %37 = call noundef signext i8 @_ZL9nibbleToXh(i8 noundef zeroext %36) #3
  invoke void %28(ptr noundef %29, i8 noundef signext %37)
          to label %38 unwind label %70

38:                                               ; preds = %27
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = load i64, ptr %13, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %41, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !13
  %45 = zext i8 %44 to i32
  %46 = and i32 %45, 15
  %47 = trunc i32 %46 to i8
  %48 = call noundef signext i8 @_ZL9nibbleToXh(i8 noundef zeroext %47) #3
  invoke void %39(ptr noundef %40, i8 noundef signext %48)
          to label %49 unwind label %70

49:                                               ; preds = %38
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  invoke void %50(ptr noundef %51, i8 noundef signext 32)
          to label %52 unwind label %70

52:                                               ; preds = %49
  br label %53

53:                                               ; preds = %52
  %54 = load i64, ptr %13, align 8, !tbaa !9
  %55 = add i64 %54, 1
  store i64 %55, ptr %13, align 8, !tbaa !9
  br label %22, !llvm.loop !14

56:                                               ; preds = %26
  %57 = load i8, ptr %9, align 1, !tbaa !11, !range !16, !noundef !17
  %58 = trunc i8 %57 to i1
  br i1 %58, label %59, label %66

59:                                               ; preds = %56
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  invoke void %60(ptr noundef %61, i8 noundef signext 13)
          to label %62 unwind label %70

62:                                               ; preds = %59
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  invoke void %63(ptr noundef %64, i8 noundef signext 10)
          to label %65 unwind label %70

65:                                               ; preds = %62
  br label %66

66:                                               ; preds = %65, %56
  store i8 1, ptr %11, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %67

67:                                               ; preds = %66, %17, %5
  %68 = load i8, ptr %11, align 1, !tbaa !11, !range !16, !noundef !17
  %69 = trunc i8 %68 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  ret i1 %69

70:                                               ; preds = %62, %59, %49, %38, %27
  %71 = landingpad { ptr, i32 }
          catch ptr null
  %72 = extractvalue { ptr, i32 } %71, 0
  call void @__clang_call_terminate(ptr %72) #4
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noinline noreturn nounwind uwtable "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 = { 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 #3 = { nounwind }
attributes #4 = { noreturn 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", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!17 = !{}


; 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"

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS4util10printXDataEPFvPvcES1_mbS1_(ptr noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, i1 noundef zeroext %3, ptr noundef %4) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %6 = icmp ne ptr %0, null
  %7 = icmp ne i64 %2, 0
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %.preheader, label %22

8:                                                ; preds = %18
  br i1 %3, label %20, label %22

.preheader:                                       ; preds = %5, %18
  %.025 = phi i64 [ %19, %18 ], [ 0, %5 ]
  %9 = getelementptr inbounds i8, ptr %1, i64 %.025
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = lshr i8 %10, 4
  %12 = tail call noundef signext i8 @_ZL9nibbleToXh(i8 noundef zeroext %11) #2
  invoke void %0(ptr noundef %4, i8 noundef signext %12)
          to label %13 unwind label %.loopexit

13:                                               ; preds = %.preheader
  %14 = load i8, ptr %9, align 1, !tbaa !5
  %15 = and i8 %14, 15
  %16 = tail call noundef signext i8 @_ZL9nibbleToXh(i8 noundef zeroext %15) #2
  invoke void %0(ptr noundef %4, i8 noundef signext %16)
          to label %17 unwind label %.loopexit

17:                                               ; preds = %13
  invoke void %0(ptr noundef %4, i8 noundef signext 32)
          to label %18 unwind label %.loopexit

18:                                               ; preds = %17
  %19 = add nuw i64 %.025, 1
  %exitcond.not = icmp eq i64 %19, %2
  br i1 %exitcond.not, label %8, label %.preheader, !llvm.loop !8

20:                                               ; preds = %8
  invoke void %0(ptr noundef %4, i8 noundef signext 13)
          to label %21 unwind label %.loopexit.split-lp

21:                                               ; preds = %20
  invoke void %0(ptr noundef %4, i8 noundef signext 10)
          to label %22 unwind label %.loopexit.split-lp

22:                                               ; preds = %8, %21, %5
  ret i1 %or.cond

.loopexit:                                        ; preds = %.preheader, %13, %17
  %lpad.loopexit = landingpad { ptr, i32 }
          catch ptr null
  br label %23

.loopexit.split-lp:                               ; preds = %20, %21
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          catch ptr null
  br label %23

23:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  %24 = extractvalue { ptr, i32 } %lpad.phi, 0
  tail call void @__clang_call_terminate(ptr %24) #3
  unreachable
}

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

attributes #0 = { noinline noreturn nounwind uwtable "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 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 }
attributes #3 = { noreturn 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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass