; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (EfiIp4Poll)

; 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._IP4_PROTOCOL = type { i32, %struct._EFI_IP4_PROTOCOL, ptr, i64, ptr, %struct._LIST_ENTRY, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct.EFI_LOCK, ptr, %struct._LIST_ENTRY, ptr, ptr, i32, ptr, i32, %struct.EFI_IP4_CONFIG_DATA }
%struct._EFI_IP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i8, i8, i8, i8, i32, i32 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct._IP4_SERVICE = type { i32, %struct._EFI_SERVICE_BINDING_PROTOCOL, i64, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, %struct.IP4_ASSEMBLE_TABLE, %struct.IGMP_SERVICE_DATA, ptr, ptr, ptr, ptr, %struct.EFI_MANAGED_NETWORK_CONFIG_DATA, %struct.EFI_SIMPLE_NETWORK_MODE, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct.IP4_ASSEMBLE_TABLE = type { [31 x %struct._LIST_ENTRY] }
%struct.IGMP_SERVICE_DATA = type { i64, %struct._LIST_ENTRY }
%struct.EFI_MANAGED_NETWORK_CONFIG_DATA = type { i32, i32, i16, i8, i8, i8, i8, i8, i8, i8 }
%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_MANAGED_NETWORK_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [149 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @EfiIp4Poll(ptr noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = 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
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i64 -9223372036854775806, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %47

10:                                               ; preds = %1
  %11 = call zeroext i8 @DebugAssertEnabled()
  %12 = zext i8 %11 to i32
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %24

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = ptrtoint ptr %15 to i64
  %17 = sub i64 %16, ptrtoint (ptr getelementptr inbounds (%struct._IP4_PROTOCOL, ptr null, i32 0, i32 1) to i64)
  %18 = inttoptr i64 %17 to ptr
  %19 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = icmp ne i32 %20, 1345605705
  br i1 %21, label %22, label %24

22:                                               ; preds = %14
  call void @DebugAssert(ptr noundef @.str, i64 noundef 2543, ptr noundef @.str.1)
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  br label %29

24:                                               ; preds = %14, %10
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = ptrtoint ptr %25 to i64
  %27 = sub i64 %26, ptrtoint (ptr getelementptr inbounds (%struct._IP4_PROTOCOL, ptr null, i32 0, i32 1) to i64)
  %28 = inttoptr i64 %27 to ptr
  br label %29

29:                                               ; preds = %24, %22
  %30 = phi ptr [ %23, %22 ], [ %28, %24 ]
  store ptr %30, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %31, i32 0, i32 3
  %33 = load i64, ptr %32, align 8, !tbaa !19
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %29
  store i64 -9223372036854775789, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %47

36:                                               ; preds = %29
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %40 = getelementptr inbounds %struct._IP4_SERVICE, ptr %39, i32 0, i32 13
  %41 = load ptr, ptr %40, align 8, !tbaa !21
  store ptr %41, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._EFI_MANAGED_NETWORK_PROTOCOL, ptr %42, i32 0, i32 7
  %44 = load ptr, ptr %43, align 8, !tbaa !28
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call i64 %44(ptr noundef %45)
  store i64 %46, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %47

47:                                               ; preds = %36, %35, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %48 = load i64, ptr %2, align 8
  ret i64 %48
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare zeroext i8 @DebugAssertEnabled() #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 0}
!10 = !{!"_IP4_PROTOCOL", !11, i64 0, !12, i64 8, !6, i64 72, !13, i64 80, !6, i64 88, !14, i64 96, !15, i64 112, !15, i64 152, !14, i64 192, !14, i64 208, !16, i64 224, !6, i64 248, !14, i64 256, !6, i64 272, !6, i64 280, !11, i64 288, !6, i64 296, !11, i64 304, !17, i64 308}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_IP4_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"", !14, i64 0, !14, i64 16, !13, i64 32}
!16 = !{!"", !13, i64 0, !13, i64 8, !11, i64 16}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !18, i64 6, !18, i64 10, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !11, i64 20, !11, i64 24}
!18 = !{!"", !7, i64 0}
!19 = !{!10, !13, i64 80}
!20 = !{!10, !6, i64 88}
!21 = !{!22, !6, i64 632}
!22 = !{!"_IP4_SERVICE", !11, i64 0, !23, i64 8, !13, i64 24, !13, i64 32, !14, i64 40, !14, i64 56, !6, i64 72, !6, i64 80, !18, i64 88, !24, i64 584, !6, i64 608, !6, i64 616, !6, i64 624, !6, i64 632, !25, i64 640, !27, i64 660, !6, i64 1320, !6, i64 1328, !6, i64 1336, !6, i64 1344, !6, i64 1352, !11, i64 1360, !11, i64 1364}
!23 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!24 = !{!"", !13, i64 0, !14, i64 8}
!25 = !{!"", !11, i64 0, !11, i64 4, !26, i64 8, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16}
!26 = !{!"short", !7, i64 0}
!27 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, 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}
!28 = !{!29, !6, i64 56}
!29 = !{!"_EFI_MANAGED_NETWORK_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}


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

@.str = external hidden unnamed_addr constant [149 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @EfiIp4Poll(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %20, label %3

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

5:                                                ; preds = %3
  %6 = load i32, ptr %.pre12, align 8, !tbaa !5
  %.not9 = icmp eq i32 %6, 1345605705
  br i1 %.not9, label %._crit_edge, label %7

7:                                                ; preds = %5
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 2543, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %3, %5, %7
  %8 = phi ptr [ %0, %7 ], [ %.pre12, %5 ], [ %.pre12, %3 ]
  %9 = getelementptr inbounds i8, ptr %8, i64 80
  %10 = load i64, ptr %9, align 8, !tbaa !18
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %20, label %12

12:                                               ; preds = %._crit_edge
  %13 = getelementptr inbounds i8, ptr %8, i64 88
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %14, i64 632
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %17 = getelementptr inbounds i8, ptr %16, i64 56
  %18 = load ptr, ptr %17, align 8, !tbaa !27
  %19 = tail call i64 %18(ptr noundef %16) #2
  br label %20

20:                                               ; preds = %._crit_edge, %1, %12
  %.0 = phi i64 [ %19, %12 ], [ -9223372036854775806, %1 ], [ -9223372036854775789, %._crit_edge ]
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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 = { "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, !7, i64 0}
!6 = !{!"_IP4_PROTOCOL", !7, i64 0, !10, i64 8, !11, i64 72, !12, i64 80, !11, i64 88, !13, i64 96, !14, i64 112, !14, i64 152, !13, i64 192, !13, i64 208, !15, i64 224, !11, i64 248, !13, i64 256, !11, i64 272, !11, i64 280, !7, i64 288, !11, i64 296, !7, i64 304, !16, i64 308}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_EFI_IP4_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!14 = !{!"", !13, i64 0, !13, i64 16, !12, i64 32}
!15 = !{!"", !12, i64 0, !12, i64 8, !7, i64 16}
!16 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !17, i64 6, !17, i64 10, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17, !7, i64 20, !7, i64 24}
!17 = !{!"", !8, i64 0}
!18 = !{!6, !12, i64 80}
!19 = !{!6, !11, i64 88}
!20 = !{!21, !11, i64 632}
!21 = !{!"_IP4_SERVICE", !7, i64 0, !22, i64 8, !12, i64 24, !12, i64 32, !13, i64 40, !13, i64 56, !11, i64 72, !11, i64 80, !17, i64 88, !23, i64 584, !11, i64 608, !11, i64 616, !11, i64 624, !11, i64 632, !24, i64 640, !26, i64 660, !11, i64 1320, !11, i64 1328, !11, i64 1336, !11, i64 1344, !11, i64 1352, !7, i64 1360, !7, i64 1364}
!22 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !11, i64 0, !11, i64 8}
!23 = !{!"", !12, i64 0, !13, i64 8}
!24 = !{!"", !7, i64 0, !7, i64 4, !25, i64 8, !8, i64 10, !8, i64 11, !8, i64 12, !8, i64 13, !8, i64 14, !8, i64 15, !8, i64 16}
!25 = !{!"short", !8, i64 0}
!26 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !8, i64 40, !17, i64 552, !17, i64 584, !17, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!27 = !{!28, !11, i64 56}
!28 = !{!"_EFI_MANAGED_NETWORK_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}


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