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

@.str.1 = external hidden unnamed_addr constant [28 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
declare dso_local i64 @Ax88772UsbCommand(ptr noundef, ptr noundef, ptr noundef) #1

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

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

; 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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %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 %66, 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 7
  %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 %65, label %34

34:                                               ; preds = %18
  br label %35

35:                                               ; preds = %34
  %36 = call zeroext i8 @DebugPrintEnabled()
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %38, label %55

38:                                               ; preds = %35
  br label %39

39:                                               ; preds = %38
  %40 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 16777280)
  %41 = icmp ne i8 %40, 0
  br i1 %41, label %42, label %52

42:                                               ; preds = %39
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NIC_DEVICE, ptr %43, i32 0, i32 7
  %45 = load i16, ptr %44, align 8, !tbaa !19
  %46 = zext i16 %45 to i32
  %47 = load i8, ptr %5, align 1, !tbaa !9
  %48 = zext i8 %47 to i32
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load i16, ptr %49, align 2, !tbaa !25
  %51 = zext i16 %50 to i32
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 16777280, ptr noundef @.str.1, i32 noundef %46, i32 noundef %48, i32 noundef %51)
  br label %52

52:                                               ; preds = %42, %39
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54, %35
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 0
  store i8 64, ptr %58, align 1, !tbaa !10
  %59 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 1
  store i8 10, ptr %59, align 1, !tbaa !13
  %60 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 2
  store i16 0, ptr %60, align 1, !tbaa !14
  %61 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 3
  store i16 0, ptr %61, align 1, !tbaa !15
  %62 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 4
  store i16 0, ptr %62, align 1, !tbaa !16
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = call i64 @Ax88772UsbCommand(ptr noundef %63, ptr noundef %7, ptr noundef null)
  store i64 %64, ptr %8, align 8, !tbaa !17
  br label %65

65:                                               ; preds = %57, %18
  br label %66

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

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 = !{!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 824}
!20 = !{!"", !18, i64 0, !6, i64 8, !6, i64 16, !21, i64 24, !22, i64 152, !7, i64 808, !6, i64 816, !12, i64 824, !7, i64 826, !7, i64 827, !7, i64 828, !7, i64 829, !7, i64 830, !6, i64 832, !18, i64 840, !6, i64 848, !6, i64 856, !6, i64 864, !7, i64 872, !6, i64 880}
!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}
!25 = !{!12, !12, 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 }

@.str.1 = external hidden unnamed_addr constant [28 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
declare dso_local i64 @Ax88772UsbCommand(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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: 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) #3
  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 %29, 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 824
  %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 %29, label %17

17:                                               ; preds = %11
  %18 = call zeroext i8 @DebugPrintEnabled() #3
  %.not = icmp eq i8 %18, 0
  br i1 %.not, label %27, label %19

19:                                               ; preds = %17
  %20 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 16777280) #3
  %.not13 = icmp eq i8 %20, 0
  br i1 %.not13, label %27, label %21

21:                                               ; preds = %19
  %22 = load i16, ptr %12, align 8, !tbaa !14
  %23 = zext i16 %22 to i32
  %24 = zext i8 %1 to i32
  %25 = load i16, ptr %2, align 2, !tbaa !22
  %26 = zext i16 %25 to i32
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 16777280, ptr noundef nonnull @.str.1, i32 noundef %23, i32 noundef %24, i32 noundef %26) #3
  br label %27

27:                                               ; preds = %19, %21, %17
  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
  %28 = call i64 @Ax88772UsbCommand(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef null)
  br label %29

29:                                               ; preds = %11, %27, %3
  %.0 = phi i64 [ %9, %3 ], [ %15, %11 ], [ %28, %27 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  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 = { "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, !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 824}
!15 = !{!"", !16, i64 0, !17, i64 8, !17, i64 16, !18, i64 24, !19, i64 152, !7, i64 808, !17, i64 816, !9, i64 824, !7, i64 826, !7, i64 827, !7, i64 828, !7, i64 829, !7, i64 830, !17, i64 832, !16, i64 840, !17, i64 848, !17, i64 856, !17, i64 864, !7, i64 872, !17, i64 880}
!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}
!22 = !{!9, !9, i64 0}


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