; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/OvmfPkg (ReadFileContent)

; 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._EFI_FILE_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i64 @ReadFileContent(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %20, label %17

17:                                               ; preds = %4
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %17, %4
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %81

21:                                               ; preds = %17
  store ptr null, ptr %12, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._EFI_FILE_PROTOCOL, ptr %22, i32 0, i32 7
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call i64 %24(ptr noundef %25, i64 noundef -1)
  store i64 %26, ptr %13, align 8, !tbaa !9
  %27 = load i64, ptr %13, align 8, !tbaa !9
  %28 = icmp slt i64 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %21
  br label %77

30:                                               ; preds = %21
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._EFI_FILE_PROTOCOL, ptr %31, i32 0, i32 6
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call i64 %33(ptr noundef %34, ptr noundef %11)
  store i64 %35, ptr %13, align 8, !tbaa !9
  %36 = load i64, ptr %13, align 8, !tbaa !9
  %37 = icmp slt i64 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %30
  br label %77

39:                                               ; preds = %30
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._EFI_FILE_PROTOCOL, ptr %40, i32 0, i32 7
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call i64 %42(ptr noundef %43, i64 noundef 0)
  store i64 %44, ptr %13, align 8, !tbaa !9
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = icmp slt i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %39
  br label %77

48:                                               ; preds = %39
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = add i64 %49, %50
  store i64 %51, ptr %10, align 8, !tbaa !9
  %52 = load i64, ptr %10, align 8, !tbaa !9
  %53 = call ptr @AllocateZeroPool(i64 noundef %52)
  store ptr %53, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = icmp eq ptr %54, null
  br i1 %55, label %56, label %57

56:                                               ; preds = %48
  store i64 -9223372036854775799, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %81

57:                                               ; preds = %48
  %58 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %58, ptr %10, align 8, !tbaa !9
  %59 = load i64, ptr %10, align 8, !tbaa !9
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %59, ptr %60, align 8, !tbaa !9
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._EFI_FILE_PROTOCOL, ptr %61, i32 0, i32 4
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = call i64 %63(ptr noundef %64, ptr noundef %10, ptr noundef %65)
  store i64 %66, ptr %13, align 8, !tbaa !9
  %67 = load i64, ptr %13, align 8, !tbaa !9
  %68 = icmp slt i64 %67, 0
  br i1 %68, label %74, label %69

69:                                               ; preds = %57
  %70 = load i64, ptr %10, align 8, !tbaa !9
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i64, ptr %71, align 8, !tbaa !9
  %73 = icmp ne i64 %70, %72
  br i1 %73, label %74, label %76

74:                                               ; preds = %69, %57
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  call void @FreePool(ptr noundef %75)
  store ptr null, ptr %12, align 8, !tbaa !5
  store i64 -9223372036854775804, ptr %13, align 8, !tbaa !9
  br label %77

76:                                               ; preds = %69
  br label %77

77:                                               ; preds = %76, %74, %47, %38, %29
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %78, ptr %79, align 8, !tbaa !5
  %80 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %80, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %81

81:                                               ; preds = %77, %56, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %82 = load i64, ptr %5, align 8
  ret i64 %82
}

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

declare ptr @AllocateZeroPool(i64 noundef) #2

declare void @FreePool(ptr noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 56}
!12 = !{!"_EFI_FILE_PROTOCOL", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112}
!13 = !{!12, !6, i64 48}
!14 = !{!12, !6, i64 32}


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

; Function Attrs: nounwind uwtable
define dso_local i64 @ReadFileContent(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %7 = icmp eq ptr %0, null
  %8 = icmp eq ptr %2, null
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %39, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = tail call i64 %11(ptr noundef nonnull %0, i64 noundef -1) #3
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %38, label %14

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = call i64 %16(ptr noundef nonnull %0, ptr noundef nonnull %6) #3
  %18 = icmp slt i64 %17, 0
  br i1 %18, label %38, label %19

19:                                               ; preds = %14
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = call i64 %20(ptr noundef nonnull %0, i64 noundef 0) #3
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %38, label %23

23:                                               ; preds = %19
  %24 = load i64, ptr %6, align 8, !tbaa !12
  %25 = add i64 %24, %3
  %26 = call ptr @AllocateZeroPool(i64 noundef %25) #3
  %27 = icmp eq ptr %26, null
  br i1 %27, label %39, label %28

28:                                               ; preds = %23
  %29 = load i64, ptr %6, align 8, !tbaa !12
  store i64 %29, ptr %5, align 8, !tbaa !12
  store i64 %29, ptr %2, align 8, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %0, i64 32
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = call i64 %31(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef nonnull %26) #3
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %37, label %34

34:                                               ; preds = %28
  %35 = load i64, ptr %5, align 8, !tbaa !12
  %36 = load i64, ptr %2, align 8, !tbaa !12
  %.not = icmp eq i64 %35, %36
  br i1 %.not, label %38, label %37

37:                                               ; preds = %34, %28
  call void @FreePool(ptr noundef nonnull %26) #3
  br label %38

38:                                               ; preds = %34, %19, %14, %9, %37
  %.024 = phi ptr [ null, %9 ], [ null, %14 ], [ null, %19 ], [ null, %37 ], [ %26, %34 ]
  %.0 = phi i64 [ %12, %9 ], [ %17, %14 ], [ %21, %19 ], [ -9223372036854775804, %37 ], [ %32, %34 ]
  store ptr %.024, ptr %1, align 8, !tbaa !14
  br label %39

39:                                               ; preds = %23, %4, %38
  %.025 = phi i64 [ %.0, %38 ], [ -9223372036854775806, %4 ], [ -9223372036854775799, %23 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i64 %.025
}

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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #2

declare void @FreePool(ptr noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !10, i64 56}
!6 = !{!"_EFI_FILE_PROTOCOL", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 48}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !10, i64 32}
!14 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass