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

; 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 @_Z21ConvertUInt64ToStringyPcj(i64 noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [72 x i8], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  %10 = load i32, ptr %6, align 4, !tbaa !11
  %11 = icmp ult i32 %10, 2
  br i1 %11, label %15, label %12

12:                                               ; preds = %3
  %13 = load i32, ptr %6, align 4, !tbaa !11
  %14 = icmp ugt i32 %13, 36
  br i1 %14, label %15, label %17

15:                                               ; preds = %12, %3
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  store i8 0, ptr %16, align 1, !tbaa !13
  br label %61

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 72, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %44, %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !11
  %21 = zext i32 %20 to i64
  %22 = urem i64 %19, %21
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %9, align 4, !tbaa !11
  %24 = load i32, ptr %9, align 4, !tbaa !11
  %25 = icmp slt i32 %24, 10
  br i1 %25, label %26, label %29

26:                                               ; preds = %18
  %27 = load i32, ptr %9, align 4, !tbaa !11
  %28 = add nsw i32 48, %27
  br label %33

29:                                               ; preds = %18
  %30 = load i32, ptr %9, align 4, !tbaa !11
  %31 = sub nsw i32 %30, 10
  %32 = add nsw i32 97, %31
  br label %33

33:                                               ; preds = %29, %26
  %34 = phi i32 [ %28, %26 ], [ %32, %29 ]
  %35 = trunc i32 %34 to i8
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %8, align 4, !tbaa !11
  %38 = sext i32 %36 to i64
  %39 = getelementptr inbounds [72 x i8], ptr %7, i64 0, i64 %38
  store i8 %35, ptr %39, align 1, !tbaa !13
  %40 = load i32, ptr %6, align 4, !tbaa !11
  %41 = zext i32 %40 to i64
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = udiv i64 %42, %41
  store i64 %43, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %44

44:                                               ; preds = %33
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %18, label %47, !llvm.loop !14

47:                                               ; preds = %44
  br label %48

48:                                               ; preds = %56, %47
  %49 = load i32, ptr %8, align 4, !tbaa !11
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr %8, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [72 x i8], ptr %7, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !13
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %5, align 8, !tbaa !9
  store i8 %53, ptr %54, align 1, !tbaa !13
  br label %56

56:                                               ; preds = %48
  %57 = load i32, ptr %8, align 4, !tbaa !11
  %58 = icmp sgt i32 %57, 0
  br i1 %58, label %48, label %59, !llvm.loop !16

59:                                               ; preds = %56
  %60 = load ptr, ptr %5, align 8, !tbaa !9
  store i8 0, ptr %60, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 72, ptr %7) #2
  br label %61

61:                                               ; preds = %59, %15
  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 = !{!"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 nofree norecurse nosync nounwind memory(write, inaccessiblemem: none) uwtable
define dso_local void @_Z21ConvertUInt64ToStringyPcj(i64 noundef %0, ptr nocapture noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [72 x i8], align 16
  %5 = add i32 %2, -37
  %or.cond = icmp ult i32 %5, -35
  br i1 %or.cond, label %6, label %7

6:                                                ; preds = %3
  store i8 0, ptr %1, align 1, !tbaa !5
  br label %31

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %4) #3
  %8 = zext nneg i32 %2 to i64
  br label %9

9:                                                ; preds = %9, %7
  %indvars.iv25 = phi i32 [ %indvars.iv.next26, %9 ], [ 1, %7 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %9 ], [ 0, %7 ]
  %.0 = phi i64 [ %17, %9 ], [ %0, %7 ]
  %10 = urem i64 %.0, %8
  %11 = trunc nuw i64 %10 to i8
  %12 = icmp ult i64 %10, 10
  %13 = or i8 %11, 48
  %14 = add nuw i8 %11, 87
  %15 = select i1 %12, i8 %13, i8 %14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = getelementptr inbounds [72 x i8], ptr %4, i64 0, i64 %indvars.iv
  store i8 %15, ptr %16, align 1, !tbaa !5
  %17 = udiv i64 %.0, %8
  %.not = icmp ult i64 %.0, %8
  %indvars.iv.next26 = add i32 %indvars.iv25, 1
  br i1 %.not, label %.preheader.preheader, label %9, !llvm.loop !8

.preheader.preheader:                             ; preds = %9
  %18 = sext i32 %indvars.iv25 to i64
  %19 = tail call i64 @llvm.smax.i64(i64 %18, i64 1)
  %min.iters.check = icmp slt i32 %indvars.iv25, 32
  br i1 %min.iters.check, label %.preheader.preheader35, label %vector.ph

vector.ph:                                        ; preds = %.preheader.preheader
  %n.vec = and i64 %19, 2147483616
  %ind.end = sub nsw i64 %18, %n.vec
  %ind.end30 = getelementptr i8, ptr %1, 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 %1, i64 %index
  %20 = xor i64 %index, -1
  %21 = add i64 %20, %18
  %22 = getelementptr inbounds [72 x i8], ptr %4, i64 0, i64 %21
  %23 = getelementptr inbounds i8, ptr %22, i64 -15
  %24 = getelementptr inbounds i8, ptr %22, i64 -31
  %wide.load = load <16 x i8>, ptr %23, 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.load33 = load <16 x i8>, ptr %24, align 1, !tbaa !5
  %reverse34 = shufflevector <16 x i8> %wide.load33, <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>
  %25 = getelementptr i8, ptr %next.gep, i64 16
  store <16 x i8> %reverse, ptr %next.gep, align 1, !tbaa !5
  store <16 x i8> %reverse34, ptr %25, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !10

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

.preheader.preheader35:                           ; preds = %middle.block, %.preheader.preheader
  %indvars.iv27.ph = phi i64 [ %18, %.preheader.preheader ], [ %ind.end, %middle.block ]
  %.017.ph = phi ptr [ %1, %.preheader.preheader ], [ %ind.end30, %middle.block ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader35, %.preheader
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %.preheader ], [ %indvars.iv27.ph, %.preheader.preheader35 ]
  %.017 = phi ptr [ %29, %.preheader ], [ %.017.ph, %.preheader.preheader35 ]
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, -1
  %27 = getelementptr inbounds [72 x i8], ptr %4, i64 0, i64 %indvars.iv.next28
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.017, i64 1
  store i8 %28, ptr %.017, align 1, !tbaa !5
  %30 = icmp sgt i64 %indvars.iv27, 1
  br i1 %30, label %.preheader, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.preheader, %middle.block
  %.lcssa = phi ptr [ %ind.end30, %middle.block ], [ %29, %.preheader ]
  store i8 0, ptr %.lcssa, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %4) #3
  br label %31

31:                                               ; preds = %.loopexit, %6
  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

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

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 = { 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 = !{!"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: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass