; LLVM IR from bnidia/push_swap :: libraries/libft (ft_itoa_base)

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

%struct.s_pf = type { ptr, i32, [1024 x i8], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @ft_itoa_base(ptr noundef %0, i64 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %14, label %23

14:                                               ; preds = %4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.s_pf, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.s_pf, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !13
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [1024 x i8], ptr %16, i64 0, i64 %21
  store i8 48, ptr %22, align 1, !tbaa !15
  store i32 1, ptr %11, align 4
  br label %65

23:                                               ; preds = %4
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !11
  %26 = call i64 @ft_numlen(i64 noundef %24, i32 noundef %25)
  %27 = trunc i64 %26 to i32
  %28 = sub nsw i32 %27, 1
  store i32 %28, ptr %9, align 4, !tbaa !11
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %33, %23
  %30 = load i32, ptr %10, align 4, !tbaa !11
  %31 = load i32, ptr %9, align 4, !tbaa !11
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %33, label %58

33:                                               ; preds = %29
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = urem i64 %35, %37
  %39 = getelementptr inbounds i8, ptr %34, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !15
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.s_pf, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.s_pf, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = load i32, ptr %9, align 4, !tbaa !11
  %47 = add nsw i32 %45, %46
  %48 = load i32, ptr %10, align 4, !tbaa !11
  %49 = sub nsw i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1024 x i8], ptr %42, i64 0, i64 %50
  store i8 %40, ptr %51, align 1, !tbaa !15
  %52 = load i32, ptr %7, align 4, !tbaa !11
  %53 = sext i32 %52 to i64
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = udiv i64 %54, %53
  store i64 %55, ptr %6, align 8, !tbaa !9
  %56 = load i32, ptr %10, align 4, !tbaa !11
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %10, align 4, !tbaa !11
  br label %29, !llvm.loop !16

58:                                               ; preds = %29
  %59 = load i32, ptr %9, align 4, !tbaa !11
  %60 = add nsw i32 %59, 1
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.s_pf, ptr %61, i32 0, i32 3
  %63 = load i32, ptr %62, align 4, !tbaa !13
  %64 = add nsw i32 %63, %60
  store i32 %64, ptr %62, align 4, !tbaa !13
  store i32 0, ptr %11, align 4
  br label %65

65:                                               ; preds = %58, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %66 = load i32, ptr %11, align 4
  switch i32 %66, label %68 [
    i32 0, label %67
    i32 1, label %67
  ]

67:                                               ; preds = %65, %65
  ret void

68:                                               ; preds = %65
  unreachable
}

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

declare i64 @ft_numlen(i64 noundef, i32 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 = { "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 }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 1036}
!14 = !{!"s_pf", !6, i64 0, !12, i64 8, !7, i64 12, !12, i64 1036, !12, i64 1040, !12, i64 1044, !12, i64 1048, !12, i64 1052, !12, i64 1056, !12, i64 1060, !12, i64 1064, !12, i64 1068, !12, i64 1072}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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 void @ft_itoa_base(ptr nocapture noundef %0, i64 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = icmp eq i64 %1, 0
  br i1 %5, label %6, label %13

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = getelementptr inbounds i8, ptr %0, i64 1036
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 %11
  store i8 48, ptr %12, align 1, !tbaa !11
  br label %34

13:                                               ; preds = %4
  %14 = tail call i64 @ft_numlen(i64 noundef %1, i32 noundef %2) #2
  %15 = trunc i64 %14 to i32
  %.not.not21 = icmp sgt i32 %15, 0
  br i1 %.not.not21, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %13
  %16 = sext i32 %2 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  %18 = getelementptr inbounds i8, ptr %0, i64 1036
  br label %19

19:                                               ; preds = %.lr.ph, %19
  %.023 = phi i32 [ 0, %.lr.ph ], [ %30, %19 ]
  %.01822 = phi i64 [ %1, %.lr.ph ], [ %29, %19 ]
  %20 = urem i64 %.01822, %16
  %21 = getelementptr inbounds i8, ptr %3, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = load i32, ptr %18, align 4, !tbaa !5
  %24 = xor i32 %.023, -1
  %25 = add nsw i32 %24, %15
  %26 = add i32 %25, %23
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1024 x i8], ptr %17, i64 0, i64 %27
  store i8 %22, ptr %28, align 1, !tbaa !11
  %29 = udiv i64 %.01822, %16
  %30 = add nuw nsw i32 %.023, 1
  %exitcond.not = icmp eq i32 %30, %15
  br i1 %exitcond.not, label %._crit_edge, label %19, !llvm.loop !12

._crit_edge:                                      ; preds = %19, %13
  %31 = getelementptr inbounds i8, ptr %0, i64 1036
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %32, %15
  store i32 %33, ptr %31, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %._crit_edge, %6
  ret void
}

declare i64 @ft_numlen(i64 noundef, i32 noundef) local_unnamed_addr #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 = { "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 }

!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, !10, i64 1036}
!6 = !{!"s_pf", !7, i64 0, !10, i64 8, !8, i64 12, !10, i64 1036, !10, i64 1040, !10, i64 1044, !10, i64 1048, !10, i64 1052, !10, i64 1056, !10, i64 1060, !10, i64 1064, !10, i64 1068, !10, i64 1072}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass