; LLVM IR from xhub/reshop :: external/itostr (itostr)

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

@unsignedstrconv_impl.charcodes = external hidden constant [37 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: nounwind uwtable
define dso_local i64 @unsignedstrconv_impl(i64 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i8, align 1
  store i64 %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !11
  %16 = load i32, ptr %9, align 4, !tbaa !11
  %17 = icmp slt i32 %16, 2
  br i1 %17, label %21, label %18

18:                                               ; preds = %4
  %19 = load i32, ptr %9, align 4, !tbaa !11
  %20 = icmp sgt i32 %19, 36
  br i1 %20, label %21, label %23

21:                                               ; preds = %18, %4
  %22 = load ptr, ptr %7, align 8, !tbaa !9
  store i8 0, ptr %22, align 1, !tbaa !13
  store i64 0, ptr %5, align 8
  br label %76

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %24, ptr %10, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %48, %23
  %26 = load i64, ptr %8, align 8, !tbaa !5
  %27 = sub i64 %26, 1
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %25
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  store i8 0, ptr %30, align 1, !tbaa !13
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %75

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %32 = load i64, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = udiv i64 %32, %34
  store i64 %35, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %36 = load i64, ptr %6, align 8, !tbaa !5
  %37 = load i64, ptr %12, align 8, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = mul i64 %37, %39
  %41 = sub i64 %36, %40
  store i64 %41, ptr %13, align 8, !tbaa !5
  %42 = load i64, ptr %12, align 8, !tbaa !5
  store i64 %42, ptr %6, align 8, !tbaa !5
  %43 = load i64, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds [37 x i8], ptr @unsignedstrconv_impl.charcodes, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !13
  %46 = load ptr, ptr %10, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %10, align 8, !tbaa !9
  store i8 %45, ptr %46, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %48

48:                                               ; preds = %31
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %25, label %51, !llvm.loop !14

51:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %52 = load ptr, ptr %10, align 8, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  %54 = ptrtoint ptr %52 to i64
  %55 = ptrtoint ptr %53 to i64
  %56 = sub i64 %54, %55
  store i64 %56, ptr %14, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !9
  %58 = getelementptr inbounds i8, ptr %57, i32 -1
  store ptr %58, ptr %10, align 8, !tbaa !9
  store i8 0, ptr %57, align 1, !tbaa !13
  br label %59

59:                                               ; preds = %63, %51
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  %61 = load ptr, ptr %10, align 8, !tbaa !9
  %62 = icmp ult ptr %60, %61
  br i1 %62, label %63, label %73

63:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #2
  %64 = load ptr, ptr %10, align 8, !tbaa !9
  %65 = load i8, ptr %64, align 1, !tbaa !13
  store i8 %65, ptr %15, align 1, !tbaa !13
  %66 = load ptr, ptr %7, align 8, !tbaa !9
  %67 = load i8, ptr %66, align 1, !tbaa !13
  %68 = load ptr, ptr %10, align 8, !tbaa !9
  %69 = getelementptr inbounds i8, ptr %68, i32 -1
  store ptr %69, ptr %10, align 8, !tbaa !9
  store i8 %67, ptr %68, align 1, !tbaa !13
  %70 = load i8, ptr %15, align 1, !tbaa !13
  %71 = load ptr, ptr %7, align 8, !tbaa !9
  %72 = getelementptr inbounds i8, ptr %71, i32 1
  store ptr %72, ptr %7, align 8, !tbaa !9
  store i8 %70, ptr %71, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #2
  br label %59, !llvm.loop !16

73:                                               ; preds = %59
  %74 = load i64, ptr %14, align 8, !tbaa !5
  store i64 %74, ptr %5, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  br label %75

75:                                               ; preds = %73, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %76

76:                                               ; preds = %75, %21
  %77 = load i64, ptr %5, align 8
  ret i64 %77
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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"

@unsignedstrconv_impl.charcodes = external hidden local_unnamed_addr constant [37 x i8], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local i64 @unsignedstrconv_impl(i64 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = add i32 %3, -37
  %or.cond = icmp ult i32 %5, -35
  br i1 %or.cond, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %4
  %6 = icmp eq i64 %2, 1
  %7 = zext nneg i32 %3 to i64
  br i1 %6, label %.loopexit.sink.split, label %.preheader.split

.preheader.split:                                 ; preds = %.preheader, %.preheader.split
  %.029 = phi ptr [ %12, %.preheader.split ], [ %1, %.preheader ]
  %.027 = phi i64 [ %8, %.preheader.split ], [ %0, %.preheader ]
  %8 = udiv i64 %.027, %7
  %9 = mul i64 %8, %7
  %.recomposed = urem i64 %.027, %7
  %10 = getelementptr inbounds [37 x i8], ptr @unsignedstrconv_impl.charcodes, i64 0, i64 %.recomposed
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.029, i64 1
  store i8 %11, ptr %.029, align 1, !tbaa !5
  %.not = icmp ult i64 %.027, %7
  br i1 %.not, label %13, label %.preheader.split, !llvm.loop !8

13:                                               ; preds = %.preheader.split
  %14 = ptrtoint ptr %12 to i64
  %15 = ptrtoint ptr %1 to i64
  %16 = sub i64 %14, %15
  store i8 0, ptr %12, align 1, !tbaa !5
  %17 = icmp ugt ptr %.029, %1
  br i1 %17, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.02835 = phi ptr [ %21, %.lr.ph ], [ %1, %13 ]
  %.13034 = phi ptr [ %20, %.lr.ph ], [ %.029, %13 ]
  %18 = load i8, ptr %.13034, align 1, !tbaa !5
  %19 = load i8, ptr %.02835, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.13034, i64 -1
  store i8 %19, ptr %.13034, align 1, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.02835, i64 1
  store i8 %18, ptr %.02835, align 1, !tbaa !5
  %22 = icmp ult ptr %21, %20
  br i1 %22, label %.lr.ph, label %.loopexit, !llvm.loop !10

.loopexit.sink.split:                             ; preds = %.preheader, %4
  store i8 0, ptr %1, align 1, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.loopexit.sink.split, %13
  %.1 = phi i64 [ %16, %13 ], [ 0, %.loopexit.sink.split ], [ %16, %.lr.ph ]
  ret i64 %.1
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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" }

!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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass