; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Bus/Usb (UsbBootDetectMedia)

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_BLOCK_IO_MEDIA = type { i32, i8, i8, i8, i8, i8, i32, i32, i64, i64, i32, i32 }
%struct._USB_MASS_DEVICE = type { i32, ptr, ptr, ptr, %struct._EFI_BLOCK_IO_PROTOCOL, %struct.EFI_BLOCK_IO_MEDIA, i8, i8, i8, ptr, ptr, %struct._EFI_DISK_INFO_PROTOCOL, %struct.USB_BOOT_INQUIRY_DATA, i8 }
%struct._EFI_BLOCK_IO_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_DISK_INFO_PROTOCOL = type { %struct.GUID, ptr, ptr, ptr, ptr }
%struct.USB_BOOT_INQUIRY_DATA = type { i8, i8, [2 x i8], i8, [3 x i8], [8 x i8], [16 x i8], [4 x i8] }
%struct.USB_INTERFACE_DESCRIPTOR = type { i8, i8, i8, i8, i8, i8, i8, i8, 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 }

@gBS = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [46 x i8], align 1
@gEfiBlockIoProtocolGuid = external global %struct.GUID, align 4
@.str.6 = external hidden unnamed_addr constant [154 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 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 zeroext i8 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBootDetectMedia(ptr noundef %0) #2 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.EFI_BLOCK_IO_MEDIA, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 1, 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 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %10, i32 0, i32 5
  store ptr %11, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %12, i32 0, i32 5
  %14 = call ptr @CopyMem(ptr noundef %4, ptr noundef %13, i64 noundef 48)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %15, i32 0, i32 10
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.USB_INTERFACE_DESCRIPTOR, ptr %17, i32 0, i32 6
  %19 = load i8, ptr %18, align 1, !tbaa !19
  store i8 %19, ptr %6, align 1, !tbaa !21
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call i64 @UsbBootIsUnitReady(ptr noundef %20)
  store i64 %21, ptr %8, align 8, !tbaa !22
  %22 = load i64, ptr %8, align 8, !tbaa !22
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %24, label %28

24:                                               ; preds = %1
  %25 = load i64, ptr %8, align 8, !tbaa !22
  %26 = icmp ne i64 %25, -9223372036854775795
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  br label %63

28:                                               ; preds = %24, %1
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %29, i32 0, i32 8
  %31 = load i8, ptr %30, align 2, !tbaa !23
  %32 = zext i8 %31 to i32
  %33 = icmp ne i32 %32, 5
  br i1 %33, label %34, label %41

34:                                               ; preds = %28
  %35 = load i8, ptr %6, align 1, !tbaa !21
  %36 = zext i8 %35 to i32
  %37 = icmp eq i32 %36, 6
  br i1 %37, label %38, label %41

38:                                               ; preds = %34
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = call i64 @UsbScsiModeSense(ptr noundef %39)
  br label %41

41:                                               ; preds = %38, %34, %28
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call i64 @UsbBootReadCapacity(ptr noundef %42)
  store i64 %43, ptr %8, align 8, !tbaa !22
  %44 = load i64, ptr %8, align 8, !tbaa !22
  %45 = icmp slt i64 %44, 0
  br i1 %45, label %46, label %62

46:                                               ; preds = %41
  br label %47

47:                                               ; preds = %46
  %48 = call zeroext i8 @DebugPrintEnabled()
  %49 = icmp ne i8 %48, 0
  br i1 %49, label %50, label %59

50:                                               ; preds = %47
  br label %51

51:                                               ; preds = %50
  %52 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %53 = icmp ne i8 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %51
  %55 = load i64, ptr %8, align 8, !tbaa !22
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.5, i64 noundef %55)
  br label %56

56:                                               ; preds = %54, %51
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58, %47
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  br label %63

62:                                               ; preds = %41
  store i64 0, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %185

63:                                               ; preds = %61, %27
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !24
  %67 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %4, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !24
  %69 = icmp ne i32 %66, %68
  br i1 %69, label %102, label %70

70:                                               ; preds = %63
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %71, i32 0, i32 2
  %73 = load i8, ptr %72, align 1, !tbaa !25
  %74 = zext i8 %73 to i32
  %75 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %4, i32 0, i32 2
  %76 = load i8, ptr %75, align 1, !tbaa !25
  %77 = zext i8 %76 to i32
  %78 = icmp ne i32 %74, %77
  br i1 %78, label %102, label %79

79:                                               ; preds = %70
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %80, i32 0, i32 4
  %82 = load i8, ptr %81, align 1, !tbaa !26
  %83 = zext i8 %82 to i32
  %84 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %4, i32 0, i32 4
  %85 = load i8, ptr %84, align 1, !tbaa !26
  %86 = zext i8 %85 to i32
  %87 = icmp ne i32 %83, %86
  br i1 %87, label %102, label %88

88:                                               ; preds = %79
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %89, i32 0, i32 6
  %91 = load i32, ptr %90, align 4, !tbaa !27
  %92 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %4, i32 0, i32 6
  %93 = load i32, ptr %92, align 4, !tbaa !27
  %94 = icmp ne i32 %91, %93
  br i1 %94, label %102, label %95

95:                                               ; preds = %88
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %96, i32 0, i32 8
  %98 = load i64, ptr %97, align 8, !tbaa !28
  %99 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %4, i32 0, i32 8
  %100 = load i64, ptr %99, align 8, !tbaa !28
  %101 = icmp ne i64 %98, %100
  br i1 %101, label %102, label %183

102:                                              ; preds = %95, %88, %79, %70, %63
  %103 = call i64 @EfiGetCurrentTpl()
  store i64 %103, ptr %7, align 8, !tbaa !22
  %104 = load ptr, ptr @gBS, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %104, i32 0, i32 2
  %106 = load ptr, ptr %105, align 8, !tbaa !29
  call void %106(i64 noundef 8)
  %107 = load ptr, ptr @gBS, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %107, i32 0, i32 15
  %109 = load ptr, ptr %108, align 8, !tbaa !32
  %110 = load ptr, ptr %3, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %110, i32 0, i32 1
  %112 = load ptr, ptr %111, align 8, !tbaa !33
  %113 = load ptr, ptr %3, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %113, i32 0, i32 4
  %115 = load ptr, ptr %3, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %115, i32 0, i32 4
  %117 = call i64 %109(ptr noundef %112, ptr noundef @gEfiBlockIoProtocolGuid, ptr noundef %114, ptr noundef %116)
  br label %118

118:                                              ; preds = %102
  %119 = call zeroext i8 @DebugAssertEnabled()
  %120 = icmp ne i8 %119, 0
  br i1 %120, label %121, label %126

121:                                              ; preds = %118
  %122 = call i64 @EfiGetCurrentTpl()
  %123 = icmp eq i64 %122, 8
  br i1 %123, label %125, label %124

124:                                              ; preds = %121
  call void @DebugAssert(ptr noundef @.str.6, i64 noundef 743, ptr noundef @.str.7)
  br label %125

125:                                              ; preds = %124, %121
  br label %126

126:                                              ; preds = %125, %118
  br label %127

127:                                              ; preds = %126
  br label %128

128:                                              ; preds = %127
  %129 = load ptr, ptr @gBS, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %129, i32 0, i32 1
  %131 = load ptr, ptr %130, align 8, !tbaa !34
  %132 = load i64, ptr %7, align 8, !tbaa !22
  %133 = call i64 %131(i64 noundef %132)
  %134 = load ptr, ptr %5, align 8, !tbaa !5
  %135 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %134, i32 0, i32 2
  %136 = load i8, ptr %135, align 1, !tbaa !25
  %137 = zext i8 %136 to i32
  %138 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %4, i32 0, i32 2
  %139 = load i8, ptr %138, align 1, !tbaa !25
  %140 = zext i8 %139 to i32
  %141 = icmp ne i32 %137, %140
  br i1 %141, label %142, label %154

142:                                              ; preds = %128
  %143 = load ptr, ptr %5, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %143, i32 0, i32 2
  %145 = load i8, ptr %144, align 1, !tbaa !25
  %146 = icmp ne i8 %145, 0
  br i1 %146, label %147, label %150

147:                                              ; preds = %142
  %148 = load ptr, ptr %5, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %148, i32 0, i32 0
  store i32 1, ptr %149, align 8, !tbaa !24
  br label %153

150:                                              ; preds = %142
  %151 = load ptr, ptr %5, align 8, !tbaa !5
  %152 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %151, i32 0, i32 0
  store i32 0, ptr %152, align 8, !tbaa !24
  br label %153

153:                                              ; preds = %150, %147
  br label %154

154:                                              ; preds = %153, %128
  %155 = load ptr, ptr %5, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %155, i32 0, i32 4
  %157 = load i8, ptr %156, align 1, !tbaa !26
  %158 = zext i8 %157 to i32
  %159 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %4, i32 0, i32 4
  %160 = load i8, ptr %159, align 1, !tbaa !26
  %161 = zext i8 %160 to i32
  %162 = icmp ne i32 %158, %161
  br i1 %162, label %177, label %163

163:                                              ; preds = %154
  %164 = load ptr, ptr %5, align 8, !tbaa !5
  %165 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %164, i32 0, i32 6
  %166 = load i32, ptr %165, align 4, !tbaa !27
  %167 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %4, i32 0, i32 6
  %168 = load i32, ptr %167, align 4, !tbaa !27
  %169 = icmp ne i32 %166, %168
  br i1 %169, label %177, label %170

170:                                              ; preds = %163
  %171 = load ptr, ptr %5, align 8, !tbaa !5
  %172 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %171, i32 0, i32 8
  %173 = load i64, ptr %172, align 8, !tbaa !28
  %174 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %4, i32 0, i32 8
  %175 = load i64, ptr %174, align 8, !tbaa !28
  %176 = icmp ne i64 %173, %175
  br i1 %176, label %177, label %182

177:                                              ; preds = %170, %163, %154
  %178 = load ptr, ptr %5, align 8, !tbaa !5
  %179 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %178, i32 0, i32 0
  %180 = load i32, ptr %179, align 8, !tbaa !24
  %181 = add i32 %180, 1
  store i32 %181, ptr %179, align 8, !tbaa !24
  br label %182

182:                                              ; preds = %177, %170
  br label %183

183:                                              ; preds = %182, %95
  %184 = load i64, ptr %8, align 8, !tbaa !22
  store i64 %184, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %185

185:                                              ; preds = %183, %62
  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 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 48, ptr %4) #3
  %186 = load i64, ptr %2, align 8
  ret i64 %186
}

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

declare i64 @EfiGetCurrentTpl() #1

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 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, !6, i64 144}
!10 = !{!"_USB_MASS_DEVICE", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !14, i64 80, !7, i64 128, !7, i64 129, !7, i64 130, !6, i64 136, !6, i64 144, !15, i64 152, !18, i64 200, !7, i64 236}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_BLOCK_IO_PROTOCOL", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !11, i64 12, !11, i64 16, !13, i64 24, !13, i64 32, !11, i64 40, !11, i64 44}
!15 = !{!"_EFI_DISK_INFO_PROTOCOL", !16, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!"", !11, i64 0, !17, i64 4, !17, i64 6, !7, i64 8}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 4, !7, i64 5, !7, i64 8, !7, i64 16, !7, i64 32}
!19 = !{!20, !7, i64 6}
!20 = !{!"", !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}
!21 = !{!7, !7, i64 0}
!22 = !{!13, !13, i64 0}
!23 = !{!10, !7, i64 130}
!24 = !{!14, !11, i64 0}
!25 = !{!14, !7, i64 5}
!26 = !{!14, !7, i64 7}
!27 = !{!14, !11, i64 12}
!28 = !{!14, !13, i64 24}
!29 = !{!30, !6, i64 32}
!30 = !{!"", !31, 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}
!31 = !{!"", !13, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!32 = !{!30, !6, i64 136}
!33 = !{!10, !6, i64 8}
!34 = !{!30, !6, i64 24}


; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_BLOCK_IO_MEDIA = type { i32, i8, i8, i8, i8, i8, i32, i32, i64, i64, i32, i32 }

@gBS = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [46 x i8], align 1
@gEfiBlockIoProtocolGuid = external global %struct.GUID, align 4
@.str.6 = external hidden unnamed_addr constant [154 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 x i8], align 1

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

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @UsbBootIsUnitReady(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @UsbBootReadCapacity(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @UsbScsiModeSense(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBootDetectMedia(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca %struct.EFI_BLOCK_IO_MEDIA, align 8
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %2) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = call ptr @CopyMem(ptr noundef nonnull %2, ptr noundef nonnull %3, i64 noundef 48) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 144
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 6
  %8 = load i8, ptr %7, align 1, !tbaa !18
  %9 = call i64 @UsbBootIsUnitReady(ptr noundef %0)
  %10 = icmp slt i64 %9, 0
  %11 = icmp ne i64 %9, -9223372036854775795
  %or.cond = and i1 %10, %11
  br i1 %or.cond, label %27, label %12

12:                                               ; preds = %1
  %13 = getelementptr inbounds i8, ptr %0, i64 130
  %14 = load i8, ptr %13, align 2, !tbaa !20
  %15 = icmp ne i8 %14, 5
  %16 = icmp eq i8 %8, 6
  %or.cond4 = select i1 %15, i1 %16, i1 false
  br i1 %or.cond4, label %17, label %19

17:                                               ; preds = %12
  %18 = call i64 @UsbScsiModeSense(ptr noundef nonnull %0)
  br label %19

19:                                               ; preds = %17, %12
  %20 = call i64 @UsbBootReadCapacity(ptr noundef nonnull %0)
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %22, label %94

22:                                               ; preds = %19
  %23 = call zeroext i8 @DebugPrintEnabled() #3
  %.not = icmp eq i8 %23, 0
  br i1 %.not, label %27, label %24

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

26:                                               ; preds = %24
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.5, i64 noundef %20) #3
  br label %27

27:                                               ; preds = %22, %26, %24, %1
  %.0 = phi i64 [ %9, %1 ], [ %20, %26 ], [ %20, %24 ], [ %20, %22 ]
  %28 = load i32, ptr %3, align 8, !tbaa !21
  %29 = load i32, ptr %2, align 8, !tbaa !21
  %.not38 = icmp eq i32 %28, %29
  br i1 %.not38, label %30, label %50

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %0, i64 85
  %32 = load i8, ptr %31, align 1, !tbaa !22
  %33 = getelementptr inbounds i8, ptr %2, i64 5
  %34 = load i8, ptr %33, align 1, !tbaa !22
  %.not39 = icmp eq i8 %32, %34
  br i1 %.not39, label %35, label %50

35:                                               ; preds = %30
  %36 = getelementptr inbounds i8, ptr %0, i64 87
  %37 = load i8, ptr %36, align 1, !tbaa !23
  %38 = getelementptr inbounds i8, ptr %2, i64 7
  %39 = load i8, ptr %38, align 1, !tbaa !23
  %.not40 = icmp eq i8 %37, %39
  br i1 %.not40, label %40, label %50

40:                                               ; preds = %35
  %41 = getelementptr inbounds i8, ptr %0, i64 92
  %42 = load i32, ptr %41, align 4, !tbaa !24
  %43 = getelementptr inbounds i8, ptr %2, i64 12
  %44 = load i32, ptr %43, align 4, !tbaa !24
  %.not41 = icmp eq i32 %42, %44
  br i1 %.not41, label %45, label %50

45:                                               ; preds = %40
  %46 = getelementptr inbounds i8, ptr %0, i64 104
  %47 = load i64, ptr %46, align 8, !tbaa !25
  %48 = getelementptr inbounds i8, ptr %2, i64 24
  %49 = load i64, ptr %48, align 8, !tbaa !25
  %.not42 = icmp eq i64 %47, %49
  br i1 %.not42, label %94, label %50

50:                                               ; preds = %45, %40, %35, %30, %27
  %51 = call i64 @EfiGetCurrentTpl() #3
  %52 = load ptr, ptr @gBS, align 8, !tbaa !26
  %53 = getelementptr inbounds i8, ptr %52, i64 32
  %54 = load ptr, ptr %53, align 8, !tbaa !27
  call void %54(i64 noundef 8) #3
  %55 = load ptr, ptr @gBS, align 8, !tbaa !26
  %56 = getelementptr inbounds i8, ptr %55, i64 136
  %57 = load ptr, ptr %56, align 8, !tbaa !30
  %58 = getelementptr inbounds i8, ptr %0, i64 8
  %59 = load ptr, ptr %58, align 8, !tbaa !31
  %60 = getelementptr inbounds i8, ptr %0, i64 32
  %61 = call i64 %57(ptr noundef %59, ptr noundef nonnull @gEfiBlockIoProtocolGuid, ptr noundef nonnull %60, ptr noundef nonnull %60) #3
  %62 = call zeroext i8 @DebugAssertEnabled() #3
  %.not43 = icmp eq i8 %62, 0
  br i1 %.not43, label %67, label %63

63:                                               ; preds = %50
  %64 = call i64 @EfiGetCurrentTpl() #3
  %65 = icmp eq i64 %64, 8
  br i1 %65, label %67, label %66

66:                                               ; preds = %63
  call void @DebugAssert(ptr noundef nonnull @.str.6, i64 noundef 743, ptr noundef nonnull @.str.7) #3
  br label %67

67:                                               ; preds = %63, %66, %50
  %68 = load ptr, ptr @gBS, align 8, !tbaa !26
  %69 = getelementptr inbounds i8, ptr %68, i64 24
  %70 = load ptr, ptr %69, align 8, !tbaa !32
  %71 = call i64 %70(i64 noundef %51) #3
  %72 = getelementptr inbounds i8, ptr %0, i64 85
  %73 = load i8, ptr %72, align 1, !tbaa !22
  %74 = getelementptr inbounds i8, ptr %2, i64 5
  %75 = load i8, ptr %74, align 1, !tbaa !22
  %.not44 = icmp eq i8 %73, %75
  br i1 %.not44, label %76, label %.sink.split

.sink.split:                                      ; preds = %67
  %.not45 = icmp ne i8 %73, 0
  %. = zext i1 %.not45 to i32
  store i32 %., ptr %3, align 8, !tbaa !21
  br label %76

76:                                               ; preds = %.sink.split, %67
  %77 = getelementptr inbounds i8, ptr %0, i64 87
  %78 = load i8, ptr %77, align 1, !tbaa !23
  %79 = getelementptr inbounds i8, ptr %2, i64 7
  %80 = load i8, ptr %79, align 1, !tbaa !23
  %.not46 = icmp eq i8 %78, %80
  br i1 %.not46, label %81, label %91

81:                                               ; preds = %76
  %82 = getelementptr inbounds i8, ptr %0, i64 92
  %83 = load i32, ptr %82, align 4, !tbaa !24
  %84 = getelementptr inbounds i8, ptr %2, i64 12
  %85 = load i32, ptr %84, align 4, !tbaa !24
  %.not47 = icmp eq i32 %83, %85
  br i1 %.not47, label %86, label %91

86:                                               ; preds = %81
  %87 = getelementptr inbounds i8, ptr %0, i64 104
  %88 = load i64, ptr %87, align 8, !tbaa !25
  %89 = getelementptr inbounds i8, ptr %2, i64 24
  %90 = load i64, ptr %89, align 8, !tbaa !25
  %.not48 = icmp eq i64 %88, %90
  br i1 %.not48, label %94, label %91

91:                                               ; preds = %86, %81, %76
  %92 = load i32, ptr %3, align 8, !tbaa !21
  %93 = add i32 %92, 1
  store i32 %93, ptr %3, align 8, !tbaa !21
  br label %94

94:                                               ; preds = %45, %91, %86, %19
  %.034 = phi i64 [ 0, %19 ], [ %.0, %86 ], [ %.0, %91 ], [ %.0, %45 ]
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %2) #3
  ret i64 %.034
}

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare i64 @EfiGetCurrentTpl() local_unnamed_addr #1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

attributes #0 = { mustprogress 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, !10, i64 144}
!6 = !{!"_USB_MASS_DEVICE", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !13, i64 80, !8, i64 128, !8, i64 129, !8, i64 130, !10, i64 136, !10, i64 144, !14, i64 152, !17, i64 200, !8, i64 236}
!7 = !{!"int", !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", !12, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"", !7, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !7, i64 12, !7, i64 16, !12, i64 24, !12, i64 32, !7, i64 40, !7, i64 44}
!14 = !{!"_EFI_DISK_INFO_PROTOCOL", !15, i64 0, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!15 = !{!"", !7, i64 0, !16, i64 4, !16, i64 6, !8, i64 8}
!16 = !{!"short", !8, i64 0}
!17 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 4, !8, i64 5, !8, i64 8, !8, i64 16, !8, i64 32}
!18 = !{!19, !8, i64 6}
!19 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8}
!20 = !{!6, !8, i64 130}
!21 = !{!13, !7, i64 0}
!22 = !{!13, !8, i64 5}
!23 = !{!13, !8, i64 7}
!24 = !{!13, !7, i64 12}
!25 = !{!13, !12, i64 24}
!26 = !{!10, !10, i64 0}
!27 = !{!28, !10, i64 32}
!28 = !{!"", !29, 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}
!29 = !{!"", !12, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!30 = !{!28, !10, i64 136}
!31 = !{!6, !10, i64 8}
!32 = !{!28, !10, i64 24}


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