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

; 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.__va_list_tag = type { i32, i32, ptr, ptr }
%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_printf(ptr noundef %0, ...) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca [1 x %struct.__va_list_tag], align 16
  %5 = alloca %struct.s_pf, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.s_pf, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 1080, ptr %5) #6
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %86

11:                                               ; preds = %1
  %12 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %12)
  call void @llvm.memset.p0.i64(ptr align 8 %7, i8 0, i64 1080, i1 false)
  %13 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 0
  %14 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 1
  %15 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 2
  %16 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 3
  %17 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 4
  %18 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 5
  %19 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 6
  %20 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 7
  %21 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 8
  %22 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 9
  %23 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 10
  %24 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 11
  %25 = getelementptr inbounds %struct.s_pf, ptr %7, i32 0, i32 12
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %7, i64 1080, i1 false), !tbaa.struct !9
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.s_pf, ptr %5, i32 0, i32 0
  store ptr %26, ptr %27, align 8, !tbaa !13
  br label %28

28:                                               ; preds = %71, %52, %11
  %29 = getelementptr inbounds %struct.s_pf, ptr %5, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = getelementptr inbounds %struct.s_pf, ptr %5, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !15
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %30, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !12
  %36 = icmp ne i8 %35, 0
  br i1 %36, label %37, label %72

37:                                               ; preds = %28
  %38 = getelementptr inbounds %struct.s_pf, ptr %5, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = getelementptr inbounds %struct.s_pf, ptr %5, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !15
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %39, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !12
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %45, 37
  br i1 %46, label %47, label %53

47:                                               ; preds = %37
  call void @process_width_precision(ptr noundef %5)
  %48 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  %49 = call i32 @process_type_field(ptr noundef %48, ptr noundef %5)
  %50 = icmp eq i32 %49, -1
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %86

52:                                               ; preds = %47
  call void @reset_width_precision(ptr noundef %5)
  br label %28, !llvm.loop !16

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

70:                                               ; preds = %53
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %86

71:                                               ; preds = %53
  br label %28, !llvm.loop !16

72:                                               ; preds = %28
  %73 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %73)
  %74 = getelementptr inbounds %struct.s_pf, ptr %5, i32 0, i32 2
  %75 = getelementptr inbounds [1024 x i8], ptr %74, i64 0, i64 0
  %76 = getelementptr inbounds %struct.s_pf, ptr %5, i32 0, i32 3
  %77 = load i32, ptr %76, align 4, !tbaa !18
  %78 = sext i32 %77 to i64
  %79 = call i64 @write(i32 noundef 1, ptr noundef %75, i64 noundef %78)
  %80 = trunc i64 %79 to i32
  %81 = getelementptr inbounds %struct.s_pf, ptr %5, i32 0, i32 4
  %82 = load i32, ptr %81, align 8, !tbaa !19
  %83 = add nsw i32 %82, %80
  store i32 %83, ptr %81, align 8, !tbaa !19
  %84 = getelementptr inbounds %struct.s_pf, ptr %5, i32 0, i32 4
  %85 = load i32, ptr %84, align 8, !tbaa !19
  store i32 %85, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %86

86:                                               ; preds = %72, %70, %51, %10
  call void @llvm.lifetime.end.p0(i64 1080, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #6
  %87 = load i32, ptr %2, align 4
  ret i32 %87
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

; Function Attrs: nounwind uwtable
declare hidden i32 @process_type_field(ptr noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @ft_print_out(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #5

; 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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { "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 #6 = { 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 = !{i64 0, i64 8, !5, i64 8, i64 4, !10, i64 12, i64 1024, !12, i64 1036, i64 4, !10, i64 1040, i64 4, !10, i64 1044, i64 4, !10, i64 1048, i64 4, !10, i64 1052, i64 4, !10, i64 1056, i64 4, !10, i64 1060, i64 4, !10, i64 1064, i64 4, !10, i64 1068, i64 4, !10, i64 1072, i64 4, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"s_pf", !6, i64 0, !11, i64 8, !7, i64 12, !11, i64 1036, !11, i64 1040, !11, i64 1044, !11, i64 1048, !11, i64 1052, !11, i64 1056, !11, i64 1060, !11, i64 1064, !11, i64 1068, !11, i64 1072}
!15 = !{!14, !11, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!14, !11, i64 1036}
!19 = !{!14, !11, i64 1040}


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

%struct.__va_list_tag = type { i32, i32, ptr, ptr }
%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_printf(ptr noundef %0, ...) local_unnamed_addr #0 {
  %2 = alloca [1 x %struct.__va_list_tag], align 16
  %3 = alloca %struct.s_pf, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 1080, ptr nonnull %3) #5
  %4 = icmp eq ptr %0, null
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %1
  call void @llvm.va_start.p0(ptr nonnull %2)
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1080) %6, i8 0, i64 1072, i1 false)
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  %8 = getelementptr inbounds i8, ptr %3, i64 12
  %9 = getelementptr inbounds i8, ptr %3, i64 1036
  br label %10

10:                                               ; preds = %.backedge, %5
  %11 = phi ptr [ %.pre, %.backedge ], [ %0, %5 ]
  %12 = load i32, ptr %7, align 8, !tbaa !11
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %11, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !12
  switch i8 %15, label %20 [
    i8 0, label %29
    i8 37, label %16
  ]

16:                                               ; preds = %10
  call void @process_width_precision(ptr noundef nonnull %3)
  %17 = call i32 @process_type_field(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %16
  call void @reset_width_precision(ptr noundef nonnull %3)
  br label %.backedge

.backedge:                                        ; preds = %19, %20
  %.pre = load ptr, ptr %3, align 8, !tbaa !5
  br label %10, !llvm.loop !13

20:                                               ; preds = %10
  %21 = add nsw i32 %12, 1
  store i32 %21, ptr %7, align 8, !tbaa !11
  %22 = load i8, ptr %14, align 1, !tbaa !12
  %23 = load i32, ptr %9, align 4, !tbaa !15
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %9, align 4, !tbaa !15
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 %25
  store i8 %22, ptr %26, align 1, !tbaa !12
  %27 = call i32 @ft_print_out(ptr noundef nonnull %3)
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %.loopexit, label %.backedge

29:                                               ; preds = %10
  call void @llvm.va_end.p0(ptr nonnull %2)
  %30 = load i32, ptr %9, align 4, !tbaa !15
  %31 = sext i32 %30 to i64
  %32 = call i64 @write(i32 noundef 1, ptr noundef nonnull %8, i64 noundef %31) #5
  %33 = trunc i64 %32 to i32
  %34 = getelementptr inbounds i8, ptr %3, i64 1040
  %35 = load i32, ptr %34, align 8, !tbaa !16
  %36 = add nsw i32 %35, %33
  br label %.loopexit

.loopexit:                                        ; preds = %20, %16, %1, %29
  %.0 = phi i32 [ %36, %29 ], [ -1, %1 ], [ -1, %16 ], [ -1, %20 ]
  call void @llvm.lifetime.end.p0(i64 1080, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  ret i32 %.0
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
declare hidden i32 @process_type_field(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @ft_print_out(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nofree "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 #5 = { 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, !7, i64 0}
!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 8}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 1036}
!16 = !{!6, !10, i64 1040}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass