; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (PartitionFlushBlocksEx)

; 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.PARTITION_PRIVATE_DATA = type { i64, ptr, ptr, %struct._EFI_BLOCK_IO_PROTOCOL, %struct._EFI_BLOCK_IO2_PROTOCOL, %struct.EFI_BLOCK_IO_MEDIA, %struct.EFI_BLOCK_IO_MEDIA, ptr, ptr, ptr, ptr, i64, i64, i32, ptr }
%struct._EFI_BLOCK_IO_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_BLOCK_IO2_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr }
%struct.EFI_BLOCK_IO_MEDIA = type { i32, i8, i8, i8, i8, i8, i32, i32, i64, i64, i32, i32 }
%struct.EFI_BLOCK_IO2_TOKEN = type { ptr, i64 }
%struct._EFI_DISK_IO2_PROTOCOL = type { i64, ptr, ptr, ptr, ptr }
%struct.PARTITION_ACCESS_TASK = type { %struct.EFI_DISK_IO2_TOKEN, ptr }
%struct.EFI_DISK_IO2_TOKEN = type { ptr, i64 }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@gBS = external global ptr, align 8
@.str = external hidden unnamed_addr constant [154 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 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

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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

declare void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @PartitionCreateAccessTask(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @PartitionFlushBlocksEx(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = call zeroext i8 @DebugAssertEnabled()
  %11 = zext i8 %10 to i32
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %23

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = ptrtoint ptr %14 to i64
  %16 = sub i64 %15, ptrtoint (ptr getelementptr inbounds (%struct.PARTITION_PRIVATE_DATA, ptr null, i32 0, i32 4) to i64)
  %17 = inttoptr i64 %16 to ptr
  %18 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %17, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = icmp ne i64 %19, 1953653072
  br i1 %20, label %21, label %23

21:                                               ; preds = %13
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1084, ptr noundef @.str.1)
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  br label %28

23:                                               ; preds = %13, %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = ptrtoint ptr %24 to i64
  %26 = sub i64 %25, ptrtoint (ptr getelementptr inbounds (%struct.PARTITION_PRIVATE_DATA, ptr null, i32 0, i32 4) to i64)
  %27 = inttoptr i64 %26 to ptr
  br label %28

28:                                               ; preds = %23, %21
  %29 = phi ptr [ %22, %21 ], [ %27, %23 ]
  store ptr %29, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %68

32:                                               ; preds = %28
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.EFI_BLOCK_IO2_TOKEN, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %68

37:                                               ; preds = %32
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = call ptr @PartitionCreateAccessTask(ptr noundef %38)
  store ptr %39, ptr %8, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %80

43:                                               ; preds = %37
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %44, i32 0, i32 8
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = getelementptr inbounds %struct._EFI_DISK_IO2_PROTOCOL, ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %49, i32 0, i32 8
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.PARTITION_ACCESS_TASK, ptr %52, i32 0, i32 0
  %54 = call i64 %48(ptr noundef %51, ptr noundef %53)
  store i64 %54, ptr %6, align 8, !tbaa !21
  %55 = load i64, ptr %6, align 8, !tbaa !21
  %56 = icmp slt i64 %55, 0
  br i1 %56, label %57, label %67

57:                                               ; preds = %43
  %58 = load ptr, ptr @gBS, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %58, i32 0, i32 12
  %60 = load ptr, ptr %59, align 8, !tbaa !22
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.PARTITION_ACCESS_TASK, ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds %struct.EFI_DISK_IO2_TOKEN, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !25
  %65 = call i64 %60(ptr noundef %64)
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  call void @FreePool(ptr noundef %66)
  br label %67

67:                                               ; preds = %57, %43
  br label %78

68:                                               ; preds = %32, %28
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %69, i32 0, i32 8
  %71 = load ptr, ptr %70, align 8, !tbaa !18
  %72 = getelementptr inbounds %struct._EFI_DISK_IO2_PROTOCOL, ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !19
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %74, i32 0, i32 8
  %76 = load ptr, ptr %75, align 8, !tbaa !18
  %77 = call i64 %73(ptr noundef %76, ptr noundef null)
  store i64 %77, ptr %6, align 8, !tbaa !21
  br label %78

78:                                               ; preds = %68, %67
  %79 = load i64, ptr %6, align 8, !tbaa !21
  store i64 %79, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %80

80:                                               ; preds = %78, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %81 = load i64, ptr %3, align 8
  ret i64 %81
}

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 = !{!"", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !13, i64 72, !14, i64 112, !14, i64 160, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !11, i64 240, !11, i64 248, !15, i64 256, !6, i64 264}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"_EFI_BLOCK_IO_PROTOCOL", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"_EFI_BLOCK_IO2_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!"", !15, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !15, i64 12, !15, i64 16, !11, i64 24, !11, i64 32, !15, i64 40, !15, i64 44}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !11, i64 8}
!18 = !{!10, !6, i64 216}
!19 = !{!20, !6, i64 32}
!20 = !{!"_EFI_DISK_IO2_PROTOCOL", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!21 = !{!11, !11, i64 0}
!22 = !{!23, !6, i64 112}
!23 = !{!"", !24, i64 0, !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, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!24 = !{!"", !11, i64 0, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20}
!25 = !{!26, !6, i64 0}
!26 = !{!"", !17, i64 0, !6, i64 16}


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

@gBS = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [154 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @PartitionCreateAccessTask(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @PartitionFlushBlocksEx(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %3, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre23 = add i64 %.pre, -72
  %.pre25 = inttoptr i64 %.pre23 to ptr
  br i1 %.not, label %._crit_edge, label %4

4:                                                ; preds = %2
  %5 = load i64, ptr %.pre25, align 8, !tbaa !5
  %.not20 = icmp eq i64 %5, 1953653072
  br i1 %.not20, label %._crit_edge, label %6

6:                                                ; preds = %4
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1084, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %2, %4, %6
  %7 = phi ptr [ %0, %6 ], [ %.pre25, %4 ], [ %.pre25, %2 ]
  %.not21 = icmp eq ptr %1, null
  br i1 %.not21, label %26, label %8

8:                                                ; preds = %._crit_edge
  %9 = load ptr, ptr %1, align 8, !tbaa !15
  %.not22 = icmp eq ptr %9, null
  br i1 %.not22, label %26, label %10

10:                                               ; preds = %8
  %11 = tail call ptr @PartitionCreateAccessTask(ptr noundef nonnull %1)
  %12 = icmp eq ptr %11, null
  br i1 %12, label %32, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %7, i64 216
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %15, i64 32
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = tail call i64 %17(ptr noundef %15, ptr noundef nonnull %11) #2
  %19 = icmp slt i64 %18, 0
  br i1 %19, label %20, label %32

20:                                               ; preds = %13
  %21 = load ptr, ptr @gBS, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %21, i64 112
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %24 = load ptr, ptr %11, align 8, !tbaa !24
  %25 = tail call i64 %23(ptr noundef %24) #2
  tail call void @FreePool(ptr noundef nonnull %11) #2
  br label %32

26:                                               ; preds = %8, %._crit_edge
  %27 = getelementptr inbounds i8, ptr %7, i64 216
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %28, i64 32
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = tail call i64 %30(ptr noundef %28, ptr noundef null) #2
  br label %32

32:                                               ; preds = %26, %20, %13, %10
  %.0 = phi i64 [ -9223372036854775799, %10 ], [ %18, %20 ], [ %18, %13 ], [ %31, %26 ]
  ret i64 %.0
}

attributes #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 = { 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 #2 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 72, !13, i64 112, !13, i64 160, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !7, i64 240, !7, i64 248, !14, i64 256, !10, i64 264}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EFI_BLOCK_IO_PROTOCOL", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!12 = !{!"_EFI_BLOCK_IO2_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!"", !14, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !14, i64 12, !14, i64 16, !7, i64 24, !7, i64 32, !14, i64 40, !14, i64 44}
!14 = !{!"int", !8, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !7, i64 8}
!17 = !{!6, !10, i64 216}
!18 = !{!19, !10, i64 32}
!19 = !{!"_EFI_DISK_IO2_PROTOCOL", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!20 = !{!10, !10, i64 0}
!21 = !{!22, !10, i64 112}
!22 = !{!"", !23, i64 0, !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, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368}
!23 = !{!"", !7, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!24 = !{!25, !10, i64 0}
!25 = !{!"", !16, i64 0, !10, i64 16}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass