; 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.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [32 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

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

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

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

39:                                               ; preds = %31
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i8, ptr %7, align 1, !tbaa !15
  call void @stringAppendChar(ptr noundef %40, i8 noundef signext %41)
  br label %31, !llvm.loop !16

42:                                               ; preds = %31
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TxtFileLoader, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = call i32 @fclose(ptr noundef %45)
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.String, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  call void @CuAssertStrEquals_LineMsg(ptr noundef %47, ptr noundef @.str.3, i32 noundef 100, ptr noundef null, ptr noundef %48, ptr noundef %51)
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  call void @destroyString(ptr noundef %52)
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  call void @destroyString(ptr noundef %53)
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  call void @destroyTxtFileLoader(ptr noundef %54)
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, 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 @txtLoaderWriteS(ptr noundef, ptr noundef) #1

declare void @stringChangeStringC(ptr noundef, 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.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [32 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

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

; Function Attrs: nounwind uwtable
define dso_local void @testTxtLoaderWriteS(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 @txtLoaderWriteS(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 80, ptr noundef null, i32 noundef -83386157, i32 noundef %5) #3
  tail call void @txtLoaderWriteS(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 83, ptr noundef null, i32 noundef -83384987, i32 noundef %7) #3
  %8 = tail call ptr @stringInitialization(i32 noundef 10) #3
  tail call void @stringChangeStringC(ptr noundef %8, ptr noundef nonnull @.str.7) #3
  tail call void @txtLoaderWriteS(ptr noundef %3, ptr noundef %8) #3
  %9 = tail call ptr @stringInitialization(i32 noundef 10) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !12
  %11 = tail call noalias ptr @fopen(ptr noundef %10, ptr noundef nonnull @.str.6)
  %12 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %11, ptr %12, align 8, !tbaa !14
  %13 = tail call i32 @fgetc(ptr noundef %11)
  %sext.mask18 = and i32 %13, 255
  %.not19 = icmp eq i32 %sext.mask18, 255
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %14 = phi i32 [ %17, %.lr.ph ], [ %13, %1 ]
  %15 = trunc i32 %14 to i8
  tail call void @stringAppendChar(ptr noundef %9, i8 noundef signext %15) #3
  %16 = load ptr, ptr %12, align 8, !tbaa !14
  %17 = tail call i32 @fgetc(ptr noundef %16)
  %sext.mask = and i32 %17, 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
  %18 = load ptr, ptr %12, align 8, !tbaa !14
  %19 = tail call i32 @fclose(ptr noundef %18)
  %20 = load ptr, ptr %9, align 8, !tbaa !17
  tail call void @CuAssertStrEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str.3, i32 noundef 100, ptr noundef null, ptr noundef nonnull @.str.7, ptr noundef %20) #3
  tail call void @destroyString(ptr noundef %8) #3
  tail call void @destroyString(ptr noundef nonnull %9) #3
  tail call void @destroyTxtFileLoader(ptr noundef nonnull %3) #3
  ret void
}

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

declare void @stringChangeStringC(ptr noundef, 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