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

; 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_LOCK = type { i64, i64, i32 }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%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 }
%struct._EFI_DRIVER_BINDING_PROTOCOL = type { ptr, ptr, ptr, i32, ptr, ptr }
%struct.BIOS_BLOCK_IO_DEV = type { i64, ptr, ptr, %struct._EFI_BLOCK_IO_PROTOCOL, %struct.EFI_BLOCK_IO_MEDIA, ptr, ptr, ptr, %struct.BIOS_LEGACY_DRIVE }
%struct._EFI_BLOCK_IO_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_BLOCK_IO_MEDIA = type { i32, i8, i8, i8, i8, i8, i32, i32, i64, i64, i32, i32 }
%struct.BIOS_LEGACY_DRIVE = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, ptr, i8, i8, i8, i8, i16, i16, %struct.EDD_DRIVE_PARAMETERS }
%struct.EDD_DRIVE_PARAMETERS = type <{ i16, i16, i32, i32, i32, i64, i16, i32, i16, i8, i8, i16, [4 x i8], [8 x i8], %union.EDD_INTERFACE_PATH, %union.EDD_DEVICE_PATH, i8, i8 }>
%union.EDD_INTERFACE_PATH = type { %struct.EDD_PCI }
%struct.EDD_PCI = type { i8, i8, i8, i8, i32 }
%union.EDD_DEVICE_PATH = type { %struct.EDD_USB }
%struct.EDD_USB = type { i64, i64 }
%struct._EFI_PCI_IO_PROTOCOL = type { ptr, ptr, %struct.EFI_PCI_IO_PROTOCOL_ACCESS, %struct.EFI_PCI_IO_PROTOCOL_ACCESS, %struct.EFI_PCI_IO_PROTOCOL_CONFIG_ACCESS, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr }
%struct.EFI_PCI_IO_PROTOCOL_ACCESS = type { ptr, ptr }
%struct.EFI_PCI_IO_PROTOCOL_CONFIG_ACCESS = type { ptr, ptr }

@mGlobalDataLock = external dso_local global %struct.EFI_LOCK, align 8
@mActiveInstances = external dso_local global i64, align 8
@mBufferUnder1Mb = external dso_local global i64, align 8
@gBS = external global ptr, align 8
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@gEfiPciIoProtocolGuid = external global %struct.GUID, align 4
@.str = external hidden unnamed_addr constant [162 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@gEfiBlockIoProtocolGuid = external global %struct.GUID, align 4
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @BiosBlockIoDriverBindingStop(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 1, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load i64, ptr @mActiveInstances, align 8, !tbaa !9
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %4
  call void @EfiAcquireLock(ptr noundef @mGlobalDataLock)
  %19 = load i64, ptr @mActiveInstances, align 8, !tbaa !9
  %20 = add i64 %19, -1
  store i64 %20, ptr @mActiveInstances, align 8, !tbaa !9
  call void @EfiReleaseLock(ptr noundef @mGlobalDataLock)
  br label %21

21:                                               ; preds = %18, %4
  %22 = load i64, ptr @mActiveInstances, align 8, !tbaa !9
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %59

24:                                               ; preds = %21
  %25 = load i64, ptr @mBufferUnder1Mb, align 8, !tbaa !9
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %27, label %59

27:                                               ; preds = %24
  %28 = load ptr, ptr @gBS, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %28, i32 0, i32 4
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = load i64, ptr @mBufferUnder1Mb, align 8, !tbaa !9
  %32 = call i64 %30(i64 noundef %31, i64 noundef 16)
  store i64 %32, ptr %10, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %27
  %34 = call zeroext i8 @DebugAssertEnabled()
  %35 = icmp ne i8 %34, 0
  br i1 %35, label %36, label %56

36:                                               ; preds = %33
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %39, label %55

39:                                               ; preds = %36
  br label %40

40:                                               ; preds = %39
  %41 = call zeroext i8 @DebugPrintEnabled()
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %43, label %52

43:                                               ; preds = %40
  br label %44

44:                                               ; preds = %43
  %45 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = load i64, ptr %10, align 8, !tbaa !9
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.2, i64 noundef %48)
  br label %49

49:                                               ; preds = %47, %44
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51, %40
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  call void @DebugAssert(ptr noundef @.str, i64 noundef 542, ptr noundef @.str.3)
  br label %55

55:                                               ; preds = %54, %36
  br label %56

56:                                               ; preds = %55, %33
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  call void @EfiAcquireLock(ptr noundef @mGlobalDataLock)
  store i64 0, ptr @mBufferUnder1Mb, align 8, !tbaa !9
  call void @EfiReleaseLock(ptr noundef @mGlobalDataLock)
  br label %59

59:                                               ; preds = %58, %24, %21
  store i8 1, ptr %11, align 1, !tbaa !15
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %145, %59
  %61 = load i64, ptr %14, align 8, !tbaa !9
  %62 = load i64, ptr %8, align 8, !tbaa !9
  %63 = icmp ult i64 %61, %62
  br i1 %63, label %64, label %148

64:                                               ; preds = %60
  %65 = load ptr, ptr @gBS, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %65, i32 0, i32 33
  %67 = load ptr, ptr %66, align 8, !tbaa !16
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load i64, ptr %14, align 8, !tbaa !9
  %70 = getelementptr inbounds ptr, ptr %68, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %72, i32 0, i32 5
  %74 = load ptr, ptr %73, align 8, !tbaa !17
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = call i64 %67(ptr noundef %71, ptr noundef @gEfiBlockIoProtocolGuid, ptr noundef %12, ptr noundef %74, ptr noundef %75, i32 noundef 2)
  store i64 %76, ptr %10, align 8, !tbaa !9
  %77 = load i64, ptr %10, align 8, !tbaa !9
  %78 = icmp slt i64 %77, 0
  br i1 %78, label %79, label %81

79:                                               ; preds = %64
  %80 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %80, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %171

81:                                               ; preds = %64
  %82 = call zeroext i8 @DebugAssertEnabled()
  %83 = zext i8 %82 to i32
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %95

85:                                               ; preds = %81
  %86 = load ptr, ptr %12, align 8, !tbaa !5
  %87 = ptrtoint ptr %86 to i64
  %88 = sub i64 %87, ptrtoint (ptr getelementptr inbounds (%struct.BIOS_BLOCK_IO_DEV, ptr null, i32 0, i32 3) to i64)
  %89 = inttoptr i64 %88 to ptr
  %90 = getelementptr inbounds %struct.BIOS_BLOCK_IO_DEV, ptr %89, i32 0, i32 0
  %91 = load i64, ptr %90, align 8, !tbaa !19
  %92 = icmp ne i64 %91, 1869177442
  br i1 %92, label %93, label %95

93:                                               ; preds = %85
  call void @DebugAssert(ptr noundef @.str, i64 noundef 564, ptr noundef @.str.4)
  %94 = load ptr, ptr %12, align 8, !tbaa !5
  br label %100

95:                                               ; preds = %85, %81
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = ptrtoint ptr %96 to i64
  %98 = sub i64 %97, ptrtoint (ptr getelementptr inbounds (%struct.BIOS_BLOCK_IO_DEV, ptr null, i32 0, i32 3) to i64)
  %99 = inttoptr i64 %98 to ptr
  br label %100

100:                                              ; preds = %95, %93
  %101 = phi ptr [ %94, %93 ], [ %99, %95 ]
  store ptr %101, ptr %13, align 8, !tbaa !5
  %102 = load ptr, ptr @gBS, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %102, i32 0, i32 40
  %104 = load ptr, ptr %103, align 8, !tbaa !26
  %105 = load ptr, ptr %9, align 8, !tbaa !5
  %106 = load i64, ptr %14, align 8, !tbaa !9
  %107 = getelementptr inbounds ptr, ptr %105, i64 %106
  %108 = load ptr, ptr %107, align 8, !tbaa !5
  %109 = load ptr, ptr %13, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.BIOS_BLOCK_IO_DEV, ptr %109, i32 0, i32 3
  %111 = load ptr, ptr %13, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.BIOS_BLOCK_IO_DEV, ptr %111, i32 0, i32 5
  %113 = load ptr, ptr %112, align 8, !tbaa !27
  %114 = call i64 (ptr, ...) %104(ptr noundef %108, ptr noundef @gEfiBlockIoProtocolGuid, ptr noundef %110, ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %113, ptr noundef null)
  store i64 %114, ptr %10, align 8, !tbaa !9
  %115 = load i64, ptr %10, align 8, !tbaa !9
  %116 = icmp slt i64 %115, 0
  br i1 %116, label %117, label %118

117:                                              ; preds = %100
  store i8 0, ptr %11, align 1, !tbaa !15
  br label %118

118:                                              ; preds = %117, %100
  %119 = load ptr, ptr %13, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.BIOS_BLOCK_IO_DEV, ptr %119, i32 0, i32 6
  %121 = load ptr, ptr %120, align 8, !tbaa !28
  %122 = getelementptr inbounds %struct._EFI_PCI_IO_PROTOCOL, ptr %121, i32 0, i32 12
  %123 = load ptr, ptr %122, align 8, !tbaa !29
  %124 = load ptr, ptr %13, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.BIOS_BLOCK_IO_DEV, ptr %124, i32 0, i32 6
  %126 = load ptr, ptr %125, align 8, !tbaa !28
  %127 = call i64 %123(ptr noundef %126, i32 noundef 3, i64 noundef 1792, ptr noundef null)
  %128 = load ptr, ptr @gBS, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %128, i32 0, i32 34
  %130 = load ptr, ptr %129, align 8, !tbaa !32
  %131 = load ptr, ptr %7, align 8, !tbaa !5
  %132 = load ptr, ptr %6, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %132, i32 0, i32 5
  %134 = load ptr, ptr %133, align 8, !tbaa !17
  %135 = load ptr, ptr %9, align 8, !tbaa !5
  %136 = load i64, ptr %14, align 8, !tbaa !9
  %137 = getelementptr inbounds ptr, ptr %135, i64 %136
  %138 = load ptr, ptr %137, align 8, !tbaa !5
  %139 = call i64 %130(ptr noundef %131, ptr noundef @gEfiPciIoProtocolGuid, ptr noundef %134, ptr noundef %138)
  %140 = load ptr, ptr @gBS, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %140, i32 0, i32 7
  %142 = load ptr, ptr %141, align 8, !tbaa !33
  %143 = load ptr, ptr %13, align 8, !tbaa !5
  %144 = call i64 %142(ptr noundef %143)
  br label %145

145:                                              ; preds = %118
  %146 = load i64, ptr %14, align 8, !tbaa !9
  %147 = add i64 %146, 1
  store i64 %147, ptr %14, align 8, !tbaa !9
  br label %60, !llvm.loop !34

148:                                              ; preds = %60
  %149 = load i8, ptr %11, align 1, !tbaa !15
  %150 = icmp ne i8 %149, 0
  br i1 %150, label %152, label %151

151:                                              ; preds = %148
  store i64 -9223372036854775801, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %171

152:                                              ; preds = %148
  %153 = load ptr, ptr @gBS, align 8, !tbaa !5
  %154 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %153, i32 0, i32 34
  %155 = load ptr, ptr %154, align 8, !tbaa !32
  %156 = load ptr, ptr %7, align 8, !tbaa !5
  %157 = load ptr, ptr %6, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %157, i32 0, i32 5
  %159 = load ptr, ptr %158, align 8, !tbaa !17
  %160 = load ptr, ptr %7, align 8, !tbaa !5
  %161 = call i64 %155(ptr noundef %156, ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %159, ptr noundef %160)
  store i64 %161, ptr %10, align 8, !tbaa !9
  %162 = load ptr, ptr @gBS, align 8, !tbaa !5
  %163 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %162, i32 0, i32 34
  %164 = load ptr, ptr %163, align 8, !tbaa !32
  %165 = load ptr, ptr %7, align 8, !tbaa !5
  %166 = load ptr, ptr %6, align 8, !tbaa !5
  %167 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %166, i32 0, i32 5
  %168 = load ptr, ptr %167, align 8, !tbaa !17
  %169 = load ptr, ptr %7, align 8, !tbaa !5
  %170 = call i64 %164(ptr noundef %165, ptr noundef @gEfiPciIoProtocolGuid, ptr noundef %168, ptr noundef %169)
  store i64 %170, ptr %10, align 8, !tbaa !9
  store i64 0, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %171

171:                                              ; preds = %152, %151, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  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 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %172 = load i64, ptr %5, align 8
  ret i64 %172
}

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

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

declare zeroext i8 @DebugAssertEnabled() #2

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

declare void @EfiAcquireLock(ptr noundef) #2

declare void @EfiReleaseLock(ptr noundef) #2

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #2

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 48}
!12 = !{!"", !13, 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}
!13 = !{!"", !10, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !6, i64 280}
!17 = !{!18, !6, i64 40}
!18 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !6, i64 32, !6, i64 40}
!19 = !{!20, !10, i64 0}
!20 = !{!"", !10, i64 0, !6, i64 8, !6, i64 16, !21, i64 24, !22, i64 72, !6, i64 120, !6, i64 128, !6, i64 136, !23, i64 144}
!21 = !{!"_EFI_BLOCK_IO_PROTOCOL", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!22 = !{!"", !14, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !14, i64 12, !14, i64 16, !10, i64 24, !10, i64 32, !14, i64 40, !14, i64 44}
!23 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !24, i64 28, !24, i64 30, !25, i64 32}
!24 = !{!"short", !7, i64 0}
!25 = !{!"", !24, i64 0, !24, i64 2, !14, i64 4, !14, i64 8, !14, i64 12, !10, i64 16, !24, i64 24, !14, i64 26, !24, i64 30, !7, i64 32, !7, i64 33, !24, i64 34, !7, i64 36, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 72, !7, i64 73}
!26 = !{!12, !6, i64 336}
!27 = !{!20, !6, i64 120}
!28 = !{!20, !6, i64 128}
!29 = !{!30, !6, i64 120}
!30 = !{!"_EFI_PCI_IO_PROTOCOL", !6, i64 0, !6, i64 8, !31, i64 16, !31, i64 32, !31, i64 48, !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, !10, i64 144, !6, i64 152}
!31 = !{!"", !6, i64 0, !6, i64 8}
!32 = !{!12, !6, i64 288}
!33 = !{!12, !6, i64 72}
!34 = distinct !{!34, !35}
!35 = !{!"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"

%struct.EFI_LOCK = type { i64, i64, i32 }
%struct.GUID = type { i32, i16, i16, [8 x i8] }

@mGlobalDataLock = external dso_local global %struct.EFI_LOCK, align 8
@mActiveInstances = external dso_local local_unnamed_addr global i64, align 8
@mBufferUnder1Mb = external dso_local local_unnamed_addr global i64, align 8
@gBS = external local_unnamed_addr global ptr, align 8
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@gEfiPciIoProtocolGuid = external global %struct.GUID, align 4
@.str = external hidden unnamed_addr constant [162 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@gEfiBlockIoProtocolGuid = external global %struct.GUID, align 4
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @BiosBlockIoDriverBindingStop(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %6 = load i64, ptr @mActiveInstances, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %11, label %7

7:                                                ; preds = %4
  tail call void @EfiAcquireLock(ptr noundef nonnull @mGlobalDataLock) #3
  %8 = load i64, ptr @mActiveInstances, align 8, !tbaa !5
  %9 = add i64 %8, -1
  store i64 %9, ptr @mActiveInstances, align 8, !tbaa !5
  tail call void @EfiReleaseLock(ptr noundef nonnull @mGlobalDataLock) #3
  %.pre = load i64, ptr @mActiveInstances, align 8, !tbaa !5
  %10 = icmp eq i64 %.pre, 0
  br label %11

11:                                               ; preds = %7, %4
  %12 = phi i1 [ %10, %7 ], [ true, %4 ]
  %13 = load i64, ptr @mBufferUnder1Mb, align 8
  %14 = icmp ne i64 %13, 0
  %or.cond = select i1 %12, i1 %14, i1 false
  br i1 %or.cond, label %15, label %30

15:                                               ; preds = %11
  %16 = load ptr, ptr @gBS, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %16, i64 48
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = tail call i64 %18(i64 noundef %13, i64 noundef 16) #3
  %20 = tail call zeroext i8 @DebugAssertEnabled() #3
  %21 = icmp ne i8 %20, 0
  %22 = icmp slt i64 %19, 0
  %or.cond3 = select i1 %21, i1 %22, i1 false
  br i1 %or.cond3, label %23, label %29

23:                                               ; preds = %15
  %24 = tail call zeroext i8 @DebugPrintEnabled() #3
  %.not38 = icmp eq i8 %24, 0
  br i1 %.not38, label %28, label %25

25:                                               ; preds = %23
  %26 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #3
  %.not39 = icmp eq i8 %26, 0
  br i1 %.not39, label %28, label %27

27:                                               ; preds = %25
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.2, i64 noundef %19) #3
  br label %28

28:                                               ; preds = %25, %27, %23
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 542, ptr noundef nonnull @.str.3) #3
  br label %29

29:                                               ; preds = %28, %15
  tail call void @EfiAcquireLock(ptr noundef nonnull @mGlobalDataLock) #3
  store i64 0, ptr @mBufferUnder1Mb, align 8, !tbaa !5
  tail call void @EfiReleaseLock(ptr noundef nonnull @mGlobalDataLock) #3
  br label %30

30:                                               ; preds = %29, %11
  %.not46 = icmp eq i64 %2, 0
  br i1 %.not46, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %30
  %31 = getelementptr inbounds i8, ptr %0, i64 40
  br label %32

32:                                               ; preds = %.lr.ph, %._crit_edge49
  %.045 = phi i64 [ 0, %.lr.ph ], [ %72, %._crit_edge49 ]
  %.03444 = phi i8 [ 1, %.lr.ph ], [ %spec.select, %._crit_edge49 ]
  %33 = load ptr, ptr @gBS, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %33, i64 280
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = getelementptr inbounds ptr, ptr %3, i64 %.045
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = load ptr, ptr %31, align 8, !tbaa !16
  %39 = call i64 %35(ptr noundef %37, ptr noundef nonnull @gEfiBlockIoProtocolGuid, ptr noundef nonnull %5, ptr noundef %38, ptr noundef %1, i32 noundef 2) #3
  %40 = icmp slt i64 %39, 0
  br i1 %40, label %.loopexit, label %41

41:                                               ; preds = %32
  %42 = call zeroext i8 @DebugAssertEnabled() #3
  %.not41 = icmp eq i8 %42, 0
  %.pre48 = load ptr, ptr %5, align 8, !tbaa !9
  %.pre50 = ptrtoint ptr %.pre48 to i64
  %.pre51 = add i64 %.pre50, -24
  %.pre53 = inttoptr i64 %.pre51 to ptr
  br i1 %.not41, label %._crit_edge49, label %43

43:                                               ; preds = %41
  %44 = load i64, ptr %.pre53, align 8, !tbaa !18
  %.not42 = icmp eq i64 %44, 1869177442
  br i1 %.not42, label %._crit_edge49, label %45

45:                                               ; preds = %43
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 564, ptr noundef nonnull @.str.4) #3
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  br label %._crit_edge49

._crit_edge49:                                    ; preds = %41, %43, %45
  %47 = phi ptr [ %46, %45 ], [ %.pre53, %43 ], [ %.pre53, %41 ]
  %48 = load ptr, ptr @gBS, align 8, !tbaa !9
  %49 = getelementptr inbounds i8, ptr %48, i64 336
  %50 = load ptr, ptr %49, align 8, !tbaa !25
  %51 = load ptr, ptr %36, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %47, i64 24
  %53 = getelementptr inbounds i8, ptr %47, i64 120
  %54 = load ptr, ptr %53, align 8, !tbaa !26
  %55 = call i64 (ptr, ...) %50(ptr noundef %51, ptr noundef nonnull @gEfiBlockIoProtocolGuid, ptr noundef nonnull %52, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef %54, ptr noundef null) #3
  %56 = icmp slt i64 %55, 0
  %spec.select = select i1 %56, i8 0, i8 %.03444
  %57 = getelementptr inbounds i8, ptr %47, i64 128
  %58 = load ptr, ptr %57, align 8, !tbaa !27
  %59 = getelementptr inbounds i8, ptr %58, i64 120
  %60 = load ptr, ptr %59, align 8, !tbaa !28
  %61 = call i64 %60(ptr noundef %58, i32 noundef 3, i64 noundef 1792, ptr noundef null) #3
  %62 = load ptr, ptr @gBS, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %62, i64 288
  %64 = load ptr, ptr %63, align 8, !tbaa !31
  %65 = load ptr, ptr %31, align 8, !tbaa !16
  %66 = load ptr, ptr %36, align 8, !tbaa !9
  %67 = call i64 %64(ptr noundef %1, ptr noundef nonnull @gEfiPciIoProtocolGuid, ptr noundef %65, ptr noundef %66) #3
  %68 = load ptr, ptr @gBS, align 8, !tbaa !9
  %69 = getelementptr inbounds i8, ptr %68, i64 72
  %70 = load ptr, ptr %69, align 8, !tbaa !32
  %71 = call i64 %70(ptr noundef %47) #3
  %72 = add nuw i64 %.045, 1
  %exitcond.not = icmp eq i64 %72, %2
  br i1 %exitcond.not, label %._crit_edge, label %32, !llvm.loop !33

._crit_edge:                                      ; preds = %._crit_edge49
  %73 = icmp eq i8 %spec.select, 0
  br i1 %73, label %.loopexit, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %30, %._crit_edge
  %74 = load ptr, ptr @gBS, align 8, !tbaa !9
  %75 = getelementptr inbounds i8, ptr %74, i64 288
  %76 = load ptr, ptr %75, align 8, !tbaa !31
  %77 = getelementptr inbounds i8, ptr %0, i64 40
  %78 = load ptr, ptr %77, align 8, !tbaa !16
  %79 = call i64 %76(ptr noundef %1, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef %78, ptr noundef %1) #3
  %80 = load ptr, ptr @gBS, align 8, !tbaa !9
  %81 = getelementptr inbounds i8, ptr %80, i64 288
  %82 = load ptr, ptr %81, align 8, !tbaa !31
  %83 = load ptr, ptr %77, align 8, !tbaa !16
  %84 = call i64 %82(ptr noundef %1, ptr noundef nonnull @gEfiPciIoProtocolGuid, ptr noundef %83, ptr noundef %1) #3
  br label %.loopexit

.loopexit:                                        ; preds = %32, %._crit_edge, %._crit_edge.thread
  %.033 = phi i64 [ 0, %._crit_edge.thread ], [ -9223372036854775801, %._crit_edge ], [ %39, %32 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i64 %.033
}

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

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

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

declare void @EfiAcquireLock(ptr noundef) local_unnamed_addr #2

declare void @EfiReleaseLock(ptr noundef) local_unnamed_addr #2

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) local_unnamed_addr #2

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, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"", !13, 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}
!13 = !{!"", !6, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !10, i64 280}
!16 = !{!17, !10, i64 40}
!17 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !14, i64 24, !10, i64 32, !10, i64 40}
!18 = !{!19, !6, i64 0}
!19 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !20, i64 24, !21, i64 72, !10, i64 120, !10, i64 128, !10, i64 136, !22, i64 144}
!20 = !{!"_EFI_BLOCK_IO_PROTOCOL", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!21 = !{!"", !14, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !14, i64 12, !14, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !14, i64 44}
!22 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !23, i64 28, !23, i64 30, !24, i64 32}
!23 = !{!"short", !7, i64 0}
!24 = !{!"", !23, i64 0, !23, i64 2, !14, i64 4, !14, i64 8, !14, i64 12, !6, i64 16, !23, i64 24, !14, i64 26, !23, i64 30, !7, i64 32, !7, i64 33, !23, i64 34, !7, i64 36, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 72, !7, i64 73}
!25 = !{!12, !10, i64 336}
!26 = !{!19, !10, i64 120}
!27 = !{!19, !10, i64 128}
!28 = !{!29, !10, i64 120}
!29 = !{!"_EFI_PCI_IO_PROTOCOL", !10, i64 0, !10, i64 8, !30, i64 16, !30, i64 32, !30, i64 48, !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, !6, i64 144, !10, i64 152}
!30 = !{!"", !10, i64 0, !10, i64 8}
!31 = !{!12, !10, i64 288}
!32 = !{!12, !10, i64 72}
!33 = distinct !{!33, !34}
!34 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass