; 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_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 @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) #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 !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 %42, 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 8
  %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 %41, label %33

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

41:                                               ; preds = %33, %18
  br label %42

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

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, !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 952}
!21 = !{!"", !19, i64 0, !6, i64 8, !6, i64 16, !22, i64 24, !22, i64 152, !23, i64 280, !7, i64 936, !6, i64 944, !11, i64 952, !7, i64 954, !7, i64 955, !7, i64 956, !7, i64 957, !19, i64 960, !19, i64 968, !11, i64 976, !6, i64 984, !6, i64 992, !7, i64 1000, !25, i64 1008, !7, i64 1040, !6, i64 1048, !6, i64 1056, !6, i64 1064, !6, i64 1072, !6, i64 1080, !19, i64 1088, !6, i64 1096}
!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 }

; 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 @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) #2
  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 %20, 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 952
  %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 %20, label %18

18:                                               ; preds = %12
  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
  %19 = call i64 @Ax88772UsbCommand(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef null)
  br label %20

20:                                               ; preds = %12, %18, %3
  %.0 = phi i64 [ %10, %3 ], [ %16, %12 ], [ %19, %18 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #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, !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 952}
!16 = !{!"", !17, i64 0, !18, i64 8, !18, i64 16, !19, i64 24, !19, i64 152, !20, i64 280, !7, i64 936, !18, i64 944, !6, i64 952, !7, i64 954, !7, i64 955, !7, i64 956, !7, i64 957, !17, i64 960, !17, i64 968, !6, i64 976, !18, i64 984, !18, i64 992, !7, i64 1000, !22, i64 1008, !7, i64 1040, !18, i64 1048, !18, i64 1056, !18, i64 1064, !18, i64 1072, !18, i64 1080, !17, i64 1088, !18, i64 1096}
!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