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

; 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.1 = external hidden unnamed_addr constant [16 x i8], align 1

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

9:                                                ; preds = %2
  %10 = call zeroext i8 @DebugAssertEnabled()
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %9
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp uge i32 %13, 1
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @DebugAssert(ptr noundef @.str, i64 noundef 47, ptr noundef @.str.1)
  br label %16

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

17:                                               ; preds = %16, %9
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sub i32 %20, 1
  %22 = zext i32 %21 to i64
  %23 = mul i64 %22, 40
  %24 = add i64 176, %23
  %25 = call ptr @AllocateZeroPool(i64 noundef %24)
  store ptr %25, ptr %6, align 8, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %19
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %67

29:                                               ; preds = %19
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.NET_BUF, ptr %30, i32 0, i32 0
  store i32 1718968942, ptr %31, align 8, !tbaa !11
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.NET_BUF, ptr %32, i32 0, i32 1
  store i64 1, ptr %33, align 8, !tbaa !15
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.NET_BUF, ptr %35, i32 0, i32 8
  store i32 %34, ptr %36, align 8, !tbaa !16
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.NET_BUF, ptr %37, i32 0, i32 2
  %39 = call ptr @InitializeListHead(ptr noundef %38)
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %63

42:                                               ; preds = %29
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sub i32 %43, 1
  %45 = zext i32 %44 to i64
  %46 = mul i64 %45, 16
  %47 = add i64 64, %46
  %48 = call ptr @AllocateZeroPool(i64 noundef %47)
  store ptr %48, ptr %7, align 8, !tbaa !9
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  %50 = icmp eq ptr %49, null
  br i1 %50, label %51, label %52

51:                                               ; preds = %42
  br label %65

52:                                               ; preds = %42
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.NET_VECTOR, ptr %53, i32 0, i32 0
  store i32 1667593838, ptr %54, align 8, !tbaa !17
  %55 = load ptr, ptr %7, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.NET_VECTOR, ptr %55, i32 0, i32 1
  store i64 1, ptr %56, align 8, !tbaa !19
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.NET_VECTOR, ptr %58, i32 0, i32 6
  store i32 %57, ptr %59, align 8, !tbaa !20
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  %61 = load ptr, ptr %6, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.NET_BUF, ptr %61, i32 0, i32 7
  store ptr %60, ptr %62, align 8, !tbaa !21
  br label %63

63:                                               ; preds = %52, %29
  %64 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %64, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %67

65:                                               ; preds = %51
  %66 = load ptr, ptr %6, align 8, !tbaa !9
  call void @FreePool(ptr noundef %66)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %67

67:                                               ; preds = %65, %63, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %68 = load ptr, ptr %3, align 8
  ret ptr %68
}

; 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 ptr @AllocateZeroPool(i64 noundef) #2

declare ptr @InitializeListHead(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

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, !6, i64 0}
!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 = !{!12, !13, i64 8}
!16 = !{!12, !6, i64 128}
!17 = !{!18, !6, i64 0}
!18 = !{!"", !6, i64 0, !13, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !6, i64 36, !6, i64 40, !7, i64 48}
!19 = !{!18, !13, i64 8}
!20 = !{!18, !6, i64 40}
!21 = !{!12, !10, i64 120}


; 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.1 = external hidden unnamed_addr constant [16 x i8], align 1

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

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

7:                                                ; preds = %6, %2
  %8 = add i32 %1, -1
  %9 = zext i32 %8 to i64
  %10 = mul nuw nsw i64 %9, 40
  %11 = add nuw nsw i64 %10, 176
  %12 = tail call ptr @AllocateZeroPool(i64 noundef %11) #2
  %13 = icmp eq ptr %12, null
  br i1 %13, label %31, label %14

14:                                               ; preds = %7
  store i32 1718968942, ptr %12, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %12, i64 8
  store i64 1, ptr %15, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %12, i64 128
  store i32 %1, ptr %16, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %12, i64 16
  %18 = tail call ptr @InitializeListHead(ptr noundef nonnull %17) #2
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %31, label %19

19:                                               ; preds = %14
  %20 = add i32 %0, -1
  %21 = zext i32 %20 to i64
  %22 = shl nuw nsw i64 %21, 4
  %23 = add nuw nsw i64 %22, 64
  %24 = tail call ptr @AllocateZeroPool(i64 noundef %23) #2
  %25 = icmp eq ptr %24, null
  br i1 %25, label %30, label %26

26:                                               ; preds = %19
  store i32 1667593838, ptr %24, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %24, i64 8
  store i64 1, ptr %27, align 8, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %24, i64 40
  store i32 %0, ptr %28, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %12, i64 120
  store ptr %24, ptr %29, align 8, !tbaa !19
  br label %31

30:                                               ; preds = %19
  tail call void @FreePool(ptr noundef nonnull %12) #2
  br label %31

31:                                               ; preds = %14, %26, %7, %30
  %.0 = phi ptr [ null, %30 ], [ null, %7 ], [ %12, %26 ], [ %12, %14 ]
  ret ptr %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #1

declare ptr @InitializeListHead(ptr noundef) local_unnamed_addr #1

declare void @FreePool(ptr 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, !7, i64 0}
!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 = !{!6, !10, i64 8}
!14 = !{!6, !7, i64 128}
!15 = !{!16, !7, i64 0}
!16 = !{!"", !7, i64 0, !10, i64 8, !12, i64 16, !12, i64 24, !7, i64 32, !7, i64 36, !7, i64 40, !8, i64 48}
!17 = !{!16, !10, i64 8}
!18 = !{!16, !7, i64 40}
!19 = !{!6, !12, i64 120}


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