; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/Common/IntToString.ll (Z25ConvertUInt32ToHex8DigitsjPc)

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

9:                                                ; preds = %34, %2
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = icmp sge i32 %10, 0
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %37

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = and i32 %14, 15
  store i32 %15, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = lshr i32 %16, 4
  store i32 %17, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = icmp ult i32 %18, 10
  br i1 %19, label %20, label %23

20:                                               ; preds = %13
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = add i32 48, %21
  br label %27

23:                                               ; preds = %13
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = sub i32 %24, 10
  %26 = add i32 65, %25
  br label %27

27:                                               ; preds = %23, %20
  %28 = phi i32 [ %22, %20 ], [ %26, %23 ]
  %29 = trunc i32 %28 to i8
  %30 = load ptr, ptr %4, align 8, !tbaa !9
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  store i8 %29, ptr %33, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %34

34:                                               ; preds = %27
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr %5, align 4, !tbaa !5
  br label %9, !llvm.loop !12

37:                                               ; preds = %12
  ret void
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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 nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @_Z25ConvertUInt32ToHex8DigitsjPc(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  store i8 0, ptr %3, align 1, !tbaa !5
  %4 = and i32 %0, 15
  %5 = lshr i32 %0, 4
  %6 = icmp ult i32 %4, 10
  %7 = or disjoint i32 %4, 48
  %8 = add nuw nsw i32 %4, 55
  %9 = select i1 %6, i32 %7, i32 %8
  %10 = trunc nuw nsw i32 %9 to i8
  %11 = getelementptr inbounds i8, ptr %1, i64 7
  store i8 %10, ptr %11, align 1, !tbaa !5
  %12 = and i32 %5, 15
  %13 = lshr i32 %0, 8
  %14 = icmp ult i32 %12, 10
  %15 = or disjoint i32 %12, 48
  %16 = add nuw nsw i32 %12, 55
  %17 = select i1 %14, i32 %15, i32 %16
  %18 = trunc nuw nsw i32 %17 to i8
  %19 = getelementptr inbounds i8, ptr %1, i64 6
  store i8 %18, ptr %19, align 1, !tbaa !5
  %20 = and i32 %13, 15
  %21 = insertelement <4 x i32> poison, i32 %0, i64 0
  %22 = shufflevector <4 x i32> %21, <4 x i32> poison, <4 x i32> zeroinitializer
  %23 = lshr <4 x i32> %22, <i32 24, i32 20, i32 16, i32 12>
  %24 = icmp ult i32 %20, 10
  %25 = or disjoint i32 %20, 48
  %26 = add nuw nsw i32 %20, 55
  %27 = select i1 %24, i32 %25, i32 %26
  %28 = trunc nuw nsw i32 %27 to i8
  %29 = getelementptr inbounds i8, ptr %1, i64 5
  store i8 %28, ptr %29, align 1, !tbaa !5
  %30 = lshr i32 %0, 28
  %31 = getelementptr inbounds i8, ptr %1, i64 1
  %32 = and <4 x i32> %23, <i32 15, i32 15, i32 15, i32 15>
  %33 = icmp ult <4 x i32> %32, <i32 10, i32 10, i32 10, i32 10>
  %34 = or disjoint <4 x i32> %32, <i32 48, i32 48, i32 48, i32 48>
  %35 = add nuw nsw <4 x i32> %32, <i32 55, i32 55, i32 55, i32 55>
  %36 = select <4 x i1> %33, <4 x i32> %34, <4 x i32> %35
  %37 = trunc nuw nsw <4 x i32> %36 to <4 x i8>
  store <4 x i8> %37, ptr %31, align 1, !tbaa !5
  %38 = icmp ult i32 %0, -1610612736
  %39 = or disjoint i32 %30, 48
  %40 = add nuw nsw i32 %30, 55
  %41 = select i1 %38, i32 %39, i32 %40
  %42 = trunc nuw nsw i32 %41 to i8
  store i8 %42, ptr %1, align 1, !tbaa !5
  ret void
}

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


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass