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

; 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.IP4_ARP_QUE = type { i32, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, i32, %struct.EFI_MAC_ADDRESS }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.IP4_LINK_TX_TOKEN = type { i32, %struct._LIST_ENTRY, ptr, ptr, ptr, ptr, ptr, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, %struct.EFI_MANAGED_NETWORK_COMPLETION_TOKEN, %struct.EFI_MANAGED_NETWORK_TRANSMIT_DATA }
%struct.EFI_MANAGED_NETWORK_COMPLETION_TOKEN = type { ptr, i64, %union.anon }
%union.anon = type { ptr }
%struct.EFI_MANAGED_NETWORK_TRANSMIT_DATA = type { ptr, ptr, i16, i32, i16, i16, [1 x %struct.EFI_MANAGED_NETWORK_FRAGMENT_DATA] }
%struct.EFI_MANAGED_NETWORK_FRAGMENT_DATA = type { i32, ptr }

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

; 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
declare dso_local void @Ip4FreeLinkTxToken(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @Ip4CancelFrameArp(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.IP4_ARP_QUE, ptr %12, i32 0, i32 2
  %14 = getelementptr inbounds %struct._LIST_ENTRY, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %9, align 8, !tbaa !5
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._LIST_ENTRY, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  store ptr %18, ptr %10, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %56, %4
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.IP4_ARP_QUE, ptr %21, i32 0, i32 2
  %23 = icmp ne ptr %20, %22
  br i1 %23, label %24, label %61

24:                                               ; preds = %19
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = ptrtoint ptr %25 to i64
  %27 = sub i64 %26, ptrtoint (ptr getelementptr inbounds (%struct.IP4_LINK_TX_TOKEN, ptr null, i32 0, i32 1) to i64)
  %28 = inttoptr i64 %27 to ptr
  store ptr %28, ptr %11, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %38, label %31

31:                                               ; preds = %24
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = call zeroext i8 %32(ptr noundef %33, ptr noundef %34)
  %36 = zext i8 %35 to i32
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %55

38:                                               ; preds = %31, %24
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = call ptr @RemoveEntryList(ptr noundef %39)
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.IP4_LINK_TX_TOKEN, ptr %41, i32 0, i32 4
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.IP4_LINK_TX_TOKEN, ptr %44, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !22
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.IP4_LINK_TX_TOKEN, ptr %47, i32 0, i32 5
  %49 = load ptr, ptr %48, align 8, !tbaa !23
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.IP4_LINK_TX_TOKEN, ptr %51, i32 0, i32 6
  %53 = load ptr, ptr %52, align 8, !tbaa !24
  call void %43(ptr noundef %46, ptr noundef %49, i64 noundef %50, i32 noundef 0, ptr noundef %53)
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  call void @Ip4FreeLinkTxToken(ptr noundef %54)
  br label %55

55:                                               ; preds = %38, %31
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %57, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._LIST_ENTRY, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  store ptr %60, ptr %10, align 8, !tbaa !5
  br label %19, !llvm.loop !25

61:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

declare ptr @RemoveEntryList(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @Ip4FreeLinkTxToken(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Ip4CancelFrameArp(ptr noundef readonly %0, i64 noundef %1, ptr noundef readonly %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not21 = icmp eq ptr %6, %5
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %.01720 = load ptr, ptr %6, align 8, !tbaa !13
  %7 = icmp eq ptr %2, null
  br i1 %7, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.01723.us = phi ptr [ %.017.us, %.lr.ph.split.us ], [ %.01720, %.lr.ph ]
  %.022.us = phi ptr [ %.01723.us, %.lr.ph.split.us ], [ %6, %.lr.ph ]
  %8 = ptrtoint ptr %.022.us to i64
  %9 = add i64 %8, -8
  %10 = inttoptr i64 %9 to ptr
  %11 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.022.us) #2
  %12 = getelementptr inbounds i8, ptr %10, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %10, i64 32
  %15 = load ptr, ptr %14, align 8, !tbaa !20
  %16 = getelementptr inbounds i8, ptr %10, i64 48
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %10, i64 56
  %19 = load ptr, ptr %18, align 8, !tbaa !22
  tail call void %13(ptr noundef %15, ptr noundef %17, i64 noundef %1, i32 noundef 0, ptr noundef %19) #2
  tail call void @Ip4FreeLinkTxToken(ptr noundef %10)
  %.017.us = load ptr, ptr %.01723.us, align 8, !tbaa !13
  %.not.us = icmp eq ptr %.01723.us, %5
  br i1 %.not.us, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !23

.lr.ph.split:                                     ; preds = %.lr.ph, %34
  %.01723 = phi ptr [ %.017, %34 ], [ %.01720, %.lr.ph ]
  %.022 = phi ptr [ %.01723, %34 ], [ %6, %.lr.ph ]
  %20 = ptrtoint ptr %.022 to i64
  %21 = add i64 %20, -8
  %22 = inttoptr i64 %21 to ptr
  %23 = tail call zeroext i8 %2(ptr noundef %22, ptr noundef %3) #2
  %.not19 = icmp eq i8 %23, 0
  br i1 %.not19, label %34, label %24

24:                                               ; preds = %.lr.ph.split
  %25 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.022) #2
  %26 = getelementptr inbounds i8, ptr %22, i64 40
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %22, i64 32
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  %30 = getelementptr inbounds i8, ptr %22, i64 48
  %31 = load ptr, ptr %30, align 8, !tbaa !21
  %32 = getelementptr inbounds i8, ptr %22, i64 56
  %33 = load ptr, ptr %32, align 8, !tbaa !22
  tail call void %27(ptr noundef %29, ptr noundef %31, i64 noundef %1, i32 noundef 0, ptr noundef %33) #2
  tail call void @Ip4FreeLinkTxToken(ptr noundef %22)
  br label %34

34:                                               ; preds = %.lr.ph.split, %24
  %.017 = load ptr, ptr %.01723, align 8, !tbaa !13
  %.not = icmp eq ptr %.01723, %5
  br i1 %.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !23

._crit_edge:                                      ; preds = %34, %.lr.ph.split.us, %4
  ret void
}

declare ptr @RemoveEntryList(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, !11, i64 24}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 24, !11, i64 40, !11, i64 48, !7, i64 56, !12, i64 60}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"", !8, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!15, !11, i64 40}
!15 = !{!"", !7, i64 0, !10, i64 8, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !12, i64 64, !12, i64 96, !16, i64 128, !18, i64 152}
!16 = !{!"", !11, i64 0, !17, i64 8, !8, i64 16}
!17 = !{!"long long", !8, i64 0}
!18 = !{!"", !11, i64 0, !11, i64 8, !19, i64 16, !7, i64 20, !19, i64 24, !19, i64 26, !8, i64 32}
!19 = !{!"short", !8, i64 0}
!20 = !{!15, !11, i64 32}
!21 = !{!15, !11, i64 48}
!22 = !{!15, !11, i64 56}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass