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

; 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_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._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.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.1 = external hidden unnamed_addr constant [18 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: nounwind uwtable
define dso_local void @UdpIoFreeRxToken(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %3, i32 0, i32 1
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds %struct._UDP_IO, ptr %5, i32 0, i32 3
  %7 = load i8, ptr %6, align 8, !tbaa !12
  %8 = zext i8 %7 to i32
  %9 = icmp eq i32 %8, 4
  br i1 %9, label %10, label %19

10:                                               ; preds = %1
  %11 = load ptr, ptr @gBS, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %11, i32 0, i32 12
  %13 = load ptr, ptr %12, align 8, !tbaa !18
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %14, i32 0, i32 5
  %16 = getelementptr inbounds %struct.EFI_UDP4_COMPLETION_TOKEN, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %18 = call i64 %13(ptr noundef %17)
  br label %44

19:                                               ; preds = %1
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct._UDP_IO, ptr %22, i32 0, i32 3
  %24 = load i8, ptr %23, align 8, !tbaa !12
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 6
  br i1 %26, label %27, label %36

27:                                               ; preds = %19
  %28 = load ptr, ptr @gBS, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %28, i32 0, i32 12
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %31, i32 0, i32 5
  %33 = getelementptr inbounds %struct.EFI_UDP6_COMPLETION_TOKEN, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = call i64 %30(ptr noundef %34)
  br label %43

36:                                               ; preds = %19
  br label %37

37:                                               ; preds = %36
  %38 = call zeroext i8 @DebugAssertEnabled()
  %39 = icmp ne i8 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %37
  call void @DebugAssert(ptr noundef @.str, i64 noundef 67, ptr noundef @.str.1)
  br label %41

41:                                               ; preds = %40, %37
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42, %27
  br label %44

44:                                               ; preds = %43, %10
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %45)
  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" }

!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, !6, i64 8}
!10 = !{!"", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !7, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 32}
!13 = !{!"_UDP_IO", !11, i64 0, !14, i64 8, !15, i64 24, !7, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !16, i64 64, !14, i64 720, !6, i64 736, !7, i64 744, !7, i64 752}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !7, i64 40, !17, i64 552, !17, i64 584, !17, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!17 = !{!"", !7, i64 0}
!18 = !{!19, !6, i64 112}
!19 = !{!"", !20, 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}
!20 = !{!"", !15, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!21 = !{!7, !7, 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.1 = external hidden unnamed_addr constant [18 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
define dso_local void @UdpIoFreeRxToken(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 32
  %5 = load i8, ptr %4, align 8, !tbaa !11
  switch i8 %5, label %20 [
    i8 4, label %6
    i8 6, label %13
  ]

6:                                                ; preds = %1
  %7 = load ptr, ptr @gBS, align 8, !tbaa !17
  %8 = getelementptr inbounds i8, ptr %7, i64 112
  %9 = load ptr, ptr %8, align 8, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load ptr, ptr %10, align 8, !tbaa !21
  %12 = tail call i64 %9(ptr noundef %11) #2
  br label %23

13:                                               ; preds = %1
  %14 = load ptr, ptr @gBS, align 8, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %14, i64 112
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = load ptr, ptr %17, align 8, !tbaa !21
  %19 = tail call i64 %16(ptr noundef %18) #2
  br label %23

20:                                               ; preds = %1
  %21 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %21, 0
  br i1 %.not, label %23, label %22

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

23:                                               ; preds = %13, %20, %22, %6
  tail call void @FreePool(ptr noundef nonnull %0) #2
  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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !8, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !8, i64 32}
!12 = !{!"_UDP_IO", !7, i64 0, !13, i64 8, !14, i64 24, !8, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !15, i64 64, !13, i64 720, !10, i64 736, !8, i64 744, !8, i64 752}
!13 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!14 = !{!"long long", !8, i64 0}
!15 = !{!"", !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, !16, i64 552, !16, i64 584, !16, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!16 = !{!"", !8, i64 0}
!17 = !{!10, !10, i64 0}
!18 = !{!19, !10, i64 112}
!19 = !{!"", !20, 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}
!20 = !{!"", !14, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!21 = !{!8, !8, i64 0}


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