; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Bundles/LzmaSpec/LzmaSpec.ll (Z21ConvertUInt64ToStringyPc)

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

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

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

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

29:                                               ; preds = %32, %22
  %30 = load i32, ptr %6, align 4, !tbaa !11
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %41

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

41:                                               ; preds = %29
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  store i8 0, ptr %42, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #2
  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 = !{!"long long", !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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, inaccessiblemem: none) uwtable
define dso_local void @_Z21ConvertUInt64ToStringyPc(i64 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #2
  %4 = icmp ugt i64 %0, 9
  br i1 %4, label %.lr.ph, label %._crit_edge.thread

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

._crit_edge:                                      ; preds = %.lr.ph
  %15 = trunc nuw i64 %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 [32 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 [32 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 32, ptr nonnull %3) #2
  ret void
}

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