; LLVM IR from yinqiwen/ardb :: src/common/util/string_helper.ll (ZN4ardb9fast_itoaEPcjm)

; 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"

@_ZZN4ardb9fast_itoaEPcjmE6digits = external hidden constant [201 x i8], align 16

; 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 uwtable
define dso_local noundef i32 @_ZN4ardb9fast_itoaEPcjm(ptr noundef %0, i32 noundef %1, i64 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %13 = load i64, ptr %7, align 8, !tbaa !11
  %14 = call noundef i32 @_ZN4ardb8digits10El(i64 noundef %13)
  store i32 %14, ptr %8, align 4, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp uge i32 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %88

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = sub i32 %20, 1
  store i32 %21, ptr %10, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %25, %19
  %23 = load i64, ptr %7, align 8, !tbaa !11
  %24 = icmp uge i64 %23, 100
  br i1 %24, label %25, label %52

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %26 = load i64, ptr %7, align 8, !tbaa !11
  %27 = urem i64 %26, 100
  %28 = mul i64 %27, 2
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %11, align 4, !tbaa !9
  %30 = load i64, ptr %7, align 8, !tbaa !11
  %31 = udiv i64 %30, 100
  store i64 %31, ptr %7, align 8, !tbaa !11
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = add i32 %32, 1
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [201 x i8], ptr @_ZZN4ardb9fast_itoaEPcjmE6digits, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !13
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  store i8 %36, ptr %40, align 1, !tbaa !13
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds [201 x i8], ptr @_ZZN4ardb9fast_itoaEPcjmE6digits, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !13
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = sub i32 %46, 1
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %45, i64 %48
  store i8 %44, ptr %49, align 1, !tbaa !13
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = sub i32 %50, 2
  store i32 %51, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %22, !llvm.loop !14

52:                                               ; preds = %22
  %53 = load i64, ptr %7, align 8, !tbaa !11
  %54 = icmp ult i64 %53, 10
  br i1 %54, label %55, label %64

55:                                               ; preds = %52
  %56 = load i64, ptr %7, align 8, !tbaa !11
  %57 = trunc i64 %56 to i32
  %58 = add i32 48, %57
  %59 = trunc i32 %58 to i8
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %60, i64 %62
  store i8 %59, ptr %63, align 1, !tbaa !13
  br label %86

64:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %65 = load i64, ptr %7, align 8, !tbaa !11
  %66 = trunc i64 %65 to i32
  %67 = mul i32 %66, 2
  store i32 %67, ptr %12, align 4, !tbaa !9
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = add i32 %68, 1
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds [201 x i8], ptr @_ZZN4ardb9fast_itoaEPcjmE6digits, i64 0, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !13
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds i8, ptr %73, i64 %75
  store i8 %72, ptr %76, align 1, !tbaa !13
  %77 = load i32, ptr %12, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds [201 x i8], ptr @_ZZN4ardb9fast_itoaEPcjmE6digits, i64 0, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !13
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i32, ptr %10, align 4, !tbaa !9
  %83 = sub i32 %82, 1
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %81, i64 %84
  store i8 %80, ptr %85, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %86

86:                                               ; preds = %64, %55
  %87 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %87, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %88

88:                                               ; preds = %86, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %89 = load i32, ptr %4, align 4
  ret i32 %89
}

declare noundef i32 @_ZN4ardb8digits10El(i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@_ZZN4ardb9fast_itoaEPcjmE6digits = external hidden local_unnamed_addr constant [201 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4ardb9fast_itoaEPcjm(ptr nocapture noundef writeonly %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noundef i32 @_ZN4ardb8digits10El(i64 noundef %2)
  %.not = icmp ult i32 %4, %1
  br i1 %.not, label %5, label %44

5:                                                ; preds = %3
  %6 = add i32 %4, -1
  %7 = icmp ugt i64 %2, 99
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.02630 = phi i64 [ %10, %.lr.ph ], [ %2, %5 ]
  %.02729 = phi i32 [ %23, %.lr.ph ], [ %6, %5 ]
  %8 = urem i64 %.02630, 100
  %.tr = trunc nuw nsw i64 %8 to i32
  %9 = shl nuw nsw i32 %.tr, 1
  %10 = udiv i64 %.02630, 100
  %11 = or disjoint i32 %9, 1
  %12 = zext nneg i32 %11 to i64
  %13 = getelementptr inbounds [201 x i8], ptr @_ZZN4ardb9fast_itoaEPcjmE6digits, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = zext i32 %.02729 to i64
  %16 = getelementptr inbounds i8, ptr %0, i64 %15
  store i8 %14, ptr %16, align 1, !tbaa !5
  %17 = zext nneg i32 %9 to i64
  %18 = getelementptr inbounds [201 x i8], ptr @_ZZN4ardb9fast_itoaEPcjmE6digits, i64 0, i64 %17
  %19 = load i8, ptr %18, align 2, !tbaa !5
  %20 = add i32 %.02729, -1
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %0, i64 %21
  store i8 %19, ptr %22, align 1, !tbaa !5
  %23 = add i32 %.02729, -2
  %24 = icmp ugt i64 %.02630, 9999
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.027.lcssa = phi i32 [ %6, %5 ], [ %23, %.lr.ph ]
  %.026.lcssa = phi i64 [ %2, %5 ], [ %10, %.lr.ph ]
  %25 = icmp ult i64 %.026.lcssa, 10
  br i1 %25, label %26, label %29

26:                                               ; preds = %._crit_edge
  %27 = trunc nuw i64 %.026.lcssa to i8
  %28 = or disjoint i8 %27, 48
  br label %.sink.split

29:                                               ; preds = %._crit_edge
  %30 = trunc nuw nsw i64 %.026.lcssa to i32
  %31 = shl nuw nsw i32 %30, 1
  %32 = or disjoint i32 %31, 1
  %33 = zext nneg i32 %32 to i64
  %34 = getelementptr inbounds [201 x i8], ptr @_ZZN4ardb9fast_itoaEPcjmE6digits, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = zext i32 %.027.lcssa to i64
  %37 = getelementptr inbounds i8, ptr %0, i64 %36
  store i8 %35, ptr %37, align 1, !tbaa !5
  %38 = zext nneg i32 %31 to i64
  %39 = getelementptr inbounds [201 x i8], ptr @_ZZN4ardb9fast_itoaEPcjmE6digits, i64 0, i64 %38
  %40 = load i8, ptr %39, align 2, !tbaa !5
  %41 = add i32 %.027.lcssa, -1
  br label %.sink.split

.sink.split:                                      ; preds = %29, %26
  %.027.lcssa.sink = phi i32 [ %.027.lcssa, %26 ], [ %41, %29 ]
  %.sink = phi i8 [ %28, %26 ], [ %40, %29 ]
  %42 = zext i32 %.027.lcssa.sink to i64
  %43 = getelementptr inbounds i8, ptr %0, i64 %42
  store i8 %.sink, ptr %43, align 1, !tbaa !5
  br label %44

44:                                               ; preds = %.sink.split, %3
  %.0 = phi i32 [ -1, %3 ], [ %4, %.sink.split ]
  ret i32 %.0
}

declare noundef i32 @_ZN4ardb8digits10El(i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { "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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass