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

; 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_PROTOCOL, %struct.EFI_SIMPLE_NETWORK_MODE, i8, ptr, i16, i8, i8, i8, i8, i64, i64, i16, ptr, ptr, [8 x i8], %struct.EFI_MAC_ADDRESS, i8, ptr, ptr, ptr, ptr, ptr, i64, 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] }

; 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
declare dso_local i64 @Ax88772UsbCommand(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Ax88772PhyRead(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca %struct.USB_DEVICE_REQUEST, align 1
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %9 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 0
  store i8 64, ptr %9, align 1, !tbaa !10
  %10 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 1
  store i8 6, ptr %10, align 1, !tbaa !13
  %11 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 2
  store i16 0, ptr %11, align 1, !tbaa !14
  %12 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 3
  store i16 0, ptr %12, align 1, !tbaa !15
  %13 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 4
  store i16 0, ptr %13, align 1, !tbaa !16
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i64 @Ax88772UsbCommand(ptr noundef %14, ptr noundef %7, ptr noundef null)
  store i64 %15, ptr %8, align 8, !tbaa !17
  %16 = load i64, ptr %8, align 8, !tbaa !17
  %17 = icmp slt i64 %16, 0
  br i1 %17, label %43, label %18

18:                                               ; preds = %3
  %19 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 0
  store i8 -64, ptr %19, align 1, !tbaa !10
  %20 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 1
  store i8 7, ptr %20, align 1, !tbaa !13
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.NIC_DEVICE, ptr %21, i32 0, i32 8
  %23 = load i16, ptr %22, align 8, !tbaa !19
  %24 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 2
  store i16 %23, ptr %24, align 1, !tbaa !14
  %25 = load i8, ptr %5, align 1, !tbaa !9
  %26 = zext i8 %25 to i16
  %27 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 3
  store i16 %26, ptr %27, align 1, !tbaa !15
  %28 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 4
  store i16 2, ptr %28, align 1, !tbaa !16
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i64 @Ax88772UsbCommand(ptr noundef %29, ptr noundef %7, ptr noundef %30)
  store i64 %31, ptr %8, align 8, !tbaa !17
  %32 = load i64, ptr %8, align 8, !tbaa !17
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %42, label %34

34:                                               ; preds = %18
  %35 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 0
  store i8 64, ptr %35, align 1, !tbaa !10
  %36 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 1
  store i8 10, ptr %36, align 1, !tbaa !13
  %37 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 2
  store i16 0, ptr %37, align 1, !tbaa !14
  %38 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 3
  store i16 0, ptr %38, align 1, !tbaa !15
  %39 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 4
  store i16 0, ptr %39, align 1, !tbaa !16
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = call i64 @Ax88772UsbCommand(ptr noundef %40, ptr noundef %7, ptr noundef null)
  store i64 %41, ptr %8, align 8, !tbaa !17
  br label %42

42:                                               ; preds = %34, %18
  br label %43

43:                                               ; preds = %42, %3
  %44 = load i64, ptr %8, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %44
}

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, !7, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 1, !12, i64 2, !12, i64 4, !12, i64 6}
!12 = !{!"short", !7, i64 0}
!13 = !{!11, !7, i64 1}
!14 = !{!11, !12, i64 2}
!15 = !{!11, !12, i64 4}
!16 = !{!11, !12, i64 6}
!17 = !{!18, !18, i64 0}
!18 = !{!"long long", !7, i64 0}
!19 = !{!20, !12, i64 952}
!20 = !{!"", !18, i64 0, !6, i64 8, !6, i64 16, !21, i64 24, !21, i64 152, !22, i64 280, !7, i64 936, !6, i64 944, !12, i64 952, !7, i64 954, !7, i64 955, !7, i64 956, !7, i64 957, !18, i64 960, !18, i64 968, !12, i64 976, !6, i64 984, !6, i64 992, !7, i64 1000, !24, i64 1008, !7, i64 1040, !6, i64 1048, !6, i64 1056, !6, i64 1064, !6, i64 1072, !6, i64 1080, !18, i64 1088, !6, i64 1096}
!21 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !18, 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}
!22 = !{!"", !23, i64 0, !23, i64 4, !23, i64 8, !23, i64 12, !23, i64 16, !23, i64 20, !23, i64 24, !23, i64 28, !23, i64 32, !23, i64 36, !7, i64 40, !24, i64 552, !24, i64 584, !24, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!23 = !{!"int", !7, i64 0}
!24 = !{!"", !7, 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"

%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
declare dso_local i64 @Ax88772UsbCommand(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Ax88772PhyRead(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.USB_DEVICE_REQUEST, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  store i8 64, ptr %4, align 1, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 6, ptr %5, align 1, !tbaa !10
  %6 = getelementptr inbounds i8, ptr %4, i64 2
  store i16 0, ptr %6, align 1, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %4, i64 4
  store i16 0, ptr %7, align 1, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %4, i64 6
  store i16 0, ptr %8, align 1, !tbaa !13
  %9 = call i64 @Ax88772UsbCommand(ptr noundef %0, ptr noundef nonnull %4, ptr noundef null)
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %19, label %11

11:                                               ; preds = %3
  store i8 -64, ptr %4, align 1, !tbaa !5
  store i8 7, ptr %5, align 1, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %0, i64 952
  %13 = load i16, ptr %12, align 8, !tbaa !14
  store i16 %13, ptr %6, align 1, !tbaa !11
  %14 = zext i8 %1 to i16
  store i16 %14, ptr %7, align 1, !tbaa !12
  store i16 2, ptr %8, align 1, !tbaa !13
  %15 = call i64 @Ax88772UsbCommand(ptr noundef %0, ptr noundef nonnull %4, ptr noundef %2)
  %16 = icmp slt i64 %15, 0
  br i1 %16, label %19, label %17

17:                                               ; preds = %11
  store i8 64, ptr %4, align 1, !tbaa !5
  store i8 10, ptr %5, align 1, !tbaa !10
  store i16 0, ptr %6, align 1, !tbaa !11
  store i16 0, ptr %7, align 1, !tbaa !12
  store i16 0, ptr %8, align 1, !tbaa !13
  %18 = call i64 @Ax88772UsbCommand(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef null)
  br label %19

19:                                               ; preds = %11, %17, %3
  %.0 = phi i64 [ %9, %3 ], [ %15, %11 ], [ %18, %17 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  ret i64 %.0
}

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 = !{!6, !9, i64 4}
!13 = !{!6, !9, i64 6}
!14 = !{!15, !9, i64 952}
!15 = !{!"", !16, i64 0, !17, i64 8, !17, i64 16, !18, i64 24, !18, i64 152, !19, i64 280, !7, i64 936, !17, i64 944, !9, i64 952, !7, i64 954, !7, i64 955, !7, i64 956, !7, i64 957, !16, i64 960, !16, i64 968, !9, i64 976, !17, i64 984, !17, i64 992, !7, i64 1000, !21, i64 1008, !7, i64 1040, !17, i64 1048, !17, i64 1056, !17, i64 1064, !17, i64 1072, !17, i64 1080, !16, i64 1088, !17, i64 1096}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"any pointer", !7, i64 0}
!18 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !16, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !17, i64 40, !17, i64 48, !17, i64 56, !17, i64 64, !17, i64 72, !17, i64 80, !17, i64 88, !17, i64 96, !17, i64 104, !17, i64 112, !17, i64 120}
!19 = !{!"", !20, i64 0, !20, i64 4, !20, i64 8, !20, i64 12, !20, i64 16, !20, i64 20, !20, i64 24, !20, i64 28, !20, i64 32, !20, i64 36, !7, i64 40, !21, i64 552, !21, i64 584, !21, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!20 = !{!"int", !7, i64 0}
!21 = !{!"", !7, i64 0}


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