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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbMassInitTransport(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %struct.USB_INTERFACE_DESCRIPTOR, align 1
  %14 = alloca i8, align 1
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 9, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %17 = load ptr, ptr @gBS, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %17, i32 0, i32 33
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %21, i32 0, i32 5
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call i64 %19(ptr noundef %20, ptr noundef @gEfiUsbIoProtocolGuid, ptr noundef %12, ptr noundef %23, ptr noundef %24, i32 noundef 16)
  store i64 %25, ptr %15, align 8, !tbaa !16
  %26 = load i64, ptr %15, align 8, !tbaa !16
  %27 = icmp slt i64 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %5
  %29 = load i64, ptr %15, align 8, !tbaa !16
  store i64 %29, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %103

30:                                               ; preds = %5
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %31, i32 0, i32 8
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = call i64 %33(ptr noundef %34, ptr noundef %13)
  store i64 %35, ptr %15, align 8, !tbaa !16
  %36 = load i64, ptr %15, align 8, !tbaa !16
  %37 = icmp slt i64 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %30
  br label %92

39:                                               ; preds = %30
  store i64 -9223372036854775805, ptr %15, align 8, !tbaa !16
  store i8 0, ptr %14, align 1, !tbaa !19
  br label %40

40:                                               ; preds = %68, %39
  %41 = load i8, ptr %14, align 1, !tbaa !19
  %42 = zext i8 %41 to i32
  %43 = icmp slt i32 %42, 3
  br i1 %43, label %44, label %71

44:                                               ; preds = %40
  %45 = load i8, ptr %14, align 1, !tbaa !19
  %46 = zext i8 %45 to i64
  %47 = getelementptr inbounds [3 x ptr], ptr @mUsbMassTransport, i64 0, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %48, ptr %49, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.USB_INTERFACE_DESCRIPTOR, ptr %13, i32 0, i32 7
  %51 = load i8, ptr %50, align 1, !tbaa !20
  %52 = zext i8 %51 to i32
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._USB_MASS_TRANSPORT, ptr %54, i32 0, i32 0
  %56 = load i8, ptr %55, align 8, !tbaa !22
  %57 = zext i8 %56 to i32
  %58 = icmp eq i32 %52, %57
  br i1 %58, label %59, label %67

59:                                               ; preds = %44
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._USB_MASS_TRANSPORT, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !24
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = call i64 %63(ptr noundef %64, ptr noundef %65)
  store i64 %66, ptr %15, align 8, !tbaa !16
  br label %71

67:                                               ; preds = %44
  br label %68

68:                                               ; preds = %67
  %69 = load i8, ptr %14, align 1, !tbaa !19
  %70 = add i8 %69, 1
  store i8 %70, ptr %14, align 1, !tbaa !19
  br label %40, !llvm.loop !25

71:                                               ; preds = %59, %40
  %72 = load i64, ptr %15, align 8, !tbaa !16
  %73 = icmp slt i64 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %71
  br label %92

75:                                               ; preds = %71
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._USB_MASS_TRANSPORT, ptr %77, i32 0, i32 0
  %79 = load i8, ptr %78, align 8, !tbaa !22
  %80 = zext i8 %79 to i32
  %81 = icmp eq i32 %80, 80
  br i1 %81, label %82, label %91

82:                                               ; preds = %75
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._USB_MASS_TRANSPORT, ptr %84, i32 0, i32 4
  %86 = load ptr, ptr %85, align 8, !tbaa !27
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = load ptr, ptr %87, align 8, !tbaa !5
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  %90 = call i64 %86(ptr noundef %88, ptr noundef %89)
  br label %91

91:                                               ; preds = %82, %75
  br label %92

92:                                               ; preds = %91, %74, %38
  %93 = load ptr, ptr @gBS, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %93, i32 0, i32 34
  %95 = load ptr, ptr %94, align 8, !tbaa !28
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %97, i32 0, i32 5
  %99 = load ptr, ptr %98, align 8, !tbaa !14
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = call i64 %95(ptr noundef %96, ptr noundef @gEfiUsbIoProtocolGuid, ptr noundef %99, ptr noundef %100)
  %102 = load i64, ptr %15, align 8, !tbaa !16
  store i64 %102, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %103

103:                                              ; preds = %92, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 9, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %104 = load i64, ptr %6, align 8
  ret i64 %104
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !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 = !{!7, !7, i64 0}
!20 = !{!21, !7, i64 7}
!21 = !{!"", !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}
!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 = !{!23, !6, i64 32}
!28 = !{!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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; 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
define dso_local i64 @UsbMassInitTransport(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca ptr, align 8
  %7 = alloca %struct.USB_INTERFACE_DESCRIPTOR, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #2
  call void @llvm.lifetime.start.p0(i64 9, ptr nonnull %7) #2
  %8 = load ptr, ptr @gBS, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 280
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = call i64 %10(ptr noundef %1, ptr noundef nonnull @gEfiUsbIoProtocolGuid, ptr noundef nonnull %6, ptr noundef %12, ptr noundef %1, i32 noundef 16) #2
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %54, label %15

15:                                               ; preds = %5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 64
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = call i64 %18(ptr noundef %16, ptr noundef nonnull %7) #2
  %20 = icmp slt i64 %19, 0
  br i1 %20, label %.thread, label %.preheader

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

26:                                               ; preds = %.preheader
  %27 = load ptr, ptr getelementptr inbounds (i8, ptr @mUsbMassTransport, i64 8), align 8, !tbaa !5
  store ptr %27, ptr %2, align 8, !tbaa !5
  %28 = load i8, ptr %27, align 8, !tbaa !20
  %29 = icmp eq i8 %22, %28
  br i1 %29, label %34, label %30

30:                                               ; preds = %26
  %31 = load ptr, ptr getelementptr inbounds (i8, ptr @mUsbMassTransport, i64 16), align 16, !tbaa !5
  store ptr %31, ptr %2, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 8, !tbaa !20
  %33 = icmp eq i8 %22, %32
  br i1 %33, label %34, label %.thread

34:                                               ; preds = %30, %26, %.preheader
  %.lcssa = phi ptr [ %23, %.preheader ], [ %27, %26 ], [ %31, %30 ]
  %35 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %36 = load ptr, ptr %35, align 8, !tbaa !22
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call i64 %36(ptr noundef %37, ptr noundef %3) #2
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %.thread, label %40

40:                                               ; preds = %34
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 8, !tbaa !20
  %43 = icmp eq i8 %42, 80
  br i1 %43, label %44, label %.thread

44:                                               ; preds = %40
  %45 = getelementptr inbounds i8, ptr %41, i64 32
  %46 = load ptr, ptr %45, align 8, !tbaa !23
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = call i64 %46(ptr noundef %47, ptr noundef %4) #2
  br label %.thread

.thread:                                          ; preds = %30, %40, %44, %34, %15
  %.1 = phi i64 [ %19, %15 ], [ %38, %34 ], [ %38, %44 ], [ %38, %40 ], [ -9223372036854775805, %30 ]
  %49 = load ptr, ptr @gBS, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 288
  %51 = load ptr, ptr %50, align 8, !tbaa !24
  %52 = load ptr, ptr %11, align 8, !tbaa !14
  %53 = call i64 %51(ptr noundef %1, ptr noundef nonnull @gEfiUsbIoProtocolGuid, ptr noundef %52, ptr noundef %1) #2
  br label %54

54:                                               ; preds = %5, %.thread
  %.023 = phi i64 [ %.1, %.thread ], [ %13, %5 ]
  call void @llvm.lifetime.end.p0(i64 9, ptr nonnull %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #2
  ret i64 %.023
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !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 7}
!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 = !{!21, !7, i64 0}
!21 = !{!"_USB_MASS_TRANSPORT", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!22 = !{!21, !6, i64 8}
!23 = !{!21, !6, i64 32}
!24 = !{!10, !6, i64 288}


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