; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg (Undi16SimpleNetworkStart)

; 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.PXENV_UNDI_STARTUP_T = type { i16 }
%struct.EFI_SIMPLE_NETWORK_DEV = type { i64, ptr, %struct._EFI_SIMPLE_NETWORK_PROTOCOL, %struct.EFI_SIMPLE_NETWORK_MODE, %struct._EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL, ptr, ptr, ptr, i8, ptr, ptr, i16, i16, %struct.EFI_SIMPLE_NETWORK_DEV_FIFO, ptr, ptr, %struct.PXENV_UNDI_GET_INFORMATION_T, %struct.PXENV_UNDI_GET_NIC_TYPE_T, %struct.PXENV_UNDI_GET_NDIS_INFO_T, i8, %struct.PXENV_UNDI_ISR_T, ptr, ptr, ptr, ptr, i8, i64, i64, i64, i64, ptr, ptr, ptr, 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_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL = type { i64, i64, i64, i32, [4 x i8], i8, i8, i8, i8, i16 }
%struct.EFI_SIMPLE_NETWORK_DEV_FIFO = type { i32, i32, [64 x ptr] }
%struct.PXENV_UNDI_GET_INFORMATION_T = type { i16, i16, i16, i16, i16, i16, [16 x i8], [16 x i8], i16, i16, i16 }
%struct.PXENV_UNDI_GET_NIC_TYPE_T = type <{ i16, i8, %union.PCI_PNP_INFO_T }>
%union.PCI_PNP_INFO_T = type { %struct.PCI_INFO_T }
%struct.PCI_INFO_T = type { i16, i16, i8, i8, i8, i8, i16, i16, i16 }
%struct.PXENV_UNDI_GET_NDIS_INFO_T = type <{ i16, [16 x i8], i32, i32, [4 x i32] }>
%struct.PXENV_UNDI_ISR_T = type { i16, i16, i16, i16, i16, i16, i16, i8, i8 }

@.str.29 = external hidden unnamed_addr constant [160 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [21 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
define dso_local i64 @Undi16SimpleNetworkStart(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.PXENV_UNDI_STARTUP_T, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i64 -9223372036854775806, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %67

11:                                               ; preds = %1
  store i64 0, ptr %4, align 8, !tbaa !9
  %12 = call zeroext i8 @DebugAssertEnabled()
  %13 = zext i8 %12 to i32
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %25

15:                                               ; preds = %11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = ptrtoint ptr %16 to i64
  %18 = sub i64 %17, ptrtoint (ptr getelementptr inbounds (%struct.EFI_SIMPLE_NETWORK_DEV, ptr null, i32 0, i32 2) to i64)
  %19 = inttoptr i64 %18 to ptr
  %20 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_DEV, ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = icmp ne i64 %21, 909209203
  br i1 %22, label %23, label %25

23:                                               ; preds = %15
  call void @DebugAssert(ptr noundef @.str.29, i64 noundef 1925, ptr noundef @.str.30)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  br label %30

25:                                               ; preds = %15, %11
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i64
  %28 = sub i64 %27, ptrtoint (ptr getelementptr inbounds (%struct.EFI_SIMPLE_NETWORK_DEV, ptr null, i32 0, i32 2) to i64)
  %29 = inttoptr i64 %28 to ptr
  br label %30

30:                                               ; preds = %25, %23
  %31 = phi ptr [ %24, %23 ], [ %29, %25 ]
  store ptr %31, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  store i64 -9223372036854775801, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %67

35:                                               ; preds = %30
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_DEV, ptr %36, i32 0, i32 3
  %38 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !24
  switch i32 %39, label %41 [
    i32 0, label %42
    i32 1, label %40
    i32 2, label %40
  ]

40:                                               ; preds = %35, %35
  store i64 -9223372036854775788, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %67

41:                                               ; preds = %35
  store i64 -9223372036854775801, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %67

42:                                               ; preds = %35
  %43 = getelementptr inbounds %struct.PXENV_UNDI_STARTUP_T, ptr %6, i32 0, i32 0
  store i16 -21555, ptr %43, align 1, !tbaa !25
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call i64 @PxeUndiStartup(ptr noundef %44, ptr noundef %6)
  store i64 %45, ptr %4, align 8, !tbaa !9
  %46 = load i64, ptr %4, align 8, !tbaa !9
  %47 = icmp slt i64 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %42
  %49 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %49, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %67

50:                                               ; preds = %42
  %51 = getelementptr inbounds %struct.PXENV_UNDI_STARTUP_T, ptr %6, i32 0, i32 0
  %52 = load i16, ptr %51, align 1, !tbaa !25
  %53 = zext i16 %52 to i32
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %50
  store i64 -9223372036854775801, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %67

56:                                               ; preds = %50
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_DEV, ptr %57, i32 0, i32 3
  %59 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %58, i32 0, i32 0
  store i32 1, ptr %59, align 8, !tbaa !24
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_DEV, ptr %60, i32 0, i32 3
  %62 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %61, i32 0, i32 7
  store i32 0, ptr %62, align 4, !tbaa !27
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_DEV, ptr %63, i32 0, i32 3
  %65 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %64, i32 0, i32 9
  store i32 0, ptr %65, align 4, !tbaa !28
  %66 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %66, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %67

67:                                               ; preds = %56, %55, %48, %41, %40, %34, %10
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %68 = load i64, ptr %2, align 8
  ret i64 %68
}

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

declare i64 @PxeUndiStartup(ptr noundef, ptr noundef) #2

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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !6, i64 8, !13, i64 16, !14, i64 144, !17, i64 800, !6, i64 840, !6, i64 848, !6, i64 856, !7, i64 864, !6, i64 872, !6, i64 880, !18, i64 888, !18, i64 890, !19, i64 896, !6, i64 1416, !6, i64 1424, !20, i64 1432, !21, i64 1482, !22, i64 1499, !7, i64 1541, !23, i64 1542, !6, i64 1560, !6, i64 1568, !6, i64 1576, !6, i64 1584, !7, i64 1592, !10, i64 1600, !10, i64 1608, !10, i64 1616, !10, i64 1624, !6, i64 1632, !6, i64 1640, !6, i64 1648, !6, i64 1656}
!13 = !{!"_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}
!14 = !{!"", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20, !15, i64 24, !15, i64 28, !15, i64 32, !15, i64 36, !7, i64 40, !16, i64 552, !16, i64 584, !16, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!15 = !{!"int", !7, i64 0}
!16 = !{!"", !7, i64 0}
!17 = !{!"_EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !15, i64 24, !7, i64 28, !7, i64 32, !7, i64 33, !7, i64 34, !7, i64 35, !18, i64 36}
!18 = !{!"short", !7, i64 0}
!19 = !{!"", !15, i64 0, !15, i64 4, !7, i64 8}
!20 = !{!"", !18, i64 0, !18, i64 2, !18, i64 4, !18, i64 6, !18, i64 8, !18, i64 10, !7, i64 12, !7, i64 28, !18, i64 44, !18, i64 46, !18, i64 48}
!21 = !{!"", !18, i64 0, !7, i64 2, !7, i64 3}
!22 = !{!"", !18, i64 0, !7, i64 2, !15, i64 18, !15, i64 22, !7, i64 26}
!23 = !{!"", !18, i64 0, !18, i64 2, !18, i64 4, !18, i64 6, !18, i64 8, !18, i64 10, !18, i64 12, !7, i64 14, !7, i64 15}
!24 = !{!12, !15, i64 144}
!25 = !{!26, !18, i64 0}
!26 = !{!"", !18, i64 0}
!27 = !{!12, !15, i64 172}
!28 = !{!12, !15, i64 180}


; 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.PXENV_UNDI_STARTUP_T = type { i16 }

@.str.29 = external hidden unnamed_addr constant [160 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [21 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
define dso_local i64 @Undi16SimpleNetworkStart(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.PXENV_UNDI_STARTUP_T, align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %2) #3
  %3 = icmp eq ptr %0, null
  br i1 %3, label %22, label %4

4:                                                ; preds = %1
  %5 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %5, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre18 = add i64 %.pre, -16
  %.pre20 = inttoptr i64 %.pre18 to ptr
  br i1 %.not, label %._crit_edge, label %6

6:                                                ; preds = %4
  %7 = load i64, ptr %.pre20, align 8, !tbaa !5
  %.not16 = icmp eq i64 %7, 909209203
  br i1 %.not16, label %._crit_edge, label %.thread

.thread:                                          ; preds = %6
  tail call void @DebugAssert(ptr noundef nonnull @.str.29, i64 noundef 1925, ptr noundef nonnull @.str.30) #3
  br label %9

._crit_edge:                                      ; preds = %4, %6
  %8 = icmp eq i64 %.pre18, 0
  br i1 %8, label %22, label %9

9:                                                ; preds = %.thread, %._crit_edge
  %10 = phi ptr [ %0, %.thread ], [ %.pre20, %._crit_edge ]
  %11 = getelementptr inbounds i8, ptr %10, i64 144
  %12 = load i32, ptr %11, align 8, !tbaa !22
  switch i32 %12, label %13 [
    i32 0, label %14
    i32 1, label %22
    i32 2, label %22
  ]

13:                                               ; preds = %9
  br label %22

14:                                               ; preds = %9
  store i16 -21555, ptr %2, align 2, !tbaa !23
  %15 = call i64 @PxeUndiStartup(ptr noundef nonnull %10, ptr noundef nonnull %2) #3
  %16 = icmp slt i64 %15, 0
  br i1 %16, label %22, label %17

17:                                               ; preds = %14
  %18 = load i16, ptr %2, align 2, !tbaa !23
  %.not17 = icmp eq i16 %18, 0
  br i1 %.not17, label %19, label %22

19:                                               ; preds = %17
  store i32 1, ptr %11, align 8, !tbaa !22
  %20 = getelementptr inbounds i8, ptr %10, i64 172
  store i32 0, ptr %20, align 4, !tbaa !25
  %21 = getelementptr inbounds i8, ptr %10, i64 180
  store i32 0, ptr %21, align 4, !tbaa !26
  br label %22

22:                                               ; preds = %17, %14, %9, %9, %._crit_edge, %1, %19, %13
  %.0 = phi i64 [ -9223372036854775801, %13 ], [ %15, %19 ], [ -9223372036854775806, %1 ], [ -9223372036854775801, %._crit_edge ], [ -9223372036854775788, %9 ], [ -9223372036854775788, %9 ], [ %15, %14 ], [ -9223372036854775801, %17 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %2) #3
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare i64 @PxeUndiStartup(ptr noundef, ptr noundef) local_unnamed_addr #2

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, !10, i64 8, !11, i64 16, !12, i64 144, !15, i64 800, !10, i64 840, !10, i64 848, !10, i64 856, !8, i64 864, !10, i64 872, !10, i64 880, !16, i64 888, !16, i64 890, !17, i64 896, !10, i64 1416, !10, i64 1424, !18, i64 1432, !19, i64 1482, !20, i64 1499, !8, i64 1541, !21, i64 1542, !10, i64 1560, !10, i64 1568, !10, i64 1576, !10, i64 1584, !8, i64 1592, !7, i64 1600, !7, i64 1608, !7, i64 1616, !7, i64 1624, !10, i64 1632, !10, i64 1640, !10, i64 1648, !10, i64 1656}
!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 = !{!"_EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL", !7, i64 0, !7, i64 8, !7, i64 16, !13, i64 24, !8, i64 28, !8, i64 32, !8, i64 33, !8, i64 34, !8, i64 35, !16, i64 36}
!16 = !{!"short", !8, i64 0}
!17 = !{!"", !13, i64 0, !13, i64 4, !8, i64 8}
!18 = !{!"", !16, i64 0, !16, i64 2, !16, i64 4, !16, i64 6, !16, i64 8, !16, i64 10, !8, i64 12, !8, i64 28, !16, i64 44, !16, i64 46, !16, i64 48}
!19 = !{!"", !16, i64 0, !8, i64 2, !8, i64 3}
!20 = !{!"", !16, i64 0, !8, i64 2, !13, i64 18, !13, i64 22, !8, i64 26}
!21 = !{!"", !16, i64 0, !16, i64 2, !16, i64 4, !16, i64 6, !16, i64 8, !16, i64 10, !16, i64 12, !8, i64 14, !8, i64 15}
!22 = !{!6, !13, i64 144}
!23 = !{!24, !16, i64 0}
!24 = !{!"", !16, i64 0}
!25 = !{!6, !13, i64 172}
!26 = !{!6, !13, i64 180}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass