; LLVM IR from LlimaV10/doom-nukem_v2 :: libft (ft_putnbr)

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

7:                                                ; preds = %1
  call void @ft_putchar(i8 noundef signext 48)
  br label %8

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

13:                                               ; preds = %8
  call void @ft_putchar(i8 noundef signext 45)
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = sub nsw i64 0, %14
  store i64 %15, ptr %3, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %13, %8
  store i64 1, ptr %4, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %22, %16
  %18 = load i64, ptr %3, align 8, !tbaa !9
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = sdiv i64 %18, %19
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %17
  %23 = load i64, ptr %4, align 8, !tbaa !9
  %24 = mul nsw i64 %23, 10
  store i64 %24, ptr %4, align 8, !tbaa !9
  br label %17, !llvm.loop !11

25:                                               ; preds = %17
  %26 = load i64, ptr %4, align 8, !tbaa !9
  %27 = sdiv i64 %26, 10
  store i64 %27, ptr %4, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %31, %25
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = icmp sge i64 %29, 1
  br i1 %30, label %31, label %46

31:                                               ; preds = %28
  %32 = load i64, ptr %3, align 8, !tbaa !9
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = sdiv i64 %32, %33
  %35 = add nsw i64 %34, 48
  %36 = trunc i64 %35 to i8
  call void @ft_putchar(i8 noundef signext %36)
  %37 = load i64, ptr %3, align 8, !tbaa !9
  %38 = load i64, ptr %4, align 8, !tbaa !9
  %39 = sdiv i64 %37, %38
  %40 = load i64, ptr %4, align 8, !tbaa !9
  %41 = mul nsw i64 %39, %40
  %42 = load i64, ptr %3, align 8, !tbaa !9
  %43 = sub nsw i64 %42, %41
  store i64 %43, ptr %3, align 8, !tbaa !9
  %44 = load i64, ptr %4, align 8, !tbaa !9
  %45 = sdiv i64 %44, 10
  store i64 %45, ptr %4, align 8, !tbaa !9
  br label %28, !llvm.loop !13

46:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #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(i8 noundef signext) #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(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq i32 %0, 0
  br i1 %2, label %.thread27, label %3

.thread27:                                        ; preds = %1
  tail call void @ft_putchar(i8 noundef signext 48) #2
  br label %._crit_edge

3:                                                ; preds = %1
  %4 = sext i32 %0 to i64
  %5 = icmp slt i32 %0, 0
  br i1 %5, label %6, label %8

6:                                                ; preds = %3
  tail call void @ft_putchar(i8 noundef signext 45) #2
  %7 = sub nsw i64 0, %4
  br label %8

8:                                                ; preds = %6, %3
  %.016 = phi i64 [ %7, %6 ], [ %4, %3 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.022 = phi i64 [ %9, %.lr.ph ], [ 1, %8 ]
  %9 = mul nuw nsw i64 %.022, 10
  %10 = sdiv i64 %.016, %9
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %.lr.ph26, label %.lr.ph, !llvm.loop !5

.lr.ph26:                                         ; preds = %.lr.ph, %.lr.ph26
  %.1.in25 = phi i64 [ %.1, %.lr.ph26 ], [ %9, %.lr.ph ]
  %.11724 = phi i64 [ %.recomposed, %.lr.ph26 ], [ %.016, %.lr.ph ]
  %.1 = udiv i64 %.1.in25, 10
  %11 = sdiv i64 %.11724, %.1
  %12 = trunc i64 %11 to i8
  %13 = add i8 %12, 48
  tail call void @ft_putchar(i8 noundef signext %13) #2
  %14 = mul nsw i64 %11, %.1
  %.recomposed = srem i64 %.11724, %.1
  %.not20 = icmp ult i64 %.1.in25, 100
  br i1 %.not20, label %._crit_edge, label %.lr.ph26, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph26, %.thread27
  ret void
}

declare void @ft_putchar(i8 noundef signext) 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