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

; 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.ARP_CACHE_ENTRY = type { %struct._LIST_ENTRY, i32, i32, i32, i32, [2 x %struct.NET_ARP_ADDRESS], %struct._LIST_ENTRY }
%struct.NET_ARP_ADDRESS = type { i16, i8, ptr, %union.NET_ARP_ADDRESS_UNION }
%union.NET_ARP_ADDRESS_UNION = type { [32 x i8] }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.ARP_INSTANCE_DATA = type { i32, ptr, ptr, %struct._EFI_ARP_PROTOCOL, %struct._LIST_ENTRY, %struct.EFI_ARP_CONFIG_DATA, i8, i8 }
%struct._EFI_ARP_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_ARP_CONFIG_DATA = type { i16, i8, ptr, i32, i32, i32 }

declare ptr @InitializeListHead(ptr noundef) #0

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

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

11:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %82

12:                                               ; preds = %1
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %13, i32 0, i32 0
  %15 = call ptr @InitializeListHead(ptr noundef %14)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %16, i32 0, i32 6
  %18 = call ptr @InitializeListHead(ptr noundef %17)
  store i16 0, ptr %6, align 2, !tbaa !9
  br label %19

19:                                               ; preds = %34, %12
  %20 = load i16, ptr %6, align 2, !tbaa !9
  %21 = zext i16 %20 to i32
  %22 = icmp slt i32 %21, 2
  br i1 %22, label %23, label %37

23:                                               ; preds = %19
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %24, i32 0, i32 5
  %26 = load i16, ptr %6, align 2, !tbaa !9
  %27 = zext i16 %26 to i64
  %28 = getelementptr inbounds [2 x %struct.NET_ARP_ADDRESS], ptr %25, i64 0, i64 %27
  store ptr %28, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %29, i32 0, i32 3
  %31 = getelementptr inbounds [16 x i8], ptr %30, i64 0, i64 0
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %32, i32 0, i32 2
  store ptr %31, ptr %33, align 8, !tbaa !11
  br label %34

34:                                               ; preds = %23
  %35 = load i16, ptr %6, align 2, !tbaa !9
  %36 = add i16 %35, 1
  store i16 %36, ptr %6, align 2, !tbaa !9
  br label %19, !llvm.loop !13

37:                                               ; preds = %19
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %38, i32 0, i32 5
  %40 = getelementptr inbounds [2 x %struct.NET_ARP_ADDRESS], ptr %39, i64 0, i64 0
  %41 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = call ptr @ZeroMem(ptr noundef %42, i64 noundef 32)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %71

46:                                               ; preds = %37
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ARP_INSTANCE_DATA, ptr %47, i32 0, i32 5
  %49 = getelementptr inbounds %struct.EFI_ARP_CONFIG_DATA, ptr %48, i32 0, i32 4
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %51, i32 0, i32 1
  store i32 %50, ptr %52, align 8, !tbaa !21
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ARP_INSTANCE_DATA, ptr %53, i32 0, i32 5
  %55 = getelementptr inbounds %struct.EFI_ARP_CONFIG_DATA, ptr %54, i32 0, i32 5
  %56 = load i32, ptr %55, align 8, !tbaa !23
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %57, i32 0, i32 4
  store i32 %56, ptr %58, align 4, !tbaa !24
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ARP_INSTANCE_DATA, ptr %59, i32 0, i32 5
  %61 = getelementptr inbounds %struct.EFI_ARP_CONFIG_DATA, ptr %60, i32 0, i32 3
  %62 = load i32, ptr %61, align 8, !tbaa !25
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %63, i32 0, i32 2
  store i32 %62, ptr %64, align 4, !tbaa !26
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ARP_INSTANCE_DATA, ptr %65, i32 0, i32 5
  %67 = getelementptr inbounds %struct.EFI_ARP_CONFIG_DATA, ptr %66, i32 0, i32 3
  %68 = load i32, ptr %67, align 8, !tbaa !25
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %69, i32 0, i32 3
  store i32 %68, ptr %70, align 8, !tbaa !27
  br label %80

71:                                               ; preds = %37
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %72, i32 0, i32 1
  store i32 2, ptr %73, align 8, !tbaa !21
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %74, i32 0, i32 4
  store i32 50000, ptr %75, align 4, !tbaa !24
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %76, i32 0, i32 2
  store i32 -294967296, ptr %77, align 4, !tbaa !26
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %78, i32 0, i32 3
  store i32 -294967296, ptr %79, align 8, !tbaa !27
  br label %80

80:                                               ; preds = %71, %46
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %81, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %82

82:                                               ; preds = %80, %11
  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
  %83 = load ptr, ptr %2, align 8
  ret ptr %83
}

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

declare ptr @AllocatePool(i64 noundef) #0

declare ptr @ZeroMem(ptr noundef, i64 noundef) #0

attributes #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 = { 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 #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 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"", !10, i64 0, !7, i64 2, !6, i64 8, !7, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !17, i64 116}
!16 = !{!"", !17, i64 0, !6, i64 8, !6, i64 16, !18, i64 24, !19, i64 80, !20, i64 96, !7, i64 128, !7, i64 129}
!17 = !{!"int", !7, i64 0}
!18 = !{!"_EFI_ARP_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!19 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!20 = !{!"", !10, i64 0, !7, i64 2, !6, i64 8, !17, i64 16, !17, i64 20, !17, i64 24}
!21 = !{!22, !17, i64 16}
!22 = !{!"", !19, i64 0, !17, i64 16, !17, i64 20, !17, i64 24, !17, i64 28, !7, i64 32, !19, i64 128}
!23 = !{!16, !17, i64 120}
!24 = !{!22, !17, i64 28}
!25 = !{!16, !17, i64 112}
!26 = !{!22, !17, i64 20}
!27 = !{!22, !17, i64 24}


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

declare ptr @InitializeListHead(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @ArpAllocCacheEntry(ptr noundef readonly %0) local_unnamed_addr #1 {
  %2 = tail call ptr @AllocatePool(i64 noundef 144) #2
  %3 = icmp eq ptr %2, null
  br i1 %3, label %27, label %4

4:                                                ; preds = %1
  %5 = tail call ptr @InitializeListHead(ptr noundef nonnull %2) #2
  %6 = getelementptr inbounds i8, ptr %2, i64 128
  %7 = tail call ptr @InitializeListHead(ptr noundef nonnull %6) #2
  %8 = getelementptr inbounds i8, ptr %2, i64 48
  %9 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr %8, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %2, i64 96
  %11 = getelementptr inbounds i8, ptr %2, i64 88
  store ptr %10, ptr %11, align 8, !tbaa !5
  %12 = tail call ptr @ZeroMem(ptr noundef nonnull %8, i64 noundef 32) #2
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %22, label %13

13:                                               ; preds = %4
  %14 = getelementptr inbounds i8, ptr %0, i64 116
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 %15, ptr %16, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %0, i64 120
  %18 = load i32, ptr %17, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %2, i64 28
  store i32 %18, ptr %19, align 4, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %0, i64 112
  %21 = load i32, ptr %20, align 8, !tbaa !21
  br label %.sink.split

22:                                               ; preds = %4
  %23 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 2, ptr %23, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %2, i64 28
  store i32 50000, ptr %24, align 4, !tbaa !20
  br label %.sink.split

.sink.split:                                      ; preds = %22, %13
  %.sink30 = phi i32 [ %21, %13 ], [ -294967296, %22 ]
  %25 = getelementptr inbounds i8, ptr %2, i64 20
  store i32 %.sink30, ptr %25, align 4, !tbaa !22
  %26 = getelementptr inbounds i8, ptr %2, i64 24
  store i32 %.sink30, ptr %26, align 8, !tbaa !23
  br label %27

27:                                               ; preds = %.sink.split, %1
  ret ptr %2
}

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #0

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #0

attributes #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 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !8, i64 2, !10, i64 8, !8, i64 16}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !13, i64 116}
!12 = !{!"", !13, i64 0, !10, i64 8, !10, i64 16, !14, i64 24, !15, i64 80, !16, i64 96, !8, i64 128, !8, i64 129}
!13 = !{!"int", !8, i64 0}
!14 = !{!"_EFI_ARP_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!15 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!16 = !{!"", !7, i64 0, !8, i64 2, !10, i64 8, !13, i64 16, !13, i64 20, !13, i64 24}
!17 = !{!18, !13, i64 16}
!18 = !{!"", !15, i64 0, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !8, i64 32, !15, i64 128}
!19 = !{!12, !13, i64 120}
!20 = !{!18, !13, i64 28}
!21 = !{!12, !13, i64 112}
!22 = !{!18, !13, i64 20}
!23 = !{!18, !13, i64 24}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass