; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/lzma465/CPP/Common/IntToString.ll (Z21ConvertUInt64ToStringyPw)

; 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 @_Z21ConvertUInt64ToStringyPw(i64 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [32 x i32], 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 128, 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 = %18, %2
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = urem i64 %8, 10
  %10 = trunc i64 %9 to i32
  %11 = add nsw i32 48, %10
  %12 = load i32, ptr %6, align 4, !tbaa !11
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %6, align 4, !tbaa !11
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds [32 x i32], ptr %5, i64 0, i64 %14
  store i32 %11, ptr %15, align 4, !tbaa !13
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = udiv i64 %16, 10
  store i64 %17, ptr %3, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %7
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %7, label %21, !llvm.loop !15

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %30, %21
  %23 = load i32, ptr %6, align 4, !tbaa !11
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %6, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [32 x i32], ptr %5, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = load ptr, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds i32, ptr %28, i32 1
  store ptr %29, ptr %4, align 8, !tbaa !9
  store i32 %27, ptr %28, align 4, !tbaa !13
  br label %30

30:                                               ; preds = %22
  %31 = load i32, ptr %6, align 4, !tbaa !11
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %22, label %33, !llvm.loop !17

33:                                               ; preds = %30
  %34 = load ptr, ptr %4, align 8, !tbaa !9
  store i32 0, ptr %34, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 128, 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 = !{!14, !14, i64 0}
!14 = !{!"wchar_t", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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 @_Z21ConvertUInt64ToStringyPw(i64 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = alloca [32 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #3
  br label %4

4:                                                ; preds = %4, %2
  %indvars.iv12 = phi i32 [ %indvars.iv.next13, %4 ], [ 1, %2 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %4 ], [ 0, %2 ]
  %.08 = phi i64 [ %9, %4 ], [ %0, %2 ]
  %5 = urem i64 %.08, 10
  %6 = trunc nuw nsw i64 %5 to i32
  %7 = or disjoint i32 %6, 48
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = getelementptr inbounds [32 x i32], ptr %3, i64 0, i64 %indvars.iv
  store i32 %7, ptr %8, align 4, !tbaa !5
  %9 = udiv i64 %.08, 10
  %.not = icmp ult i64 %.08, 10
  %indvars.iv.next13 = add i32 %indvars.iv12, 1
  br i1 %.not, label %.preheader.preheader, label %4, !llvm.loop !9

.preheader.preheader:                             ; preds = %4
  %10 = sext i32 %indvars.iv12 to i64
  %11 = tail call i64 @llvm.smax.i64(i64 %10, i64 1)
  %min.iters.check = icmp slt i32 %indvars.iv12, 8
  br i1 %min.iters.check, label %.preheader.preheader23, label %vector.ph

vector.ph:                                        ; preds = %.preheader.preheader
  %n.vec = and i64 %11, 2147483640
  %ind.end = sub nsw i64 %10, %n.vec
  %12 = shl nuw nsw i64 %n.vec, 2
  %ind.end17 = getelementptr i8, ptr %1, i64 %12
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx19 = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %1, i64 %offset.idx19
  %13 = xor i64 %index, -1
  %14 = add i64 %13, %10
  %15 = getelementptr inbounds [32 x i32], ptr %3, i64 0, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 -12
  %17 = getelementptr inbounds i8, ptr %15, i64 -28
  %wide.load = load <4 x i32>, ptr %16, align 4, !tbaa !5
  %reverse = shufflevector <4 x i32> %wide.load, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %wide.load21 = load <4 x i32>, ptr %17, align 4, !tbaa !5
  %reverse22 = shufflevector <4 x i32> %wide.load21, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %18 = getelementptr i8, ptr %next.gep, i64 16
  store <4 x i32> %reverse, ptr %next.gep, align 4, !tbaa !5
  store <4 x i32> %reverse22, ptr %18, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %11, %n.vec
  br i1 %cmp.n, label %.loopexit, label %.preheader.preheader23

.preheader.preheader23:                           ; preds = %middle.block, %.preheader.preheader
  %indvars.iv14.ph = phi i64 [ %10, %.preheader.preheader ], [ %ind.end, %middle.block ]
  %.07.ph = phi ptr [ %1, %.preheader.preheader ], [ %ind.end17, %middle.block ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader23, %.preheader
  %indvars.iv14 = phi i64 [ %indvars.iv.next15, %.preheader ], [ %indvars.iv14.ph, %.preheader.preheader23 ]
  %.07 = phi ptr [ %22, %.preheader ], [ %.07.ph, %.preheader.preheader23 ]
  %indvars.iv.next15 = add nsw i64 %indvars.iv14, -1
  %20 = getelementptr inbounds [32 x i32], ptr %3, i64 0, i64 %indvars.iv.next15
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.07, i64 4
  store i32 %21, ptr %.07, align 4, !tbaa !5
  %23 = icmp sgt i64 %indvars.iv14, 1
  br i1 %23, label %.preheader, label %.loopexit, !llvm.loop !14

.loopexit:                                        ; preds = %.preheader, %middle.block
  %.lcssa = phi ptr [ %ind.end17, %middle.block ], [ %22, %.preheader ]
  store i32 0, ptr %.lcssa, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #2

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


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