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

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

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @NetbufAllocStruct(i32 noundef, i32 noundef) #0

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

declare zeroext i8 @DebugAssertEnabled() #2

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

declare void @FreePool(ptr noundef) #2

; 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
define dso_local ptr @NetbufAlloc(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  br label %8

8:                                                ; preds = %1
  %9 = call zeroext i8 @DebugAssertEnabled()
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %16

11:                                               ; preds = %8
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = icmp ugt i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @DebugAssert(ptr noundef @.str, i64 noundef 105, ptr noundef @.str.2)
  br label %15

15:                                               ; preds = %14, %11
  br label %16

16:                                               ; preds = %15, %8
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  %19 = call ptr @NetbufAllocStruct(i32 noundef 1, i32 noundef 1)
  store ptr %19, ptr %4, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !9
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %77

23:                                               ; preds = %18
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = zext i32 %24 to i64
  %26 = call ptr @AllocatePool(i64 noundef %25)
  store ptr %26, ptr %6, align 8, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %23
  br label %75

30:                                               ; preds = %23
  %31 = load ptr, ptr %4, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.NET_BUF, ptr %31, i32 0, i32 7
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  store ptr %33, ptr %5, align 8, !tbaa !9
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.NET_VECTOR, ptr %35, i32 0, i32 5
  store i32 %34, ptr %36, align 4, !tbaa !15
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.NET_VECTOR, ptr %38, i32 0, i32 7
  %40 = getelementptr inbounds [1 x %struct.NET_BLOCK], ptr %39, i64 0, i64 0
  %41 = getelementptr inbounds %struct.NET_BLOCK, ptr %40, i32 0, i32 1
  store ptr %37, ptr %41, align 8, !tbaa !17
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.NET_VECTOR, ptr %43, i32 0, i32 7
  %45 = getelementptr inbounds [1 x %struct.NET_BLOCK], ptr %44, i64 0, i64 0
  %46 = getelementptr inbounds %struct.NET_BLOCK, ptr %45, i32 0, i32 0
  store i32 %42, ptr %46, align 8, !tbaa !19
  %47 = load ptr, ptr %6, align 8, !tbaa !9
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.NET_BUF, ptr %48, i32 0, i32 10
  %50 = getelementptr inbounds [1 x %struct.NET_BLOCK_OP], ptr %49, i64 0, i64 0
  %51 = getelementptr inbounds %struct.NET_BLOCK_OP, ptr %50, i32 0, i32 0
  store ptr %47, ptr %51, align 8, !tbaa !20
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %52, i64 %54
  %56 = load ptr, ptr %4, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.NET_BUF, ptr %56, i32 0, i32 10
  %58 = getelementptr inbounds [1 x %struct.NET_BLOCK_OP], ptr %57, i64 0, i64 0
  %59 = getelementptr inbounds %struct.NET_BLOCK_OP, ptr %58, i32 0, i32 1
  store ptr %55, ptr %59, align 8, !tbaa !22
  %60 = load ptr, ptr %6, align 8, !tbaa !9
  %61 = load ptr, ptr %4, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.NET_BUF, ptr %61, i32 0, i32 10
  %63 = getelementptr inbounds [1 x %struct.NET_BLOCK_OP], ptr %62, i64 0, i64 0
  %64 = getelementptr inbounds %struct.NET_BLOCK_OP, ptr %63, i32 0, i32 2
  store ptr %60, ptr %64, align 8, !tbaa !23
  %65 = load ptr, ptr %6, align 8, !tbaa !9
  %66 = load ptr, ptr %4, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.NET_BUF, ptr %66, i32 0, i32 10
  %68 = getelementptr inbounds [1 x %struct.NET_BLOCK_OP], ptr %67, i64 0, i64 0
  %69 = getelementptr inbounds %struct.NET_BLOCK_OP, ptr %68, i32 0, i32 3
  store ptr %65, ptr %69, align 8, !tbaa !24
  %70 = load ptr, ptr %4, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.NET_BUF, ptr %70, i32 0, i32 10
  %72 = getelementptr inbounds [1 x %struct.NET_BLOCK_OP], ptr %71, i64 0, i64 0
  %73 = getelementptr inbounds %struct.NET_BLOCK_OP, ptr %72, i32 0, i32 4
  store i32 0, ptr %73, align 8, !tbaa !25
  %74 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %74, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %77

75:                                               ; preds = %29
  %76 = load ptr, ptr %4, align 8, !tbaa !9
  call void @FreePool(ptr noundef %76)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %77

77:                                               ; preds = %75, %30, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %78 = load ptr, ptr %2, align 8
  ret ptr %78
}

declare ptr @AllocatePool(i64 noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 120}
!12 = !{!"", !6, i64 0, !13, i64 8, !14, i64 16, !7, i64 32, !10, i64 40, !10, i64 48, !7, i64 56, !10, i64 120, !6, i64 128, !6, i64 132, !7, i64 136}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!15 = !{!16, !6, i64 36}
!16 = !{!"", !6, i64 0, !13, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !6, i64 36, !6, i64 40, !7, i64 48}
!17 = !{!18, !10, i64 8}
!18 = !{!"", !6, i64 0, !10, i64 8}
!19 = !{!18, !6, i64 0}
!20 = !{!21, !10, i64 0}
!21 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32}
!22 = !{!21, !10, i64 8}
!23 = !{!21, !10, i64 16}
!24 = !{!21, !10, i64 24}
!25 = !{!21, !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 [144 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @NetbufAllocStruct(i32 noundef, i32 noundef) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare void @FreePool(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @NetbufAlloc(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call zeroext i8 @DebugAssertEnabled() #2
  %3 = icmp eq i8 %2, 0
  %4 = icmp ne i32 %0, 0
  %or.cond = or i1 %4, %3
  br i1 %or.cond, label %6, label %5

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

6:                                                ; preds = %5, %1
  %7 = tail call ptr @NetbufAllocStruct(i32 noundef 1, i32 noundef 1)
  %8 = icmp eq ptr %7, null
  br i1 %8, label %26, label %9

9:                                                ; preds = %6
  %10 = zext i32 %0 to i64
  %11 = tail call ptr @AllocatePool(i64 noundef %10) #2
  %12 = icmp eq ptr %11, null
  br i1 %12, label %25, label %13

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %7, i64 120
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 36
  store i32 %0, ptr %16, align 4, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %15, i64 48
  %18 = getelementptr inbounds i8, ptr %15, i64 56
  store ptr %11, ptr %18, align 8, !tbaa !15
  store i32 %0, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %7, i64 136
  store ptr %11, ptr %19, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %11, i64 %10
  %21 = getelementptr inbounds i8, ptr %7, i64 144
  store ptr %20, ptr %21, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %7, i64 152
  store ptr %11, ptr %22, align 8, !tbaa !21
  %23 = getelementptr inbounds i8, ptr %7, i64 160
  store ptr %11, ptr %23, align 8, !tbaa !22
  %24 = getelementptr inbounds i8, ptr %7, i64 168
  store i32 0, ptr %24, align 8, !tbaa !23
  br label %26

25:                                               ; preds = %9
  tail call void @FreePool(ptr noundef nonnull %7) #2
  br label %26

26:                                               ; preds = %6, %25, %13
  %.0 = phi ptr [ null, %25 ], [ %7, %13 ], [ null, %6 ]
  ret ptr %.0
}

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 }

!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, !12, i64 120}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 16, !8, i64 32, !12, i64 40, !12, i64 48, !8, i64 56, !12, i64 120, !7, i64 128, !7, i64 132, !8, i64 136}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"_LIST_ENTRY", !12, i64 0, !12, i64 8}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !7, i64 36}
!14 = !{!"", !7, i64 0, !10, i64 8, !12, i64 16, !12, i64 24, !7, i64 32, !7, i64 36, !7, i64 40, !8, i64 48}
!15 = !{!16, !12, i64 8}
!16 = !{!"", !7, i64 0, !12, i64 8}
!17 = !{!16, !7, i64 0}
!18 = !{!19, !12, i64 0}
!19 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !7, i64 32}
!20 = !{!19, !12, i64 8}
!21 = !{!19, !12, i64 16}
!22 = !{!19, !12, i64 24}
!23 = !{!19, !7, i64 32}


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