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

; 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.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] }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@gBS = external global ptr, align 8

; 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
define dso_local i64 @Ax88772NegotiateLinkStart(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i16, align 2
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call i64 @Ax88772PhyWrite(ptr noundef %6, i8 noundef zeroext 4, i16 noundef zeroext 481)
  store i64 %7, ptr %4, align 8, !tbaa !9
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = icmp slt i64 %8, 0
  br i1 %9, label %34, label %10

10:                                               ; preds = %1
  store i16 4608, ptr %3, align 2, !tbaa !11
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.NIC_DEVICE, ptr %11, i32 0, i32 9
  %13 = load i8, ptr %12, align 2, !tbaa !13
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %10
  %16 = load i16, ptr %3, align 2, !tbaa !11
  %17 = zext i16 %16 to i32
  %18 = or i32 %17, 8192
  %19 = trunc i32 %18 to i16
  store i16 %19, ptr %3, align 2, !tbaa !11
  br label %20

20:                                               ; preds = %15, %10
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.NIC_DEVICE, ptr %21, i32 0, i32 11
  %23 = load i8, ptr %22, align 4, !tbaa !19
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %20
  %26 = load i16, ptr %3, align 2, !tbaa !11
  %27 = zext i16 %26 to i32
  %28 = or i32 %27, 256
  %29 = trunc i32 %28 to i16
  store i16 %29, ptr %3, align 2, !tbaa !11
  br label %30

30:                                               ; preds = %25, %20
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = load i16, ptr %3, align 2, !tbaa !11
  %33 = call i64 @Ax88772PhyWrite(ptr noundef %31, i8 noundef zeroext 0, i16 noundef zeroext %32)
  store i64 %33, ptr %4, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %30, %1
  %35 = load i64, ptr %4, align 8, !tbaa !9
  %36 = icmp slt i64 %35, 0
  br i1 %36, label %97, label %37

37:                                               ; preds = %34
  store i32 0, ptr %5, align 4, !tbaa !20
  br label %38

38:                                               ; preds = %94, %37
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.NIC_DEVICE, ptr %39, i32 0, i32 10
  %41 = load i8, ptr %40, align 1, !tbaa !21
  %42 = zext i8 %41 to i32
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %66

44:                                               ; preds = %38
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.NIC_DEVICE, ptr %45, i32 0, i32 12
  %47 = load i8, ptr %46, align 1, !tbaa !22
  %48 = zext i8 %47 to i32
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %66

50:                                               ; preds = %44
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.NIC_DEVICE, ptr %51, i32 0, i32 12
  %53 = load i8, ptr %52, align 1, !tbaa !22
  %54 = zext i8 %53 to i32
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.NIC_DEVICE, ptr %55, i32 0, i32 10
  %57 = load i8, ptr %56, align 1, !tbaa !21
  %58 = zext i8 %57 to i32
  %59 = and i32 %54, %58
  %60 = trunc i32 %59 to i8
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.NIC_DEVICE, ptr %61, i32 0, i32 3
  %63 = getelementptr inbounds %struct._EFI_SIMPLE_NETWORK_PROTOCOL, ptr %62, i32 0, i32 15
  %64 = load ptr, ptr %63, align 8, !tbaa !23
  %65 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %64, i32 0, i32 18
  store i8 %60, ptr %65, align 4, !tbaa !24
  br label %96

66:                                               ; preds = %44, %38
  %67 = load ptr, ptr @gBS, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %67, i32 0, i32 29
  %69 = load ptr, ptr %68, align 8, !tbaa !25
  %70 = call i64 %69(i64 noundef 500000)
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.NIC_DEVICE, ptr %72, i32 0, i32 14
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.NIC_DEVICE, ptr %74, i32 0, i32 10
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.NIC_DEVICE, ptr %76, i32 0, i32 12
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.NIC_DEVICE, ptr %78, i32 0, i32 9
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.NIC_DEVICE, ptr %80, i32 0, i32 11
  %82 = call i64 @Ax88772NegotiateLinkComplete(ptr noundef %71, ptr noundef %73, ptr noundef %75, ptr noundef %77, ptr noundef %79, ptr noundef %81)
  store i64 %82, ptr %4, align 8, !tbaa !9
  %83 = load i32, ptr %5, align 4, !tbaa !20
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %5, align 4, !tbaa !20
  br label %85

85:                                               ; preds = %66
  br label %86

86:                                               ; preds = %85
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.NIC_DEVICE, ptr %87, i32 0, i32 12
  %89 = load i8, ptr %88, align 1, !tbaa !22
  %90 = icmp ne i8 %89, 0
  br i1 %90, label %94, label %91

91:                                               ; preds = %86
  %92 = load i32, ptr %5, align 4, !tbaa !20
  %93 = icmp slt i32 %92, 20
  br label %94

94:                                               ; preds = %91, %86
  %95 = phi i1 [ false, %86 ], [ %93, %91 ]
  br i1 %95, label %38, label %96, !llvm.loop !28

96:                                               ; preds = %94, %50
  br label %97

97:                                               ; preds = %96, %34
  %98 = load i64, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #2
  ret i64 %98
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @Ax88772PhyWrite(ptr noundef, i8 noundef zeroext, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Ax88772NegotiateLinkComplete(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !7, i64 954}
!14 = !{!"", !10, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !15, i64 152, !16, i64 280, !7, i64 936, !6, i64 944, !12, i64 952, !7, i64 954, !7, i64 955, !7, i64 956, !7, i64 957, !10, i64 960, !10, i64 968, !12, i64 976, !6, i64 984, !6, i64 992, !7, i64 1000, !18, i64 1008, !7, i64 1040, !6, i64 1048, !6, i64 1056, !6, i64 1064, !6, i64 1072, !6, i64 1080, !10, i64 1088, !6, i64 1096}
!15 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !10, 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}
!16 = !{!"", !17, i64 0, !17, i64 4, !17, i64 8, !17, i64 12, !17, i64 16, !17, i64 20, !17, i64 24, !17, i64 28, !17, i64 32, !17, i64 36, !7, i64 40, !18, i64 552, !18, i64 584, !18, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!17 = !{!"int", !7, i64 0}
!18 = !{!"", !7, i64 0}
!19 = !{!14, !7, i64 956}
!20 = !{!17, !17, i64 0}
!21 = !{!14, !7, i64 955}
!22 = !{!14, !7, i64 957}
!23 = !{!14, !6, i64 144}
!24 = !{!16, !7, i64 652}
!25 = !{!26, !6, i64 248}
!26 = !{!"", !27, i64 0, !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, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!27 = !{!"", !10, i64 0, !17, i64 8, !17, i64 12, !17, i64 16, !17, i64 20}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}


; 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"

@gBS = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @Ax88772NegotiateLinkStart(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @Ax88772PhyWrite(ptr noundef %0, i8 noundef zeroext 4, i16 noundef zeroext 481)
  %3 = icmp slt i64 %2, 0
  br i1 %3, label %.thread, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 954
  %6 = load i8, ptr %5, align 2, !tbaa !5
  %.not = icmp eq i8 %6, 0
  %spec.select = select i1 %.not, i16 4608, i16 12800
  %7 = getelementptr inbounds i8, ptr %0, i64 956
  %8 = load i8, ptr %7, align 4, !tbaa !16
  %.not29 = icmp eq i8 %8, 0
  %9 = or disjoint i16 %spec.select, 256
  %.125 = select i1 %.not29, i16 %spec.select, i16 %9
  %10 = tail call i64 @Ax88772PhyWrite(ptr noundef %0, i8 noundef zeroext 0, i16 noundef zeroext %.125)
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %.thread, label %.preheader

.preheader:                                       ; preds = %4
  %12 = getelementptr inbounds i8, ptr %0, i64 955
  %13 = getelementptr inbounds i8, ptr %0, i64 957
  %14 = getelementptr inbounds i8, ptr %0, i64 968
  br label %15

15:                                               ; preds = %.preheader, %24
  %.1 = phi i64 [ %29, %24 ], [ %10, %.preheader ]
  %.0 = phi i32 [ %30, %24 ], [ 0, %.preheader ]
  %16 = load i8, ptr %12, align 1, !tbaa !17
  %.not30 = icmp eq i8 %16, 0
  br i1 %.not30, label %24, label %17

17:                                               ; preds = %15
  %18 = load i8, ptr %13, align 1, !tbaa !18
  %.not31 = icmp eq i8 %18, 0
  br i1 %.not31, label %24, label %19

19:                                               ; preds = %17
  %20 = and i8 %18, %16
  %21 = getelementptr inbounds i8, ptr %0, i64 144
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %22, i64 652
  store i8 %20, ptr %23, align 4, !tbaa !20
  br label %.thread

24:                                               ; preds = %17, %15
  %25 = load ptr, ptr @gBS, align 8, !tbaa !21
  %26 = getelementptr inbounds i8, ptr %25, i64 248
  %27 = load ptr, ptr %26, align 8, !tbaa !22
  %28 = tail call i64 %27(i64 noundef 500000) #1
  %29 = tail call i64 @Ax88772NegotiateLinkComplete(ptr noundef nonnull %0, ptr noundef nonnull %14, ptr noundef nonnull %12, ptr noundef nonnull %13, ptr noundef nonnull %5, ptr noundef nonnull %7)
  %30 = add nuw nsw i32 %.0, 1
  %31 = load i8, ptr %13, align 1, !tbaa !18
  %.not32 = icmp eq i8 %31, 0
  %32 = icmp ult i32 %.0, 19
  %33 = select i1 %.not32, i1 %32, i1 false
  br i1 %33, label %15, label %.thread, !llvm.loop !25

.thread:                                          ; preds = %24, %1, %19, %4
  %.2 = phi i64 [ %10, %4 ], [ %.1, %19 ], [ %2, %1 ], [ %29, %24 ]
  ret i64 %.2
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @Ax88772PhyWrite(ptr noundef, i8 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @Ax88772NegotiateLinkComplete(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { 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 954}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !11, i64 152, !12, i64 280, !8, i64 936, !10, i64 944, !15, i64 952, !8, i64 954, !8, i64 955, !8, i64 956, !8, i64 957, !7, i64 960, !7, i64 968, !15, i64 976, !10, i64 984, !10, i64 992, !8, i64 1000, !14, i64 1008, !8, i64 1040, !10, i64 1048, !10, i64 1056, !10, i64 1064, !10, i64 1072, !10, i64 1080, !7, i64 1088, !10, i64 1096}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120}
!12 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !8, i64 40, !14, i64 552, !14, i64 584, !14, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!13 = !{!"int", !8, i64 0}
!14 = !{!"", !8, i64 0}
!15 = !{!"short", !8, i64 0}
!16 = !{!6, !8, i64 956}
!17 = !{!6, !8, i64 955}
!18 = !{!6, !8, i64 957}
!19 = !{!6, !10, i64 144}
!20 = !{!12, !8, i64 652}
!21 = !{!10, !10, i64 0}
!22 = !{!23, !10, i64 248}
!23 = !{!"", !24, i64 0, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368}
!24 = !{!"", !7, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass