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

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

declare i32 @ft_print_out(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @output_of_finite_spaces(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.s_pf, ptr %10, i32 0, i32 5
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = sub nsw i32 %12, %13
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = sub nsw i32 %14, %15
  store i32 %16, ptr %8, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.s_pf, ptr %17, i32 0, i32 5
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.s_pf, ptr %20, i32 0, i32 6
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = icmp sge i32 %19, %22
  br i1 %23, label %24, label %40

24:                                               ; preds = %3
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.s_pf, ptr %25, i32 0, i32 6
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp sgt i32 %27, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %24
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.s_pf, ptr %31, i32 0, i32 5
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.s_pf, ptr %34, i32 0, i32 6
  %36 = load i32, ptr %35, align 8, !tbaa !13
  %37 = sub nsw i32 %33, %36
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = sub nsw i32 %37, %38
  store i32 %39, ptr %8, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %30, %24, %3
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.s_pf, ptr %41, i32 0, i32 5
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.s_pf, ptr %44, i32 0, i32 6
  %46 = load i32, ptr %45, align 8, !tbaa !13
  %47 = icmp slt i32 %43, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %40
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %48, %40
  br label %50

50:                                               ; preds = %73, %49
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.s_pf, ptr %51, i32 0, i32 7
  %53 = load i32, ptr %52, align 4, !tbaa !14
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %58

55:                                               ; preds = %50
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = icmp sgt i32 %56, 0
  br label %58

58:                                               ; preds = %55, %50
  %59 = phi i1 [ false, %50 ], [ %57, %55 ]
  br i1 %59, label %60, label %76

60:                                               ; preds = %58
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.s_pf, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.s_pf, ptr %63, i32 0, i32 3
  %65 = load i32, ptr %64, align 4, !tbaa !15
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %64, align 4, !tbaa !15
  %67 = sext i32 %65 to i64
  %68 = getelementptr inbounds [1024 x i8], ptr %62, i64 0, i64 %67
  store i8 32, ptr %68, align 1, !tbaa !16
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = call i32 @ft_print_out(ptr noundef %69)
  %71 = icmp eq i32 %70, -1
  br i1 %71, label %72, label %73

72:                                               ; preds = %60
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %77

73:                                               ; preds = %60
  %74 = load i32, ptr %8, align 4, !tbaa !9
  %75 = add nsw i32 %74, -1
  store i32 %75, ptr %8, align 4, !tbaa !9
  br label %50, !llvm.loop !17

76:                                               ; preds = %58
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %77

77:                                               ; preds = %76, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %78 = load i32, ptr %4, align 4
  ret i32 %78
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"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 1044}
!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 1048}
!14 = !{!12, !10, i64 1052}
!15 = !{!12, !10, i64 1036}
!16 = !{!7, !7, i64 0}
!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, 1) i32 @output_of_finite_spaces(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 1044
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 1048
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %.not.not = icmp sge i32 %5, %7
  %8 = tail call i32 @llvm.smax.i32(i32 %7, i32 %1)
  %.pn21 = select i1 %.not.not, i32 %8, i32 %1
  %9 = add i32 %.pn21, %2
  %.0 = sub i32 %5, %9
  %10 = getelementptr inbounds i8, ptr %0, i64 12
  %11 = getelementptr inbounds i8, ptr %0, i64 1036
  %12 = getelementptr inbounds i8, ptr %0, i64 1052
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = icmp ne i32 %13, 0
  %15 = icmp sgt i32 %.0, 0
  %16 = select i1 %14, i1 %.not.not, i1 false
  %17 = select i1 %16, i1 %15, i1 false
  br i1 %17, label %.lr.ph, label %._crit_edge

18:                                               ; preds = %.lr.ph
  %19 = add nsw i32 %.222, -1
  %20 = load i32, ptr %12, align 4, !tbaa !12
  %21 = icmp ne i32 %20, 0
  %22 = icmp sgt i32 %.222, 1
  %23 = select i1 %21, i1 %22, i1 false
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !13

.lr.ph:                                           ; preds = %3, %18
  %.222 = phi i32 [ %19, %18 ], [ %.0, %3 ]
  %24 = load i32, ptr %11, align 4, !tbaa !15
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %11, align 4, !tbaa !15
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 %26
  store i8 32, ptr %27, align 1, !tbaa !16
  %28 = tail call i32 @ft_print_out(ptr noundef nonnull %0) #3
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %._crit_edge, label %18

._crit_edge:                                      ; preds = %.lr.ph, %18, %3
  %.018 = phi i32 [ 0, %3 ], [ 0, %18 ], [ -1, %.lr.ph ]
  ret i32 %.018
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 1044}
!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 1048}
!12 = !{!6, !10, i64 1052}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 1036}
!16 = !{!8, !8, i64 0}


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