; 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 ptr @stringInitialization(i32 noundef) #4

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 @stringChangeStringC(ptr noundef, ptr noundef) #4

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

; Function Attrs: nounwind uwtable
define dso_local void @txtLoaderAddAllC(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 ptr, align 8
  %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 = %54, %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 %57

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %46 = call ptr @stringInitialization(i32 noundef 10)
  store ptr %46, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = call ptr @vectorGet(ptr noundef %48, i32 noundef %49)
  call void @stringChangeStringC(ptr noundef %47, ptr noundef %50)
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !9
  call void @vectorAddAtIndex(ptr noundef %51, ptr noundef %52, i32 noundef %53)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %54

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

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

59:                                               ; preds = %82, %57
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = call i32 @vectorGetLength(ptr noundef %61)
  %63 = icmp slt i32 %60, %62
  br i1 %63, label %65, label %64

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

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

82:                                               ; preds = %65
  %83 = load i32, ptr %10, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %10, align 4, !tbaa !9
  br label %59, !llvm.loop !17

85:                                               ; preds = %64
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  call void @destroyVector(ptr noundef %86)
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.TxtFileLoader, ptr %87, i32 0, i32 1
  %89 = load ptr, ptr %88, align 8, !tbaa !13
  %90 = call i32 @fclose(ptr noundef %89)
  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}


; 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

declare ptr @stringInitialization(i32 noundef) local_unnamed_addr #3

; 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 @stringChangeStringC(ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local void @txtLoaderAddAllC(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.ph34, label %._crit_edge35

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

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

._crit_edge35:                                    ; preds = %33, %._crit_edge
  tail call void @destroyVector(ptr noundef %14) #6
  %30 = getelementptr inbounds i8, ptr %0, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = tail call i32 @fclose(ptr noundef %31)
  ret void

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

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}


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