; LLVM IR from bnidia/push_swap :: libraries/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"

@.str = external hidden unnamed_addr constant [20 x i8], align 1

; 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 ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = 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
  %8 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %8, ptr %4, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %65

12:                                               ; preds = %1
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %13, ptr %6, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %14, ptr %5, align 8, !tbaa !9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = srem i32 %15, 10
  %17 = add nsw i32 9, %16
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [20 x i8], ptr @.str, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i32 1
  store ptr %22, ptr %4, align 8, !tbaa !9
  store i8 %20, ptr %21, align 1, !tbaa !11
  br label %23

23:                                               ; preds = %27, %12
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sdiv i32 %24, 10
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %38

27:                                               ; preds = %23
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sdiv i32 %28, 10
  store i32 %29, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = srem i32 %30, 10
  %32 = add nsw i32 9, %31
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [20 x i8], ptr @.str, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %36, i32 1
  store ptr %37, ptr %4, align 8, !tbaa !9
  store i8 %35, ptr %36, align 1, !tbaa !11
  br label %23, !llvm.loop !12

38:                                               ; preds = %23
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = icmp slt i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %4, align 8, !tbaa !9
  store i8 45, ptr %42, align 1, !tbaa !11
  br label %44

44:                                               ; preds = %41, %38
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %45, i32 -1
  store ptr %46, ptr %4, align 8, !tbaa !9
  store i8 0, ptr %45, align 1, !tbaa !11
  br label %47

47:                                               ; preds = %51, %44
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = load ptr, ptr %4, align 8, !tbaa !9
  %50 = icmp ult ptr %48, %49
  br i1 %50, label %51, label %63

51:                                               ; preds = %47
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = load i8, ptr %52, align 1, !tbaa !11
  %54 = sext i8 %53 to i32
  store i32 %54, ptr %3, align 4, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !9
  %56 = load i8, ptr %55, align 1, !tbaa !11
  %57 = load ptr, ptr %4, align 8, !tbaa !9
  %58 = getelementptr inbounds i8, ptr %57, i32 -1
  store ptr %58, ptr %4, align 8, !tbaa !9
  store i8 %56, ptr %57, align 1, !tbaa !11
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = trunc i32 %59 to i8
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %5, align 8, !tbaa !9
  store i8 %60, ptr %61, align 1, !tbaa !11
  br label %47, !llvm.loop !14

63:                                               ; preds = %47
  %64 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %64, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %65

65:                                               ; preds = %63, %11
  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
  %66 = load ptr, ptr %2, align 8
  ret ptr %66
}

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

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

; 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 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@.str = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef ptr @ft_itoa(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = srem i32 %0, 10
  %5 = add nsw i32 %4, 9
  %6 = zext nneg i32 %5 to i64
  %7 = getelementptr inbounds [20 x i8], ptr @.str, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !5
  store i8 %8, ptr %2, align 1, !tbaa !5
  %.02126 = getelementptr inbounds i8, ptr %2, i64 1
  %.022.off27 = add i32 %0, 9
  %.not2528 = icmp ult i32 %.022.off27, 19
  br i1 %.not2528, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.02130 = phi ptr [ %.021, %.lr.ph ], [ %.02126, %3 ]
  %.02229 = phi i32 [ %9, %.lr.ph ], [ %0, %3 ]
  %9 = sdiv i32 %.02229, 10
  %10 = srem i32 %9, 10
  %11 = add nsw i32 %10, 9
  %12 = zext nneg i32 %11 to i64
  %13 = getelementptr inbounds [20 x i8], ptr @.str, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !5
  store i8 %14, ptr %.02130, align 1, !tbaa !5
  %.021 = getelementptr inbounds i8, ptr %.02130, i64 1
  %.022.off = add nsw i32 %9, 9
  %.not25 = icmp ult i32 %.022.off, 19
  br i1 %.not25, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.022.lcssa = phi i32 [ %0, %3 ], [ %9, %.lr.ph ]
  %.pn.lcssa = phi ptr [ %2, %3 ], [ %.02130, %.lr.ph ]
  %.021.lcssa = phi ptr [ %.02126, %3 ], [ %.021, %.lr.ph ]
  %15 = icmp slt i32 %.022.lcssa, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %._crit_edge
  %17 = getelementptr inbounds i8, ptr %.pn.lcssa, i64 2
  store i8 45, ptr %.021.lcssa, align 1, !tbaa !5
  br label %18

18:                                               ; preds = %16, %._crit_edge
  %.1 = phi ptr [ %17, %16 ], [ %.021.lcssa, %._crit_edge ]
  store i8 0, ptr %.1, align 1, !tbaa !5
  %.233 = getelementptr inbounds i8, ptr %.1, i64 -1
  %19 = icmp ult ptr %2, %.233
  br i1 %19, label %.lr.ph37, label %.loopexit

.lr.ph37:                                         ; preds = %18, %.lr.ph37
  %.235 = phi ptr [ %.2, %.lr.ph37 ], [ %.233, %18 ]
  %.02034 = phi ptr [ %22, %.lr.ph37 ], [ %2, %18 ]
  %20 = load i8, ptr %.235, align 1, !tbaa !5
  %21 = load i8, ptr %.02034, align 1, !tbaa !5
  store i8 %21, ptr %.235, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.02034, i64 1
  store i8 %20, ptr %.02034, align 1, !tbaa !5
  %.2 = getelementptr inbounds i8, ptr %.235, i64 -1
  %23 = icmp ult ptr %22, %.2
  br i1 %23, label %.lr.ph37, label %.loopexit, !llvm.loop !10

.loopexit:                                        ; preds = %.lr.ph37, %18, %1
  ret ptr %2
}

; 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

attributes #0 = { nofree 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"}
!10 = distinct !{!10, !9}


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