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

; 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.GUID = type { i32, i16, i16, [8 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.MNP_SERVICE_DATA = type { i32, %struct._LIST_ENTRY, ptr, ptr, %struct._EFI_SERVICE_BINDING_PROTOCOL, ptr, %struct._LIST_ENTRY, i64, i32, i16, i8 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.MNP_DEVICE_DATA = type { i32, ptr, ptr, %struct._EFI_VLAN_CONFIG_PROTOCOL, i64, ptr, ptr, %struct._LIST_ENTRY, i64, %struct._LIST_ENTRY, i32, ptr, %struct.NET_BUF_QUEUE, i64, ptr, i8, ptr, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr }
%struct._EFI_VLAN_CONFIG_PROTOCOL = type { ptr, ptr, ptr }
%struct.NET_BUF_QUEUE = type { i32, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32 }

@gBS = external global ptr, align 8
@gEfiVlanConfigProtocolGuid = external global %struct.GUID, align 4
@gEfiManagedNetworkServiceBindingProtocolGuid = external global %struct.GUID, align 4
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4

; 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 i64 @MnpDestroyServiceData(ptr noundef %0) #2 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = load ptr, ptr @gBS, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %6, i32 0, i32 40
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %9, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %12, i32 0, i32 4
  %14 = call i64 (ptr, ...) %8(ptr noundef %11, ptr noundef @gEfiManagedNetworkServiceBindingProtocolGuid, ptr noundef %13, ptr noundef null)
  store i64 %14, ptr %4, align 8, !tbaa !19
  %15 = load i64, ptr %4, align 8, !tbaa !19
  %16 = icmp slt i64 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %1
  %18 = load i64, ptr %4, align 8, !tbaa !19
  store i64 %18, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %78

19:                                               ; preds = %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %20, i32 0, i32 9
  %22 = load i16, ptr %21, align 4, !tbaa !20
  %23 = zext i16 %22 to i32
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %72

25:                                               ; preds = %19
  %26 = load ptr, ptr @gBS, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %26, i32 0, i32 34
  %28 = load ptr, ptr %27, align 8, !tbaa !21
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  %32 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !23
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !22
  %37 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !27
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = call i64 %28(ptr noundef %33, ptr noundef @gEfiVlanConfigProtocolGuid, ptr noundef %38, ptr noundef %41)
  store i64 %42, ptr %4, align 8, !tbaa !19
  %43 = load i64, ptr %4, align 8, !tbaa !19
  %44 = icmp slt i64 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %25
  %46 = load i64, ptr %4, align 8, !tbaa !19
  store i64 %46, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %78

47:                                               ; preds = %25
  %48 = load ptr, ptr @gBS, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %48, i32 0, i32 40
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %54, i32 0, i32 5
  %56 = load ptr, ptr %55, align 8, !tbaa !28
  %57 = call i64 (ptr, ...) %50(ptr noundef %53, ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %56, ptr noundef null)
  store i64 %57, ptr %4, align 8, !tbaa !19
  %58 = load i64, ptr %4, align 8, !tbaa !19
  %59 = icmp slt i64 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %47
  %61 = load i64, ptr %4, align 8, !tbaa !19
  store i64 %61, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %78

62:                                               ; preds = %47
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %63, i32 0, i32 5
  %65 = load ptr, ptr %64, align 8, !tbaa !28
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %71

67:                                               ; preds = %62
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %68, i32 0, i32 5
  %70 = load ptr, ptr %69, align 8, !tbaa !28
  call void @FreePool(ptr noundef %70)
  br label %71

71:                                               ; preds = %67, %62
  br label %72

72:                                               ; preds = %71, %19
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %73, i32 0, i32 1
  %75 = call ptr @RemoveEntryList(ptr noundef %74)
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  call void @FreePool(ptr noundef %76)
  %77 = load i64, ptr %4, align 8, !tbaa !19
  store i64 %77, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %78

78:                                               ; preds = %72, %60, %45, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %79 = load i64, ptr %2, align 8
  ret i64 %79
}

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 336}
!10 = !{!"", !11, 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}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 32}
!15 = !{!"", !13, i64 0, !16, i64 8, !6, i64 24, !6, i64 32, !17, i64 40, !6, i64 56, !16, i64 64, !12, i64 80, !13, i64 88, !18, i64 92, !7, i64 94}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!18 = !{!"short", !7, i64 0}
!19 = !{!12, !12, i64 0}
!20 = !{!15, !18, i64 92}
!21 = !{!10, !6, i64 288}
!22 = !{!15, !6, i64 24}
!23 = !{!24, !6, i64 8}
!24 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !25, i64 24, !12, i64 48, !6, i64 56, !6, i64 64, !16, i64 72, !12, i64 88, !16, i64 96, !13, i64 112, !6, i64 120, !26, i64 128, !12, i64 184, !6, i64 192, !7, i64 200, !6, i64 208, !6, i64 216, !13, i64 224, !13, i64 228, !13, i64 232, !13, i64 236, !13, i64 240, !13, i64 244, !6, i64 248, !6, i64 256}
!25 = !{!"_EFI_VLAN_CONFIG_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}
!26 = !{!"", !13, i64 0, !12, i64 8, !16, i64 16, !16, i64 32, !13, i64 48, !13, i64 52}
!27 = !{!24, !6, i64 16}
!28 = !{!15, !6, i64 56}


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

%struct.GUID = type { i32, i16, i16, [8 x i8] }

@gBS = external local_unnamed_addr global ptr, align 8
@gEfiVlanConfigProtocolGuid = external global %struct.GUID, align 4
@gEfiManagedNetworkServiceBindingProtocolGuid = external global %struct.GUID, align 4
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @MnpDestroyServiceData(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr @gBS, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 336
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = tail call i64 (ptr, ...) %4(ptr noundef %6, ptr noundef nonnull @gEfiManagedNetworkServiceBindingProtocolGuid, ptr noundef nonnull %7, ptr noundef null) #2
  %9 = icmp slt i64 %8, 0
  br i1 %9, label %41, label %10

10:                                               ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 92
  %12 = load i16, ptr %11, align 4, !tbaa !19
  %.not = icmp eq i16 %12, 0
  br i1 %.not, label %38, label %13

13:                                               ; preds = %10
  %14 = load ptr, ptr @gBS, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 288
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !21
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !22
  %21 = getelementptr inbounds i8, ptr %18, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !26
  %23 = load ptr, ptr %5, align 8, !tbaa !14
  %24 = tail call i64 %16(ptr noundef %20, ptr noundef nonnull @gEfiVlanConfigProtocolGuid, ptr noundef %22, ptr noundef %23) #2
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %41, label %26

26:                                               ; preds = %13
  %27 = load ptr, ptr @gBS, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 336
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !14
  %31 = getelementptr inbounds i8, ptr %0, i64 56
  %32 = load ptr, ptr %31, align 8, !tbaa !27
  %33 = tail call i64 (ptr, ...) %29(ptr noundef %30, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef %32, ptr noundef null) #2
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %41, label %35

35:                                               ; preds = %26
  %36 = load ptr, ptr %31, align 8, !tbaa !27
  %.not25 = icmp eq ptr %36, null
  br i1 %.not25, label %38, label %37

37:                                               ; preds = %35
  tail call void @FreePool(ptr noundef nonnull %36) #2
  br label %38

38:                                               ; preds = %35, %37, %10
  %.0 = phi i64 [ %33, %37 ], [ %33, %35 ], [ %8, %10 ]
  %39 = getelementptr inbounds i8, ptr %0, i64 8
  %40 = tail call ptr @RemoveEntryList(ptr noundef nonnull %39) #2
  tail call void @FreePool(ptr noundef nonnull %0) #2
  br label %41

41:                                               ; preds = %26, %13, %1, %38
  %.019 = phi i64 [ %.0, %38 ], [ %8, %1 ], [ %24, %13 ], [ %33, %26 ]
  ret i64 %.019
}

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 336}
!10 = !{!"", !11, 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}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 32}
!15 = !{!"", !13, i64 0, !16, i64 8, !6, i64 24, !6, i64 32, !17, i64 40, !6, i64 56, !16, i64 64, !12, i64 80, !13, i64 88, !18, i64 92, !7, i64 94}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!18 = !{!"short", !7, i64 0}
!19 = !{!15, !18, i64 92}
!20 = !{!10, !6, i64 288}
!21 = !{!15, !6, i64 24}
!22 = !{!23, !6, i64 8}
!23 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !24, i64 24, !12, i64 48, !6, i64 56, !6, i64 64, !16, i64 72, !12, i64 88, !16, i64 96, !13, i64 112, !6, i64 120, !25, i64 128, !12, i64 184, !6, i64 192, !7, i64 200, !6, i64 208, !6, i64 216, !13, i64 224, !13, i64 228, !13, i64 232, !13, i64 236, !13, i64 240, !13, i64 244, !6, i64 248, !6, i64 256}
!24 = !{!"_EFI_VLAN_CONFIG_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}
!25 = !{!"", !13, i64 0, !12, i64 8, !16, i64 16, !16, i64 32, !13, i64 48, !13, i64 52}
!26 = !{!23, !6, i64 16}
!27 = !{!15, !6, i64 56}


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