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

; 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_MASS_DEVICE = type { i32, ptr, ptr, ptr, %struct._EFI_BLOCK_IO_PROTOCOL, %struct.EFI_BLOCK_IO_MEDIA, i8, i8, i8, ptr, ptr, %struct._EFI_DISK_INFO_PROTOCOL, %struct.USB_BOOT_INQUIRY_DATA, i8 }
%struct._EFI_BLOCK_IO_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_BLOCK_IO_MEDIA = type { i32, i8, i8, i8, i8, i8, i32, i32, i64, i64, i32, i32 }
%struct._EFI_DISK_INFO_PROTOCOL = type { %struct.GUID, ptr, ptr, ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct.USB_BOOT_INQUIRY_DATA = type { i8, i8, [2 x i8], i8, [3 x i8], [8 x i8], [16 x i8], [4 x i8] }
%struct._USB_MASS_TRANSPORT = type { i8, ptr, ptr, ptr, ptr, ptr }

@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @UsbBootRequestSense(ptr noundef) #0

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

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBootExecCmd(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6) #0 {
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i8 %2, ptr %11, align 1, !tbaa !9
  store i32 %3, ptr %12, align 4, !tbaa !10
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i32 %5, ptr %14, align 4, !tbaa !10
  store i32 %6, ptr %15, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %20, i32 0, i32 9
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  store ptr %22, ptr %16, align 8, !tbaa !5
  %23 = load ptr, ptr %16, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._USB_MASS_TRANSPORT, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %26, i32 0, i32 10
  %28 = load ptr, ptr %27, align 8, !tbaa !23
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load i8, ptr %11, align 1, !tbaa !9
  %31 = load i32, ptr %12, align 4, !tbaa !10
  %32 = load ptr, ptr %13, align 8, !tbaa !5
  %33 = load i32, ptr %14, align 4, !tbaa !10
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %34, i32 0, i32 7
  %36 = load i8, ptr %35, align 1, !tbaa !24
  %37 = load i32, ptr %15, align 4, !tbaa !10
  %38 = call i64 %25(ptr noundef %28, ptr noundef %29, i8 noundef zeroext %30, i32 noundef %31, ptr noundef %32, i32 noundef %33, i8 noundef zeroext %36, i32 noundef %37, ptr noundef %18)
  store i64 %38, ptr %17, align 8, !tbaa !25
  %39 = load i64, ptr %17, align 8, !tbaa !25
  %40 = icmp eq i64 %39, -9223372036854775790
  br i1 %40, label %41, label %59

41:                                               ; preds = %7
  br label %42

42:                                               ; preds = %41
  %43 = call zeroext i8 @DebugPrintEnabled()
  %44 = icmp ne i8 %43, 0
  br i1 %44, label %45, label %56

45:                                               ; preds = %42
  br label %46

46:                                               ; preds = %45
  %47 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %48 = icmp ne i8 %47, 0
  br i1 %48, label %49, label %53

49:                                               ; preds = %46
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = load i8, ptr %50, align 1, !tbaa !9
  %52 = zext i8 %51 to i32
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.2, i32 noundef %52)
  br label %53

53:                                               ; preds = %49, %46
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55, %42
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  store i64 -9223372036854775790, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %69

59:                                               ; preds = %7
  %60 = load i32, ptr %18, align 4, !tbaa !10
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %66

62:                                               ; preds = %59
  %63 = load i64, ptr %17, align 8, !tbaa !25
  %64 = icmp slt i64 %63, 0
  br i1 %64, label %66, label %65

65:                                               ; preds = %62
  store i64 0, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %69

66:                                               ; preds = %62, %59
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = call i64 @UsbBootRequestSense(ptr noundef %67)
  store i64 %68, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %69

69:                                               ; preds = %66, %65, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  %70 = load i64, ptr %8, align 8
  ret i64 %70
}

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 = { "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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 136}
!13 = !{!"_USB_MASS_DEVICE", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !16, i64 80, !7, i64 128, !7, i64 129, !7, i64 130, !6, i64 136, !6, i64 144, !17, i64 152, !20, i64 200, !7, i64 236}
!14 = !{!"_EFI_BLOCK_IO_PROTOCOL", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !11, i64 12, !11, i64 16, !15, i64 24, !15, i64 32, !11, i64 40, !11, i64 44}
!17 = !{!"_EFI_DISK_INFO_PROTOCOL", !18, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!"", !11, i64 0, !19, i64 4, !19, i64 6, !7, i64 8}
!19 = !{!"short", !7, i64 0}
!20 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 4, !7, i64 5, !7, i64 8, !7, i64 16, !7, i64 32}
!21 = !{!22, !6, i64 16}
!22 = !{!"_USB_MASS_TRANSPORT", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!23 = !{!13, !6, i64 144}
!24 = !{!13, !7, i64 129}
!25 = !{!15, !15, 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.2 = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @UsbBootRequestSense(ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBootExecCmd(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  %9 = getelementptr inbounds i8, ptr %0, i64 136
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %0, i64 144
  %14 = load ptr, ptr %13, align 8, !tbaa !20
  %15 = getelementptr inbounds i8, ptr %0, i64 129
  %16 = load i8, ptr %15, align 1, !tbaa !21
  %17 = call i64 %12(ptr noundef %14, ptr noundef %1, i8 noundef zeroext %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, i8 noundef zeroext %16, i32 noundef %6, ptr noundef nonnull %8) #3
  %18 = icmp eq i64 %17, -9223372036854775790
  br i1 %18, label %19, label %26

19:                                               ; preds = %7
  %20 = call zeroext i8 @DebugPrintEnabled() #3
  %.not = icmp eq i8 %20, 0
  br i1 %.not, label %32, label %21

21:                                               ; preds = %19
  %22 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #3
  %.not16 = icmp eq i8 %22, 0
  br i1 %.not16, label %32, label %23

23:                                               ; preds = %21
  %24 = load i8, ptr %1, align 1, !tbaa !22
  %25 = zext i8 %24 to i32
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.2, i32 noundef %25) #3
  br label %32

26:                                               ; preds = %7
  %27 = load i32, ptr %8, align 4, !tbaa !23
  %28 = icmp ne i32 %27, 0
  %29 = icmp slt i64 %17, 0
  %or.cond = or i1 %29, %28
  br i1 %or.cond, label %30, label %32

30:                                               ; preds = %26
  %31 = call i64 @UsbBootRequestSense(ptr noundef nonnull %0)
  br label %32

32:                                               ; preds = %26, %19, %23, %21, %30
  %.0 = phi i64 [ %31, %30 ], [ -9223372036854775790, %21 ], [ -9223372036854775790, %23 ], [ -9223372036854775790, %19 ], [ 0, %26 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  ret i64 %.0
}

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 = { "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, !10, i64 136}
!6 = !{!"_USB_MASS_DEVICE", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !13, i64 80, !8, i64 128, !8, i64 129, !8, i64 130, !10, i64 136, !10, i64 144, !14, i64 152, !17, i64 200, !8, i64 236}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EFI_BLOCK_IO_PROTOCOL", !12, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"", !7, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !7, i64 12, !7, i64 16, !12, i64 24, !12, i64 32, !7, i64 40, !7, i64 44}
!14 = !{!"_EFI_DISK_INFO_PROTOCOL", !15, i64 0, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!15 = !{!"", !7, i64 0, !16, i64 4, !16, i64 6, !8, i64 8}
!16 = !{!"short", !8, i64 0}
!17 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 4, !8, i64 5, !8, i64 8, !8, i64 16, !8, i64 32}
!18 = !{!19, !10, i64 16}
!19 = !{!"_USB_MASS_TRANSPORT", !8, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!20 = !{!6, !10, i64 144}
!21 = !{!6, !8, i64 129}
!22 = !{!8, !8, i64 0}
!23 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass