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

; 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.EFI_SCSI_DISK_CAPACITY_DATA16 = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, [16 x i8] }
%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] }

; 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 ptr @ZeroMem(ptr noundef, i64 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
declare dso_local i64 @UsbBootExecCmdWithRetry(ptr noundef, ptr noundef, i8 noundef zeroext, i32 noundef, ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBootReadCapacity16(ptr noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [16 x i8], align 16
  %5 = alloca %struct.EFI_SCSI_DISK_CAPACITY_DATA16, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._USB_MASS_DEVICE, ptr %10, i32 0, i32 5
  store ptr %11, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %12, i32 0, i32 2
  store i8 0, ptr %13, align 1, !tbaa !9
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %14, i32 0, i32 8
  store i64 0, ptr %15, align 8, !tbaa !13
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %16, i32 0, i32 6
  store i32 0, ptr %17, align 4, !tbaa !14
  %18 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 0
  %19 = call ptr @ZeroMem(ptr noundef %18, i64 noundef 16)
  %20 = call ptr @ZeroMem(ptr noundef %5, i64 noundef 32)
  %21 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 0
  store i8 -98, ptr %21, align 16, !tbaa !15
  %22 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 1
  store i8 16, ptr %22, align 1, !tbaa !15
  %23 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 0
  %24 = getelementptr inbounds i8, ptr %23, i64 2
  %25 = call ptr @ZeroMem(ptr noundef %24, i64 noundef 8)
  %26 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 13
  store i8 32, ptr %26, align 1, !tbaa !15
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 0
  %29 = call i64 @UsbBootExecCmdWithRetry(ptr noundef %27, ptr noundef %28, i8 noundef zeroext 16, i32 noundef 0, ptr noundef %5, i32 noundef 32, i32 noundef 5000000)
  store i64 %29, ptr %7, align 8, !tbaa !16
  %30 = load i64, ptr %7, align 8, !tbaa !16
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %1
  %33 = load i64, ptr %7, align 8, !tbaa !16
  store i64 %33, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %73

34:                                               ; preds = %1
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %35, i32 0, i32 2
  store i8 1, ptr %36, align 1, !tbaa !9
  %37 = getelementptr inbounds %struct.EFI_SCSI_DISK_CAPACITY_DATA16, ptr %5, i32 0, i32 0
  %38 = call i64 @ReadUnaligned64(ptr noundef %37)
  %39 = call i64 @SwapBytes64(i64 noundef %38)
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %40, i32 0, i32 8
  store i64 %39, ptr %41, align 8, !tbaa !13
  %42 = getelementptr inbounds %struct.EFI_SCSI_DISK_CAPACITY_DATA16, ptr %5, i32 0, i32 8
  %43 = call i32 @ReadUnaligned32(ptr noundef %42)
  %44 = call i32 @SwapBytes32(i32 noundef %43)
  store i32 %44, ptr %8, align 4, !tbaa !17
  %45 = getelementptr inbounds %struct.EFI_SCSI_DISK_CAPACITY_DATA16, ptr %5, i32 0, i32 14
  %46 = load i8, ptr %45, align 1, !tbaa !18
  %47 = zext i8 %46 to i32
  %48 = shl i32 %47, 8
  %49 = getelementptr inbounds %struct.EFI_SCSI_DISK_CAPACITY_DATA16, ptr %5, i32 0, i32 15
  %50 = load i8, ptr %49, align 1, !tbaa !20
  %51 = zext i8 %50 to i32
  %52 = or i32 %48, %51
  %53 = sext i32 %52 to i64
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %54, i32 0, i32 9
  store i64 %53, ptr %55, align 8, !tbaa !21
  %56 = getelementptr inbounds %struct.EFI_SCSI_DISK_CAPACITY_DATA16, ptr %5, i32 0, i32 13
  %57 = load i8, ptr %56, align 1, !tbaa !22
  %58 = zext i8 %57 to i32
  %59 = shl i32 1, %58
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %60, i32 0, i32 10
  store i32 %59, ptr %61, align 8, !tbaa !23
  %62 = load i32, ptr %8, align 4, !tbaa !17
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %67

64:                                               ; preds = %34
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = call i64 @UsbBootRequestSense(ptr noundef %65)
  store i64 %66, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %73

67:                                               ; preds = %34
  %68 = load i32, ptr %8, align 4, !tbaa !17
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.EFI_BLOCK_IO_MEDIA, ptr %69, i32 0, i32 6
  store i32 %68, ptr %70, align 4, !tbaa !14
  br label %71

71:                                               ; preds = %67
  %72 = load i64, ptr %7, align 8, !tbaa !16
  store i64 %72, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %73

73:                                               ; preds = %71, %64, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  %74 = load i64, ptr %2, align 8
  ret i64 %74
}

declare i64 @SwapBytes64(i64 noundef) #2

declare i64 @ReadUnaligned64(ptr noundef) #2

declare i32 @SwapBytes32(i32 noundef) #2

declare i32 @ReadUnaligned32(ptr noundef) #2

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 = !{!10, !7, i64 5}
!10 = !{!"", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !11, i64 12, !11, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !11, i64 44}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !12, i64 24}
!14 = !{!10, !11, i64 12}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !12, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!19, !7, i64 14}
!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, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16}
!20 = !{!19, !7, i64 15}
!21 = !{!10, !12, i64 32}
!22 = !{!19, !7, i64 13}
!23 = !{!10, !11, i64 40}


; 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.EFI_SCSI_DISK_CAPACITY_DATA16 = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, [16 x i8] }

; 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 ptr @ZeroMem(ptr noundef, i64 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
declare dso_local i64 @UsbBootExecCmdWithRetry(ptr noundef, ptr noundef, i8 noundef zeroext, i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @UsbBootReadCapacity16(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [16 x i8], align 16
  %3 = alloca %struct.EFI_SCSI_DISK_CAPACITY_DATA16, align 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 85
  store i8 0, ptr %4, align 1, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 0, ptr %5, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 0, ptr %6, align 4, !tbaa !12
  %7 = call ptr @ZeroMem(ptr noundef nonnull %2, i64 noundef 16) #3
  %8 = call ptr @ZeroMem(ptr noundef nonnull %3, i64 noundef 32) #3
  store i8 -98, ptr %2, align 16, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 16, ptr %9, align 1, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %2, i64 2
  %11 = call ptr @ZeroMem(ptr noundef nonnull %10, i64 noundef 8) #3
  %12 = getelementptr inbounds i8, ptr %2, i64 13
  store i8 32, ptr %12, align 1, !tbaa !13
  %13 = call i64 @UsbBootExecCmdWithRetry(ptr noundef %0, ptr noundef nonnull %2, i8 noundef zeroext 16, i32 noundef 0, ptr noundef nonnull %3, i32 noundef 32, i32 noundef 5000000)
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %39, label %15

15:                                               ; preds = %1
  store i8 1, ptr %4, align 1, !tbaa !5
  %16 = call i64 @ReadUnaligned64(ptr noundef nonnull %3) #3
  %17 = call i64 @SwapBytes64(i64 noundef %16) #3
  store i64 %17, ptr %5, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %3, i64 8
  %19 = call i32 @ReadUnaligned32(ptr noundef nonnull %18) #3
  %20 = call i32 @SwapBytes32(i32 noundef %19) #3
  %21 = getelementptr inbounds i8, ptr %3, i64 14
  %22 = load i8, ptr %21, align 1, !tbaa !14
  %23 = zext i8 %22 to i64
  %24 = shl nuw nsw i64 %23, 8
  %25 = getelementptr inbounds i8, ptr %3, i64 15
  %26 = load i8, ptr %25, align 1, !tbaa !16
  %27 = zext i8 %26 to i64
  %28 = or disjoint i64 %24, %27
  %29 = getelementptr inbounds i8, ptr %0, i64 112
  store i64 %28, ptr %29, align 8, !tbaa !17
  %30 = getelementptr inbounds i8, ptr %3, i64 13
  %31 = load i8, ptr %30, align 1, !tbaa !18
  %32 = zext nneg i8 %31 to i32
  %33 = shl nuw i32 1, %32
  %34 = getelementptr inbounds i8, ptr %0, i64 120
  store i32 %33, ptr %34, align 8, !tbaa !19
  %35 = icmp eq i32 %20, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %15
  %37 = call i64 @UsbBootRequestSense(ptr noundef nonnull %0)
  br label %39

38:                                               ; preds = %15
  store i32 %20, ptr %6, align 4, !tbaa !12
  br label %39

39:                                               ; preds = %1, %38, %36
  %.0 = phi i64 [ %37, %36 ], [ %13, %38 ], [ %13, %1 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  ret i64 %.0
}

declare i64 @SwapBytes64(i64 noundef) local_unnamed_addr #2

declare i64 @ReadUnaligned64(ptr noundef) local_unnamed_addr #2

declare i32 @SwapBytes32(i32 noundef) local_unnamed_addr #2

declare i32 @ReadUnaligned32(ptr noundef) local_unnamed_addr #2

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, !8, i64 5}
!6 = !{!"", !7, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !7, i64 12, !7, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 44}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!6, !7, i64 12}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !8, i64 14}
!15 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !8, i64 12, !8, i64 13, !8, i64 14, !8, i64 15, !8, i64 16}
!16 = !{!15, !8, i64 15}
!17 = !{!6, !10, i64 32}
!18 = !{!15, !8, i64 13}
!19 = !{!6, !7, i64 40}


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