; LLVM IR from simon-zerisenay/42_Push_Swap :: 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = icmp eq i64 %6, -2147483648
  br i1 %7, label %8, label %11

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = call i64 @write(i32 noundef %9, ptr noundef @.str, i64 noundef 2)
  store i32 147483648, ptr %3, align 4, !tbaa !5
  br label %11

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

14:                                               ; preds = %11
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = mul nsw i32 %15, -1
  store i32 %16, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = call i64 @write(i32 noundef %17, ptr noundef @.str.1, i64 noundef 1)
  br label %19

19:                                               ; preds = %14, %11
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %22, label %30

22:                                               ; preds = %19
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = icmp sle i32 %23, 9
  br i1 %24, label %25, label %30

25:                                               ; preds = %22
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = add nsw i32 %26, 48
  %28 = trunc i32 %27 to i8
  %29 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putchar_fd(i8 noundef signext %28, i32 noundef %29)
  br label %37

30:                                               ; preds = %22, %19
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sdiv i32 %31, 10
  %33 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putnbr_fd(i32 noundef %32, i32 noundef %33)
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = srem i32 %34, 10
  %36 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putnbr_fd(i32 noundef %35, i32 noundef %36)
  br label %37

37:                                               ; preds = %30, %25
  ret void
}

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #1

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

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


; 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 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 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %15, %2
  %.tr = phi i32 [ %0, %2 ], [ %17, %15 ]
  %3 = icmp eq i32 %.tr, -2147483648
  br i1 %3, label %.thread15, label %5

.thread15:                                        ; preds = %tailrecurse
  %4 = tail call i64 @write(i32 noundef %1, ptr noundef nonnull @.str, i64 noundef 2) #3
  br label %15

5:                                                ; preds = %tailrecurse
  %6 = icmp slt i32 %.tr, 0
  br i1 %6, label %7, label %10

7:                                                ; preds = %5
  %8 = sub nsw i32 0, %.tr
  %9 = tail call i64 @write(i32 noundef %1, ptr noundef nonnull @.str.1, i64 noundef 1) #3
  br label %10

10:                                               ; preds = %7, %5
  %.1 = phi i32 [ %8, %7 ], [ %.tr, %5 ]
  %11 = icmp ult i32 %.1, 10
  br i1 %11, label %12, label %15

12:                                               ; preds = %10
  %13 = trunc nuw i32 %.1 to i8
  %14 = or disjoint i8 %13, 48
  tail call void @ft_putchar_fd(i8 noundef signext %14, i32 noundef %1) #3
  ret void

15:                                               ; preds = %.thread15, %10
  %.117 = phi i32 [ 147483648, %.thread15 ], [ %.1, %10 ]
  %16 = udiv i32 %.117, 10
  tail call void @ft_putnbr_fd(i32 noundef %16, i32 noundef %1)
  %17 = urem i32 %.117, 10
  br label %tailrecurse
}

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #1

declare void @ft_putchar_fd(i8 noundef signext, i32 noundef) local_unnamed_addr #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 = { nofree "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 = { "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)"}


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