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

; 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.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 }
%struct._EFI_DRIVER_BINDING_PROTOCOL = type { ptr, ptr, ptr, i32, ptr, ptr }
%struct._EFI_USB_IO_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._USB_MASS_TRANSPORT = type { i8, ptr, ptr, ptr, ptr, ptr }

@mUsbMassTransport = external dso_local global [3 x ptr], align 16
@gBS = external global ptr, align 8
@gEfiUsbIoProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @USBMassDriverBindingSupported(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 ptr, align 8
  %9 = alloca %struct.USB_INTERFACE_DESCRIPTOR, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %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 9, 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 8, ptr %12) #2
  %14 = load ptr, ptr @gBS, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %14, i32 0, i32 33
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %18, i32 0, i32 5
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = call i64 %16(ptr noundef %17, ptr noundef @gEfiUsbIoProtocolGuid, ptr noundef %8, ptr noundef %20, ptr noundef %21, i32 noundef 16)
  store i64 %22, ptr %11, align 8, !tbaa !16
  %23 = load i64, ptr %11, align 8, !tbaa !16
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %3
  %26 = load i64, ptr %11, align 8, !tbaa !16
  store i64 %26, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %80

27:                                               ; preds = %3
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %28, i32 0, i32 8
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = call i64 %30(ptr noundef %31, ptr noundef %9)
  store i64 %32, ptr %11, align 8, !tbaa !16
  %33 = load i64, ptr %11, align 8, !tbaa !16
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %27
  br label %69

36:                                               ; preds = %27
  store i64 -9223372036854775805, ptr %11, align 8, !tbaa !16
  %37 = getelementptr inbounds %struct.USB_INTERFACE_DESCRIPTOR, ptr %9, i32 0, i32 5
  %38 = load i8, ptr %37, align 1, !tbaa !19
  %39 = zext i8 %38 to i32
  %40 = icmp ne i32 %39, 8
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  br label %69

42:                                               ; preds = %36
  store i64 0, ptr %12, align 8, !tbaa !16
  br label %43

43:                                               ; preds = %65, %42
  %44 = load i64, ptr %12, align 8, !tbaa !16
  %45 = icmp ult i64 %44, 3
  br i1 %45, label %46, label %68

46:                                               ; preds = %43
  %47 = load i64, ptr %12, align 8, !tbaa !16
  %48 = getelementptr inbounds [3 x ptr], ptr @mUsbMassTransport, i64 0, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  store ptr %49, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.USB_INTERFACE_DESCRIPTOR, ptr %9, i32 0, i32 7
  %51 = load i8, ptr %50, align 1, !tbaa !21
  %52 = zext i8 %51 to i32
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._USB_MASS_TRANSPORT, ptr %53, i32 0, i32 0
  %55 = load i8, ptr %54, align 8, !tbaa !22
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %52, %56
  br i1 %57, label %58, label %64

58:                                               ; preds = %46
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._USB_MASS_TRANSPORT, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !24
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = call i64 %61(ptr noundef %62, ptr noundef null)
  store i64 %63, ptr %11, align 8, !tbaa !16
  br label %68

64:                                               ; preds = %46
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %12, align 8, !tbaa !16
  %67 = add i64 %66, 1
  store i64 %67, ptr %12, align 8, !tbaa !16
  br label %43, !llvm.loop !25

68:                                               ; preds = %58, %43
  br label %69

69:                                               ; preds = %68, %41, %35
  %70 = load ptr, ptr @gBS, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %70, i32 0, i32 34
  %72 = load ptr, ptr %71, align 8, !tbaa !27
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %74, i32 0, i32 5
  %76 = load ptr, ptr %75, align 8, !tbaa !14
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = call i64 %72(ptr noundef %73, ptr noundef @gEfiUsbIoProtocolGuid, ptr noundef %76, ptr noundef %77)
  %79 = load i64, ptr %11, align 8, !tbaa !16
  store i64 %79, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %80

80:                                               ; preds = %69, %25
  call void @llvm.lifetime.end.p0(i64 8, 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 9, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %81 = load i64, ptr %4, align 8
  ret i64 %81
}

; 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 280}
!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 = !{!15, !6, i64 40}
!15 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!12, !12, i64 0}
!17 = !{!18, !6, i64 64}
!18 = !{!"_EFI_USB_IO_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!19 = !{!20, !7, i64 5}
!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 = !{!20, !7, i64 7}
!22 = !{!23, !7, i64 0}
!23 = !{!"_USB_MASS_TRANSPORT", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!24 = !{!23, !6, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!10, !6, i64 288}


; 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.USB_INTERFACE_DESCRIPTOR = type { i8, i8, i8, i8, i8, i8, i8, i8, i8 }

@mUsbMassTransport = external dso_local local_unnamed_addr global [3 x ptr], align 16
@gBS = external local_unnamed_addr global ptr, align 8
@gEfiUsbIoProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @USBMassDriverBindingSupported(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef readnone %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca %struct.USB_INTERFACE_DESCRIPTOR, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 9, ptr nonnull %5) #2
  %6 = load ptr, ptr @gBS, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 280
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = call i64 %8(ptr noundef %1, ptr noundef nonnull @gEfiUsbIoProtocolGuid, ptr noundef nonnull %4, ptr noundef %10, ptr noundef %1, i32 noundef 16) #2
  %12 = icmp slt i64 %11, 0
  br i1 %12, label %45, label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 64
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = call i64 %16(ptr noundef %14, ptr noundef nonnull %5) #2
  %18 = icmp slt i64 %17, 0
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %13
  %20 = getelementptr inbounds i8, ptr %5, i64 5
  %21 = load i8, ptr %20, align 1, !tbaa !18
  %.not = icmp eq i8 %21, 8
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %19
  %22 = getelementptr inbounds i8, ptr %5, i64 7
  %23 = load i8, ptr %22, align 1, !tbaa !20
  %24 = load ptr, ptr @mUsbMassTransport, align 16, !tbaa !5
  %25 = load i8, ptr %24, align 8, !tbaa !21
  %26 = icmp eq i8 %23, %25
  br i1 %26, label %35, label %27

27:                                               ; preds = %.preheader
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @mUsbMassTransport, i64 8), align 8, !tbaa !5
  %29 = load i8, ptr %28, align 8, !tbaa !21
  %30 = icmp eq i8 %23, %29
  br i1 %30, label %35, label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr getelementptr inbounds (i8, ptr @mUsbMassTransport, i64 16), align 16, !tbaa !5
  %33 = load i8, ptr %32, align 8, !tbaa !21
  %34 = icmp eq i8 %23, %33
  br i1 %34, label %35, label %.loopexit

35:                                               ; preds = %31, %27, %.preheader
  %.lcssa = phi ptr [ %24, %.preheader ], [ %28, %27 ], [ %32, %31 ]
  %36 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %37 = load ptr, ptr %36, align 8, !tbaa !23
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call i64 %37(ptr noundef %38, ptr noundef null) #2
  br label %.loopexit

.loopexit:                                        ; preds = %31, %35, %19, %13
  %.015 = phi i64 [ %17, %13 ], [ -9223372036854775805, %19 ], [ %39, %35 ], [ -9223372036854775805, %31 ]
  %40 = load ptr, ptr @gBS, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 288
  %42 = load ptr, ptr %41, align 8, !tbaa !24
  %43 = load ptr, ptr %9, align 8, !tbaa !14
  %44 = call i64 %42(ptr noundef %1, ptr noundef nonnull @gEfiUsbIoProtocolGuid, ptr noundef %43, ptr noundef %1) #2
  br label %45

45:                                               ; preds = %3, %.loopexit
  %.016 = phi i64 [ %.015, %.loopexit ], [ %11, %3 ]
  call void @llvm.lifetime.end.p0(i64 9, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  ret i64 %.016
}

; 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 280}
!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 = !{!15, !6, i64 40}
!15 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!17, !6, i64 64}
!17 = !{!"_EFI_USB_IO_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!18 = !{!19, !7, i64 5}
!19 = !{!"", !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}
!20 = !{!19, !7, i64 7}
!21 = !{!22, !7, i64 0}
!22 = !{!"_USB_MASS_TRANSPORT", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!23 = !{!22, !6, i64 8}
!24 = !{!10, !6, i64 288}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass