; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: Unit Test/Tests/FilesHandlersTests/TxtFileLoaderTest (TxtFileLoaderTest)

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

@filePath = external dso_local global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [151 x i8], align 1
@ERROR_TEST = external dso_local global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

declare i32 @fclose(ptr noundef) #1

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

declare ptr @txtFileLoaderInitialization(ptr noundef) #1

declare void @CuAssertIntEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) #1

declare void @destroyTxtFileLoader(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @testTxtLoaderWriteC(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %7 = load ptr, ptr @filePath, align 8, !tbaa !5
  %8 = call ptr @txtFileLoaderInitialization(ptr noundef %7)
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @txtLoaderWriteC(ptr noundef null, ptr noundef null)
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ErrorTestStruct, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %9, ptr noundef @.str.3, i32 noundef 49, ptr noundef null, i32 noundef -83386157, i32 noundef %12)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  call void @txtLoaderWriteC(ptr noundef %13, ptr noundef null)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ErrorTestStruct, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %14, ptr noundef @.str.3, i32 noundef 52, ptr noundef null, i32 noundef -83384987, i32 noundef %17)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr @.str.5, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  call void @txtLoaderWriteC(ptr noundef %18, ptr noundef %19)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %20 = call ptr @stringInitialization(i32 noundef 10)
  store ptr %20, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TxtFileLoader, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = call noalias ptr @fopen(ptr noundef %23, ptr noundef @.str.6)
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TxtFileLoader, ptr %25, i32 0, i32 1
  store ptr %24, ptr %26, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  br label %27

27:                                               ; preds = %35, %1
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TxtFileLoader, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = call i32 @fgetc(ptr noundef %30)
  %32 = trunc i32 %31 to i8
  store i8 %32, ptr %6, align 1, !tbaa !15
  %33 = sext i8 %32 to i32
  %34 = icmp ne i32 %33, -1
  br i1 %34, label %35, label %38

35:                                               ; preds = %27
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i8, ptr %6, align 1, !tbaa !15
  call void @stringAppendChar(ptr noundef %36, i8 noundef signext %37)
  br label %27, !llvm.loop !16

38:                                               ; preds = %27
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TxtFileLoader, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = call i32 @fclose(ptr noundef %41)
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.String, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  call void @CuAssertStrEquals_LineMsg(ptr noundef %43, ptr noundef @.str.3, i32 noundef 67, ptr noundef null, ptr noundef %44, ptr noundef %47)
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  call void @destroyString(ptr noundef %48)
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  call void @destroyTxtFileLoader(ptr noundef %49)
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare void @txtLoaderWriteC(ptr noundef, ptr noundef) #1

declare ptr @stringInitialization(i32 noundef) #1

declare i32 @fgetc(ptr noundef) #1

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

declare void @CuAssertStrEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare void @destroyString(ptr noundef) #1

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

@filePath = external dso_local local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [151 x i8], align 1
@ERROR_TEST = external dso_local local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #0

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

declare ptr @txtFileLoaderInitialization(ptr noundef) local_unnamed_addr #1

declare void @CuAssertIntEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @destroyTxtFileLoader(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @testTxtLoaderWriteC(ptr noundef %0) local_unnamed_addr #2 {
  %2 = load ptr, ptr @filePath, align 8, !tbaa !5
  %3 = tail call ptr @txtFileLoaderInitialization(ptr noundef %2) #3
  tail call void @txtLoaderWriteC(ptr noundef null, ptr noundef null) #3
  %4 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str.3, i32 noundef 49, ptr noundef null, i32 noundef -83386157, i32 noundef %5) #3
  tail call void @txtLoaderWriteC(ptr noundef %3, ptr noundef null) #3
  %6 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %7 = load i32, ptr %6, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str.3, i32 noundef 52, ptr noundef null, i32 noundef -83384987, i32 noundef %7) #3
  tail call void @txtLoaderWriteC(ptr noundef %3, ptr noundef nonnull @.str.5) #3
  %8 = tail call ptr @stringInitialization(i32 noundef 10) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !12
  %10 = tail call noalias ptr @fopen(ptr noundef %9, ptr noundef nonnull @.str.6)
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %10, ptr %11, align 8, !tbaa !14
  %12 = tail call i32 @fgetc(ptr noundef %10)
  %sext.mask15 = and i32 %12, 255
  %.not16 = icmp eq i32 %sext.mask15, 255
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %13 = phi i32 [ %16, %.lr.ph ], [ %12, %1 ]
  %14 = trunc i32 %13 to i8
  tail call void @stringAppendChar(ptr noundef %8, i8 noundef signext %14) #3
  %15 = load ptr, ptr %11, align 8, !tbaa !14
  %16 = tail call i32 @fgetc(ptr noundef %15)
  %sext.mask = and i32 %16, 255
  %.not = icmp eq i32 %sext.mask, 255
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %1
  %17 = load ptr, ptr %11, align 8, !tbaa !14
  %18 = tail call i32 @fclose(ptr noundef %17)
  %19 = load ptr, ptr %8, align 8, !tbaa !17
  tail call void @CuAssertStrEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str.3, i32 noundef 67, ptr noundef null, ptr noundef nonnull @.str.5, ptr noundef %19) #3
  tail call void @destroyString(ptr noundef nonnull %8) #3
  tail call void @destroyTxtFileLoader(ptr noundef nonnull %3) #3
  ret void
}

declare void @txtLoaderWriteC(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @stringInitialization(i32 noundef) local_unnamed_addr #1

; 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 #1

declare void @CuAssertStrEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @destroyString(ptr noundef) local_unnamed_addr #1

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 = { "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 = { 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, !11, i64 0}
!10 = !{!"ErrorTestStruct", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"TxtFileLoader", !6, i64 0, !6, i64 8}
!14 = !{!13, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !6, i64 0}
!18 = !{!"String", !6, i64 0, !11, i64 8, !11, i64 12}


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