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

; 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_file = type { i32, [1024 x i8], ptr, i64, i64, i64, i64, ptr }

@get_next_line.file = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @get_next_line(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = call i64 @read(i32 noundef %4, ptr noundef null, i64 noundef 0)
  %6 = icmp slt i64 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  store ptr null, ptr %2, align 8
  br label %66

8:                                                ; preds = %1
  %9 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %15, label %11

11:                                               ; preds = %8
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = call ptr @check_file(i32 noundef %12, ptr noundef @get_next_line.file)
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %11, %8
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = call ptr @init_file(i32 noundef %16, ptr noundef @get_next_line.file)
  store ptr %17, ptr @get_next_line.file, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %15, %11
  %19 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store ptr null, ptr %2, align 8
  br label %66

22:                                               ; preds = %18
  %23 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.s_file, ptr %23, i32 0, i32 6
  store i64 0, ptr %24, align 8, !tbaa !11
  %25 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.s_file, ptr %25, i32 0, i32 2
  store ptr null, ptr %26, align 8, !tbaa !14
  %27 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  call void @make_string(ptr noundef %27)
  %28 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.s_file, ptr %28, i32 0, i32 3
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = icmp eq i64 %30, -1
  br i1 %31, label %32, label %43

32:                                               ; preds = %22
  %33 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.s_file, ptr %33, i32 0, i32 6
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = icmp ugt i64 %35, 0
  br i1 %36, label %37, label %43

37:                                               ; preds = %32
  %38 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.s_file, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  call void @free(ptr noundef %40) #3
  %41 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.s_file, ptr %41, i32 0, i32 2
  store ptr null, ptr %42, align 8, !tbaa !14
  br label %43

43:                                               ; preds = %37, %32, %22
  %44 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.s_file, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !14
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %49

48:                                               ; preds = %43
  call void @delete_file(ptr noundef @get_next_line.file)
  store ptr null, ptr %2, align 8
  br label %66

49:                                               ; preds = %43
  %50 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.s_file, ptr %50, i32 0, i32 6
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = icmp ugt i64 %52, 0
  br i1 %53, label %54, label %62

54:                                               ; preds = %49
  %55 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.s_file, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.s_file, ptr %58, i32 0, i32 6
  %60 = load i64, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds i8, ptr %57, i64 %60
  store i8 0, ptr %61, align 1, !tbaa !16
  br label %62

62:                                               ; preds = %54, %49
  %63 = load ptr, ptr @get_next_line.file, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.s_file, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !14
  store ptr %65, ptr %2, align 8
  br label %66

66:                                               ; preds = %62, %48, %21, %7
  %67 = load ptr, ptr %2, align 8
  ret ptr %67
}

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #1

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

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

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 "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 1064}
!12 = !{!"s_file", !6, i64 0, !7, i64 4, !10, i64 1032, !13, i64 1040, !13, i64 1048, !13, i64 1056, !13, i64 1064, !10, i64 1072}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 1032}
!15 = !{!12, !13, i64 1040}
!16 = !{!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"

@get_next_line.file = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @get_next_line(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @read(i32 noundef %0, ptr noundef null, i64 noundef 0) #3
  %3 = icmp slt i64 %2, 0
  br i1 %3, label %41, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr @get_next_line.file, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %10, label %7

7:                                                ; preds = %4
  %8 = tail call ptr @check_file(i32 noundef %0, ptr noundef nonnull @get_next_line.file)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %thread-pre-split

10:                                               ; preds = %7, %4
  %11 = tail call ptr @init_file(i32 noundef %0, ptr noundef nonnull @get_next_line.file)
  store ptr %11, ptr @get_next_line.file, align 8, !tbaa !5
  br label %12

thread-pre-split:                                 ; preds = %7
  %.pr = load ptr, ptr @get_next_line.file, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %thread-pre-split, %10
  %13 = phi ptr [ %.pr, %thread-pre-split ], [ %11, %10 ]
  %14 = icmp eq ptr %13, null
  br i1 %14, label %41, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %13, i64 1064
  store i64 0, ptr %16, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %13, i64 1032
  store ptr null, ptr %17, align 8, !tbaa !13
  tail call void @make_string(ptr noundef nonnull %13)
  %18 = load ptr, ptr @get_next_line.file, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 1040
  %20 = load i64, ptr %19, align 8, !tbaa !14
  %21 = icmp eq i64 %20, -1
  br i1 %21, label %22, label %30

22:                                               ; preds = %15
  %23 = getelementptr inbounds i8, ptr %18, i64 1064
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %.not = icmp eq i64 %24, 0
  br i1 %.not, label %30, label %25

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %18, i64 1032
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  tail call void @free(ptr noundef %27) #3
  %28 = load ptr, ptr @get_next_line.file, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 1032
  store ptr null, ptr %29, align 8, !tbaa !13
  br label %30

30:                                               ; preds = %25, %22, %15
  %31 = phi ptr [ %28, %25 ], [ %18, %22 ], [ %18, %15 ]
  %32 = getelementptr inbounds i8, ptr %31, i64 1032
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %30
  tail call void @delete_file(ptr noundef nonnull @get_next_line.file)
  br label %41

36:                                               ; preds = %30
  %37 = getelementptr inbounds i8, ptr %31, i64 1064
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %.not6 = icmp eq i64 %38, 0
  br i1 %.not6, label %41, label %39

39:                                               ; preds = %36
  %40 = getelementptr inbounds i8, ptr %33, i64 %38
  store i8 0, ptr %40, align 1, !tbaa !15
  %.pre = load ptr, ptr @get_next_line.file, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.pre, i64 1032
  %.pre7 = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !13
  br label %41

41:                                               ; preds = %36, %39, %12, %1, %35
  %.0 = phi ptr [ null, %35 ], [ null, %1 ], [ null, %12 ], [ %.pre7, %39 ], [ %33, %36 ]
  ret ptr %.0
}

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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

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 = { 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 #2 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !12, i64 1064}
!10 = !{!"s_file", !11, i64 0, !7, i64 4, !6, i64 1032, !12, i64 1040, !12, i64 1048, !12, i64 1056, !12, i64 1064, !6, i64 1072}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 1032}
!14 = !{!10, !12, i64 1040}
!15 = !{!7, !7, i64 0}


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