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

; 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] }

@.str.3 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [60 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

declare zeroext i8 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

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

; 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
declare dso_local i64 @UsbBootInquiry(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBootGetParams(ptr noundef %0) #2 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %7, i32 0, i32 5
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i64 @UsbBootInquiry(ptr noundef %9)
  store i64 %10, ptr %5, align 8, !tbaa !9
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = icmp slt i64 %11, 0
  br i1 %12, label %13, label %30

13:                                               ; preds = %1
  br label %14

14:                                               ; preds = %13
  %15 = call zeroext i8 @DebugPrintEnabled()
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %17, label %26

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %17
  %19 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = load i64, ptr %5, align 8, !tbaa !9
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.3, i64 noundef %22)
  br label %23

23:                                               ; preds = %21, %18
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25, %14
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %29, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %94

30:                                               ; preds = %1
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %31, i32 0, i32 8
  %33 = load i8, ptr %32, align 2, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %73

36:                                               ; preds = %30
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %37, i32 0, i32 8
  %39 = load i8, ptr %38, align 2, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = icmp ne i32 %40, 5
  br i1 %41, label %42, label %73

42:                                               ; preds = %36
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %43, i32 0, i32 8
  %45 = load i8, ptr %44, align 2, !tbaa !11
  %46 = zext i8 %45 to i32
  %47 = icmp ne i32 %46, 7
  br i1 %47, label %48, label %73

48:                                               ; preds = %42
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %49, i32 0, i32 8
  %51 = load i8, ptr %50, align 2, !tbaa !11
  %52 = zext i8 %51 to i32
  %53 = icmp ne i32 %52, 14
  br i1 %53, label %54, label %73

54:                                               ; preds = %48
  br label %55

55:                                               ; preds = %54
  %56 = call zeroext i8 @DebugPrintEnabled()
  %57 = icmp ne i8 %56, 0
  br i1 %57, label %58, label %70

58:                                               ; preds = %55
  br label %59

59:                                               ; preds = %58
  %60 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %61 = icmp ne i8 %60, 0
  br i1 %61, label %62, label %67

62:                                               ; preds = %59
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %63, i32 0, i32 8
  %65 = load i8, ptr %64, align 2, !tbaa !11
  %66 = zext i8 %65 to i32
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.4, i32 noundef %66)
  br label %67

67:                                               ; preds = %62, %59
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69, %55
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  store i64 -9223372036854775805, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %94

73:                                               ; preds = %48, %42, %36, %30
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %74, i32 0, i32 8
  %76 = load i8, ptr %75, align 2, !tbaa !11
  %77 = zext i8 %76 to i32
  %78 = icmp eq i32 %77, 5
  br i1 %78, label %85, label %79

79:                                               ; preds = %73
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %80, i32 0, i32 8
  %82 = load i8, ptr %81, align 2, !tbaa !11
  %83 = zext i8 %82 to i32
  %84 = icmp eq i32 %83, 7
  br i1 %84, label %85, label %90

85:                                               ; preds = %79, %73
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %86, i32 0, i32 6
  store i8 1, ptr %87, align 8, !tbaa !20
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %88, i32 0, i32 6
  store i32 2048, ptr %89, align 4, !tbaa !21
  br label %90

90:                                               ; preds = %85, %79
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = call i64 @UsbBootDetectMedia(ptr noundef %91)
  store i64 %92, ptr %5, align 8, !tbaa !9
  %93 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %93, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %94

94:                                               ; preds = %90, %72, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %95 = load i64, ptr %2, align 8
  ret i64 %95
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @UsbBootDetectMedia(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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 = !{!"long long", !7, i64 0}
!11 = !{!12, !7, i64 130}
!12 = !{!"_USB_MASS_DEVICE", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !15, i64 80, !7, i64 128, !7, i64 129, !7, i64 130, !6, i64 136, !6, i64 144, !16, i64 152, !19, i64 200, !7, i64 236}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_EFI_BLOCK_IO_PROTOCOL", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!"", !13, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !13, i64 12, !13, i64 16, !10, i64 24, !10, i64 32, !13, i64 40, !13, i64 44}
!16 = !{!"_EFI_DISK_INFO_PROTOCOL", !17, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!17 = !{!"", !13, i64 0, !18, i64 4, !18, i64 6, !7, i64 8}
!18 = !{!"short", !7, i64 0}
!19 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 4, !7, i64 5, !7, i64 8, !7, i64 16, !7, i64 32}
!20 = !{!12, !7, i64 128}
!21 = !{!15, !13, i64 12}


; 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.3 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [60 x i8], align 1

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBootGetParams(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i64 @UsbBootInquiry(ptr noundef %0)
  %3 = icmp slt i64 %2, 0
  br i1 %3, label %4, label %9

4:                                                ; preds = %1
  %5 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not24 = icmp eq i8 %5, 0
  br i1 %.not24, label %24, label %6

6:                                                ; preds = %4
  %7 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not25 = icmp eq i8 %7, 0
  br i1 %.not25, label %24, label %8

8:                                                ; preds = %6
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.3, i64 noundef %2) #2
  br label %24

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 130
  %11 = load i8, ptr %10, align 2, !tbaa !5
  switch i8 %11, label %12 [
    i8 5, label %19
    i8 7, label %19
    i8 0, label %22
    i8 14, label %22
  ]

12:                                               ; preds = %9
  %13 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not22 = icmp eq i8 %13, 0
  br i1 %.not22, label %24, label %14

14:                                               ; preds = %12
  %15 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not23 = icmp eq i8 %15, 0
  br i1 %.not23, label %24, label %16

16:                                               ; preds = %14
  %17 = load i8, ptr %10, align 2, !tbaa !5
  %18 = zext i8 %17 to i32
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.4, i32 noundef %18) #2
  br label %24

19:                                               ; preds = %9, %9
  %20 = getelementptr inbounds i8, ptr %0, i64 128
  store i8 1, ptr %20, align 8, !tbaa !18
  %21 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 2048, ptr %21, align 4, !tbaa !19
  br label %22

22:                                               ; preds = %9, %9, %19
  %23 = tail call i64 @UsbBootDetectMedia(ptr noundef nonnull %0)
  br label %24

24:                                               ; preds = %12, %16, %14, %4, %8, %6, %22
  %.0 = phi i64 [ %23, %22 ], [ %2, %6 ], [ %2, %8 ], [ %2, %4 ], [ -9223372036854775805, %14 ], [ -9223372036854775805, %16 ], [ -9223372036854775805, %12 ]
  ret i64 %.0
}

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

attributes #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 = { 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, !8, i64 130}
!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 = !{!6, !8, i64 128}
!19 = !{!13, !7, i64 12}


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