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

; 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: nounwind uwtable
define dso_local i32 @ft_s(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  call void @null_exception(ptr noundef %12)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %77

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i64 @ft_strlen(ptr noundef %14)
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %7, align 4, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = call i32 @output_of_initial_spaces(ptr noundef %17, i32 noundef %18, i32 noundef 0)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.s_pf, ptr %20, i32 0, i32 6
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp sgt i32 %22, %23
  br i1 %24, label %30, label %25

25:                                               ; preds = %13
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.s_pf, ptr %26, i32 0, i32 6
  %28 = load i32, ptr %27, align 8, !tbaa !11
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %30, label %34

30:                                               ; preds = %25, %13
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.s_pf, ptr %32, i32 0, i32 6
  store i32 %31, ptr %33, align 8, !tbaa !11
  br label %34

34:                                               ; preds = %30, %25
  br label %35

35:                                               ; preds = %70, %34
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = sext i8 %40 to i32
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %49

43:                                               ; preds = %35
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.s_pf, ptr %45, i32 0, i32 6
  %47 = load i32, ptr %46, align 8, !tbaa !11
  %48 = icmp slt i32 %44, %47
  br label %49

49:                                               ; preds = %43, %35
  %50 = phi i1 [ false, %35 ], [ %48, %43 ]
  br i1 %50, label %51, label %71

51:                                               ; preds = %49
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !9
  %55 = sext i32 %53 to i64
  %56 = getelementptr inbounds i8, ptr %52, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !13
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.s_pf, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.s_pf, ptr %60, i32 0, i32 3
  %62 = load i32, ptr %61, align 4, !tbaa !14
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %61, align 4, !tbaa !14
  %64 = sext i32 %62 to i64
  %65 = getelementptr inbounds [1024 x i8], ptr %59, i64 0, i64 %64
  store i8 %57, ptr %65, align 1, !tbaa !13
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = call i32 @ft_print_out(ptr noundef %66)
  %68 = icmp eq i32 %67, -1
  br i1 %68, label %69, label %70

69:                                               ; preds = %51
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %77

70:                                               ; preds = %51
  br label %35, !llvm.loop !15

71:                                               ; preds = %49
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.s_pf, ptr %73, i32 0, i32 6
  %75 = load i32, ptr %74, align 8, !tbaa !11
  %76 = call i32 @output_of_finite_spaces(ptr noundef %72, i32 noundef %75, i32 noundef 0)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %77

77:                                               ; preds = %71, %69, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %78 = load i32, ptr %3, align 4
  ret i32 %78
}

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

; Function Attrs: nounwind uwtable
declare hidden void @null_exception(ptr noundef) #0

declare i64 @ft_strlen(ptr noundef) #2

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

declare i32 @ft_print_out(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 = !{!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 = !{!7, !7, i64 0}
!14 = !{!12, !10, i64 1036}
!15 = distinct !{!15, !16}
!16 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @ft_s(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %4, label %5

4:                                                ; preds = %2
  tail call void @null_exception(ptr noundef %0)
  br label %.loopexit

5:                                                ; preds = %2
  %6 = tail call i64 @ft_strlen(ptr noundef nonnull %1) #2
  %7 = trunc i64 %6 to i32
  %8 = tail call i32 @output_of_initial_spaces(ptr noundef %0, i32 noundef %7, i32 noundef 0) #2
  %9 = getelementptr inbounds i8, ptr %0, i64 1048
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = icmp sgt i32 %10, %7
  %12 = icmp eq i32 %10, -1
  %or.cond = or i1 %11, %12
  br i1 %or.cond, label %13, label %14

13:                                               ; preds = %5
  store i32 %7, ptr %9, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %5, %13
  %15 = getelementptr inbounds i8, ptr %0, i64 12
  %16 = getelementptr inbounds i8, ptr %0, i64 1036
  br label %17

17:                                               ; preds = %22, %14
  %indvars.iv = phi i64 [ %indvars.iv.next, %22 ], [ 0, %14 ]
  %18 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %.not = icmp ne i8 %19, 0
  %.pre = load i32, ptr %9, align 8, !tbaa !5
  %20 = sext i32 %.pre to i64
  %21 = icmp slt i64 %indvars.iv, %20
  %or.cond27 = select i1 %.not, i1 %21, i1 false
  br i1 %or.cond27, label %22, label %.critedge

22:                                               ; preds = %17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr %16, align 4, !tbaa !12
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %16, align 4, !tbaa !12
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [1024 x i8], ptr %15, i64 0, i64 %25
  store i8 %19, ptr %26, align 1, !tbaa !11
  %27 = tail call i32 @ft_print_out(ptr noundef nonnull %0) #2
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %.loopexit, label %17, !llvm.loop !13

.critedge:                                        ; preds = %17
  %29 = tail call i32 @output_of_finite_spaces(ptr noundef nonnull %0, i32 noundef %.pre, i32 noundef 0) #2
  br label %.loopexit

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

; Function Attrs: nounwind uwtable
declare hidden void @null_exception(ptr noundef) local_unnamed_addr #0

declare i64 @ft_strlen(ptr noundef) local_unnamed_addr #1

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

declare i32 @ft_print_out(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 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 = !{!8, !8, i64 0}
!12 = !{!6, !10, i64 1036}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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