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

; 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 [12 x i8], align 1

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

10:                                               ; preds = %2
  %11 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putstr_fd(ptr noundef @.str, i32 noundef %11)
  store i32 1, ptr %6, align 4
  br label %43

12:                                               ; preds = %2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %15, label %19

15:                                               ; preds = %12
  %16 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putchar_fd(i8 noundef signext 45, i32 noundef %16)
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sub nsw i32 0, %17
  store i32 %18, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %15, %12
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp sge i32 %20, 10
  br i1 %21, label %22, label %32

22:                                               ; preds = %19
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sdiv i32 %23, 10
  %25 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putnbr_fd(i32 noundef %24, i32 noundef %25)
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = srem i32 %26, 10
  %28 = add nsw i32 %27, 48
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %5, align 1, !tbaa !9
  %30 = load i8, ptr %5, align 1, !tbaa !9
  %31 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putchar_fd(i8 noundef signext %30, i32 noundef %31)
  br label %32

32:                                               ; preds = %22, %19
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 10
  br i1 %34, label %35, label %42

35:                                               ; preds = %32
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = srem i32 %36, 10
  %38 = add nsw i32 %37, 48
  %39 = trunc i32 %38 to i8
  store i8 %39, ptr %5, align 1, !tbaa !9
  %40 = load i8, ptr %5, align 1, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putchar_fd(i8 noundef signext %40, i32 noundef %41)
  br label %42

42:                                               ; preds = %35, %32
  store i32 0, ptr %6, align 4
  br label %43

43:                                               ; preds = %42, %10
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  %44 = load i32, ptr %6, align 4
  switch i32 %44, label %46 [
    i32 0, label %45
    i32 1, label %45
  ]

45:                                               ; preds = %43, %43
  ret void

46:                                               ; preds = %43
  unreachable
}

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

declare void @ft_putstr_fd(ptr noundef, i32 noundef) #2

declare void @ft_putchar_fd(i8 noundef signext, 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!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"

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

; Function Attrs: nounwind uwtable
define dso_local void @ft_putnbr_fd(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, -2147483648
  br i1 %3, label %4, label %5

4:                                                ; preds = %2
  tail call void @ft_putstr_fd(ptr noundef nonnull @.str, i32 noundef %1) #2
  br label %common.ret16

5:                                                ; preds = %2
  %6 = icmp slt i32 %0, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %5
  tail call void @ft_putchar_fd(i8 noundef signext 45, i32 noundef %1) #2
  %8 = sub nsw i32 0, %0
  br label %9

9:                                                ; preds = %7, %5
  %.0 = phi i32 [ %8, %7 ], [ %0, %5 ]
  %10 = icmp ugt i32 %.0, 9
  br i1 %10, label %11, label %16

common.ret16:                                     ; preds = %16, %4, %11
  ret void

11:                                               ; preds = %9
  %12 = udiv i32 %.0, 10
  tail call void @ft_putnbr_fd(i32 noundef %12, i32 noundef %1)
  %13 = urem i32 %.0, 10
  %14 = trunc nuw nsw i32 %13 to i8
  %15 = or disjoint i8 %14, 48
  tail call void @ft_putchar_fd(i8 noundef signext %15, i32 noundef %1) #2
  br label %common.ret16

16:                                               ; preds = %9
  %17 = trunc nuw nsw i32 %.0 to i8
  %18 = or disjoint i8 %17, 48
  tail call void @ft_putchar_fd(i8 noundef signext %18, i32 noundef %1) #2
  br label %common.ret16
}

declare void @ft_putstr_fd(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @ft_putchar_fd(i8 noundef signext, 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass