; LLVM IR from Mohamed-Ouarar/C_piscine :: C00/ex07-ft_putnbr (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"

@.str = external hidden unnamed_addr constant [12 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(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = icmp eq i64 %6, -2147483648
  br i1 %7, label %8, label %10

8:                                                ; preds = %1
  %9 = call i64 @write(i32 noundef 1, ptr noundef @.str, i64 noundef 11)
  store i32 1, ptr %4, align 4
  br label %31

10:                                               ; preds = %1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %17

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

17:                                               ; preds = %13, %10
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp sgt i32 %18, 9
  br i1 %19, label %20, label %25

20:                                               ; preds = %17
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sdiv i32 %21, 10
  call void @ft_putnbr(i32 noundef %22)
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = srem i32 %23, 10
  call void @ft_putnbr(i32 noundef %24)
  br label %30

25:                                               ; preds = %17
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = add nsw i32 %26, 48
  %28 = trunc i32 %27 to i8
  store i8 %28, ptr %3, align 1, !tbaa !9
  %29 = call i64 @write(i32 noundef 1, ptr noundef %3, i64 noundef 1)
  br label %30

30:                                               ; preds = %25, %20
  store i32 0, ptr %4, align 4
  br label %31

31:                                               ; preds = %30, %8
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  %32 = load i32, ptr %4, align 4
  switch i32 %32, label %34 [
    i32 0, label %33
    i32 1, label %33
  ]

33:                                               ; preds = %31, %31
  ret void

34:                                               ; preds = %31
  unreachable
}

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

declare i64 @write(i32 noundef, ptr noundef, i64 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
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @ft_putnbr(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #3
  %3 = icmp eq i32 %0, -2147483648
  br i1 %3, label %4, label %6

4:                                                ; preds = %1
  %5 = tail call i64 @write(i32 noundef 1, ptr noundef nonnull @.str, i64 noundef 11) #3
  br label %20

6:                                                ; preds = %1
  %7 = icmp slt i32 %0, 0
  br i1 %7, label %8, label %11

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

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

13:                                               ; preds = %11
  %14 = udiv i32 %.0, 10
  tail call void @ft_putnbr(i32 noundef %14)
  %15 = urem i32 %.0, 10
  tail call void @ft_putnbr(i32 noundef %15)
  br label %20

16:                                               ; preds = %11
  %17 = trunc nuw i32 %.0 to i8
  %18 = or disjoint i8 %17, 48
  store i8 %18, ptr %2, align 1, !tbaa !5
  %19 = call i64 @write(i32 noundef 1, ptr noundef nonnull %2, i64 noundef 1) #3
  br label %20

20:                                               ; preds = %13, %16, %4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #3
  ret void
}

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

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

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

attributes #0 = { nofree 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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