; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/UefiPxeBcDxe_ (PxeBcCheckArpCache)

; 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.EFI_PXE_BASE_CODE_MODE = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, %union.EFI_IP_ADDRESS, %union.EFI_IP_ADDRESS, %union.EFI_PXE_BASE_CODE_PACKET, %union.EFI_PXE_BASE_CODE_PACKET, %union.EFI_PXE_BASE_CODE_PACKET, %union.EFI_PXE_BASE_CODE_PACKET, %union.EFI_PXE_BASE_CODE_PACKET, %union.EFI_PXE_BASE_CODE_PACKET, %struct.EFI_PXE_BASE_CODE_IP_FILTER, i32, [8 x %struct.EFI_PXE_BASE_CODE_ARP_ENTRY], i32, [8 x %struct.EFI_PXE_BASE_CODE_ROUTE_ENTRY], %struct.EFI_PXE_BASE_CODE_ICMP_ERROR, %struct.EFI_PXE_BASE_CODE_TFTP_ERROR }
%union.EFI_IP_ADDRESS = type { [4 x i32] }
%union.EFI_PXE_BASE_CODE_PACKET = type { %struct.EFI_PXE_BASE_CODE_DHCPV6_PACKET, [444 x i8] }
%struct.EFI_PXE_BASE_CODE_DHCPV6_PACKET = type { i32, [1024 x i8] }
%struct.EFI_PXE_BASE_CODE_IP_FILTER = type { i8, i8, i16, [8 x %union.EFI_IP_ADDRESS] }
%struct.EFI_PXE_BASE_CODE_ARP_ENTRY = type { %union.EFI_IP_ADDRESS, %struct.EFI_MAC_ADDRESS }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.EFI_PXE_BASE_CODE_ROUTE_ENTRY = type { %union.EFI_IP_ADDRESS, %union.EFI_IP_ADDRESS, %union.EFI_IP_ADDRESS }
%struct.EFI_PXE_BASE_CODE_ICMP_ERROR = type { i8, i8, i16, %union.anon, [494 x i8] }
%union.anon = type { i32 }
%struct.EFI_PXE_BASE_CODE_TFTP_ERROR = type { i8, [127 x i8] }

@.str = external hidden unnamed_addr constant [140 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 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

declare zeroext i8 @DebugAssertEnabled() #1

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

; 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 zeroext i8 @PxeBcCheckArpCache(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  br label %10

10:                                               ; preds = %3
  %11 = call zeroext i8 @DebugAssertEnabled()
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %20

13:                                               ; preds = %10
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.EFI_PXE_BASE_CODE_MODE, ptr %14, i32 0, i32 3
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  call void @DebugAssert(ptr noundef @.str, i64 noundef 127, ptr noundef @.str.3)
  br label %19

19:                                               ; preds = %18, %13
  br label %20

20:                                               ; preds = %19, %10
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  store i32 0, ptr %8, align 4, !tbaa !16
  br label %23

23:                                               ; preds = %49, %22
  %24 = load i32, ptr %8, align 4, !tbaa !16
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.EFI_PXE_BASE_CODE_MODE, ptr %25, i32 0, i32 28
  %27 = load i32, ptr %26, align 4, !tbaa !17
  %28 = icmp ult i32 %24, %27
  br i1 %28, label %29, label %52

29:                                               ; preds = %23
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EFI_PXE_BASE_CODE_MODE, ptr %30, i32 0, i32 29
  %32 = load i32, ptr %8, align 4, !tbaa !16
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [8 x %struct.EFI_PXE_BASE_CODE_ARP_ENTRY], ptr %31, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.EFI_PXE_BASE_CODE_ARP_ENTRY, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = call i64 @CompareMem(ptr noundef %35, ptr noundef %36, i64 noundef 4)
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %48

39:                                               ; preds = %29
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.EFI_PXE_BASE_CODE_MODE, ptr %41, i32 0, i32 29
  %43 = load i32, ptr %8, align 4, !tbaa !16
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds [8 x %struct.EFI_PXE_BASE_CODE_ARP_ENTRY], ptr %42, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.EFI_PXE_BASE_CODE_ARP_ENTRY, ptr %45, i32 0, i32 1
  %47 = call ptr @CopyMem(ptr noundef %40, ptr noundef %46, i64 noundef 32)
  store i8 1, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %53

48:                                               ; preds = %29
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %8, align 4, !tbaa !16
  %51 = add i32 %50, 1
  store i32 %51, ptr %8, align 4, !tbaa !16
  br label %23, !llvm.loop !18

52:                                               ; preds = %23
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %53

53:                                               ; preds = %52, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %54 = load i8, ptr %4, align 1
  ret i8 %54
}

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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, !7, i64 3}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 20, !7, i64 36, !7, i64 52, !7, i64 1524, !7, i64 2996, !7, i64 4468, !7, i64 5940, !7, i64 7412, !11, i64 8884, !13, i64 9016, !7, i64 9020, !13, i64 9404, !7, i64 9408, !14, i64 9792, !15, i64 10296}
!11 = !{!"", !7, i64 0, !7, i64 1, !12, i64 2, !7, i64 4}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 1, !12, i64 2, !7, i64 4, !7, i64 8}
!15 = !{!"", !7, i64 0, !7, i64 1}
!16 = !{!13, !13, i64 0}
!17 = !{!10, !13, i64 9016}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.EFI_PXE_BASE_CODE_ARP_ENTRY = type { %union.EFI_IP_ADDRESS, %struct.EFI_MAC_ADDRESS }
%union.EFI_IP_ADDRESS = type { [4 x i32] }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }

@.str = external hidden unnamed_addr constant [140 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @PxeBcCheckArpCache(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %9, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 3
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %.not11 = icmp eq i8 %7, 0
  br i1 %.not11, label %9, label %8

8:                                                ; preds = %5
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 127, ptr noundef nonnull @.str.3) #2
  br label %9

9:                                                ; preds = %5, %8, %3
  %10 = getelementptr inbounds i8, ptr %0, i64 9016
  %11 = load i32, ptr %10, align 4, !tbaa !14
  %.not13 = icmp eq i32 %11, 0
  br i1 %.not13, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 9020
  br label %17

13:                                               ; preds = %17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = load i32, ptr %10, align 4, !tbaa !14
  %15 = zext i32 %14 to i64
  %16 = icmp ult i64 %indvars.iv.next, %15
  br i1 %16, label %17, label %.loopexit, !llvm.loop !15

17:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %18 = getelementptr inbounds [8 x %struct.EFI_PXE_BASE_CODE_ARP_ENTRY], ptr %12, i64 0, i64 %indvars.iv
  %19 = tail call i64 @CompareMem(ptr noundef nonnull %18, ptr noundef %1, i64 noundef 4) #2
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %13

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %18, i64 16
  %23 = tail call ptr @CopyMem(ptr noundef %2, ptr noundef nonnull %22, i64 noundef 32) #2
  br label %.loopexit

.loopexit:                                        ; preds = %13, %9, %21
  %.010 = phi i8 [ 1, %21 ], [ 0, %9 ], [ 0, %13 ]
  ret i8 %.010
}

declare i64 @CompareMem(ptr noundef, 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 3}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 20, !7, i64 36, !7, i64 52, !7, i64 1524, !7, i64 2996, !7, i64 4468, !7, i64 5940, !7, i64 7412, !9, i64 8884, !11, i64 9016, !7, i64 9020, !11, i64 9404, !7, i64 9408, !12, i64 9792, !13, i64 10296}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"", !7, i64 0, !7, i64 1, !10, i64 2, !7, i64 4}
!10 = !{!"short", !7, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !7, i64 0, !7, i64 1, !10, i64 2, !7, i64 4, !7, i64 8}
!13 = !{!"", !7, i64 0, !7, i64 1}
!14 = !{!6, !11, i64 9016}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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