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

; 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_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._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_ARP_CONFIG_DATA = type { i16, i8, ptr, i32, i32, i32 }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

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

; 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

; 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 @ArpFind(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i8 noundef zeroext %6) #2 {
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i8, align 1
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i8 %1, ptr %10, align 1, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i8 %6, ptr %15, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %40, label %22

22:                                               ; preds = %7
  %23 = load i8, ptr %15, align 1, !tbaa !9
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %31, label %25

25:                                               ; preds = %22
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %40, label %31

31:                                               ; preds = %28, %25, %22
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %41

34:                                               ; preds = %31
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %40, label %37

37:                                               ; preds = %34
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %41

40:                                               ; preds = %37, %34, %28, %7
  store i64 -9223372036854775806, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %85

41:                                               ; preds = %37, %31
  %42 = call zeroext i8 @DebugAssertEnabled()
  %43 = zext i8 %42 to i32
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %55

45:                                               ; preds = %41
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = ptrtoint ptr %46 to i64
  %48 = sub i64 %47, ptrtoint (ptr getelementptr inbounds (%struct.ARP_INSTANCE_DATA, ptr null, i32 0, i32 3) to i64)
  %49 = inttoptr i64 %48 to ptr
  %50 = getelementptr inbounds %struct.ARP_INSTANCE_DATA, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !10
  %52 = icmp ne i32 %51, 1230000705
  br i1 %52, label %53, label %55

53:                                               ; preds = %45
  call void @DebugAssert(ptr noundef @.str, i64 noundef 337, ptr noundef @.str.1)
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  br label %60

55:                                               ; preds = %45, %41
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = ptrtoint ptr %56 to i64
  %58 = sub i64 %57, ptrtoint (ptr getelementptr inbounds (%struct.ARP_INSTANCE_DATA, ptr null, i32 0, i32 3) to i64)
  %59 = inttoptr i64 %58 to ptr
  br label %60

60:                                               ; preds = %55, %53
  %61 = phi ptr [ %54, %53 ], [ %59, %55 ]
  store ptr %61, ptr %17, align 8, !tbaa !5
  %62 = load ptr, ptr %17, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ARP_INSTANCE_DATA, ptr %62, i32 0, i32 6
  %64 = load i8, ptr %63, align 8, !tbaa !17
  %65 = icmp ne i8 %64, 0
  br i1 %65, label %67, label %66

66:                                               ; preds = %60
  store i64 -9223372036854775789, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %85

67:                                               ; preds = %60
  %68 = load ptr, ptr @gBS, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !18
  %71 = call i64 %70(i64 noundef 8)
  store i64 %71, ptr %18, align 8, !tbaa !22
  %72 = load ptr, ptr %17, align 8, !tbaa !5
  %73 = load i8, ptr %10, align 1, !tbaa !9
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = load ptr, ptr %14, align 8, !tbaa !5
  %78 = load i8, ptr %15, align 1, !tbaa !9
  %79 = call i64 @ArpFindCacheEntry(ptr noundef %72, i8 noundef zeroext %73, ptr noundef %74, ptr noundef %75, ptr noundef %76, ptr noundef %77, i8 noundef zeroext %78)
  store i64 %79, ptr %16, align 8, !tbaa !22
  %80 = load ptr, ptr @gBS, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %80, i32 0, i32 2
  %82 = load ptr, ptr %81, align 8, !tbaa !23
  %83 = load i64, ptr %18, align 8, !tbaa !22
  call void %82(i64 noundef %83)
  %84 = load i64, ptr %16, align 8, !tbaa !22
  store i64 %84, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %85

85:                                               ; preds = %67, %66, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  %86 = load i64, ptr %8, align 8
  ret i64 %86
}

declare i64 @ArpFindCacheEntry(ptr noundef, i8 noundef zeroext, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) #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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !14, i64 80, !15, i64 96, !7, i64 128, !7, i64 129}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_EFI_ARP_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"", !16, i64 0, !7, i64 2, !6, i64 8, !12, i64 16, !12, i64 20, !12, i64 24}
!16 = !{!"short", !7, i64 0}
!17 = !{!11, !7, i64 128}
!18 = !{!19, !6, i64 24}
!19 = !{!"", !20, i64 0, !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, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!20 = !{!"", !21, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!21 = !{!"long long", !7, i64 0}
!22 = !{!21, !21, i64 0}
!23 = !{!19, !6, i64 32}


; 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
@gBS = external local_unnamed_addr global ptr, align 8

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ArpFind(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i8 noundef zeroext %6) local_unnamed_addr #1 {
  %8 = icmp eq ptr %0, null
  br i1 %8, label %31, label %9

9:                                                ; preds = %7
  %10 = icmp eq i8 %6, 0
  %11 = icmp eq ptr %4, null
  %or.cond = and i1 %11, %10
  %12 = icmp eq ptr %3, null
  %or.cond3 = and i1 %12, %or.cond
  br i1 %or.cond3, label %31, label %13

13:                                               ; preds = %9
  %.not = icmp ne ptr %5, null
  %or.cond5 = or i1 %12, %11
  %or.cond29 = and i1 %.not, %or.cond5
  br i1 %or.cond29, label %31, label %14

14:                                               ; preds = %13
  %15 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not26 = icmp eq i8 %15, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre30 = add i64 %.pre, -24
  %.pre32 = inttoptr i64 %.pre30 to ptr
  br i1 %.not26, label %._crit_edge, label %16

16:                                               ; preds = %14
  %17 = load i32, ptr %.pre32, align 8, !tbaa !5
  %.not27 = icmp eq i32 %17, 1230000705
  br i1 %.not27, label %._crit_edge, label %18

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

._crit_edge:                                      ; preds = %14, %16, %18
  %19 = phi ptr [ %0, %18 ], [ %.pre32, %16 ], [ %.pre32, %14 ]
  %20 = getelementptr inbounds i8, ptr %19, i64 128
  %21 = load i8, ptr %20, align 8, !tbaa !15
  %.not28 = icmp eq i8 %21, 0
  br i1 %.not28, label %31, label %22

22:                                               ; preds = %._crit_edge
  %23 = load ptr, ptr @gBS, align 8, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %23, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = tail call i64 %25(i64 noundef 8) #2
  %27 = tail call i64 @ArpFindCacheEntry(ptr noundef nonnull %19, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i8 noundef zeroext %6) #2
  %28 = load ptr, ptr @gBS, align 8, !tbaa !16
  %29 = getelementptr inbounds i8, ptr %28, i64 32
  %30 = load ptr, ptr %29, align 8, !tbaa !21
  tail call void %30(i64 noundef %26) #2
  br label %31

31:                                               ; preds = %._crit_edge, %7, %9, %13, %22
  %.0 = phi i64 [ %27, %22 ], [ -9223372036854775806, %13 ], [ -9223372036854775806, %9 ], [ -9223372036854775806, %7 ], [ -9223372036854775789, %._crit_edge ]
  ret i64 %.0
}

declare i64 @ArpFindCacheEntry(ptr noundef, i8 noundef zeroext, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) 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, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 80, !13, i64 96, !8, i64 128, !8, i64 129}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EFI_ARP_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!12 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!13 = !{!"", !14, i64 0, !8, i64 2, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24}
!14 = !{!"short", !8, i64 0}
!15 = !{!6, !8, i64 128}
!16 = !{!10, !10, i64 0}
!17 = !{!18, !10, i64 24}
!18 = !{!"", !19, i64 0, !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, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368}
!19 = !{!"", !20, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!20 = !{!"long long", !8, i64 0}
!21 = !{!18, !10, i64 32}


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