; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: FilesHandler/Sources (TxtFileLoader)

; 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.TxtFileLoader = type { ptr, ptr }
%struct.String = type { ptr, i32, i32 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @txtLoaderOpenFile(ptr noundef, ptr noundef) #3

declare i32 @fclose(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local ptr @txtLoaderReadFileLines(ptr noundef) #3

declare ptr @vectorGet(ptr noundef, i32 noundef) #4

declare i32 @vectorGetLength(ptr noundef) #4

declare void @destroyVector(ptr noundef) #4

declare void @vectorAddAtIndex(ptr noundef, ptr noundef, i32 noundef) #4

declare ptr @vectorRemoveAtIndexWtFr(ptr noundef, i32 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @txtLoaderAddAllS(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %16

13:                                               ; preds = %3
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str.6, ptr noundef @.str.4, ptr noundef @.str.2) #5
  call void @exit(i32 noundef -83386157) #6
  unreachable

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str, ptr noundef @.str.16, ptr noundef @.str.2) #5
  call void @exit(i32 noundef -83384987) #6
  unreachable

22:                                               ; preds = %16
  br label %23

23:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call ptr @txtLoaderReadFileLines(ptr noundef %24)
  store ptr %25, ptr %7, align 8, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %33, label %28

28:                                               ; preds = %23
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = call i32 @vectorGetLength(ptr noundef %30)
  %32 = icmp sge i32 %29, %31
  br i1 %32, label %33, label %37

33:                                               ; preds = %28, %23
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  call void @destroyVector(ptr noundef %34)
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str, ptr noundef @.str.26, ptr noundef @.str.2) #5
  call void @exit(i32 noundef -83384987) #6
  unreachable

37:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = call i32 @vectorGetLength(ptr noundef %38)
  %40 = sub nsw i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %51, %37
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = icmp sge i32 %42, 0
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %54

45:                                               ; preds = %41
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = call ptr @vectorGet(ptr noundef %47, i32 noundef %48)
  %50 = load i32, ptr %6, align 4, !tbaa !9
  call void @vectorAddAtIndex(ptr noundef %46, ptr noundef %49, i32 noundef %50)
  br label %51

51:                                               ; preds = %45
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr %8, align 4, !tbaa !9
  br label %41, !llvm.loop !11

54:                                               ; preds = %44
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void @txtLoaderOpenFile(ptr noundef %55, ptr noundef @.str.12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %79, %54
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = call i32 @vectorGetLength(ptr noundef %58)
  %60 = icmp slt i32 %57, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %82

62:                                               ; preds = %56
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.TxtFileLoader, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !13
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = call ptr @vectorGet(ptr noundef %66, i32 noundef %67)
  %69 = getelementptr inbounds %struct.String, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = call i32 @vectorGetLength(ptr noundef %72)
  %74 = sub nsw i32 %73, 1
  %75 = icmp ne i32 %71, %74
  %76 = zext i1 %75 to i64
  %77 = select i1 %75, i32 10, i32 0
  %78 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %65, ptr noundef @.str.20, ptr noundef %70, i32 noundef %77) #5
  br label %79

79:                                               ; preds = %62
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %9, align 4, !tbaa !9
  br label %56, !llvm.loop !17

82:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %93, %82
  %84 = load i32, ptr %10, align 4, !tbaa !9
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = call i32 @vectorGetLength(ptr noundef %85)
  %87 = icmp slt i32 %84, %86
  br i1 %87, label %89, label %88

88:                                               ; preds = %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %96

89:                                               ; preds = %83
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = call ptr @vectorRemoveAtIndexWtFr(ptr noundef %90, i32 noundef %91)
  br label %93

93:                                               ; preds = %89
  %94 = load i32, ptr %10, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %10, align 4, !tbaa !9
  br label %83, !llvm.loop !18

96:                                               ; preds = %88
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  call void @destroyVector(ptr noundef %97)
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.TxtFileLoader, ptr %98, i32 0, i32 1
  %100 = load ptr, ptr %99, align 8, !tbaa !13
  %101 = call i32 @fclose(ptr noundef %100)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

attributes #0 = { 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 #1 = { noreturn 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { "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 }
attributes #6 = { noreturn 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 8}
!14 = !{!"TxtFileLoader", !6, i64 0, !6, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"String", !6, i64 0, !10, i64 8, !10, i64 12}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !12}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @txtLoaderOpenFile(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @txtLoaderReadFileLines(ptr noundef) local_unnamed_addr #2

declare ptr @vectorGet(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @vectorGetLength(ptr noundef) local_unnamed_addr #3

declare void @destroyVector(ptr noundef) local_unnamed_addr #3

declare void @vectorAddAtIndex(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare ptr @vectorRemoveAtIndexWtFr(ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @txtLoaderAddAllS(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %5, label %8

5:                                                ; preds = %3
  %6 = load ptr, ptr @stderr, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.2) #4
  tail call void @exit(i32 noundef -83386157) #5
  unreachable

8:                                                ; preds = %3
  %9 = icmp eq ptr %1, null
  br i1 %9, label %10, label %13

10:                                               ; preds = %8
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str, ptr noundef nonnull @.str.16, ptr noundef nonnull @.str.2) #4
  tail call void @exit(i32 noundef -83384987) #5
  unreachable

13:                                               ; preds = %8
  %14 = tail call ptr @txtLoaderReadFileLines(ptr noundef nonnull %0)
  %15 = icmp slt i32 %2, 0
  br i1 %15, label %18, label %16

16:                                               ; preds = %13
  %17 = tail call i32 @vectorGetLength(ptr noundef %14) #6
  %.not = icmp sgt i32 %17, %2
  br i1 %.not, label %21, label %18

18:                                               ; preds = %16, %13
  tail call void @destroyVector(ptr noundef %14) #6
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str, ptr noundef nonnull @.str.26, ptr noundef nonnull @.str.2) #4
  tail call void @exit(i32 noundef -83384987) #5
  unreachable

21:                                               ; preds = %16
  %22 = tail call i32 @vectorGetLength(ptr noundef nonnull %1) #6
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %21
  tail call void @txtLoaderOpenFile(ptr noundef nonnull %0, ptr noundef nonnull @.str.12)
  %24 = tail call i32 @vectorGetLength(ptr noundef %14) #6
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph38, label %.preheader

.lr.ph38:                                         ; preds = %._crit_edge
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  br label %31

.lr.ph:                                           ; preds = %21, %.lr.ph
  %.030.in35 = phi i32 [ %.030, %.lr.ph ], [ %22, %21 ]
  %.030 = add nsw i32 %.030.in35, -1
  %27 = tail call ptr @vectorGet(ptr noundef nonnull %1, i32 noundef %.030) #6
  tail call void @vectorAddAtIndex(ptr noundef %14, ptr noundef %27, i32 noundef %2) #6
  %28 = icmp ugt i32 %.030.in35, 1
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %31, %._crit_edge
  %29 = tail call i32 @vectorGetLength(ptr noundef nonnull %1) #6
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.lr.ph40, label %._crit_edge41

31:                                               ; preds = %.lr.ph38, %31
  %.02936 = phi i32 [ 0, %.lr.ph38 ], [ %39, %31 ]
  %32 = load ptr, ptr %26, align 8, !tbaa !11
  %33 = tail call ptr @vectorGet(ptr noundef %14, i32 noundef %.02936) #6
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = tail call i32 @vectorGetLength(ptr noundef %14) #6
  %36 = add nsw i32 %35, -1
  %.not34 = icmp eq i32 %.02936, %36
  %37 = select i1 %.not34, i32 0, i32 10
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.20, ptr noundef %34, i32 noundef %37) #6
  %39 = add nuw nsw i32 %.02936, 1
  %40 = tail call i32 @vectorGetLength(ptr noundef %14) #6
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %31, label %.preheader, !llvm.loop !16

._crit_edge41:                                    ; preds = %.lr.ph40, %.preheader
  tail call void @destroyVector(ptr noundef %14) #6
  %42 = getelementptr inbounds i8, ptr %0, i64 8
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = tail call i32 @fclose(ptr noundef %43)
  ret void

.lr.ph40:                                         ; preds = %.preheader, %.lr.ph40
  %.039 = phi i32 [ %46, %.lr.ph40 ], [ 0, %.preheader ]
  %45 = tail call ptr @vectorRemoveAtIndexWtFr(ptr noundef %14, i32 noundef %2) #6
  %46 = add nuw nsw i32 %.039, 1
  %47 = tail call i32 @vectorGetLength(ptr noundef nonnull %1) #6
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %.lr.ph40, label %._crit_edge41, !llvm.loop !17
}

attributes #0 = { nofree 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 #1 = { noreturn 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 #2 = { 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 #3 = { "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 #4 = { cold nounwind }
attributes #5 = { noreturn nounwind }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 8}
!12 = !{!"TxtFileLoader", !6, i64 0, !6, i64 8}
!13 = !{!14, !6, i64 0}
!14 = !{!"String", !6, i64 0, !15, i64 8, !15, i64 12}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass