; LLVM IR from yettabaa/cub3D :: Common/Libft (ft_itoa)

; 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 ptr @ft_itoa(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  store i64 %10, ptr %6, align 8, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = call i32 @pow_10(i32 noundef %11)
  %13 = sext i32 %12 to i64
  store i64 %13, ptr %5, align 8, !tbaa !9
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = call i32 @nb_n(i32 noundef %14)
  %16 = add nsw i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = call noalias ptr @malloc(i64 noundef %17) #4
  store ptr %18, ptr %7, align 8, !tbaa !11
  %19 = load ptr, ptr %7, align 8, !tbaa !11
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %63

22:                                               ; preds = %1
  store i64 0, ptr %4, align 8, !tbaa !9
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %25, label %32

25:                                               ; preds = %22
  %26 = load ptr, ptr %7, align 8, !tbaa !11
  %27 = load i64, ptr %4, align 8, !tbaa !9
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %26, i64 %27
  store i8 45, ptr %29, align 1, !tbaa !13
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = mul nsw i64 %30, -1
  store i64 %31, ptr %6, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %25, %22
  br label %33

33:                                               ; preds = %39, %32
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = call i32 @nb_n(i32 noundef %35)
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %34, %37
  br i1 %38, label %39, label %58

39:                                               ; preds = %33
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = sdiv i64 %40, %41
  %43 = add nsw i64 %42, 48
  %44 = trunc i64 %43 to i8
  %45 = load ptr, ptr %7, align 8, !tbaa !11
  %46 = load i64, ptr %4, align 8, !tbaa !9
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %4, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %45, i64 %46
  store i8 %44, ptr %48, align 1, !tbaa !13
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = load i64, ptr %5, align 8, !tbaa !9
  %52 = sdiv i64 %50, %51
  %53 = load i64, ptr %5, align 8, !tbaa !9
  %54 = mul nsw i64 %52, %53
  %55 = sub nsw i64 %49, %54
  store i64 %55, ptr %6, align 8, !tbaa !9
  %56 = load i64, ptr %5, align 8, !tbaa !9
  %57 = sdiv i64 %56, 10
  store i64 %57, ptr %5, align 8, !tbaa !9
  br label %33, !llvm.loop !14

58:                                               ; preds = %33
  %59 = load ptr, ptr %7, align 8, !tbaa !11
  %60 = load i64, ptr %4, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  store i8 0, ptr %61, align 1, !tbaa !13
  %62 = load ptr, ptr %7, align 8, !tbaa !11
  store ptr %62, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %63

63:                                               ; preds = %58, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %64 = load ptr, ptr %2, align 8
  ret ptr %64
}

; 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 hidden i32 @pow_10(i32 noundef) #0

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @nb_n(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 allocsize(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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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"

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @ft_itoa(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = tail call i32 @pow_10(i32 noundef %0)
  %4 = sext i32 %3 to i64
  %5 = tail call i32 @nb_n(i32 noundef %0)
  %6 = add nsw i32 %5, 1
  %7 = sext i32 %6 to i64
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #2
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %28, label %9

9:                                                ; preds = %1
  %10 = icmp slt i32 %0, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %9
  store i8 45, ptr %8, align 1, !tbaa !5
  %12 = sub nsw i64 0, %2
  br label %13

13:                                               ; preds = %11, %9
  %.024 = phi i64 [ 1, %11 ], [ 0, %9 ]
  %.022 = phi i64 [ %12, %11 ], [ %2, %9 ]
  %14 = tail call i32 @nb_n(i32 noundef %0)
  %15 = sext i32 %14 to i64
  %16 = icmp slt i64 %.024, %15
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.131 = phi i64 [ %.recomposed, %.lr.ph ], [ %.022, %13 ]
  %.02330 = phi i64 [ %23, %.lr.ph ], [ %4, %13 ]
  %.12529 = phi i64 [ %20, %.lr.ph ], [ %.024, %13 ]
  %17 = sdiv i64 %.131, %.02330
  %18 = trunc i64 %17 to i8
  %19 = add i8 %18, 48
  %20 = add nuw nsw i64 %.12529, 1
  %21 = getelementptr inbounds i8, ptr %8, i64 %.12529
  store i8 %19, ptr %21, align 1, !tbaa !5
  %22 = mul nsw i64 %17, %.02330
  %.recomposed = srem i64 %.131, %.02330
  %23 = sdiv i64 %.02330, 10
  %24 = tail call i32 @nb_n(i32 noundef %0)
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %20, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %13
  %.125.lcssa = phi i64 [ %.024, %13 ], [ %20, %.lr.ph ]
  %27 = getelementptr inbounds i8, ptr %8, i64 %.125.lcssa
  store i8 0, ptr %27, align 1, !tbaa !5
  br label %28

28:                                               ; preds = %1, %._crit_edge
  ret ptr %8
}

; Function Attrs: nounwind uwtable
declare hidden i32 @pow_10(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @nb_n(i32 noundef) local_unnamed_addr #0

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }

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


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