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

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

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [107 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

; 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
declare dso_local ptr @NetbufAlloc(i32 noundef) #2

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

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

10:                                               ; preds = %3
  %11 = call zeroext i8 @DebugAssertEnabled()
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %23

13:                                               ; preds = %10
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %21

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.NET_BUF, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i32 %19, 1718968942
  br i1 %20, label %22, label %21

21:                                               ; preds = %16, %13
  call void @DebugAssert(ptr noundef @.str, i64 noundef 300, ptr noundef @.str.7)
  br label %22

22:                                               ; preds = %21, %16
  br label %23

23:                                               ; preds = %22, %10
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %35

28:                                               ; preds = %25
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.NET_BUF, ptr %29, i32 0, i32 9
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = add i32 %31, %32
  %34 = call ptr @NetbufAlloc(i32 noundef %33)
  store ptr %34, ptr %6, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %28, %25
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %61

39:                                               ; preds = %35
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.NET_BUF, ptr %40, i32 0, i32 6
  %42 = getelementptr inbounds [64 x i8], ptr %41, i64 0, i64 0
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NET_BUF, ptr %43, i32 0, i32 6
  %45 = getelementptr inbounds [64 x i8], ptr %44, i64 0, i64 0
  %46 = call ptr @CopyMem(ptr noundef %42, ptr noundef %45, i64 noundef 64)
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  call void @NetbufReserve(ptr noundef %47, i32 noundef %48)
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.NET_BUF, ptr %50, i32 0, i32 9
  %52 = load i32, ptr %51, align 4, !tbaa !15
  %53 = call ptr @NetbufAllocSpace(ptr noundef %49, i32 noundef %52, i8 noundef zeroext 0)
  store ptr %53, ptr %8, align 8, !tbaa !5
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.NET_BUF, ptr %55, i32 0, i32 9
  %57 = load i32, ptr %56, align 4, !tbaa !15
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = call i32 @NetbufCopy(ptr noundef %54, i32 noundef 0, i32 noundef %57, ptr noundef %58)
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %60, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %61

61:                                               ; preds = %39, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %62 = load ptr, ptr %4, align 8
  ret ptr %62
}

; Function Attrs: nounwind uwtable
declare dso_local void @NetbufReserve(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) #2

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

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !13, i64 8, !14, i64 16, !7, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !10, i64 128, !10, i64 132, !7, i64 136}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!12, !10, i64 132}


; 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.7 = external hidden unnamed_addr constant [107 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

; Function Attrs: nounwind uwtable
declare dso_local ptr @NetbufAlloc(i32 noundef) local_unnamed_addr #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

5:                                                ; preds = %3
  %.not19 = icmp eq ptr %0, null
  br i1 %.not19, label %9, label %6

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

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

10:                                               ; preds = %6, %9, %3
  %11 = icmp eq ptr %1, null
  br i1 %11, label %12, label %.thread

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %0, i64 132
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = add i32 %14, %2
  %16 = tail call ptr @NetbufAlloc(i32 noundef %15)
  %17 = icmp eq ptr %16, null
  br i1 %17, label %26, label %.thread

.thread:                                          ; preds = %10, %12
  %.01621 = phi ptr [ %16, %12 ], [ %1, %10 ]
  %18 = getelementptr inbounds i8, ptr %.01621, i64 56
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = tail call ptr @CopyMem(ptr noundef nonnull %18, ptr noundef nonnull %19, i64 noundef 64) #2
  tail call void @NetbufReserve(ptr noundef nonnull %.01621, i32 noundef %2)
  %21 = getelementptr inbounds i8, ptr %0, i64 132
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = tail call ptr @NetbufAllocSpace(ptr noundef nonnull %.01621, i32 noundef %22, i8 noundef zeroext 0)
  %24 = load i32, ptr %21, align 4, !tbaa !13
  %25 = tail call i32 @NetbufCopy(ptr noundef %0, i32 noundef 0, i32 noundef %24, ptr noundef %23)
  br label %26

26:                                               ; preds = %12, %.thread
  %.0 = phi ptr [ %.01621, %.thread ], [ null, %12 ]
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare dso_local void @NetbufReserve(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

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

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, !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, !7, i64 132}


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