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

; 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 [17 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_x(ptr noundef %0, i32 noundef %1, i8 noundef signext %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i8 %2, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = call i32 @for_zero_put_empty_string(ptr noundef %11, i32 noundef %12)
  %14 = icmp sle i32 %13, 0
  br i1 %14, label %15, label %19

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.s_pf, ptr %16, i32 0, i32 12
  %18 = load i32, ptr %17, align 8, !tbaa !12
  store i32 %18, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %91

19:                                               ; preds = %3
  store i32 0, ptr %9, align 4, !tbaa !9
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.s_pf, ptr %20, i32 0, i32 9
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %19
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = add nsw i32 %25, 2
  store i32 %26, ptr %9, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %24, %19
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = uitofp i32 %28 to double
  %30 = call double @ft_abs_d(double noundef %29)
  %31 = fptoui double %30 to i64
  %32 = call i64 @ft_numlen(i64 noundef %31, i32 noundef 16)
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %8, align 4, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !9
  call void @reset_insignificant_values(ptr noundef %34, i32 noundef %35)
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = call i32 @output_of_initial_spaces(ptr noundef %36, i32 noundef %37, i32 noundef %38)
  %40 = icmp eq i32 %39, -1
  br i1 %40, label %41, label %42

41:                                               ; preds = %27
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %91

42:                                               ; preds = %27
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = load i8, ptr %7, align 1, !tbaa !11
  call void @put_prefix(ptr noundef %43, i32 noundef %44, i8 noundef signext %45)
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = call i32 @output_of_zeros(ptr noundef %46, i32 noundef %47, i32 noundef %48)
  %50 = icmp eq i32 %49, -1
  br i1 %50, label %51, label %52

51:                                               ; preds = %42
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %91

52:                                               ; preds = %42
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.s_pf, ptr %53, i32 0, i32 10
  %55 = load i32, ptr %54, align 8, !tbaa !15
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %66

57:                                               ; preds = %52
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.s_pf, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.s_pf, ptr %60, i32 0, i32 3
  %62 = load i32, ptr %61, align 4, !tbaa !16
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %61, align 4, !tbaa !16
  %64 = sext i32 %62 to i64
  %65 = getelementptr inbounds [1024 x i8], ptr %59, i64 0, i64 %64
  store i8 32, ptr %65, align 1, !tbaa !11
  br label %66

66:                                               ; preds = %57, %52
  %67 = load i8, ptr %7, align 1, !tbaa !11
  %68 = sext i8 %67 to i32
  %69 = icmp eq i32 %68, 120
  br i1 %69, label %70, label %74

70:                                               ; preds = %66
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = zext i32 %72 to i64
  call void @ft_itoa_base(ptr noundef %71, i64 noundef %73, i32 noundef 16, ptr noundef @.str)
  br label %83

74:                                               ; preds = %66
  %75 = load i8, ptr %7, align 1, !tbaa !11
  %76 = sext i8 %75 to i32
  %77 = icmp eq i32 %76, 88
  br i1 %77, label %78, label %82

78:                                               ; preds = %74
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = zext i32 %80 to i64
  call void @ft_itoa_base(ptr noundef %79, i64 noundef %81, i32 noundef 16, ptr noundef @.str.1)
  br label %82

82:                                               ; preds = %78, %74
  br label %83

83:                                               ; preds = %82, %70
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = call i32 @output_of_finite_spaces(ptr noundef %84, i32 noundef %85, i32 noundef %86)
  %88 = icmp eq i32 %87, -1
  br i1 %88, label %89, label %90

89:                                               ; preds = %83
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %91

90:                                               ; preds = %83
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %91

91:                                               ; preds = %90, %89, %51, %41, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %92 = load i32, ptr %4, align 4
  ret i32 %92
}

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

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

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

declare double @ft_abs_d(double noundef) #2

declare void @reset_insignificant_values(ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden void @put_prefix(ptr noundef, i32 noundef, i8 noundef signext) #0

declare i32 @output_of_zeros(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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 1072}
!13 = !{!"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}
!14 = !{!13, !10, i64 1060}
!15 = !{!13, !10, i64 1064}
!16 = !{!13, !10, i64 1036}


; 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 [17 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_x(ptr noundef %0, i32 noundef %1, i8 noundef signext %2) local_unnamed_addr #0 {
  %4 = tail call i32 @for_zero_put_empty_string(ptr noundef %0, i32 noundef %1) #2
  %5 = icmp slt i32 %4, 1
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 1072
  %8 = load i32, ptr %7, align 8, !tbaa !5
  br label %38

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 1060
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %.not = icmp eq i32 %11, 0
  %spec.select = select i1 %.not, i32 0, i32 2
  %12 = uitofp i32 %1 to double
  %13 = tail call double @ft_abs_d(double noundef %12) #2
  %14 = fptoui double %13 to i64
  %15 = tail call i64 @ft_numlen(i64 noundef %14, i32 noundef 16) #2
  %16 = trunc i64 %15 to i32
  tail call void @reset_insignificant_values(ptr noundef %0, i32 noundef %spec.select) #2
  %17 = tail call i32 @output_of_initial_spaces(ptr noundef %0, i32 noundef %16, i32 noundef %spec.select) #2
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %38, label %19

19:                                               ; preds = %9
  tail call void @put_prefix(ptr noundef nonnull %0, i32 noundef %1, i8 noundef signext %2)
  %20 = tail call i32 @output_of_zeros(ptr noundef nonnull %0, i32 noundef %16, i32 noundef %spec.select) #2
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %38, label %22

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %0, i64 1064
  %24 = load i32, ptr %23, align 8, !tbaa !12
  %.not31 = icmp eq i32 %24, 0
  br i1 %.not31, label %32, label %25

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %0, i64 12
  %27 = getelementptr inbounds i8, ptr %0, i64 1036
  %28 = load i32, ptr %27, align 4, !tbaa !13
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %27, align 4, !tbaa !13
  %30 = sext i32 %28 to i64
  %31 = getelementptr inbounds [1024 x i8], ptr %26, i64 0, i64 %30
  store i8 32, ptr %31, align 1, !tbaa !14
  br label %32

32:                                               ; preds = %25, %22
  switch i8 %2, label %35 [
    i8 120, label %.sink.split
    i8 88, label %33
  ]

33:                                               ; preds = %32
  br label %.sink.split

.sink.split:                                      ; preds = %32, %33
  %.str.1.sink = phi ptr [ @.str.1, %33 ], [ @.str, %32 ]
  %34 = zext i32 %1 to i64
  tail call void @ft_itoa_base(ptr noundef nonnull %0, i64 noundef %34, i32 noundef 16, ptr noundef nonnull %.str.1.sink) #2
  br label %35

35:                                               ; preds = %.sink.split, %32
  %36 = tail call i32 @output_of_finite_spaces(ptr noundef nonnull %0, i32 noundef %16, i32 noundef %spec.select) #2
  %37 = icmp eq i32 %36, -1
  %. = sext i1 %37 to i32
  br label %38

38:                                               ; preds = %35, %19, %9, %6
  %.029 = phi i32 [ %8, %6 ], [ -1, %9 ], [ -1, %19 ], [ %., %35 ]
  ret i32 %.029
}

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

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

declare double @ft_abs_d(double noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare hidden void @put_prefix(ptr noundef, i32 noundef, i8 noundef signext) local_unnamed_addr #0

declare i32 @output_of_zeros(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 1072}
!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 1060}
!12 = !{!6, !10, i64 1064}
!13 = !{!6, !10, i64 1036}
!14 = !{!8, !8, i64 0}


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