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

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

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ft_p(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = call i64 @ft_numlen(i64 noundef %8, i32 noundef 16)
  %10 = trunc i64 %9 to i32
  %11 = add nsw i32 %10, 2
  store i32 %11, ptr %6, align 4, !tbaa !11
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %14, label %20

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call i32 @ft_s(ptr noundef %15, ptr noundef @.str, i1 noundef zeroext false)
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

19:                                               ; preds = %14
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

20:                                               ; preds = %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !11
  %23 = call i32 @output_of_initial_spaces(ptr noundef %21, i32 noundef %22, i32 noundef 0)
  %24 = icmp eq i32 %23, -1
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

26:                                               ; preds = %20
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.s_pf, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.s_pf, ptr %29, i32 0, i32 3
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %30, align 4, !tbaa !13
  %33 = sext i32 %31 to i64
  %34 = getelementptr inbounds [1024 x i8], ptr %28, i64 0, i64 %33
  store i8 48, ptr %34, align 1, !tbaa !15
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.s_pf, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.s_pf, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, align 4, !tbaa !13
  %41 = sext i32 %39 to i64
  %42 = getelementptr inbounds [1024 x i8], ptr %36, i64 0, i64 %41
  store i8 120, ptr %42, align 1, !tbaa !15
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %5, align 8, !tbaa !9
  call void @ft_itoa_base(ptr noundef %43, i64 noundef %44, i32 noundef 16, ptr noundef @.str.1)
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %6, align 4, !tbaa !11
  %47 = call i32 @output_of_finite_spaces(ptr noundef %45, i32 noundef %46, i32 noundef 0)
  %48 = icmp eq i32 %47, -1
  br i1 %48, label %49, label %50

49:                                               ; preds = %26
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

50:                                               ; preds = %26
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

51:                                               ; preds = %50, %49, %25, %19, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %52 = load i32, ptr %3, align 4
  ret i32 %52
}

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

declare i64 @ft_numlen(i64 noundef, i32 noundef) #2

declare i32 @ft_s(ptr noundef, ptr noundef, i1 noundef zeroext) #2

declare i32 @output_of_initial_spaces(ptr noundef, i32 noundef, i32 noundef) #2

declare void @ft_itoa_base(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #2

declare i32 @output_of_finite_spaces(ptr noundef, i32 noundef, 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 1036}
!14 = !{!"s_pf", !6, i64 0, !12, i64 8, !7, i64 12, !12, i64 1036, !12, i64 1040, !12, i64 1044, !12, i64 1048, !12, i64 1052, !12, i64 1056, !12, i64 1060, !12, i64 1064, !12, i64 1068, !12, i64 1072}
!15 = !{!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 [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @ft_p(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @ft_numlen(i64 noundef %1, i32 noundef 16) #2
  %4 = trunc i64 %3 to i32
  %5 = add nsw i32 %4, 2
  %6 = icmp eq i64 %1, 0
  br i1 %6, label %7, label %10

7:                                                ; preds = %2
  %8 = tail call i32 @ft_s(ptr noundef %0, ptr noundef nonnull @.str, i1 noundef zeroext false) #2
  %9 = icmp eq i32 %8, -1
  %. = sext i1 %9 to i32
  br label %26

10:                                               ; preds = %2
  %11 = tail call i32 @output_of_initial_spaces(ptr noundef %0, i32 noundef %5, i32 noundef 0) #2
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %26, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 12
  %15 = getelementptr inbounds i8, ptr %0, i64 1036
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %15, align 4, !tbaa !5
  %18 = sext i32 %16 to i64
  %19 = getelementptr inbounds [1024 x i8], ptr %14, i64 0, i64 %18
  store i8 48, ptr %19, align 1, !tbaa !11
  %20 = load i32, ptr %15, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %15, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [1024 x i8], ptr %14, i64 0, i64 %22
  store i8 120, ptr %23, align 1, !tbaa !11
  tail call void @ft_itoa_base(ptr noundef %0, i64 noundef %1, i32 noundef 16, ptr noundef nonnull @.str.1) #2
  %24 = tail call i32 @output_of_finite_spaces(ptr noundef %0, i32 noundef %5, i32 noundef 0) #2
  %25 = icmp eq i32 %24, -1
  %.14 = sext i1 %25 to i32
  br label %26

26:                                               ; preds = %13, %10, %7
  %.0 = phi i32 [ %., %7 ], [ -1, %10 ], [ %.14, %13 ]
  ret i32 %.0
}

declare i64 @ft_numlen(i64 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @ft_s(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

declare i32 @output_of_initial_spaces(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @ft_itoa_base(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @output_of_finite_spaces(ptr noundef, i32 noundef, 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 = !{!6, !10, i64 1036}
!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 = !{!8, !8, i64 0}


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