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

; Function Attrs: nounwind uwtable
declare dso_local i64 @unsignedstrconv_impl(i64 noundef, ptr noundef, i64 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @unsignedtostr(i64 noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store i64 %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !11
  %12 = load ptr, ptr %9, align 8, !tbaa !9
  %13 = icmp eq ptr %12, null
  br i1 %13, label %17, label %14

14:                                               ; preds = %5
  %15 = load i64, ptr %10, align 8, !tbaa !5
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %14, %5
  store i64 0, ptr %6, align 8
  br label %44

18:                                               ; preds = %14
  %19 = load i64, ptr %8, align 8, !tbaa !5
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %30, label %21

21:                                               ; preds = %18
  %22 = load i64, ptr %8, align 8, !tbaa !5
  %23 = load i64, ptr %8, align 8, !tbaa !5
  %24 = sub i64 %23, 1
  %25 = and i64 %22, %24
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %30, label %27

27:                                               ; preds = %21
  %28 = load i64, ptr %8, align 8, !tbaa !5
  %29 = icmp ugt i64 %28, 8
  br i1 %29, label %30, label %32

30:                                               ; preds = %27, %21, %18
  %31 = load ptr, ptr %9, align 8, !tbaa !9
  store i8 48, ptr %31, align 1, !tbaa !13
  store i64 0, ptr %6, align 8
  br label %44

32:                                               ; preds = %27
  %33 = load i64, ptr %7, align 8, !tbaa !5
  %34 = load i64, ptr %8, align 8, !tbaa !5
  %35 = sub i64 %34, 1
  %36 = shl i64 %35, 3
  %37 = shl i64 256, %36
  %38 = sub i64 %37, 1
  %39 = and i64 %33, %38
  %40 = load ptr, ptr %9, align 8, !tbaa !9
  %41 = load i64, ptr %10, align 8, !tbaa !5
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = call i64 @unsignedstrconv_impl(i64 noundef %39, ptr noundef %40, i64 noundef %41, i32 noundef %42)
  store i64 %43, ptr %6, align 8
  br label %44

44:                                               ; preds = %32, %30, %17
  %45 = load i64, ptr %6, align 8
  ret i64 %45
}

attributes #0 = { 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" }

!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}


; 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: nounwind uwtable
declare dso_local i64 @unsignedstrconv_impl(i64 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @unsignedtostr(i64 noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %2, null
  %7 = icmp eq i64 %3, 0
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %22, label %8

8:                                                ; preds = %5
  %9 = icmp eq i64 %1, 0
  br i1 %9, label %14, label %10

10:                                               ; preds = %8
  %11 = tail call range(i64 0, 65) i64 @llvm.ctpop.i64(i64 %1)
  %12 = icmp ugt i64 %11, 1
  %13 = icmp ugt i64 %1, 8
  %or.cond3 = or i1 %13, %12
  br i1 %or.cond3, label %14, label %15

14:                                               ; preds = %10, %8
  store i8 48, ptr %2, align 1, !tbaa !5
  br label %22

15:                                               ; preds = %10
  %16 = shl nuw nsw i64 %1, 3
  %17 = add nsw i64 %16, -8
  %18 = shl i64 256, %17
  %19 = add nsw i64 %18, -1
  %20 = and i64 %19, %0
  %21 = tail call i64 @unsignedstrconv_impl(i64 noundef %20, ptr noundef nonnull %2, i64 noundef %3, i32 noundef %4)
  br label %22

22:                                               ; preds = %5, %15, %14
  %.0 = phi i64 [ 0, %14 ], [ %21, %15 ], [ 0, %5 ]
  ret i64 %.0
}

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

attributes #0 = { 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 speculatable willreturn memory(none) }

!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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass