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

; 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._UDP_IO = type { i32, %struct._LIST_ENTRY, i64, i8, ptr, ptr, ptr, %struct.EFI_SIMPLE_NETWORK_MODE, %struct._LIST_ENTRY, ptr, %union.anon.1, %union.anon.2 }
%struct.EFI_SIMPLE_NETWORK_MODE = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x %struct.EFI_MAC_ADDRESS], %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i8, i8, i8, i8, i8 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct._LIST_ENTRY = type { ptr, ptr }
%union.anon.1 = type { ptr }
%union.anon.2 = type { %struct.EFI_UDP6_CONFIG_DATA }
%struct.EFI_UDP6_CONFIG_DATA = type { i8, i8, i8, i8, i8, i32, i32, %struct.EFI_IPv6_ADDRESS, i16, %struct.EFI_IPv6_ADDRESS, i16 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct.UDP_TX_TOKEN = type { i32, %struct._LIST_ENTRY, ptr, ptr, ptr, ptr, %struct.EFI_IPv4_ADDRESS, %union.UDP_SESSION_DATA, %union.UDP_COMPLETION_TOKEN, %union.UDP_TRANSMIT_DATA }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%union.UDP_SESSION_DATA = type { %struct.EFI_UDP6_SESSION_DATA }
%struct.EFI_UDP6_SESSION_DATA = type { %struct.EFI_IPv6_ADDRESS, i16, %struct.EFI_IPv6_ADDRESS, i16 }
%union.UDP_COMPLETION_TOKEN = type { %struct.EFI_UDP4_COMPLETION_TOKEN }
%struct.EFI_UDP4_COMPLETION_TOKEN = type { ptr, i64, %union.anon }
%union.anon = type { ptr }
%union.UDP_TRANSMIT_DATA = type { %struct.EFI_UDP4_TRANSMIT_DATA }
%struct.EFI_UDP4_TRANSMIT_DATA = type { ptr, ptr, i32, i32, [1 x %struct.EFI_UDP4_FRAGMENT_DATA] }
%struct.EFI_UDP4_FRAGMENT_DATA = type { i32, ptr }
%struct._EFI_UDP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_UDP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [148 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [53 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @UdpIoCancelDgrams(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %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
  br label %12

12:                                               ; preds = %4
  %13 = call zeroext i8 @DebugAssertEnabled()
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %29

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._UDP_IO, ptr %16, i32 0, i32 3
  %18 = load i8, ptr %17, align 8, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = icmp eq i32 %19, 4
  br i1 %20, label %28, label %21

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._UDP_IO, ptr %22, i32 0, i32 3
  %24 = load i8, ptr %23, align 8, !tbaa !11
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 6
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  call void @DebugAssert(ptr noundef @.str, i64 noundef 753, ptr noundef @.str.6)
  br label %28

28:                                               ; preds = %27, %21, %15
  br label %29

29:                                               ; preds = %28, %12
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._UDP_IO, ptr %32, i32 0, i32 8
  %34 = getelementptr inbounds %struct._LIST_ENTRY, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  store ptr %35, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._LIST_ENTRY, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  store ptr %38, ptr %10, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %90, %31
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._UDP_IO, ptr %41, i32 0, i32 8
  %43 = icmp ne ptr %40, %42
  br i1 %43, label %44, label %95

44:                                               ; preds = %39
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = ptrtoint ptr %45 to i64
  %47 = sub i64 %46, ptrtoint (ptr getelementptr inbounds (%struct.UDP_TX_TOKEN, ptr null, i32 0, i32 1) to i64)
  %48 = inttoptr i64 %47 to ptr
  store ptr %48, ptr %11, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = icmp eq ptr %49, null
  br i1 %50, label %58, label %51

51:                                               ; preds = %44
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = call zeroext i8 %52(ptr noundef %53, ptr noundef %54)
  %56 = zext i8 %55 to i32
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %89

58:                                               ; preds = %51, %44
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._UDP_IO, ptr %59, i32 0, i32 3
  %61 = load i8, ptr %60, align 8, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = icmp eq i32 %62, 4
  br i1 %63, label %64, label %76

64:                                               ; preds = %58
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._UDP_IO, ptr %65, i32 0, i32 10
  %67 = load ptr, ptr %66, align 8, !tbaa !19
  %68 = getelementptr inbounds %struct._EFI_UDP4_PROTOCOL, ptr %67, i32 0, i32 6
  %69 = load ptr, ptr %68, align 8, !tbaa !20
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._UDP_IO, ptr %70, i32 0, i32 10
  %72 = load ptr, ptr %71, align 8, !tbaa !19
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.UDP_TX_TOKEN, ptr %73, i32 0, i32 8
  %75 = call i64 %69(ptr noundef %72, ptr noundef %74)
  br label %88

76:                                               ; preds = %58
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._UDP_IO, ptr %77, i32 0, i32 10
  %79 = load ptr, ptr %78, align 8, !tbaa !19
  %80 = getelementptr inbounds %struct._EFI_UDP6_PROTOCOL, ptr %79, i32 0, i32 5
  %81 = load ptr, ptr %80, align 8, !tbaa !22
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._UDP_IO, ptr %82, i32 0, i32 10
  %84 = load ptr, ptr %83, align 8, !tbaa !19
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.UDP_TX_TOKEN, ptr %85, i32 0, i32 8
  %87 = call i64 %81(ptr noundef %84, ptr noundef %86)
  br label %88

88:                                               ; preds = %76, %64
  br label %89

89:                                               ; preds = %88, %51
  br label %90

90:                                               ; preds = %89
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %91, ptr %9, align 8, !tbaa !5
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._LIST_ENTRY, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !18
  store ptr %94, ptr %10, align 8, !tbaa !5
  br label %39, !llvm.loop !24

95:                                               ; preds = %39
  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
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !7, i64 32}
!12 = !{!"_UDP_IO", !13, i64 0, !14, i64 8, !10, i64 24, !7, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !15, i64 64, !14, i64 720, !6, i64 736, !7, i64 744, !7, i64 752}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !7, i64 40, !16, i64 552, !16, i64 584, !16, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!16 = !{!"", !7, i64 0}
!17 = !{!12, !6, i64 720}
!18 = !{!14, !6, i64 0}
!19 = !{!7, !7, i64 0}
!20 = !{!21, !6, i64 48}
!21 = !{!"_EFI_UDP4_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!22 = !{!23, !6, i64 40}
!23 = !{!"_EFI_UDP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!24 = distinct !{!24, !25}
!25 = !{!"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"

@.str = external hidden unnamed_addr constant [148 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [53 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

; Function Attrs: nounwind uwtable
define dso_local void @UdpIoCancelDgrams(ptr noundef readonly %0, i64 noundef %1, ptr noundef readonly %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %10, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load i8, ptr %7, align 8, !tbaa !5
  switch i8 %8, label %9 [
    i8 4, label %10
    i8 6, label %10
  ]

9:                                                ; preds = %6
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 753, ptr noundef nonnull @.str.6) #2
  br label %10

10:                                               ; preds = %6, %6, %9, %4
  %11 = getelementptr inbounds i8, ptr %0, i64 720
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %.not2326 = icmp eq ptr %12, %11
  br i1 %.not2326, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %.02025 = load ptr, ptr %12, align 8, !tbaa !16
  %13 = icmp eq ptr %2, null
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = getelementptr inbounds i8, ptr %0, i64 744
  br i1 %13, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.02028.us = phi ptr [ %.020.us, %.lr.ph.split.us ], [ %.02025, %.lr.ph ]
  %.027.us = phi ptr [ %.02028.us, %.lr.ph.split.us ], [ %12, %.lr.ph ]
  %16 = ptrtoint ptr %.027.us to i64
  %17 = add i64 %16, -8
  %18 = inttoptr i64 %17 to ptr
  %19 = load i8, ptr %14, align 8, !tbaa !5
  %20 = icmp eq i8 %19, 4
  %21 = load ptr, ptr %15, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %18, i64 96
  %. = select i1 %20, i64 48, i64 40
  %23 = getelementptr inbounds i8, ptr %21, i64 %.
  %24 = load ptr, ptr %23, align 8, !tbaa !18
  %25 = tail call i64 %24(ptr noundef %21, ptr noundef nonnull %22) #2
  %.020.us = load ptr, ptr %.02028.us, align 8, !tbaa !16
  %.not23.us = icmp eq ptr %.02028.us, %11
  br i1 %.not23.us, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !19

.lr.ph.split:                                     ; preds = %.lr.ph, %37
  %.02028 = phi ptr [ %.020, %37 ], [ %.02025, %.lr.ph ]
  %.027 = phi ptr [ %.02028, %37 ], [ %12, %.lr.ph ]
  %26 = ptrtoint ptr %.027 to i64
  %27 = add i64 %26, -8
  %28 = inttoptr i64 %27 to ptr
  %29 = tail call zeroext i8 %2(ptr noundef %28, ptr noundef %3) #2
  %.not24 = icmp eq i8 %29, 0
  br i1 %.not24, label %37, label %.sink.split

.sink.split:                                      ; preds = %.lr.ph.split
  %30 = load i8, ptr %14, align 8, !tbaa !5
  %31 = icmp eq i8 %30, 4
  %32 = load ptr, ptr %15, align 8, !tbaa !17
  %33 = getelementptr inbounds i8, ptr %28, i64 96
  %.35 = select i1 %31, i64 48, i64 40
  %34 = getelementptr inbounds i8, ptr %32, i64 %.35
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = tail call i64 %35(ptr noundef %32, ptr noundef nonnull %33) #2
  br label %37

37:                                               ; preds = %.sink.split, %.lr.ph.split
  %.020 = load ptr, ptr %.02028, align 8, !tbaa !16
  %.not23 = icmp eq ptr %.02028, %11
  br i1 %.not23, label %._crit_edge, label %.lr.ph.split, !llvm.loop !19

._crit_edge:                                      ; preds = %37, %.lr.ph.split.us, %10
  ret void
}

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, !8, i64 32}
!6 = !{!"_UDP_IO", !7, i64 0, !10, i64 8, !12, i64 24, !8, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !13, i64 64, !10, i64 720, !11, i64 736, !8, i64 744, !8, i64 752}
!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 = !{!"long long", !8, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !8, i64 40, !14, i64 552, !14, i64 584, !14, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!14 = !{!"", !8, i64 0}
!15 = !{!6, !11, i64 720}
!16 = !{!10, !11, i64 0}
!17 = !{!8, !8, i64 0}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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