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

; 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_ARP_CONFIG_DATA = type { i16, i8, ptr, i32, i32, i32 }
%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_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: nounwind uwtable
define dso_local i64 @ArpConfigure(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %67

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %34

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EFI_ARP_CONFIG_DATA, ptr %17, i32 0, i32 1
  %19 = load i8, ptr %18, align 2, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %33, label %22

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.EFI_ARP_CONFIG_DATA, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = icmp eq ptr %25, null
  br i1 %26, label %33, label %27

27:                                               ; preds = %22
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.EFI_ARP_CONFIG_DATA, ptr %28, i32 0, i32 0
  %30 = load i16, ptr %29, align 8, !tbaa !14
  %31 = zext i16 %30 to i32
  %32 = icmp sle i32 %31, 1500
  br i1 %32, label %33, label %34

33:                                               ; preds = %27, %22, %16
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %67

34:                                               ; preds = %27, %13
  %35 = call zeroext i8 @DebugAssertEnabled()
  %36 = zext i8 %35 to i32
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %48

38:                                               ; preds = %34
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = ptrtoint ptr %39 to i64
  %41 = sub i64 %40, ptrtoint (ptr getelementptr inbounds (%struct.ARP_INSTANCE_DATA, ptr null, i32 0, i32 3) to i64)
  %42 = inttoptr i64 %41 to ptr
  %43 = getelementptr inbounds %struct.ARP_INSTANCE_DATA, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !15
  %45 = icmp ne i32 %44, 1230000705
  br i1 %45, label %46, label %48

46:                                               ; preds = %38
  call void @DebugAssert(ptr noundef @.str, i64 noundef 68, ptr noundef @.str.1)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  br label %53

48:                                               ; preds = %38, %34
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = ptrtoint ptr %49 to i64
  %51 = sub i64 %50, ptrtoint (ptr getelementptr inbounds (%struct.ARP_INSTANCE_DATA, ptr null, i32 0, i32 3) to i64)
  %52 = inttoptr i64 %51 to ptr
  br label %53

53:                                               ; preds = %48, %46
  %54 = phi ptr [ %47, %46 ], [ %52, %48 ]
  store ptr %54, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr @gBS, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !19
  %58 = call i64 %57(i64 noundef 8)
  store i64 %58, ptr %8, align 8, !tbaa !23
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call i64 @ArpConfigureInstance(ptr noundef %59, ptr noundef %60)
  store i64 %61, ptr %6, align 8, !tbaa !23
  %62 = load ptr, ptr @gBS, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !24
  %65 = load i64, ptr %8, align 8, !tbaa !23
  call void %64(i64 noundef %65)
  %66 = load i64, ptr %6, align 8, !tbaa !23
  store i64 %66, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %67

67:                                               ; preds = %53, %33, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %68 = load i64, ptr %3, align 8
  ret i64 %68
}

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

declare zeroext i8 @DebugAssertEnabled() #2

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

declare i64 @ArpConfigureInstance(ptr noundef, ptr noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 2}
!10 = !{!"", !11, i64 0, !7, i64 2, !6, i64 8, !12, i64 16, !12, i64 20, !12, i64 24}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !11, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"", !12, i64 0, !6, i64 8, !6, i64 16, !17, i64 24, !18, i64 80, !10, i64 96, !7, i64 128, !7, i64 129}
!17 = !{!"_EFI_ARP_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!18 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!19 = !{!20, !6, i64 24}
!20 = !{!"", !21, 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}
!21 = !{!"", !22, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!22 = !{!"long long", !7, i64 0}
!23 = !{!22, !22, i64 0}
!24 = !{!20, !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

; Function Attrs: nounwind uwtable
define dso_local i64 @ArpConfigure(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %30, label %4

4:                                                ; preds = %2
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %16, label %5

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

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = icmp eq ptr %11, null
  br i1 %12, label %30, label %13

13:                                               ; preds = %9
  %14 = load i16, ptr %1, align 8, !tbaa !13
  %15 = icmp ult i16 %14, 1501
  br i1 %15, label %30, label %16

16:                                               ; preds = %13, %4
  %17 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not14 = icmp eq i8 %17, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre16 = add i64 %.pre, -24
  %.pre18 = inttoptr i64 %.pre16 to ptr
  br i1 %.not14, label %._crit_edge, label %18

18:                                               ; preds = %16
  %19 = load i32, ptr %.pre18, align 8, !tbaa !14
  %.not15 = icmp eq i32 %19, 1230000705
  br i1 %.not15, label %._crit_edge, label %20

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

._crit_edge:                                      ; preds = %16, %18, %20
  %21 = phi ptr [ %0, %20 ], [ %.pre18, %18 ], [ %.pre18, %16 ]
  %22 = load ptr, ptr @gBS, align 8, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %22, i64 24
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  %25 = tail call i64 %24(i64 noundef 8) #2
  %26 = tail call i64 @ArpConfigureInstance(ptr noundef %21, ptr noundef %1) #2
  %27 = load ptr, ptr @gBS, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %27, i64 32
  %29 = load ptr, ptr %28, align 8, !tbaa !23
  tail call void %29(i64 noundef %25) #2
  br label %30

30:                                               ; preds = %5, %9, %13, %2, %._crit_edge
  %.0 = phi i64 [ %26, %._crit_edge ], [ -9223372036854775806, %2 ], [ -9223372036854775806, %13 ], [ -9223372036854775806, %9 ], [ -9223372036854775806, %5 ]
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare i64 @ArpConfigureInstance(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 }

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


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