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

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

declare ptr @InitializeListHead(ptr noundef) #1

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

declare ptr @AllocatePool(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @NetbufClone(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, 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) #4
  br label %6

6:                                                ; preds = %1
  %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.NET_BUF, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = icmp eq i32 %15, 1718968942
  br i1 %16, label %18, label %17

17:                                               ; preds = %12, %9
  call void @DebugAssert(ptr noundef @.str, i64 noundef 246, ptr noundef @.str.7)
  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
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.NET_BUF, ptr %22, i32 0, i32 8
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = sub i32 %24, 1
  %26 = zext i32 %25 to i64
  %27 = mul i64 %26, 40
  %28 = add i64 176, %27
  %29 = call ptr @AllocatePool(i64 noundef %28)
  store ptr %29, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %21
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %91

33:                                               ; preds = %21
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.NET_BUF, ptr %34, i32 0, i32 0
  store i32 1718968942, ptr %35, align 8, !tbaa !9
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.NET_BUF, ptr %36, i32 0, i32 1
  store i64 1, ptr %37, align 8, !tbaa !15
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.NET_BUF, ptr %38, i32 0, i32 2
  %40 = call ptr @InitializeListHead(ptr noundef %39)
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.NET_BUF, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NET_BUF, ptr %43, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %42, ptr align 8 %44, i64 8, i1 false), !tbaa.struct !16
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.NET_BUF, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.NET_BUF, ptr %48, i32 0, i32 4
  store ptr %47, ptr %49, align 8, !tbaa !18
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.NET_BUF, ptr %50, i32 0, i32 6
  %52 = getelementptr inbounds [64 x i8], ptr %51, i64 0, i64 0
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.NET_BUF, ptr %53, i32 0, i32 6
  %55 = getelementptr inbounds [64 x i8], ptr %54, i64 0, i64 0
  %56 = call ptr @CopyMem(ptr noundef %52, ptr noundef %55, i64 noundef 64)
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.NET_BUF, ptr %57, i32 0, i32 7
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = getelementptr inbounds %struct.NET_VECTOR, ptr %59, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !20
  %62 = add nsw i64 %61, 1
  store i64 %62, ptr %60, align 8, !tbaa !20
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.NET_BUF, ptr %63, i32 0, i32 7
  %65 = load ptr, ptr %64, align 8, !tbaa !19
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.NET_BUF, ptr %66, i32 0, i32 7
  store ptr %65, ptr %67, align 8, !tbaa !19
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.NET_BUF, ptr %68, i32 0, i32 8
  %70 = load i32, ptr %69, align 8, !tbaa !14
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.NET_BUF, ptr %71, i32 0, i32 8
  store i32 %70, ptr %72, align 8, !tbaa !14
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.NET_BUF, ptr %73, i32 0, i32 9
  %75 = load i32, ptr %74, align 4, !tbaa !22
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.NET_BUF, ptr %76, i32 0, i32 9
  store i32 %75, ptr %77, align 4, !tbaa !22
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.NET_BUF, ptr %78, i32 0, i32 10
  %80 = getelementptr inbounds [1 x %struct.NET_BLOCK_OP], ptr %79, i64 0, i64 0
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.NET_BUF, ptr %81, i32 0, i32 10
  %83 = getelementptr inbounds [1 x %struct.NET_BLOCK_OP], ptr %82, i64 0, i64 0
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.NET_BUF, ptr %84, i32 0, i32 8
  %86 = load i32, ptr %85, align 8, !tbaa !14
  %87 = zext i32 %86 to i64
  %88 = mul i64 40, %87
  %89 = call ptr @CopyMem(ptr noundef %80, ptr noundef %83, i64 noundef %88)
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %90, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %91

91:                                               ; preds = %33, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %92 = load ptr, ptr %2, align 8
  ret ptr %92
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !12, i64 8, !13, 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}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!10, !11, i64 128}
!15 = !{!10, !12, i64 8}
!16 = !{i64 0, i64 8, !17}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !6, i64 40}
!19 = !{!10, !6, i64 120}
!20 = !{!21, !12, i64 8}
!21 = !{!"", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !7, i64 48}
!22 = !{!10, !11, 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

declare ptr @InitializeListHead(ptr noundef) local_unnamed_addr #0

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #0

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

3:                                                ; preds = %1
  %.not27 = icmp eq ptr %0, null
  br i1 %.not27, label %7, label %4

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

7:                                                ; preds = %4, %3
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 246, ptr noundef nonnull @.str.7) #2
  br label %8

8:                                                ; preds = %4, %7, %1
  %9 = getelementptr inbounds i8, ptr %0, i64 128
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = add i32 %10, -1
  %12 = zext i32 %11 to i64
  %13 = mul nuw nsw i64 %12, 40
  %14 = add nuw nsw i64 %13, 176
  %15 = tail call ptr @AllocatePool(i64 noundef %14) #2
  %16 = icmp eq ptr %15, null
  br i1 %16, label %44, label %17

17:                                               ; preds = %8
  store i32 1718968942, ptr %15, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %15, i64 8
  store i64 1, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %15, i64 16
  %20 = tail call ptr @InitializeListHead(ptr noundef nonnull %19) #2
  %21 = getelementptr inbounds i8, ptr %15, i64 32
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  %23 = load i64, ptr %22, align 8, !tbaa !15
  store i64 %23, ptr %21, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %0, i64 40
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %15, i64 40
  store ptr %25, ptr %26, align 8, !tbaa !16
  %27 = getelementptr inbounds i8, ptr %15, i64 56
  %28 = getelementptr inbounds i8, ptr %0, i64 56
  %29 = tail call ptr @CopyMem(ptr noundef nonnull %27, ptr noundef nonnull %28, i64 noundef 64) #2
  %30 = getelementptr inbounds i8, ptr %0, i64 120
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  %33 = load i64, ptr %32, align 8, !tbaa !18
  %34 = add nsw i64 %33, 1
  store i64 %34, ptr %32, align 8, !tbaa !18
  %35 = getelementptr inbounds i8, ptr %15, i64 120
  store ptr %31, ptr %35, align 8, !tbaa !17
  %36 = getelementptr inbounds i8, ptr %15, i64 128
  %37 = load <2 x i32>, ptr %9, align 8, !tbaa !20
  store <2 x i32> %37, ptr %36, align 8, !tbaa !20
  %38 = getelementptr inbounds i8, ptr %15, i64 136
  %39 = getelementptr inbounds i8, ptr %0, i64 136
  %40 = extractelement <2 x i32> %37, i64 0
  %41 = zext i32 %40 to i64
  %42 = mul nuw nsw i64 %41, 40
  %43 = tail call ptr @CopyMem(ptr noundef nonnull %38, ptr noundef nonnull %39, i64 noundef %42) #2
  br label %44

44:                                               ; preds = %8, %17
  ret ptr %15
}

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


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