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

; 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_RX_TOKEN = type { i32, ptr, ptr, ptr, i32, %union.UDP_COMPLETION_TOKEN }
%union.UDP_COMPLETION_TOKEN = type { %struct.EFI_UDP4_COMPLETION_TOKEN }
%struct.EFI_UDP4_COMPLETION_TOKEN = type { ptr, i64, %union.anon }
%union.anon = type { 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 }
%struct.EFI_UDP6_COMPLETION_TOKEN = type { ptr, i64, %union.anon.0 }
%union.anon.0 = type { ptr }

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

declare void @FreePool(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
declare dso_local void @UdpIoOnDgramRcvd(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @UdpIoCreateRxToken(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  br label %13

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

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

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

28:                                               ; preds = %22
  call void @DebugAssert(ptr noundef @.str, i64 noundef 339, ptr noundef @.str.6)
  br label %29

29:                                               ; preds = %28, %22, %16
  br label %30

30:                                               ; preds = %29, %13
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = call ptr @AllocatePool(i64 noundef 64)
  store ptr %33, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %94

37:                                               ; preds = %32
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %38, i32 0, i32 0
  store i32 1380992085, ptr %39, align 8, !tbaa !17
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %41, i32 0, i32 1
  store ptr %40, ptr %42, align 8, !tbaa !19
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %44, i32 0, i32 2
  store ptr %43, ptr %45, align 8, !tbaa !20
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %47, i32 0, i32 3
  store ptr %46, ptr %48, align 8, !tbaa !21
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %50, i32 0, i32 4
  store i32 %49, ptr %51, align 8, !tbaa !22
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._UDP_IO, ptr %52, i32 0, i32 3
  %54 = load i8, ptr %53, align 8, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = icmp eq i32 %55, 4
  br i1 %56, label %57, label %72

57:                                               ; preds = %37
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %58, i32 0, i32 5
  %60 = getelementptr inbounds %struct.EFI_UDP4_COMPLETION_TOKEN, ptr %59, i32 0, i32 1
  store i64 -9223372036854775802, ptr %60, align 8, !tbaa !23
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %61, i32 0, i32 5
  %63 = getelementptr inbounds %struct.EFI_UDP4_COMPLETION_TOKEN, ptr %62, i32 0, i32 2
  store ptr null, ptr %63, align 8, !tbaa !23
  %64 = load ptr, ptr @gBS, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %64, i32 0, i32 8
  %66 = load ptr, ptr %65, align 8, !tbaa !24
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %68, i32 0, i32 5
  %70 = getelementptr inbounds %struct.EFI_UDP4_COMPLETION_TOKEN, ptr %69, i32 0, i32 0
  %71 = call i64 %66(i32 noundef 512, i64 noundef 16, ptr noundef @UdpIoOnDgramRcvd, ptr noundef %67, ptr noundef %70)
  store i64 %71, ptr %11, align 8, !tbaa !27
  br label %87

72:                                               ; preds = %37
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %73, i32 0, i32 5
  %75 = getelementptr inbounds %struct.EFI_UDP6_COMPLETION_TOKEN, ptr %74, i32 0, i32 1
  store i64 -9223372036854775802, ptr %75, align 8, !tbaa !23
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %76, i32 0, i32 5
  %78 = getelementptr inbounds %struct.EFI_UDP6_COMPLETION_TOKEN, ptr %77, i32 0, i32 2
  store ptr null, ptr %78, align 8, !tbaa !23
  %79 = load ptr, ptr @gBS, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %79, i32 0, i32 8
  %81 = load ptr, ptr %80, align 8, !tbaa !24
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %83, i32 0, i32 5
  %85 = getelementptr inbounds %struct.EFI_UDP6_COMPLETION_TOKEN, ptr %84, i32 0, i32 0
  %86 = call i64 %81(i32 noundef 512, i64 noundef 16, ptr noundef @UdpIoOnDgramRcvd, ptr noundef %82, ptr noundef %85)
  store i64 %86, ptr %11, align 8, !tbaa !27
  br label %87

87:                                               ; preds = %72, %57
  %88 = load i64, ptr %11, align 8, !tbaa !27
  %89 = icmp slt i64 %88, 0
  br i1 %89, label %90, label %92

90:                                               ; preds = %87
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  call void @FreePool(ptr noundef %91)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %94

92:                                               ; preds = %87
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %93, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %94

94:                                               ; preds = %92, %90, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %95 = load ptr, ptr %5, align 8
  ret ptr %95
}

declare ptr @AllocatePool(i64 noundef) #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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 32}
!12 = !{!"_UDP_IO", !10, i64 0, !13, i64 8, !14, i64 24, !7, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !15, i64 64, !13, i64 720, !6, i64 736, !7, i64 744, !7, i64 752}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, 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 = !{!18, !10, i64 0}
!18 = !{!"", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !7, i64 40}
!19 = !{!18, !6, i64 8}
!20 = !{!18, !6, i64 16}
!21 = !{!18, !6, i64 24}
!22 = !{!18, !10, i64 32}
!23 = !{!7, !7, i64 0}
!24 = !{!25, !6, i64 80}
!25 = !{!"", !26, 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}
!26 = !{!"", !14, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!27 = !{!14, !14, i64 0}


; 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"

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

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @UdpIoOnDgramRcvd(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @UdpIoCreateRxToken(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 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 339, ptr noundef nonnull @.str.6) #2
  br label %10

10:                                               ; preds = %6, %6, %9, %4
  %11 = tail call ptr @AllocatePool(i64 noundef 64) #2
  %12 = icmp eq ptr %11, null
  br i1 %12, label %27, label %13

13:                                               ; preds = %10
  store i32 1380992085, ptr %11, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %0, ptr %14, align 8, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr %1, ptr %15, align 8, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %11, i64 24
  store ptr %2, ptr %16, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %11, i64 32
  store i32 %3, ptr %17, align 8, !tbaa !20
  %18 = getelementptr inbounds i8, ptr %11, i64 40
  %19 = getelementptr inbounds i8, ptr %11, i64 48
  store i64 -9223372036854775802, ptr %19, align 8, !tbaa !21
  %20 = getelementptr inbounds i8, ptr %11, i64 56
  store ptr null, ptr %20, align 8, !tbaa !21
  %21 = load ptr, ptr @gBS, align 8, !tbaa !22
  %22 = getelementptr inbounds i8, ptr %21, i64 80
  %23 = load ptr, ptr %22, align 8, !tbaa !23
  %24 = tail call i64 %23(i32 noundef 512, i64 noundef 16, ptr noundef nonnull @UdpIoOnDgramRcvd, ptr noundef nonnull %11, ptr noundef nonnull %18) #2
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %13
  tail call void @FreePool(ptr noundef nonnull %11) #2
  br label %27

27:                                               ; preds = %13, %10, %26
  %.024 = phi ptr [ null, %26 ], [ null, %10 ], [ %11, %13 ]
  ret ptr %.024
}

declare ptr @AllocatePool(i64 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, !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 = !{!16, !7, i64 0}
!16 = !{!"", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !7, i64 32, !8, i64 40}
!17 = !{!16, !11, i64 8}
!18 = !{!16, !11, i64 16}
!19 = !{!16, !11, i64 24}
!20 = !{!16, !7, i64 32}
!21 = !{!8, !8, i64 0}
!22 = !{!11, !11, i64 0}
!23 = !{!24, !11, i64 80}
!24 = !{!"", !25, i64 0, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !11, i64 216, !11, i64 224, !11, i64 232, !11, i64 240, !11, i64 248, !11, i64 256, !11, i64 264, !11, i64 272, !11, i64 280, !11, i64 288, !11, i64 296, !11, i64 304, !11, i64 312, !11, i64 320, !11, i64 328, !11, i64 336, !11, i64 344, !11, i64 352, !11, i64 360, !11, i64 368}
!25 = !{!"", !12, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}


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