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

; 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._IP_IO_SEND_ENTRY = type { %struct._LIST_ENTRY, ptr, ptr, ptr, %union.IP_IO_IP_PROTOCOL, ptr, %union.IP_IO_IP_COMPLETION_TOKEN }
%struct._LIST_ENTRY = type { ptr, ptr }
%union.IP_IO_IP_PROTOCOL = type { ptr }
%union.IP_IO_IP_COMPLETION_TOKEN = type { %struct.EFI_IP4_COMPLETION_TOKEN }
%struct.EFI_IP4_COMPLETION_TOKEN = type { ptr, i64, %union.anon }
%union.anon = type { ptr }
%struct._IP_IO = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, ptr, %union.IP_IO_IP_PROTOCOL, i8, i8, %union.IP_IO_IP_COMPLETION_TOKEN, %struct._LIST_ENTRY, ptr, ptr, ptr, ptr, i8 }
%struct.EFI_IP4_TRANSMIT_DATA = type { %struct.EFI_IPv4_ADDRESS, ptr, i32, ptr, i32, i32, [1 x %struct.EFI_IP4_FRAGMENT_DATA] }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct.EFI_IP4_FRAGMENT_DATA = type { i32, ptr }
%struct.EFI_IP6_COMPLETION_TOKEN = type { ptr, i64, %union.anon.0 }
%union.anon.0 = type { ptr }
%struct._EFI_IP6_TRANSMIT_DATA = type { %struct.EFI_IPv6_ADDRESS, ptr, i32, ptr, i8, i32, i32, [1 x %struct._EFI_IP6_FRAGMENT_DATA] }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct._EFI_IP6_FRAGMENT_DATA = type { i32, 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 }

@gBS = external global ptr, align 8

; 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

declare void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @IpIoDestroySndEntry(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct._IP_IO, ptr %9, i32 0, i32 14
  %11 = load i8, ptr %10, align 8, !tbaa !12
  %12 = zext i8 %11 to i32
  %13 = icmp eq i32 %12, 4
  br i1 %13, label %14, label %26

14:                                               ; preds = %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %15, i32 0, i32 6
  %17 = getelementptr inbounds %struct.EFI_IP4_COMPLETION_TOKEN, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  store ptr %18, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %19, i32 0, i32 6
  %21 = getelementptr inbounds %struct.EFI_IP4_COMPLETION_TOKEN, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  store ptr %22, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.EFI_IP4_TRANSMIT_DATA, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  store ptr %25, ptr %5, align 8, !tbaa !5
  br label %48

26:                                               ; preds = %1
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct._IP_IO, ptr %29, i32 0, i32 14
  %31 = load i8, ptr %30, align 8, !tbaa !12
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %32, 6
  br i1 %33, label %34, label %46

34:                                               ; preds = %26
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %35, i32 0, i32 6
  %37 = getelementptr inbounds %struct.EFI_IP6_COMPLETION_TOKEN, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  store ptr %38, ptr %3, align 8, !tbaa !5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %39, i32 0, i32 6
  %41 = getelementptr inbounds %struct.EFI_IP6_COMPLETION_TOKEN, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  store ptr %42, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  store ptr %45, ptr %5, align 8, !tbaa !5
  br label %47

46:                                               ; preds = %26
  store i32 1, ptr %6, align 4
  br label %67

47:                                               ; preds = %34
  br label %48

48:                                               ; preds = %47, %14
  %49 = load ptr, ptr @gBS, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %49, i32 0, i32 12
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = call i64 %51(ptr noundef %52)
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  call void @FreePool(ptr noundef %54)
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = icmp ne ptr null, %55
  br i1 %56, label %57, label %59

57:                                               ; preds = %48
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  call void @FreePool(ptr noundef %58)
  br label %59

59:                                               ; preds = %57, %48
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %60, i32 0, i32 5
  %62 = load ptr, ptr %61, align 8, !tbaa !20
  call void @NetbufFree(ptr noundef %62)
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %63, i32 0, i32 0
  %65 = call ptr @RemoveEntryList(ptr noundef %64)
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %66)
  store i32 0, ptr %6, align 4
  br label %67

67:                                               ; preds = %59, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %68 = load i32, ptr %6, align 4
  switch i32 %68, label %70 [
    i32 0, label %69
    i32 1, label %69
  ]

69:                                               ; preds = %67, %67
  ret void

70:                                               ; preds = %67
  unreachable
}

declare void @NetbufFree(ptr noundef) #1

declare ptr @RemoveEntryList(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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, !6, i64 16}
!10 = !{!"_IP_IO_SEND_ENTRY", !11, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !6, i64 48, !7, i64 56}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = !{!13, !7, i64 144}
!13 = !{!"_IP_IO", !11, i64 0, !11, i64 16, !6, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !7, i64 64, !7, i64 65, !7, i64 72, !11, i64 96, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !7, i64 144}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !6, i64 112}
!16 = !{!"", !17, 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}
!17 = !{!"", !18, i64 0, !19, i64 8, !19, i64 12, !19, i64 16, !19, i64 20}
!18 = !{!"long long", !7, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!10, !6, i64 48}


; 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

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @IpIoDestroySndEntry(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 144
  %5 = load i8, ptr %4, align 8, !tbaa !11
  switch i8 %5, label %20 [
    i8 4, label %7
    i8 6, label %6
  ]

6:                                                ; preds = %1
  br label %7

7:                                                ; preds = %1, %6
  %.sink18 = phi i64 [ 16, %6 ], [ 8, %1 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %9, i64 %.sink18
  %.0 = load ptr, ptr %10, align 8, !tbaa !13
  %.016.in = getelementptr inbounds i8, ptr %0, i64 56
  %.016 = load ptr, ptr %.016.in, align 8, !tbaa !13
  %11 = load ptr, ptr @gBS, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %11, i64 112
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = tail call i64 %13(ptr noundef %.016) #2
  tail call void @FreePool(ptr noundef %9) #2
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %16, label %15

15:                                               ; preds = %7
  tail call void @FreePool(ptr noundef nonnull %.0) #2
  br label %16

16:                                               ; preds = %15, %7
  %17 = getelementptr inbounds i8, ptr %0, i64 48
  %18 = load ptr, ptr %17, align 8, !tbaa !20
  tail call void @NetbufFree(ptr noundef %18) #2
  %19 = tail call ptr @RemoveEntryList(ptr noundef nonnull %0) #2
  tail call void @FreePool(ptr noundef nonnull %0) #2
  br label %20

20:                                               ; preds = %1, %16
  ret void
}

declare void @NetbufFree(ptr noundef) local_unnamed_addr #0

declare ptr @RemoveEntryList(ptr 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 16}
!6 = !{!"_IP_IO_SEND_ENTRY", !7, i64 0, !8, i64 16, !8, i64 24, !8, i64 32, !9, i64 40, !8, i64 48, !9, i64 56}
!7 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !9, i64 144}
!12 = !{!"_IP_IO", !7, i64 0, !7, i64 16, !8, i64 32, !8, i64 40, !8, i64 48, !9, i64 56, !9, i64 64, !9, i64 65, !9, i64 72, !7, i64 96, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !9, i64 144}
!13 = !{!9, !9, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !8, i64 112}
!16 = !{!"", !17, i64 0, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !8, i64 144, !8, i64 152, !8, i64 160, !8, i64 168, !8, i64 176, !8, i64 184, !8, i64 192, !8, i64 200, !8, i64 208, !8, i64 216, !8, i64 224, !8, i64 232, !8, i64 240, !8, i64 248, !8, i64 256, !8, i64 264, !8, i64 272, !8, i64 280, !8, i64 288, !8, i64 296, !8, i64 304, !8, i64 312, !8, i64 320, !8, i64 328, !8, i64 336, !8, i64 344, !8, i64 352, !8, i64 360, !8, i64 368}
!17 = !{!"", !18, i64 0, !19, i64 8, !19, i64 12, !19, i64 16, !19, i64 20}
!18 = !{!"long long", !9, i64 0}
!19 = !{!"int", !9, i64 0}
!20 = !{!6, !8, i64 48}


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