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

; 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.PCI_TYPE00 = type { %struct.PCI_DEVICE_INDEPENDENT_REGION, %struct.PCI_DEVICE_HEADER_TYPE_REGION }
%struct.PCI_DEVICE_INDEPENDENT_REGION = type { i16, i16, i16, i16, i8, [3 x i8], i8, i8, i8, i8 }
%struct.PCI_DEVICE_HEADER_TYPE_REGION = type { [6 x i32], i32, i16, i16, i32, i8, [3 x i8], i32, 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 }
%struct._EFI_DRIVER_BINDING_PROTOCOL = type { ptr, ptr, ptr, i32, ptr, ptr }
%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 }

@gBS = external global ptr, align 8
@gEfiLegacyBiosProtocolGuid = external global %struct.GUID, align 4
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@gEfiPciIoProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @BiosSnp16DriverBindingSupported(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.PCI_TYPE00, align 1
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 64, ptr %12) #2
  %14 = load ptr, ptr @gBS, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %14, i32 0, i32 38
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = call i64 %16(ptr noundef @gEfiLegacyBiosProtocolGuid, ptr noundef null, ptr noundef %9)
  store i64 %17, ptr %8, align 8, !tbaa !14
  %18 = load i64, ptr %8, align 8, !tbaa !14
  %19 = icmp slt i64 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %3
  %21 = load i64, ptr %8, align 8, !tbaa !14
  store i64 %21, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %89

22:                                               ; preds = %3
  %23 = load ptr, ptr @gBS, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %23, i32 0, i32 33
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %27, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i64 %25(ptr noundef %26, ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %10, ptr noundef %29, ptr noundef %30, i32 noundef 16)
  store i64 %31, ptr %8, align 8, !tbaa !14
  %32 = load i64, ptr %8, align 8, !tbaa !14
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %22
  %35 = load i64, ptr %8, align 8, !tbaa !14
  store i64 %35, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %89

36:                                               ; preds = %22
  %37 = load ptr, ptr @gBS, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %37, i32 0, i32 34
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %41, i32 0, i32 5
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = call i64 %39(ptr noundef %40, ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %43, ptr noundef %44)
  %46 = load ptr, ptr @gBS, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %46, i32 0, i32 33
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %50, i32 0, i32 5
  %52 = load ptr, ptr %51, align 8, !tbaa !16
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = call i64 %48(ptr noundef %49, ptr noundef @gEfiPciIoProtocolGuid, ptr noundef %11, ptr noundef %52, ptr noundef %53, i32 noundef 16)
  store i64 %54, ptr %8, align 8, !tbaa !14
  %55 = load i64, ptr %8, align 8, !tbaa !14
  %56 = icmp slt i64 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %36
  %58 = load i64, ptr %8, align 8, !tbaa !14
  store i64 %58, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %89

59:                                               ; preds = %36
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._EFI_PCI_IO_PROTOCOL, ptr %60, i32 0, i32 4
  %62 = getelementptr inbounds %struct.EFI_PCI_IO_PROTOCOL_CONFIG_ACCESS, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !19
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = call i64 %63(ptr noundef %64, i32 noundef 2, i32 noundef 0, i64 noundef 16, ptr noundef %12)
  store i64 %65, ptr %8, align 8, !tbaa !14
  %66 = load i64, ptr %8, align 8, !tbaa !14
  %67 = icmp slt i64 %66, 0
  br i1 %67, label %68, label %69

68:                                               ; preds = %59
  store i64 -9223372036854775805, ptr %8, align 8, !tbaa !14
  br label %78

69:                                               ; preds = %59
  store i64 -9223372036854775805, ptr %8, align 8, !tbaa !14
  %70 = getelementptr inbounds %struct.PCI_TYPE00, ptr %12, i32 0, i32 0
  %71 = getelementptr inbounds %struct.PCI_DEVICE_INDEPENDENT_REGION, ptr %70, i32 0, i32 5
  %72 = getelementptr inbounds [3 x i8], ptr %71, i64 0, i64 2
  %73 = load i8, ptr %72, align 1, !tbaa !22
  %74 = zext i8 %73 to i32
  %75 = icmp eq i32 %74, 2
  br i1 %75, label %76, label %77

76:                                               ; preds = %69
  store i64 0, ptr %8, align 8, !tbaa !14
  br label %77

77:                                               ; preds = %76, %69
  br label %78

78:                                               ; preds = %77, %68
  %79 = load ptr, ptr @gBS, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %79, i32 0, i32 34
  %81 = load ptr, ptr %80, align 8, !tbaa !18
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %83, i32 0, i32 5
  %85 = load ptr, ptr %84, align 8, !tbaa !16
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = call i64 %81(ptr noundef %82, ptr noundef @gEfiPciIoProtocolGuid, ptr noundef %85, ptr noundef %86)
  %88 = load i64, ptr %8, align 8, !tbaa !14
  store i64 %88, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %89

89:                                               ; preds = %78, %57, %34, %20
  call void @llvm.lifetime.end.p0(i64 64, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %90 = load i64, ptr %4, align 8
  ret i64 %90
}

; 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

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 = { 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 320}
!10 = !{!"", !11, 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}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !6, i64 280}
!16 = !{!17, !6, i64 40}
!17 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!10, !6, i64 288}
!19 = !{!20, !6, i64 48}
!20 = !{!"_EFI_PCI_IO_PROTOCOL", !6, i64 0, !6, i64 8, !21, i64 16, !21, i64 32, !21, 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, !12, i64 144, !6, i64 152}
!21 = !{!"", !6, i64 0, !6, i64 8}
!22 = !{!7, !7, i64 0}


; 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.PCI_TYPE00 = type { %struct.PCI_DEVICE_INDEPENDENT_REGION, %struct.PCI_DEVICE_HEADER_TYPE_REGION }
%struct.PCI_DEVICE_INDEPENDENT_REGION = type { i16, i16, i16, i16, i8, [3 x i8], i8, i8, i8, i8 }
%struct.PCI_DEVICE_HEADER_TYPE_REGION = type { [6 x i32], i32, i16, i16, i32, i8, [3 x i8], i32, i8, i8, i8, i8 }

@gBS = external local_unnamed_addr global ptr, align 8
@gEfiLegacyBiosProtocolGuid = external global %struct.GUID, align 4
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@gEfiPciIoProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @BiosSnp16DriverBindingSupported(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef readnone %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.PCI_TYPE00, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #2
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %7) #2
  %8 = load ptr, ptr @gBS, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 320
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = call i64 %10(ptr noundef nonnull @gEfiLegacyBiosProtocolGuid, ptr noundef null, ptr noundef nonnull %4) #2
  %12 = icmp slt i64 %11, 0
  br i1 %12, label %47, label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr @gBS, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 280
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = call i64 %16(ptr noundef %1, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef nonnull %5, ptr noundef %18, ptr noundef %1, i32 noundef 16) #2
  %20 = icmp slt i64 %19, 0
  br i1 %20, label %47, label %21

21:                                               ; preds = %13
  %22 = load ptr, ptr @gBS, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 288
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = load ptr, ptr %17, align 8, !tbaa !15
  %26 = call i64 %24(ptr noundef %1, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef %25, ptr noundef %1) #2
  %27 = load ptr, ptr @gBS, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 280
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = load ptr, ptr %17, align 8, !tbaa !15
  %31 = call i64 %29(ptr noundef %1, ptr noundef nonnull @gEfiPciIoProtocolGuid, ptr noundef nonnull %6, ptr noundef %30, ptr noundef %1, i32 noundef 16) #2
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %47, label %33

33:                                               ; preds = %21
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 48
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = call i64 %36(ptr noundef %34, i32 noundef 2, i32 noundef 0, i64 noundef 16, ptr noundef nonnull %7) #2
  %38 = icmp slt i64 %37, 0
  %39 = getelementptr inbounds i8, ptr %7, i64 11
  %40 = load i8, ptr %39, align 1
  %41 = icmp eq i8 %40, 2
  %spec.store.select = select i1 %41, i64 0, i64 -9223372036854775805
  %.0 = select i1 %38, i64 -9223372036854775805, i64 %spec.store.select
  %42 = load ptr, ptr @gBS, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 288
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = load ptr, ptr %17, align 8, !tbaa !15
  %46 = call i64 %44(ptr noundef %1, ptr noundef nonnull @gEfiPciIoProtocolGuid, ptr noundef %45, ptr noundef %1) #2
  br label %47

47:                                               ; preds = %21, %13, %3, %33
  %.020 = phi i64 [ %.0, %33 ], [ %11, %3 ], [ %19, %13 ], [ %31, %21 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  ret i64 %.020
}

; 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

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 = { 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 320}
!10 = !{!"", !11, 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}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !6, i64 280}
!15 = !{!16, !6, i64 40}
!16 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 40}
!17 = !{!10, !6, i64 288}
!18 = !{!19, !6, i64 48}
!19 = !{!"_EFI_PCI_IO_PROTOCOL", !6, i64 0, !6, i64 8, !20, i64 16, !20, i64 32, !20, 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, !12, i64 144, !6, i64 152}
!20 = !{!"", !6, i64 0, !6, i64 8}


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