; LLVM IR from LlimaV10/doom-nukem_v2 :: 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"

; 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 i64, align 8
  %6 = alloca i64, align 8
  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 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %11

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putchar_fd(i8 noundef signext 48, i32 noundef %10)
  br label %11

11:                                               ; preds = %9, %2
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  store i64 %13, ptr %5, align 8, !tbaa !9
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = icmp slt i64 %14, 0
  br i1 %15, label %16, label %20

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

20:                                               ; preds = %16, %11
  store i64 1, ptr %6, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %26, %20
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = sdiv i64 %22, %23
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %21
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = mul nsw i64 %27, 10
  store i64 %28, ptr %6, align 8, !tbaa !9
  br label %21, !llvm.loop !11

29:                                               ; preds = %21
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = sdiv i64 %30, 10
  store i64 %31, ptr %6, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %35, %29
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = icmp sge i64 %33, 1
  br i1 %34, label %35, label %51

35:                                               ; preds = %32
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = sdiv i64 %36, %37
  %39 = add nsw i64 %38, 48
  %40 = trunc i64 %39 to i8
  %41 = load i32, ptr %4, align 4, !tbaa !5
  call void @ft_putchar_fd(i8 noundef signext %40, i32 noundef %41)
  %42 = load i64, ptr %5, align 8, !tbaa !9
  %43 = load i64, ptr %6, align 8, !tbaa !9
  %44 = sdiv i64 %42, %43
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = mul nsw i64 %44, %45
  %47 = load i64, ptr %5, align 8, !tbaa !9
  %48 = sub nsw i64 %47, %46
  store i64 %48, ptr %5, align 8, !tbaa !9
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = sdiv i64 %49, 10
  store i64 %50, ptr %6, align 8, !tbaa !9
  br label %32, !llvm.loop !13

51:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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


; 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_putnbr_fd(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, 0
  br i1 %3, label %.thread30, label %4

.thread30:                                        ; preds = %2
  tail call void @ft_putchar_fd(i8 noundef signext 48, i32 noundef %1) #2
  br label %._crit_edge

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

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

9:                                                ; preds = %7, %4
  %.019 = phi i64 [ %8, %7 ], [ %5, %4 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %9, %.lr.ph
  %.025 = phi i64 [ %10, %.lr.ph ], [ 1, %9 ]
  %10 = mul nuw nsw i64 %.025, 10
  %11 = sdiv i64 %.019, %10
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %.lr.ph29, label %.lr.ph, !llvm.loop !5

.lr.ph29:                                         ; preds = %.lr.ph, %.lr.ph29
  %.1.in28 = phi i64 [ %.1, %.lr.ph29 ], [ %10, %.lr.ph ]
  %.12027 = phi i64 [ %.recomposed, %.lr.ph29 ], [ %.019, %.lr.ph ]
  %.1 = udiv i64 %.1.in28, 10
  %12 = sdiv i64 %.12027, %.1
  %13 = trunc i64 %12 to i8
  %14 = add i8 %13, 48
  tail call void @ft_putchar_fd(i8 noundef signext %14, i32 noundef %1) #2
  %15 = mul nsw i64 %12, %.1
  %.recomposed = srem i64 %.12027, %.1
  %.not23 = icmp ult i64 %.1.in28, 100
  br i1 %.not23, label %._crit_edge, label %.lr.ph29, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph29, %.thread30
  ret void
}

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)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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