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

; 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.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._LIST_ENTRY = type { ptr, ptr }
%struct.NET_BUF_QUEUE = type { i32, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32 }
%struct.NET_BUF = type { i32, i64, %struct._LIST_ENTRY, %union.NET_IP_HEAD, ptr, ptr, [64 x i8], ptr, i32, i32, [1 x %struct.NET_BLOCK_OP] }
%union.NET_IP_HEAD = type { ptr }
%struct.NET_BLOCK_OP = type { ptr, ptr, ptr, ptr, i32 }
%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 }

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [125 x i8], align 1
@gBS = external global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

declare ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) #1

declare i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) #1

declare void @NetbufQueAppend(ptr noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

6:                                                ; preds = %2
  %7 = call zeroext i8 @DebugAssertEnabled()
  %8 = icmp ne i8 %7, 0
  br i1 %8, label %9, label %19

9:                                                ; preds = %6
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %17

12:                                               ; preds = %9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = icmp eq i32 %15, 1148218957
  br i1 %16, label %18, label %17

17:                                               ; preds = %12, %9
  call void @DebugAssert(ptr noundef @.str, i64 noundef 186, ptr noundef @.str.1)
  br label %18

18:                                               ; preds = %17, %12
  br label %19

19:                                               ; preds = %18, %6
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = call zeroext i8 @DebugAssertEnabled()
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %32

25:                                               ; preds = %22
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.NET_BUF, ptr %26, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !16
  %29 = icmp sgt i64 %28, 1
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  call void @DebugAssert(ptr noundef @.str, i64 noundef 187, ptr noundef @.str.6)
  br label %31

31:                                               ; preds = %30, %25
  br label %32

32:                                               ; preds = %31, %22
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr @gBS, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = call i64 %37(i64 noundef 16)
  store i64 %38, ptr %5, align 8, !tbaa !21
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.NET_BUF, ptr %39, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !16
  %42 = add nsw i64 %41, -1
  store i64 %42, ptr %40, align 8, !tbaa !16
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NET_BUF, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !16
  %46 = icmp eq i64 %45, 1
  br i1 %46, label %47, label %63

47:                                               ; preds = %34
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.NET_BUF, ptr %49, i32 0, i32 9
  %51 = load i32, ptr %50, align 4, !tbaa !22
  %52 = call i32 @NetbufTrim(ptr noundef %48, i32 noundef %51, i8 noundef zeroext 0)
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = call ptr @NetbufAllocSpace(ptr noundef %53, i32 noundef 4, i8 noundef zeroext 1)
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %59

56:                                               ; preds = %47
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = call i32 @NetbufTrim(ptr noundef %57, i32 noundef 4, i8 noundef zeroext 0)
  br label %59

59:                                               ; preds = %56, %47
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %60, i32 0, i32 12
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  call void @NetbufQueAppend(ptr noundef %61, ptr noundef %62)
  br label %63

63:                                               ; preds = %59, %34
  %64 = load ptr, ptr @gBS, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !23
  %67 = load i64, ptr %5, align 8, !tbaa !21
  call void %66(i64 noundef %67)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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


; 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 [151 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [125 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [17 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 ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

declare i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

declare void @NetbufQueAppend(ptr noundef, ptr noundef) local_unnamed_addr #0

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

4:                                                ; preds = %2
  %.not11 = icmp eq ptr %0, null
  br i1 %.not11, label %8, label %5

5:                                                ; preds = %4
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 1148218957
  br i1 %7, label %9, label %8

8:                                                ; preds = %5, %4
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 186, ptr noundef nonnull @.str.1) #2
  br label %9

9:                                                ; preds = %2, %8, %5
  %10 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not12 = icmp eq i8 %10, 0
  br i1 %.not12, label %16, label %11

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %14 = icmp sgt i64 %13, 1
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 187, ptr noundef nonnull @.str.6) #2
  br label %16

16:                                               ; preds = %11, %15, %9
  %17 = load ptr, ptr @gBS, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = tail call i64 %19(i64 noundef 16) #2
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = add nsw i64 %22, -1
  store i64 %23, ptr %21, align 8, !tbaa !15
  %24 = icmp eq i64 %23, 1
  br i1 %24, label %25, label %34

25:                                               ; preds = %16
  %26 = getelementptr inbounds i8, ptr %1, i64 132
  %27 = load i32, ptr %26, align 4, !tbaa !21
  %28 = tail call i32 @NetbufTrim(ptr noundef nonnull %1, i32 noundef %27, i8 noundef zeroext 0) #2
  %29 = tail call ptr @NetbufAllocSpace(ptr noundef nonnull %1, i32 noundef 4, i8 noundef zeroext 1) #2
  %.not13 = icmp eq ptr %29, null
  br i1 %.not13, label %32, label %30

30:                                               ; preds = %25
  %31 = tail call i32 @NetbufTrim(ptr noundef nonnull %1, i32 noundef 4, i8 noundef zeroext 0) #2
  br label %32

32:                                               ; preds = %30, %25
  %33 = getelementptr inbounds i8, ptr %0, i64 128
  tail call void @NetbufQueAppend(ptr noundef nonnull %33, ptr noundef nonnull %1) #2
  br label %34

34:                                               ; preds = %32, %16
  %35 = load ptr, ptr @gBS, align 8, !tbaa !17
  %36 = getelementptr inbounds i8, ptr %35, i64 32
  %37 = load ptr, ptr %36, align 8, !tbaa !22
  tail call void %37(i64 noundef %20) #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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 48, !10, i64 56, !10, i64 64, !13, i64 72, !12, i64 88, !13, i64 96, !7, i64 112, !10, i64 120, !14, i64 128, !12, i64 184, !10, i64 192, !8, i64 200, !10, i64 208, !10, i64 216, !7, i64 224, !7, i64 228, !7, i64 232, !7, i64 236, !7, i64 240, !7, i64 244, !10, i64 248, !10, i64 256}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EFI_VLAN_CONFIG_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!14 = !{!"", !7, i64 0, !12, i64 8, !13, i64 16, !13, i64 32, !7, i64 48, !7, i64 52}
!15 = !{!16, !12, i64 8}
!16 = !{!"", !7, i64 0, !12, i64 8, !13, i64 16, !8, i64 32, !10, i64 40, !10, i64 48, !8, i64 56, !10, i64 120, !7, i64 128, !7, i64 132, !8, i64 136}
!17 = !{!10, !10, i64 0}
!18 = !{!19, !10, i64 24}
!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 = !{!"", !12, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!21 = !{!16, !7, i64 132}
!22 = !{!19, !10, i64 32}


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