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

; 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

declare i64 @DispatchDpc() #1

; Function Attrs: nounwind uwtable
define dso_local i64 @ArpCancel(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = 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 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %26, label %14

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %26, label %20

20:                                               ; preds = %17, %14
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %27

23:                                               ; preds = %20
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %23, %17, %3
  store i64 -9223372036854775806, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %71

27:                                               ; preds = %23, %20
  %28 = call zeroext i8 @DebugAssertEnabled()
  %29 = zext i8 %28 to i32
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %41

31:                                               ; preds = %27
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = ptrtoint ptr %32 to i64
  %34 = sub i64 %33, ptrtoint (ptr getelementptr inbounds (%struct.ARP_INSTANCE_DATA, ptr null, i32 0, i32 3) to i64)
  %35 = inttoptr i64 %34 to ptr
  %36 = getelementptr inbounds %struct.ARP_INSTANCE_DATA, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = icmp ne i32 %37, 1230000705
  br i1 %38, label %39, label %41

39:                                               ; preds = %31
  call void @DebugAssert(ptr noundef @.str, i64 noundef 723, ptr noundef @.str.1)
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  br label %46

41:                                               ; preds = %31, %27
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = ptrtoint ptr %42 to i64
  %44 = sub i64 %43, ptrtoint (ptr getelementptr inbounds (%struct.ARP_INSTANCE_DATA, ptr null, i32 0, i32 3) to i64)
  %45 = inttoptr i64 %44 to ptr
  br label %46

46:                                               ; preds = %41, %39
  %47 = phi ptr [ %40, %39 ], [ %45, %41 ]
  store ptr %47, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ARP_INSTANCE_DATA, ptr %48, i32 0, i32 6
  %50 = load i8, ptr %49, align 8, !tbaa !16
  %51 = icmp ne i8 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %46
  store i64 -9223372036854775789, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %71

53:                                               ; preds = %46
  %54 = load ptr, ptr @gBS, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = call i64 %56(i64 noundef 8)
  store i64 %57, ptr %10, align 8, !tbaa !21
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = call i64 @ArpCancelRequest(ptr noundef %58, ptr noundef %59, ptr noundef %60)
  store i64 %61, ptr %9, align 8, !tbaa !21
  %62 = call i64 @DispatchDpc()
  %63 = load ptr, ptr @gBS, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !22
  %66 = load i64, ptr %10, align 8, !tbaa !21
  call void %65(i64 noundef %66)
  %67 = load i64, ptr %9, align 8, !tbaa !21
  %68 = icmp eq i64 %67, 0
  %69 = zext i1 %68 to i64
  %70 = select i1 %68, i64 -9223372036854775794, i64 0
  store i64 %70, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %71

71:                                               ; preds = %53, %52, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %72 = load i64, ptr %4, align 8
  ret i64 %72
}

declare i64 @ArpCancelRequest(ptr noundef, ptr noundef, ptr 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, !11, i64 0}
!10 = !{!"", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !13, i64 80, !14, i64 96, !7, i64 128, !7, i64 129}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_ARP_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!"", !15, i64 0, !7, i64 2, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24}
!15 = !{!"short", !7, i64 0}
!16 = !{!10, !7, i64 128}
!17 = !{!18, !6, i64 24}
!18 = !{!"", !19, 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}
!19 = !{!"", !20, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!20 = !{!"long long", !7, i64 0}
!21 = !{!20, !20, i64 0}
!22 = !{!18, !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

declare i64 @DispatchDpc() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @ArpCancel(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %31, label %5

5:                                                ; preds = %3
  %6 = icmp ne ptr %1, null
  %7 = icmp eq ptr %2, null
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %31, label %8

8:                                                ; preds = %5
  %9 = icmp eq ptr %1, null
  %10 = icmp ne ptr %2, null
  %or.cond3 = and i1 %9, %10
  br i1 %or.cond3, label %31, label %11

11:                                               ; preds = %8
  %12 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %12, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre20 = add i64 %.pre, -24
  %.pre22 = inttoptr i64 %.pre20 to ptr
  br i1 %.not, label %._crit_edge, label %13

13:                                               ; preds = %11
  %14 = load i32, ptr %.pre22, align 8, !tbaa !5
  %.not18 = icmp eq i32 %14, 1230000705
  br i1 %.not18, label %._crit_edge, label %15

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

._crit_edge:                                      ; preds = %11, %13, %15
  %16 = phi ptr [ %0, %15 ], [ %.pre22, %13 ], [ %.pre22, %11 ]
  %17 = getelementptr inbounds i8, ptr %16, i64 128
  %18 = load i8, ptr %17, align 8, !tbaa !15
  %.not19 = icmp eq i8 %18, 0
  br i1 %.not19, label %31, label %19

19:                                               ; preds = %._crit_edge
  %20 = load ptr, ptr @gBS, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %20, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = tail call i64 %22(i64 noundef 8) #2
  %24 = tail call i64 @ArpCancelRequest(ptr noundef nonnull %16, ptr noundef %1, ptr noundef %2) #2
  %25 = tail call i64 @DispatchDpc() #2
  %26 = load ptr, ptr @gBS, align 8, !tbaa !16
  %27 = getelementptr inbounds i8, ptr %26, i64 32
  %28 = load ptr, ptr %27, align 8, !tbaa !21
  tail call void %28(i64 noundef %23) #2
  %29 = icmp eq i64 %24, 0
  %30 = select i1 %29, i64 -9223372036854775794, i64 0
  br label %31

31:                                               ; preds = %._crit_edge, %3, %5, %8, %19
  %.0 = phi i64 [ %30, %19 ], [ -9223372036854775806, %8 ], [ -9223372036854775806, %5 ], [ -9223372036854775806, %3 ], [ -9223372036854775789, %._crit_edge ]
  ret i64 %.0
}

declare i64 @ArpCancelRequest(ptr noundef, ptr noundef, ptr 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, !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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass