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

; 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._EFI_UDP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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_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
declare dso_local void @UdpIoCancelDgrams(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @UdpIoCleanIo(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  br label %4

4:                                                ; preds = %1
  %5 = call zeroext i8 @DebugAssertEnabled()
  %6 = icmp ne i8 %5, 0
  br i1 %6, label %7, label %21

7:                                                ; preds = %4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._UDP_IO, ptr %8, i32 0, i32 3
  %10 = load i8, ptr %9, align 8, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 4
  br i1 %12, label %20, label %13

13:                                               ; preds = %7
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._UDP_IO, ptr %14, i32 0, i32 3
  %16 = load i8, ptr %15, align 8, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = icmp eq i32 %17, 6
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  call void @DebugAssert(ptr noundef @.str, i64 noundef 875, ptr noundef @.str.6)
  br label %20

20:                                               ; preds = %19, %13, %7
  br label %21

21:                                               ; preds = %20, %4
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  call void @UdpIoCancelDgrams(ptr noundef %24, i64 noundef -9223372036854775787, ptr noundef null, ptr noundef null)
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._UDP_IO, ptr %25, i32 0, i32 3
  %27 = load i8, ptr %26, align 8, !tbaa !9
  %28 = zext i8 %27 to i32
  %29 = icmp eq i32 %28, 4
  br i1 %29, label %30, label %57

30:                                               ; preds = %23
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._UDP_IO, ptr %31, i32 0, i32 9
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  store ptr %33, ptr %3, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %47

35:                                               ; preds = %30
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._UDP_IO, ptr %36, i32 0, i32 10
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = getelementptr inbounds %struct._EFI_UDP4_PROTOCOL, ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._UDP_IO, ptr %41, i32 0, i32 10
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %44, i32 0, i32 5
  %46 = call i64 %40(ptr noundef %43, ptr noundef %45)
  br label %47

47:                                               ; preds = %35, %30
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._UDP_IO, ptr %48, i32 0, i32 10
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = getelementptr inbounds %struct._EFI_UDP4_PROTOCOL, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !20
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._UDP_IO, ptr %53, i32 0, i32 10
  %55 = load ptr, ptr %54, align 8, !tbaa !17
  %56 = call i64 %52(ptr noundef %55, ptr noundef null)
  br label %84

57:                                               ; preds = %23
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._UDP_IO, ptr %58, i32 0, i32 9
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  store ptr %60, ptr %3, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %74

62:                                               ; preds = %57
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._UDP_IO, ptr %63, i32 0, i32 10
  %65 = load ptr, ptr %64, align 8, !tbaa !17
  %66 = getelementptr inbounds %struct._EFI_UDP6_PROTOCOL, ptr %65, i32 0, i32 5
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._UDP_IO, ptr %68, i32 0, i32 10
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.UDP_RX_TOKEN, ptr %71, i32 0, i32 5
  %73 = call i64 %67(ptr noundef %70, ptr noundef %72)
  br label %74

74:                                               ; preds = %62, %57
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._UDP_IO, ptr %75, i32 0, i32 10
  %77 = load ptr, ptr %76, align 8, !tbaa !17
  %78 = getelementptr inbounds %struct._EFI_UDP6_PROTOCOL, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !23
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._UDP_IO, ptr %80, i32 0, i32 10
  %82 = load ptr, ptr %81, align 8, !tbaa !17
  %83 = call i64 %79(ptr noundef %82, ptr noundef null)
  br label %84

84:                                               ; preds = %74, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #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, !7, i64 32}
!10 = !{!"_UDP_IO", !11, i64 0, !12, i64 8, !13, i64 24, !7, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !14, i64 64, !12, i64 720, !6, i64 736, !7, i64 744, !7, i64 752}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"", !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, !15, i64 552, !15, i64 584, !15, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!15 = !{!"", !7, i64 0}
!16 = !{!10, !6, i64 736}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !6, i64 48}
!19 = !{!"_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}
!20 = !{!19, !6, i64 8}
!21 = !{!22, !6, i64 40}
!22 = !{!"_EFI_UDP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!23 = !{!22, !6, i64 8}


; 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
declare dso_local void @UdpIoCancelDgrams(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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

7:                                                ; preds = %3, %3, %6, %1
  tail call void @UdpIoCancelDgrams(ptr noundef %0, i64 noundef -9223372036854775787, ptr noundef null, ptr noundef null)
  %8 = getelementptr inbounds i8, ptr %0, i64 736
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %.not19 = icmp eq ptr %9, null
  br i1 %.not19, label %19, label %.sink.split

.sink.split:                                      ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load i8, ptr %10, align 8, !tbaa !5
  %12 = icmp eq i8 %11, 4
  %. = select i1 %12, i64 48, i64 40
  %13 = getelementptr inbounds i8, ptr %0, i64 744
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %14, i64 %.
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %9, i64 40
  %18 = tail call i64 %16(ptr noundef %14, ptr noundef nonnull %17) #2
  br label %19

19:                                               ; preds = %7, %.sink.split
  %20 = getelementptr inbounds i8, ptr %0, i64 744
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = tail call i64 %23(ptr noundef %21, ptr noundef null) #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, !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 736}
!16 = !{!8, !8, i64 0}
!17 = !{!11, !11, i64 0}


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