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

; 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.2 = 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 @Ax88772PhyWrite(ptr noundef %0, i8 noundef zeroext %1, i16 noundef zeroext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i16, align 2
  %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 i16 %2, ptr %6, align 2, !tbaa !10
  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 !12
  %10 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 1
  store i8 6, ptr %10, align 1, !tbaa !14
  %11 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 2
  store i16 0, ptr %11, align 1, !tbaa !15
  %12 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 3
  store i16 0, ptr %12, align 1, !tbaa !16
  %13 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 4
  store i16 0, ptr %13, align 1, !tbaa !17
  %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 !18
  %16 = load i64, ptr %8, align 8, !tbaa !18
  %17 = icmp slt i64 %16, 0
  br i1 %17, label %64, 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 !12
  %20 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 1
  store i8 8, ptr %20, align 1, !tbaa !14
  %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 !20
  %24 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 2
  store i16 %23, ptr %24, align 1, !tbaa !15
  %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 !16
  %28 = getelementptr inbounds %struct.USB_DEVICE_REQUEST, ptr %7, i32 0, i32 4
  store i16 2, ptr %28, align 1, !tbaa !17
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i64 @Ax88772UsbCommand(ptr noundef %29, ptr noundef %7, ptr noundef %6)
  store i64 %30, ptr %8, align 8, !tbaa !18
  %31 = load i64, ptr %8, align 8, !tbaa !18
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %63, label %33

33:                                               ; preds = %18
  br label %34

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

37:                                               ; preds = %34
  br label %38

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

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

50:                                               ; preds = %41, %38
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52, %34
  br label %54

54:                                               ; preds = %53
  br label %55

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

63:                                               ; preds = %55, %18
  br label %64

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

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, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 1, !11, i64 2, !11, i64 4, !11, i64 6}
!14 = !{!13, !7, i64 1}
!15 = !{!13, !11, i64 2}
!16 = !{!13, !11, i64 4}
!17 = !{!13, !11, i64 6}
!18 = !{!19, !19, i64 0}
!19 = !{!"long long", !7, i64 0}
!20 = !{!21, !11, i64 824}
!21 = !{!"", !19, i64 0, !6, i64 8, !6, i64 16, !22, i64 24, !23, i64 152, !7, i64 808, !6, i64 816, !11, i64 824, !7, i64 826, !7, i64 827, !7, i64 828, !7, i64 829, !7, i64 830, !6, i64 832, !19, i64 840, !6, i64 848, !6, i64 856, !6, i64 864, !7, i64 872, !6, i64 880}
!22 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !19, 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}
!23 = !{!"", !24, i64 0, !24, i64 4, !24, i64 8, !24, i64 12, !24, i64 16, !24, i64 20, !24, i64 24, !24, i64 28, !24, i64 32, !24, i64 36, !7, i64 40, !25, i64 552, !25, i64 584, !25, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!24 = !{!"int", !7, i64 0}
!25 = !{!"", !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 }

@.str.2 = 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 @Ax88772PhyWrite(ptr noundef %0, i8 noundef zeroext %1, i16 noundef zeroext %2) local_unnamed_addr #1 {
  %4 = alloca i16, align 2
  %5 = alloca %struct.USB_DEVICE_REQUEST, align 1
  store i16 %2, ptr %4, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store i8 64, ptr %5, align 1, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %5, i64 1
  store i8 6, ptr %6, align 1, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %5, i64 2
  store i16 0, ptr %7, align 1, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %5, i64 4
  store i16 0, ptr %8, align 1, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %5, i64 6
  store i16 0, ptr %9, align 1, !tbaa !14
  %10 = call i64 @Ax88772UsbCommand(ptr noundef %0, ptr noundef nonnull %5, ptr noundef null)
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %30, label %12

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

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

20:                                               ; preds = %18
  %21 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 16777280) #3
  %.not11 = icmp eq i8 %21, 0
  br i1 %.not11, label %28, label %22

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

28:                                               ; preds = %20, %22, %18
  store i8 64, ptr %5, align 1, !tbaa !9
  store i8 10, ptr %6, align 1, !tbaa !11
  store i16 0, ptr %7, align 1, !tbaa !12
  store i16 0, ptr %8, align 1, !tbaa !13
  store i16 0, ptr %9, align 1, !tbaa !14
  %29 = call i64 @Ax88772UsbCommand(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef null)
  br label %30

30:                                               ; preds = %12, %28, %3
  %.0 = phi i64 [ %10, %3 ], [ %16, %12 ], [ %29, %28 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #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, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"", !7, i64 0, !7, i64 1, !6, i64 2, !6, i64 4, !6, i64 6}
!11 = !{!10, !7, i64 1}
!12 = !{!10, !6, i64 2}
!13 = !{!10, !6, i64 4}
!14 = !{!10, !6, i64 6}
!15 = !{!16, !6, i64 824}
!16 = !{!"", !17, i64 0, !18, i64 8, !18, i64 16, !19, i64 24, !20, i64 152, !7, i64 808, !18, i64 816, !6, i64 824, !7, i64 826, !7, i64 827, !7, i64 828, !7, i64 829, !7, i64 830, !18, i64 832, !17, i64 840, !18, i64 848, !18, i64 856, !18, i64 864, !7, i64 872, !18, i64 880}
!17 = !{!"long long", !7, i64 0}
!18 = !{!"any pointer", !7, i64 0}
!19 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !17, i64 0, !18, i64 8, !18, i64 16, !18, i64 24, !18, i64 32, !18, i64 40, !18, i64 48, !18, i64 56, !18, i64 64, !18, i64 72, !18, i64 80, !18, i64 88, !18, i64 96, !18, i64 104, !18, i64 112, !18, i64 120}
!20 = !{!"", !21, i64 0, !21, i64 4, !21, i64 8, !21, i64 12, !21, i64 16, !21, i64 20, !21, i64 24, !21, i64 28, !21, i64 32, !21, i64 36, !7, i64 40, !22, i64 552, !22, i64 584, !22, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!21 = !{!"int", !7, i64 0}
!22 = !{!"", !7, i64 0}


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