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

; 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.USB_DEVICE_REQUEST = type { i8, i8, i16, i16, i16 }
%struct.USB_CBI_PROTOCOL = type { %struct.USB_INTERFACE_DESCRIPTOR, ptr, ptr, ptr, ptr }
%struct.USB_INTERFACE_DESCRIPTOR = type { i8, i8, i8, i8, i8, i8, i8, i8, i8 }
%struct._EFI_USB_IO_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; 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 @UsbCbiSendCommand(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca %struct.USB_DEVICE_REQUEST, align 1
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !10
  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 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %14 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %9, i32 0, i32 0
  store i8 33, ptr %14, align 1, !tbaa !12
  %15 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %9, i32 0, i32 1
  store i8 0, ptr %15, align 1, !tbaa !15
  %16 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %9, i32 0, i32 2
  store i16 0, ptr %16, align 1, !tbaa !16
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.USB_CBI_PROTOCOL, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.USB_INTERFACE_DESCRIPTOR, ptr %18, i32 0, i32 2
  %20 = load i8, ptr %19, align 2, !tbaa !17
  %21 = zext i8 %20 to i16
  %22 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %9, i32 0, i32 3
  store i16 %21, ptr %22, align 1, !tbaa !20
  %23 = load i8, ptr %7, align 1, !tbaa !9
  %24 = zext i8 %23 to i16
  %25 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %9, i32 0, i32 4
  store i16 %24, ptr %25, align 1, !tbaa !21
  store i64 0, ptr %10, align 8, !tbaa !22
  %26 = load i32, ptr %8, align 4, !tbaa !10
  %27 = udiv i32 %26, 1000
  store i32 %27, ptr %8, align 4, !tbaa !10
  store i64 0, ptr %13, align 8, !tbaa !22
  br label %28

28:                                               ; preds = %53, %4
  %29 = load i64, ptr %13, align 8, !tbaa !22
  %30 = icmp slt i64 %29, 3
  br i1 %30, label %31, label %56

31:                                               ; preds = %28
  store i32 0, ptr %11, align 4, !tbaa !10
  %32 = load i8, ptr %7, align 1, !tbaa !9
  %33 = zext i8 %32 to i64
  store i64 %33, ptr %12, align 8, !tbaa !22
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.USB_CBI_PROTOCOL, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !24
  %37 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !25
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.USB_CBI_PROTOCOL, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !24
  %42 = load i32, ptr %8, align 4, !tbaa !10
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load i64, ptr %12, align 8, !tbaa !22
  %45 = call i64 %38(ptr noundef %41, ptr noundef %9, i32 noundef 1, i32 noundef %42, ptr noundef %43, i64 noundef %44, ptr noundef %11)
  store i64 %45, ptr %10, align 8, !tbaa !22
  %46 = load i64, ptr %10, align 8, !tbaa !22
  %47 = icmp slt i64 %46, 0
  br i1 %47, label %48, label %52

48:                                               ; preds = %31
  %49 = load i32, ptr %11, align 4, !tbaa !10
  %50 = icmp eq i32 %49, 16
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  br label %53

52:                                               ; preds = %48, %31
  br label %56

53:                                               ; preds = %51
  %54 = load i64, ptr %13, align 8, !tbaa !22
  %55 = add nsw i64 %54, 1
  store i64 %55, ptr %13, align 8, !tbaa !22
  br label %28, !llvm.loop !27

56:                                               ; preds = %52, %28
  %57 = load i64, ptr %10, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, 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
  ret i64 %57
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 1, !14, i64 2, !14, i64 4, !14, i64 6}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !7, i64 1}
!16 = !{!13, !14, i64 2}
!17 = !{!18, !7, i64 2}
!18 = !{!"", !19, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!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 = !{!13, !14, i64 4}
!21 = !{!13, !14, i64 6}
!22 = !{!23, !23, i64 0}
!23 = !{!"long long", !7, i64 0}
!24 = !{!18, !6, i64 40}
!25 = !{!26, !6, i64 0}
!26 = !{!"_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}
!27 = distinct !{!27, !28}
!28 = !{!"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.USB_DEVICE_REQUEST = type { i8, i8, i16, i16, i16 }

; 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 @UsbCbiSendCommand(ptr nocapture noundef readonly %0, ptr noundef %1, i8 noundef zeroext %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca %struct.USB_DEVICE_REQUEST, align 1
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  store i8 33, ptr %5, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %5, i64 1
  store i8 0, ptr %7, align 1, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %5, i64 2
  store i16 0, ptr %8, align 1, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %0, i64 2
  %10 = load i8, ptr %9, align 2, !tbaa !12
  %11 = zext i8 %10 to i16
  %12 = getelementptr inbounds i8, ptr %5, i64 4
  store i16 %11, ptr %12, align 1, !tbaa !16
  %13 = zext i8 %2 to i16
  %14 = getelementptr inbounds i8, ptr %5, i64 6
  store i16 %13, ptr %14, align 1, !tbaa !17
  %15 = udiv i32 %3, 1000
  %16 = zext i8 %2 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 0, ptr %6, align 4, !tbaa !18
  %18 = load ptr, ptr %17, align 8, !tbaa !20
  %19 = load ptr, ptr %18, align 8, !tbaa !21
  %20 = call i64 %19(ptr noundef nonnull %18, ptr noundef nonnull %5, i32 noundef 1, i32 noundef %15, ptr noundef %1, i64 noundef %16, ptr noundef nonnull %6) #2
  %21 = icmp slt i64 %20, 0
  %22 = load i32, ptr %6, align 4
  %23 = icmp eq i32 %22, 16
  %or.cond = select i1 %21, i1 %23, i1 false
  br i1 %or.cond, label %24, label %35

24:                                               ; preds = %4
  store i32 0, ptr %6, align 4, !tbaa !18
  %25 = load ptr, ptr %17, align 8, !tbaa !20
  %26 = load ptr, ptr %25, align 8, !tbaa !21
  %27 = call i64 %26(ptr noundef nonnull %25, ptr noundef nonnull %5, i32 noundef 1, i32 noundef %15, ptr noundef %1, i64 noundef %16, ptr noundef nonnull %6) #2
  %28 = icmp slt i64 %27, 0
  %29 = load i32, ptr %6, align 4
  %30 = icmp eq i32 %29, 16
  %or.cond.1 = select i1 %28, i1 %30, i1 false
  br i1 %or.cond.1, label %31, label %35

31:                                               ; preds = %24
  store i32 0, ptr %6, align 4, !tbaa !18
  %32 = load ptr, ptr %17, align 8, !tbaa !20
  %33 = load ptr, ptr %32, align 8, !tbaa !21
  %34 = call i64 %33(ptr noundef nonnull %32, ptr noundef nonnull %5, i32 noundef 1, i32 noundef %15, ptr noundef %1, i64 noundef %16, ptr noundef nonnull %6) #2
  br label %35

35:                                               ; preds = %31, %24, %4
  %.lcssa = phi i64 [ %20, %4 ], [ %27, %24 ], [ %34, %31 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #2
  ret i64 %.lcssa
}

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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 1, !9, i64 2, !9, i64 4, !9, i64 6}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!6, !7, i64 1}
!11 = !{!6, !9, i64 2}
!12 = !{!13, !7, i64 2}
!13 = !{!"", !14, i64 0, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40}
!14 = !{!"", !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}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!6, !9, i64 4}
!17 = !{!6, !9, i64 6}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!13, !15, i64 40}
!21 = !{!22, !15, i64 0}
!22 = !{!"_EFI_USB_IO_PROTOCOL", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !15, i64 72, !15, i64 80, !15, i64 88, !15, i64 96}


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