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

; 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"

%struct.s_pf = type { ptr, i32, [1024 x i8], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

declare i32 @ft_print_out(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @for_zero_put_empty_string(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.s_pf, ptr %6, i32 0, i32 6
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %42

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

13:                                               ; preds = %10
  br label %14

14:                                               ; preds = %38, %13
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.s_pf, ptr %15, i32 0, i32 5
  %17 = load i32, ptr %16, align 4, !tbaa !13
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr %16, align 4, !tbaa !13
  %19 = icmp sgt i32 %17, 0
  br i1 %19, label %20, label %39

20:                                               ; preds = %14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.s_pf, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.s_pf, ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %24, align 4, !tbaa !14
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds [1024 x i8], ptr %22, i64 0, i64 %27
  store i8 32, ptr %28, align 1, !tbaa !15
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i32 @ft_print_out(ptr noundef %29)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.s_pf, ptr %31, i32 0, i32 12
  store i32 %30, ptr %32, align 8, !tbaa !16
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.s_pf, ptr %33, i32 0, i32 12
  %35 = load i32, ptr %34, align 8, !tbaa !16
  %36 = icmp eq i32 %35, -1
  br i1 %36, label %37, label %38

37:                                               ; preds = %20
  store i32 -1, ptr %3, align 4
  br label %45

38:                                               ; preds = %20
  br label %14, !llvm.loop !17

39:                                               ; preds = %14
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.s_pf, ptr %40, i32 0, i32 12
  store i32 0, ptr %41, align 8, !tbaa !16
  store i32 0, ptr %3, align 4
  br label %45

42:                                               ; preds = %10, %2
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.s_pf, ptr %43, i32 0, i32 12
  store i32 1, ptr %44, align 8, !tbaa !16
  store i32 1, ptr %3, align 4
  br label %45

45:                                               ; preds = %42, %39, %37
  %46 = load i32, ptr %3, align 4
  ret i32 %46
}

attributes #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 = { 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" }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 1048}
!12 = !{!"s_pf", !6, i64 0, !10, i64 8, !7, i64 12, !10, i64 1036, !10, i64 1040, !10, i64 1044, !10, i64 1048, !10, i64 1052, !10, i64 1056, !10, i64 1060, !10, i64 1064, !10, i64 1068, !10, i64 1072}
!13 = !{!12, !10, i64 1044}
!14 = !{!12, !10, i64 1036}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !10, i64 1072}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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"

declare i32 @ft_print_out(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @for_zero_put_empty_string(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 1048
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = or i32 %4, %1
  %or.cond = icmp eq i32 %5, 0
  br i1 %or.cond, label %.preheader, label %22

.preheader:                                       ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 1044
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = getelementptr inbounds i8, ptr %0, i64 1036
  %9 = getelementptr inbounds i8, ptr %0, i64 1072
  br label %10

10:                                               ; preds = %.preheader, %14
  %11 = load i32, ptr %6, align 4, !tbaa !11
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %6, align 4, !tbaa !11
  %13 = icmp sgt i32 %11, 0
  br i1 %13, label %14, label %21

14:                                               ; preds = %10
  %15 = load i32, ptr %8, align 4, !tbaa !12
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %8, align 4, !tbaa !12
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 %17
  store i8 32, ptr %18, align 1, !tbaa !13
  %19 = tail call i32 @ft_print_out(ptr noundef nonnull %0) #2
  store i32 %19, ptr %9, align 8, !tbaa !14
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %.loopexit, label %10, !llvm.loop !15

21:                                               ; preds = %10
  store i32 0, ptr %9, align 8, !tbaa !14
  br label %.loopexit

22:                                               ; preds = %2
  %23 = getelementptr inbounds i8, ptr %0, i64 1072
  store i32 1, ptr %23, align 8, !tbaa !14
  br label %.loopexit

.loopexit:                                        ; preds = %14, %22, %21
  %.0 = phi i32 [ 0, %21 ], [ 1, %22 ], [ -1, %14 ]
  ret i32 %.0
}

attributes #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 = { 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 #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 = !{!6, !10, i64 1048}
!6 = !{!"s_pf", !7, i64 0, !10, i64 8, !8, i64 12, !10, i64 1036, !10, i64 1040, !10, i64 1044, !10, i64 1048, !10, i64 1052, !10, i64 1056, !10, i64 1060, !10, i64 1064, !10, i64 1068, !10, i64 1072}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 1044}
!12 = !{!6, !10, i64 1036}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !10, i64 1072}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass