; LLVM IR from AdrianWR/push_swap :: libft/src (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 i32, align 4
  %5 = alloca i64, 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 4, 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 = load i32, ptr %3, align 4, !tbaa !5
  %9 = call i64 @ft_digit_counter(i32 noundef %8)
  store i64 %9, ptr %5, align 8, !tbaa !9
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %1
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sub i32 0, %13
  store i32 %14, ptr %4, align 4, !tbaa !5
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = add i64 %15, 1
  store i64 %16, ptr %5, align 8, !tbaa !9
  br label %19

17:                                               ; preds = %1
  %18 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %18, ptr %4, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %17, %12
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = add i64 %20, 1
  %22 = mul i64 %21, 1
  %23 = call noalias ptr @malloc(i64 noundef %22) #4
  store ptr %23, ptr %6, align 8, !tbaa !11
  %24 = load ptr, ptr %6, align 8, !tbaa !11
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %19
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %53

27:                                               ; preds = %19
  %28 = load ptr, ptr %6, align 8, !tbaa !11
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  store i8 0, ptr %30, align 1, !tbaa !13
  br label %31

31:                                               ; preds = %35, %27
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = add i64 %32, -1
  store i64 %33, ptr %5, align 8, !tbaa !9
  %34 = icmp ne i64 %32, 0
  br i1 %34, label %35, label %45

35:                                               ; preds = %31
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = urem i32 %36, 10
  %38 = add i32 %37, 48
  %39 = trunc i32 %38 to i8
  %40 = load ptr, ptr %6, align 8, !tbaa !11
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  store i8 %39, ptr %42, align 1, !tbaa !13
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = udiv i32 %43, 10
  store i32 %44, ptr %4, align 4, !tbaa !5
  br label %31, !llvm.loop !14

45:                                               ; preds = %31
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = icmp slt i32 %46, 0
  br i1 %47, label %48, label %51

48:                                               ; preds = %45
  %49 = load ptr, ptr %6, align 8, !tbaa !11
  %50 = getelementptr inbounds i8, ptr %49, i64 0
  store i8 45, ptr %50, align 1, !tbaa !13
  br label %51

51:                                               ; preds = %48, %45
  %52 = load ptr, ptr %6, align 8, !tbaa !11
  store ptr %52, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %53

53:                                               ; preds = %51, %26
  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 4, ptr %4) #3
  %54 = load ptr, ptr %2, align 8
  ret ptr %54
}

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

; 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 = !{!"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 = tail call i64 @ft_digit_counter(i32 noundef %0)
  %3 = icmp slt i32 %0, 0
  %.lobit = lshr i32 %0, 31
  %4 = zext nneg i32 %.lobit to i64
  %.017 = add i64 %2, %4
  %5 = add i64 %.017, 1
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #3
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %28, label %7

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %6, i64 %.017
  store i8 0, ptr %8, align 1, !tbaa !5
  %.not2324 = icmp eq i64 %.017, 0
  br i1 %.not2324, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %.018 = tail call i32 @llvm.abs.i32(i32 %0, i1 false)
  %9 = add i64 %2, %4
  %xtraiter = and i64 %.017, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %10 = add nsw i64 %.017, -1
  %11 = urem i32 %.018, 10
  %12 = trunc nuw nsw i32 %11 to i8
  %13 = or disjoint i8 %12, 48
  %14 = getelementptr inbounds i8, ptr %6, i64 %10
  store i8 %13, ptr %14, align 1, !tbaa !5
  %15 = udiv i32 %.018, 10
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.126.unr = phi i64 [ %.017, %.lr.ph.preheader ], [ %10, %.lr.ph.prol ]
  %.11925.unr = phi i32 [ %.018, %.lr.ph.preheader ], [ %15, %.lr.ph.prol ]
  %16 = icmp eq i64 %9, 1
  br i1 %16, label %._crit_edge, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %6, i64 -1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.126 = phi i64 [ %.126.unr, %.lr.ph.preheader.new ], [ %21, %.lr.ph ]
  %.11925 = phi i32 [ %.11925.unr, %.lr.ph.preheader.new ], [ %26, %.lr.ph ]
  %17 = urem i32 %.11925, 10
  %18 = trunc nuw nsw i32 %17 to i8
  %19 = or disjoint i8 %18, 48
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.126
  store i8 %19, ptr %gep, align 1, !tbaa !5
  %20 = udiv i32 %.11925, 10
  %21 = add i64 %.126, -2
  %22 = urem i32 %20, 10
  %23 = trunc nuw nsw i32 %22 to i8
  %24 = or disjoint i8 %23, 48
  %25 = getelementptr inbounds i8, ptr %6, i64 %21
  store i8 %24, ptr %25, align 1, !tbaa !5
  %26 = udiv i32 %.11925, 100
  %.not23.1 = icmp eq i64 %21, 0
  br i1 %.not23.1, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %7
  br i1 %3, label %27, label %28

27:                                               ; preds = %._crit_edge
  store i8 45, ptr %6, align 1, !tbaa !5
  br label %28

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

; Function Attrs: nounwind uwtable
declare hidden i64 @ft_digit_counter(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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass