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

@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.9 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 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 @fgetc(ptr noundef) #4

declare void @stringAppendChar(ptr noundef, i8 noundef signext) #4

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #4

declare i32 @fclose(ptr noundef) #4

declare void @destroyString(ptr noundef) #4

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

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

declare void @vectorAdd(ptr noundef, ptr noundef) #4

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @charArrContainsTxtFileLoader(ptr noundef, i8 noundef signext) #3

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

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

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %19

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

19:                                               ; preds = %13
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  call void @txtLoaderOpenFile(ptr noundef %21, ptr noundef @.str.9)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %22 = call ptr @vectorInitialization(i32 noundef 10, ptr noundef @destroyString, ptr noundef @stringCompareS)
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call ptr @stringInitialization(i32 noundef 10)
  call void @vectorAdd(ptr noundef %23, ptr noundef %24)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  br label %25

25:                                               ; preds = %43, %38, %20
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TxtFileLoader, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = call i32 @fgetc(ptr noundef %28)
  %30 = trunc i32 %29 to i8
  store i8 %30, ptr %7, align 1, !tbaa !13
  %31 = sext i8 %30 to i32
  %32 = icmp ne i32 %31, -1
  br i1 %32, label %33, label %48

33:                                               ; preds = %25
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i8, ptr %7, align 1, !tbaa !13
  %36 = call i32 @charArrContainsTxtFileLoader(ptr noundef %34, i8 noundef signext %35)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %43

38:                                               ; preds = %33
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %6, align 4, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call ptr @stringInitialization(i32 noundef 10)
  call void @vectorAdd(ptr noundef %41, ptr noundef %42)
  br label %25, !llvm.loop !14

43:                                               ; preds = %33
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = call ptr @vectorGet(ptr noundef %44, i32 noundef %45)
  %47 = load i8, ptr %7, align 1, !tbaa !13
  call void @stringAppendChar(ptr noundef %46, i8 noundef signext %47)
  br label %25, !llvm.loop !14

48:                                               ; preds = %25
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TxtFileLoader, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = call i32 @fseek(ptr noundef %51, i64 noundef 0, i32 noundef 0)
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TxtFileLoader, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = call i32 @fclose(ptr noundef %55)
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %57
}

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 = !{!12, !6, i64 8}
!12 = !{!"TxtFileLoader", !6, i64 0, !6, i64 8}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@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.9 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 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 @fgetc(ptr nocapture noundef) local_unnamed_addr #0

declare void @stringAppendChar(ptr noundef, i8 noundef signext) local_unnamed_addr #3

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

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

declare void @destroyString(ptr noundef) #3

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

declare i32 @stringCompareS(ptr noundef, ptr noundef) #3

declare void @vectorAdd(ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @charArrContainsTxtFileLoader(ptr noundef, i8 noundef signext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @txtLoaderReadFileWthDelimiter(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %4, label %7

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, 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

7:                                                ; preds = %2
  %8 = icmp eq ptr %1, null
  br i1 %8, label %9, label %12

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

12:                                               ; preds = %7
  tail call void @txtLoaderOpenFile(ptr noundef nonnull %0, ptr noundef nonnull @.str.9)
  %13 = tail call ptr @vectorInitialization(i32 noundef 10, ptr noundef nonnull @destroyString, ptr noundef nonnull @stringCompareS) #6
  %14 = tail call ptr @stringInitialization(i32 noundef 10) #6
  tail call void @vectorAdd(ptr noundef %13, ptr noundef %14) #6
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = tail call i32 @fgetc(ptr noundef %16)
  %sext.mask1820 = and i32 %17, 255
  %.not1921 = icmp eq i32 %sext.mask1820, 255
  br i1 %.not1921, label %.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12, %.outer
  %.in = phi i32 [ %24, %.outer ], [ %17, %12 ]
  %.0.ph22 = phi i32 [ %21, %.outer ], [ 0, %12 ]
  br label %18

18:                                               ; preds = %.lr.ph, %25
  %.in23 = phi i32 [ %.in, %.lr.ph ], [ %28, %25 ]
  %19 = trunc i32 %.in23 to i8
  %20 = tail call i32 @charArrContainsTxtFileLoader(ptr noundef nonnull %1, i8 noundef signext %19)
  %.not16 = icmp eq i32 %20, 0
  br i1 %.not16, label %25, label %.outer

.outer:                                           ; preds = %18
  %21 = add nuw nsw i32 %.0.ph22, 1
  %22 = tail call ptr @stringInitialization(i32 noundef 10) #6
  tail call void @vectorAdd(ptr noundef %13, ptr noundef %22) #6
  %23 = load ptr, ptr %15, align 8, !tbaa !9
  %24 = tail call i32 @fgetc(ptr noundef %23)
  %sext.mask18 = and i32 %24, 255
  %.not19 = icmp eq i32 %sext.mask18, 255
  br i1 %.not19, label %.outer._crit_edge, label %.lr.ph, !llvm.loop !11

25:                                               ; preds = %18
  %26 = tail call ptr @vectorGet(ptr noundef %13, i32 noundef %.0.ph22) #6
  tail call void @stringAppendChar(ptr noundef %26, i8 noundef signext %19) #6
  %27 = load ptr, ptr %15, align 8, !tbaa !9
  %28 = tail call i32 @fgetc(ptr noundef %27)
  %sext.mask = and i32 %28, 255
  %.not = icmp eq i32 %sext.mask, 255
  br i1 %.not, label %.outer._crit_edge, label %18, !llvm.loop !11

.outer._crit_edge:                                ; preds = %.outer, %25, %12
  %29 = load ptr, ptr %15, align 8, !tbaa !9
  %30 = tail call i32 @fseek(ptr noundef %29, i64 noundef 0, i32 noundef 0)
  %31 = load ptr, ptr %15, align 8, !tbaa !9
  %32 = tail call i32 @fclose(ptr noundef %31)
  ret ptr %13
}

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 = !{!10, !6, i64 8}
!10 = !{!"TxtFileLoader", !6, i64 0, !6, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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