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

; 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.NIC_DEVICE = type { i64, ptr, ptr, %struct._EFI_SIMPLE_NETWORK_PROTOCOL, %struct.EFI_SIMPLE_NETWORK_MODE, i8, ptr, i16, i8, i8, i8, i8, i8, ptr, i64, ptr, ptr, ptr, [2 x i32], ptr }
%struct._EFI_SIMPLE_NETWORK_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_SIMPLE_NETWORK_MODE = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x %struct.EFI_MAC_ADDRESS], %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i8, i8, i8, i8, i8 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct._EFI_USB_IO_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str.24 = external hidden unnamed_addr constant [32 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

; 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 @Ax88772UsbCommand(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i32 2, ptr %8, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %11, i32 0, i32 4
  %13 = load i16, ptr %12, align 1, !tbaa !11
  %14 = zext i16 %13 to i32
  %15 = icmp ne i32 0, %14
  br i1 %15, label %16, label %25

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %17, i32 0, i32 0
  %19 = load i8, ptr %18, align 1, !tbaa !14
  %20 = zext i8 %19 to i32
  %21 = and i32 %20, 128
  %22 = icmp ne i32 0, %21
  %23 = zext i1 %22 to i64
  %24 = select i1 %22, i32 0, i32 1
  store i32 %24, ptr %8, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %16, %3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.NIC_DEVICE, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  store ptr %28, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._EFI_USB_IO_PROTOCOL, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !21
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %36, i32 0, i32 4
  %38 = load i16, ptr %37, align 1, !tbaa !11
  %39 = zext i16 %38 to i64
  %40 = call i64 %31(ptr noundef %32, ptr noundef %33, i32 noundef %34, i32 noundef 1000, ptr noundef %35, i64 noundef %39, ptr noundef %7)
  store i64 %40, ptr %10, align 8, !tbaa !23
  %41 = load i64, ptr %10, align 8, !tbaa !23
  %42 = icmp slt i64 %41, 0
  br i1 %42, label %46, label %43

43:                                               ; preds = %25
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  store i64 %45, ptr %10, align 8, !tbaa !23
  br label %66

46:                                               ; preds = %25
  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 64)
  %53 = icmp ne i8 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %51
  %55 = load i64, ptr %10, align 8, !tbaa !23
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.24, 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
  %62 = load i64, ptr %10, align 8, !tbaa !23
  %63 = icmp eq i64 -9223372036854775790, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  store i64 -9223372036854775801, ptr %10, align 8, !tbaa !23
  br label %65

65:                                               ; preds = %64, %61
  br label %66

66:                                               ; preds = %65, %43
  %67 = load i64, ptr %10, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i64 %67
}

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

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

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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 6}
!12 = !{!"", !7, i64 0, !7, i64 1, !13, i64 2, !13, i64 4, !13, i64 6}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !7, i64 0}
!15 = !{!16, !6, i64 16}
!16 = !{!"", !17, i64 0, !6, i64 8, !6, i64 16, !18, i64 24, !19, i64 152, !7, i64 808, !6, i64 816, !13, i64 824, !7, i64 826, !7, i64 827, !7, i64 828, !7, i64 829, !7, i64 830, !6, i64 832, !17, i64 840, !6, i64 848, !6, i64 856, !6, i64 864, !7, i64 872, !6, i64 880}
!17 = !{!"long long", !7, i64 0}
!18 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !17, 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, !6, i64 104, !6, i64 112, !6, i64 120}
!19 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !20, i64 552, !20, i64 584, !20, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!20 = !{!"", !7, i64 0}
!21 = !{!22, !6, i64 0}
!22 = !{!"_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}
!23 = !{!17, !17, 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"

@.str.24 = external hidden unnamed_addr constant [32 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

; 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 range(i64 -9223372036854775808, 4294967296) i64 @Ax88772UsbCommand(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %5 = getelementptr inbounds i8, ptr %1, i64 6
  %6 = load i16, ptr %5, align 1, !tbaa !5
  %.not = icmp eq i16 %6, 0
  br i1 %.not, label %10, label %7

7:                                                ; preds = %3
  %8 = load i8, ptr %1, align 1, !tbaa !10
  %.not14 = icmp sgt i8 %8, -1
  %9 = zext i1 %.not14 to i32
  br label %10

10:                                               ; preds = %7, %3
  %.012 = phi i32 [ %9, %7 ], [ 2, %3 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = zext i16 %6 to i64
  %15 = call i64 %13(ptr noundef nonnull %12, ptr noundef nonnull %1, i32 noundef %.012, i32 noundef 1000, ptr noundef %2, i64 noundef %14, ptr noundef nonnull %4) #3
  %16 = icmp slt i64 %15, 0
  br i1 %16, label %20, label %17

17:                                               ; preds = %10
  %18 = load i32, ptr %4, align 4, !tbaa !21
  %19 = zext i32 %18 to i64
  br label %27

20:                                               ; preds = %10
  %21 = call zeroext i8 @DebugPrintEnabled() #3
  %.not15 = icmp eq i8 %21, 0
  br i1 %.not15, label %25, label %22

22:                                               ; preds = %20
  %23 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #3
  %.not16 = icmp eq i8 %23, 0
  br i1 %.not16, label %25, label %24

24:                                               ; preds = %22
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.24, i64 noundef %15) #3
  br label %25

25:                                               ; preds = %22, %24, %20
  %26 = icmp eq i64 %15, -9223372036854775790
  %spec.store.select = select i1 %26, i64 -9223372036854775801, i64 %15
  br label %27

27:                                               ; preds = %25, %17
  %.0 = phi i64 [ %spec.store.select, %25 ], [ %19, %17 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret i64 %.0
}

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #2

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

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

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 = { "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, !9, i64 6}
!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 0}
!11 = !{!12, !14, i64 16}
!12 = !{!"", !13, i64 0, !14, i64 8, !14, i64 16, !15, i64 24, !16, i64 152, !7, i64 808, !14, i64 816, !9, i64 824, !7, i64 826, !7, i64 827, !7, i64 828, !7, i64 829, !7, i64 830, !14, i64 832, !13, i64 840, !14, i64 848, !14, i64 856, !14, i64 864, !7, i64 872, !14, i64 880}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !13, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !14, i64 112, !14, i64 120}
!16 = !{!"", !17, i64 0, !17, i64 4, !17, i64 8, !17, i64 12, !17, i64 16, !17, i64 20, !17, i64 24, !17, i64 28, !17, i64 32, !17, i64 36, !7, i64 40, !18, i64 552, !18, i64 584, !18, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!17 = !{!"int", !7, i64 0}
!18 = !{!"", !7, i64 0}
!19 = !{!20, !14, i64 0}
!20 = !{!"_EFI_USB_IO_PROTOCOL", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96}
!21 = !{!17, !17, i64 0}


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