; 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
define dso_local i64 @signedtostr(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
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  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
  %14 = load ptr, ptr %9, align 8, !tbaa !9
  %15 = icmp eq ptr %14, null
  br i1 %15, label %19, label %16

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

19:                                               ; preds = %16, %5
  store i64 0, ptr %6, align 8
  br label %67

20:                                               ; preds = %16
  %21 = load i64, ptr %8, align 8, !tbaa !5
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %32, label %23

23:                                               ; preds = %20
  %24 = load i64, ptr %8, align 8, !tbaa !5
  %25 = load i64, ptr %8, align 8, !tbaa !5
  %26 = sub i64 %25, 1
  %27 = and i64 %24, %26
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %32, label %29

29:                                               ; preds = %23
  %30 = load i64, ptr %8, align 8, !tbaa !5
  %31 = icmp ugt i64 %30, 8
  br i1 %31, label %32, label %34

32:                                               ; preds = %29, %23, %20
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  store i8 48, ptr %33, align 1, !tbaa !13
  store i64 0, ptr %6, align 8
  br label %67

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %35 = load i64, ptr %8, align 8, !tbaa !5
  %36 = sub i64 %35, 1
  %37 = shl i64 %36, 3
  %38 = shl i64 128, %37
  store i64 %38, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %39 = load i64, ptr %12, align 8, !tbaa !5
  %40 = shl i64 %39, 1
  %41 = sub i64 %40, 1
  store i64 %41, ptr %13, align 8, !tbaa !5
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = icmp eq i32 %42, 10
  br i1 %43, label %44, label %57

44:                                               ; preds = %34
  %45 = load i64, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %12, align 8, !tbaa !5
  %47 = and i64 %45, %46
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %49, label %57

49:                                               ; preds = %44
  %50 = load i64, ptr %7, align 8, !tbaa !5
  %51 = load i64, ptr %13, align 8, !tbaa !5
  %52 = xor i64 %51, -1
  %53 = or i64 %50, %52
  %54 = load ptr, ptr %9, align 8, !tbaa !9
  %55 = load i64, ptr %10, align 8, !tbaa !5
  %56 = call i64 @signeddecstrconv_impl(i64 noundef %53, ptr noundef %54, i64 noundef %55)
  br label %65

57:                                               ; preds = %44, %34
  %58 = load i64, ptr %7, align 8, !tbaa !5
  %59 = load i64, ptr %13, align 8, !tbaa !5
  %60 = and i64 %58, %59
  %61 = load ptr, ptr %9, align 8, !tbaa !9
  %62 = load i64, ptr %10, align 8, !tbaa !5
  %63 = load i32, ptr %11, align 4, !tbaa !11
  %64 = call i64 @unsignedstrconv_impl(i64 noundef %60, ptr noundef %61, i64 noundef %62, i32 noundef %63)
  br label %65

65:                                               ; preds = %57, %49
  %66 = phi i64 [ %56, %49 ], [ %64, %57 ]
  store i64 %66, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %67

67:                                               ; preds = %65, %32, %19
  %68 = load i64, ptr %6, align 8
  ret i64 %68
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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", !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
define dso_local i64 @signedtostr(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 %31, 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 %31

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 = icmp eq i32 %4, 10
  br i1 %20, label %21, label %28

21:                                               ; preds = %15
  %22 = shl nuw i64 128, %17
  %23 = and i64 %22, %0
  %.not = icmp eq i64 %23, 0
  br i1 %.not, label %28, label %24

24:                                               ; preds = %21
  %25 = sub nsw i64 0, %18
  %26 = or i64 %25, %0
  %27 = tail call i64 @signeddecstrconv_impl(i64 noundef %26, ptr noundef nonnull %2, i64 noundef %3)
  br label %31

28:                                               ; preds = %21, %15
  %29 = and i64 %19, %0
  %30 = tail call i64 @unsignedstrconv_impl(i64 noundef %29, ptr noundef nonnull %2, i64 noundef %3, i32 noundef %4)
  br label %31

31:                                               ; preds = %24, %28, %5, %14
  %.0 = phi i64 [ 0, %14 ], [ 0, %5 ], [ %27, %24 ], [ %30, %28 ]
  ret i64 %.0
}

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @unsignedstrconv_impl(i64 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #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,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass