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

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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 void @ArpFillAddressInCacheEntry(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [2 x ptr], align 16
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds [2 x ptr], ptr %7, i64 0, i64 0
  store ptr %10, ptr %11, align 16, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds [2 x ptr], ptr %7, i64 0, i64 1
  store ptr %12, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %78, %3
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = icmp ult i32 %15, 2
  br i1 %16, label %17, label %81

17:                                               ; preds = %14
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds [2 x ptr], ptr %7, i64 0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %77

23:                                               ; preds = %17
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ARP_CACHE_ENTRY, ptr %24, i32 0, i32 5
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [2 x %struct.NET_ARP_ADDRESS], ptr %25, i64 0, i64 %27
  store ptr %28, ptr %8, align 8, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [2 x ptr], ptr %7, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %32, i32 0, i32 0
  %34 = load i16, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %35, i32 0, i32 0
  store i16 %34, ptr %36, align 8, !tbaa !11
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds [2 x ptr], ptr %7, i64 0, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %40, i32 0, i32 1
  %42 = load i8, ptr %41, align 2, !tbaa !14
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %43, i32 0, i32 1
  store i8 %42, ptr %44, align 2, !tbaa !14
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds [2 x ptr], ptr %7, i64 0, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %67

52:                                               ; preds = %23
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds [2 x ptr], ptr %7, i64 0, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %62, i32 0, i32 1
  %64 = load i8, ptr %63, align 2, !tbaa !14
  %65 = zext i8 %64 to i64
  %66 = call ptr @CopyMem(ptr noundef %55, ptr noundef %61, i64 noundef %65)
  br label %76

67:                                               ; preds = %23
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.NET_ARP_ADDRESS, ptr %71, i32 0, i32 1
  %73 = load i8, ptr %72, align 2, !tbaa !14
  %74 = zext i8 %73 to i64
  %75 = call ptr @ZeroMem(ptr noundef %70, i64 noundef %74)
  br label %76

76:                                               ; preds = %67, %52
  br label %77

77:                                               ; preds = %76, %17
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %9, align 4, !tbaa !9
  %80 = add i32 %79, 1
  store i32 %80, ptr %9, align 4, !tbaa !9
  br label %14, !llvm.loop !16

81:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  ret void
}

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

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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !7, i64 2, !6, i64 8, !7, i64 16}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !7, i64 2}
!15 = !{!12, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

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

; Function Attrs: nounwind uwtable
define dso_local void @ArpFillAddressInCacheEntry(ptr nocapture noundef %0, ptr noundef readonly %1, ptr noundef readonly %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %19, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i16, ptr %1, align 8, !tbaa !5
  store i16 %6, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 2
  %8 = load i8, ptr %7, align 2, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %0, i64 34
  store i8 %8, ptr %9, align 2, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %.not18 = icmp eq ptr %11, null
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = zext i8 %8 to i64
  br i1 %.not18, label %17, label %15

15:                                               ; preds = %4
  %16 = tail call ptr @CopyMem(ptr noundef %13, ptr noundef nonnull %11, i64 noundef %14) #2
  br label %19

17:                                               ; preds = %4
  %18 = tail call ptr @ZeroMem(ptr noundef %13, i64 noundef %14) #2
  br label %19

19:                                               ; preds = %3, %17, %15
  %.not.1 = icmp eq ptr %2, null
  br i1 %.not.1, label %35, label %20

20:                                               ; preds = %19
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  %22 = load i16, ptr %2, align 8, !tbaa !5
  store i16 %22, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %2, i64 2
  %24 = load i8, ptr %23, align 2, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %0, i64 82
  store i8 %24, ptr %25, align 2, !tbaa !11
  %26 = getelementptr inbounds i8, ptr %2, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %.not18.1 = icmp eq ptr %27, null
  %28 = getelementptr inbounds i8, ptr %0, i64 88
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = zext i8 %24 to i64
  br i1 %.not18.1, label %33, label %31

31:                                               ; preds = %20
  %32 = tail call ptr @CopyMem(ptr noundef %29, ptr noundef nonnull %27, i64 noundef %30) #2
  br label %35

33:                                               ; preds = %20
  %34 = tail call ptr @ZeroMem(ptr noundef %29, i64 noundef %30) #2
  br label %35

35:                                               ; preds = %33, %31, %19
  ret void
}

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, !7, i64 0}
!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 = !{!6, !8, i64 2}
!12 = !{!6, !10, i64 8}


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