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

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

7:                                                ; preds = %10, %2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp uge i32 %8, 10
  br i1 %9, label %10, label %21

10:                                               ; preds = %7
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = urem i32 %11, 10
  %13 = add i32 48, %12
  %14 = trunc i32 %13 to i8
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = add i32 %15, 1
  store i32 %16, ptr %6, align 4, !tbaa !5
  %17 = zext i32 %15 to i64
  %18 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 %17
  store i8 %14, ptr %18, align 1, !tbaa !11
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = udiv i32 %19, 10
  store i32 %20, ptr %3, align 4, !tbaa !5
  br label %7, !llvm.loop !12

21:                                               ; preds = %7
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = add i32 48, %22
  %24 = trunc i32 %23 to i8
  %25 = load ptr, ptr %4, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %25, i32 1
  store ptr %26, ptr %4, align 8, !tbaa !9
  store i8 %24, ptr %25, align 1, !tbaa !11
  br label %27

27:                                               ; preds = %30, %21
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %39

30:                                               ; preds = %27
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = add i32 %31, -1
  store i32 %32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %4, align 8, !tbaa !9
  store i8 %36, ptr %37, align 1, !tbaa !11
  br label %27, !llvm.loop !14

39:                                               ; preds = %27
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  store i8 0, ptr %40, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #2
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}
!14 = distinct !{!14, !13}


; 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(write, inaccessiblemem: none) uwtable
define dso_local void @_Z21ConvertUInt32ToStringjPc(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #2
  %4 = icmp ugt i32 %0, 9
  br i1 %4, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %2
  %5 = trunc nuw i32 %0 to i8
  %6 = or disjoint i8 %5, 48
  store i8 %6, ptr %1, align 1, !tbaa !5
  %.0101528 = getelementptr inbounds i8, ptr %1, i64 1
  br label %._crit_edge21

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.013 = phi i32 [ %10, %.lr.ph ], [ 0, %2 ]
  %.01112 = phi i32 [ %13, %.lr.ph ], [ %0, %2 ]
  %7 = urem i32 %.01112, 10
  %8 = trunc nuw nsw i32 %7 to i8
  %9 = or disjoint i8 %8, 48
  %10 = add i32 %.013, 1
  %11 = zext i32 %.013 to i64
  %12 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 %11
  store i8 %9, ptr %12, align 1, !tbaa !5
  %13 = udiv i32 %.01112, 10
  %14 = icmp ugt i32 %.01112, 99
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph
  %15 = trunc nuw i32 %13 to i8
  %16 = or disjoint i8 %15, 48
  store i8 %16, ptr %1, align 1, !tbaa !5
  %.01015 = getelementptr inbounds i8, ptr %1, i64 1
  %.not16 = icmp eq i32 %10, 0
  br i1 %.not16, label %._crit_edge21, label %.lr.ph20.preheader

.lr.ph20.preheader:                               ; preds = %._crit_edge
  %17 = zext i32 %10 to i64
  %min.iters.check = icmp ult i32 %10, 32
  br i1 %min.iters.check, label %.lr.ph20.preheader39, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph20.preheader
  %n.vec = and i64 %17, 4294967264
  %ind.end = and i64 %17, 31
  %ind.end34 = getelementptr i8, ptr %.01015, i64 %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %next.gep = getelementptr i8, ptr %.01015, i64 %index
  %18 = xor i64 %index, -1
  %19 = add i64 %18, %17
  %20 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 %19
  %21 = getelementptr inbounds i8, ptr %20, i64 -15
  %22 = getelementptr inbounds i8, ptr %20, i64 -31
  %wide.load = load <16 x i8>, ptr %21, align 1, !tbaa !5
  %reverse = shufflevector <16 x i8> %wide.load, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %wide.load37 = load <16 x i8>, ptr %22, align 1, !tbaa !5
  %reverse38 = shufflevector <16 x i8> %wide.load37, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %23 = getelementptr i8, ptr %next.gep, i64 16
  store <16 x i8> %reverse, ptr %next.gep, align 1, !tbaa !5
  store <16 x i8> %reverse38, ptr %23, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %24 = icmp eq i64 %index.next, %n.vec
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %17
  br i1 %cmp.n, label %._crit_edge21, label %.lr.ph20.preheader39

.lr.ph20.preheader39:                             ; preds = %middle.block, %.lr.ph20.preheader
  %indvars.iv.ph = phi i64 [ %17, %.lr.ph20.preheader ], [ %ind.end, %middle.block ]
  %.01018.ph = phi ptr [ %.01015, %.lr.ph20.preheader ], [ %ind.end34, %middle.block ]
  br label %.lr.ph20

.lr.ph20:                                         ; preds = %.lr.ph20.preheader39, %.lr.ph20
  %indvars.iv = phi i64 [ %25, %.lr.ph20 ], [ %indvars.iv.ph, %.lr.ph20.preheader39 ]
  %.01018 = phi ptr [ %.010, %.lr.ph20 ], [ %.01018.ph, %.lr.ph20.preheader39 ]
  %25 = add nsw i64 %indvars.iv, -1
  %26 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !5
  store i8 %27, ptr %.01018, align 1, !tbaa !5
  %.010 = getelementptr inbounds i8, ptr %.01018, i64 1
  %.not.wide = icmp eq i64 %25, 0
  br i1 %.not.wide, label %._crit_edge21, label %.lr.ph20, !llvm.loop !13

._crit_edge21:                                    ; preds = %.lr.ph20, %middle.block, %._crit_edge.thread, %._crit_edge
  %.010.lcssa = phi ptr [ %.01015, %._crit_edge ], [ %.0101528, %._crit_edge.thread ], [ %ind.end34, %middle.block ], [ %.010, %.lr.ph20 ]
  store i8 0, ptr %.010.lcssa, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #2
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9, !11, !12}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !9, !12, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass