; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/Ip6Dxe (Ip6WrapRxData)

; 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.IP6_RXDATA_WRAP = type { %struct._LIST_ENTRY, ptr, ptr, %struct._EFI_IP6_RECEIVE_DATA }
%struct._EFI_IP6_RECEIVE_DATA = type { %struct.EFI_TIME, ptr, i32, ptr, i32, i32, [1 x %struct._EFI_IP6_FRAGMENT_DATA] }
%struct.EFI_TIME = type { i16, i8, i8, i8, i8, i8, i8, i32, i16, i8, i8 }
%struct._EFI_IP6_FRAGMENT_DATA = type { i32, ptr }
%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 [130 x i8], align 1
@gBS = external global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [31 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 ptr @AllocatePool(i64 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 void @FreePool(ptr noundef) #1

declare zeroext i8 @DebugAssertEnabled() #1

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

declare ptr @Ip6NtohHead(ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip6WrapRxData(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.NET_BUF, ptr %10, i32 0, i32 8
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = sub i32 %12, 1
  %14 = zext i32 %13 to i64
  %15 = mul i64 16, %14
  %16 = add i64 96, %15
  %17 = call ptr @AllocatePool(i64 noundef %16)
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %87

21:                                               ; preds = %2
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.IP6_RXDATA_WRAP, ptr %22, i32 0, i32 0
  %24 = call ptr @InitializeListHead(ptr noundef %23)
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.IP6_RXDATA_WRAP, ptr %26, i32 0, i32 1
  store ptr %25, ptr %27, align 8, !tbaa !14
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.IP6_RXDATA_WRAP, ptr %29, i32 0, i32 2
  store ptr %28, ptr %30, align 8, !tbaa !19
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.IP6_RXDATA_WRAP, ptr %31, i32 0, i32 3
  store ptr %32, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._EFI_IP6_RECEIVE_DATA, ptr %33, i32 0, i32 0
  %35 = call ptr @ZeroMem(ptr noundef %34, i64 noundef 16)
  %36 = load ptr, ptr @gBS, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %36, i32 0, i32 8
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._EFI_IP6_RECEIVE_DATA, ptr %40, i32 0, i32 1
  %42 = call i64 %38(i32 noundef 512, i64 noundef 16, ptr noundef @Ip6OnRecyclePacket, ptr noundef %39, ptr noundef %41)
  store i64 %42, ptr %8, align 8, !tbaa !23
  %43 = load i64, ptr %8, align 8, !tbaa !23
  %44 = icmp slt i64 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %21
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  call void @FreePool(ptr noundef %46)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %87

47:                                               ; preds = %21
  br label %48

48:                                               ; preds = %47
  %49 = call zeroext i8 @DebugAssertEnabled()
  %50 = icmp ne i8 %49, 0
  br i1 %50, label %51, label %58

51:                                               ; preds = %48
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.NET_BUF, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !24
  %55 = icmp ne ptr %54, null
  br i1 %55, label %57, label %56

56:                                               ; preds = %51
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1247, ptr noundef @.str.9)
  br label %57

57:                                               ; preds = %56, %51
  br label %58

58:                                               ; preds = %57, %48
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._EFI_IP6_RECEIVE_DATA, ptr %61, i32 0, i32 2
  store i32 40, ptr %62, align 8, !tbaa !25
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.NET_BUF, ptr %63, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !24
  %66 = call ptr @Ip6NtohHead(ptr noundef %65)
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._EFI_IP6_RECEIVE_DATA, ptr %67, i32 0, i32 3
  store ptr %66, ptr %68, align 8, !tbaa !26
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.NET_BUF, ptr %69, i32 0, i32 9
  %71 = load i32, ptr %70, align 4, !tbaa !27
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._EFI_IP6_RECEIVE_DATA, ptr %72, i32 0, i32 4
  store i32 %71, ptr %73, align 8, !tbaa !28
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.NET_BUF, ptr %74, i32 0, i32 8
  %76 = load i32, ptr %75, align 8, !tbaa !9
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._EFI_IP6_RECEIVE_DATA, ptr %77, i32 0, i32 5
  store i32 %76, ptr %78, align 4, !tbaa !29
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._EFI_IP6_RECEIVE_DATA, ptr %80, i32 0, i32 6
  %82 = getelementptr inbounds [1 x %struct._EFI_IP6_FRAGMENT_DATA], ptr %81, i64 0, i64 0
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._EFI_IP6_RECEIVE_DATA, ptr %83, i32 0, i32 5
  %85 = call i64 @NetbufBuildExt(ptr noundef %79, ptr noundef %82, ptr noundef %84)
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %86, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %87

87:                                               ; preds = %60, %45, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %88 = load ptr, ptr %3, align 8
  ret ptr %88
}

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 128}
!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 = !{!15, !6, i64 16}
!15 = !{!"", !13, i64 0, !6, i64 16, !6, i64 24, !16, i64 32}
!16 = !{!"_EFI_IP6_RECEIVE_DATA", !17, i64 0, !6, i64 16, !11, i64 24, !6, i64 32, !11, i64 40, !11, i64 44, !7, i64 48}
!17 = !{!"", !18, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !11, i64 8, !18, i64 12, !7, i64 14, !7, i64 15}
!18 = !{!"short", !7, i64 0}
!19 = !{!15, !6, i64 24}
!20 = !{!21, !6, i64 80}
!21 = !{!"", !22, 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}
!22 = !{!"", !12, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!23 = !{!12, !12, i64 0}
!24 = !{!7, !7, i64 0}
!25 = !{!16, !11, i64 24}
!26 = !{!16, !6, i64 32}
!27 = !{!10, !11, i64 132}
!28 = !{!16, !11, i64 40}
!29 = !{!16, !11, i64 44}


; 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 [130 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [31 x i8], align 1

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #0

declare ptr @InitializeListHead(ptr noundef) local_unnamed_addr #0

declare void @FreePool(ptr noundef) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

declare ptr @Ip6NtohHead(ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip6WrapRxData(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 128
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = add i32 %4, -1
  %6 = zext i32 %5 to i64
  %7 = shl nuw nsw i64 %6, 4
  %8 = add nuw nsw i64 %7, 96
  %9 = tail call ptr @AllocatePool(i64 noundef %8) #2
  %10 = icmp eq ptr %9, null
  br i1 %10, label %42, label %11

11:                                               ; preds = %2
  %12 = tail call ptr @InitializeListHead(ptr noundef nonnull %9) #2
  %13 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %0, ptr %13, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %9, i64 24
  store ptr %1, ptr %14, align 8, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %9, i64 32
  %16 = tail call ptr @ZeroMem(ptr noundef nonnull %15, i64 noundef 16) #2
  %17 = load ptr, ptr @gBS, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %17, i64 80
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %9, i64 48
  %21 = tail call i64 %19(i32 noundef 512, i64 noundef 16, ptr noundef nonnull @Ip6OnRecyclePacket, ptr noundef nonnull %9, ptr noundef nonnull %20) #2
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %11
  tail call void @FreePool(ptr noundef nonnull %9) #2
  br label %42

24:                                               ; preds = %11
  %25 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %25, 0
  br i1 %.not, label %30, label %26

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %1, i64 32
  %28 = load ptr, ptr %27, align 8, !tbaa !23
  %.not26 = icmp eq ptr %28, null
  br i1 %.not26, label %29, label %30

29:                                               ; preds = %26
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1247, ptr noundef nonnull @.str.9) #2
  br label %30

30:                                               ; preds = %26, %29, %24
  %31 = getelementptr inbounds i8, ptr %9, i64 56
  store i32 40, ptr %31, align 8, !tbaa !24
  %32 = getelementptr inbounds i8, ptr %1, i64 32
  %33 = load ptr, ptr %32, align 8, !tbaa !23
  %34 = tail call ptr @Ip6NtohHead(ptr noundef %33) #2
  %35 = getelementptr inbounds i8, ptr %9, i64 64
  store ptr %34, ptr %35, align 8, !tbaa !25
  %36 = getelementptr inbounds i8, ptr %9, i64 72
  %37 = getelementptr inbounds i8, ptr %9, i64 76
  %38 = load <2 x i32>, ptr %3, align 8, !tbaa !26
  %39 = shufflevector <2 x i32> %38, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  store <2 x i32> %39, ptr %36, align 8, !tbaa !26
  %40 = getelementptr inbounds i8, ptr %9, i64 80
  %41 = tail call i64 @NetbufBuildExt(ptr noundef nonnull %1, ptr noundef nonnull %40, ptr noundef nonnull %37) #2
  br label %42

42:                                               ; preds = %2, %30, %23
  %.0 = phi ptr [ null, %23 ], [ %9, %30 ], [ null, %2 ]
  ret ptr %.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 128}
!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, !12, i64 16}
!14 = !{!"", !11, i64 0, !12, i64 16, !12, i64 24, !15, i64 32}
!15 = !{!"_EFI_IP6_RECEIVE_DATA", !16, i64 0, !12, i64 16, !7, i64 24, !12, i64 32, !7, i64 40, !7, i64 44, !8, i64 48}
!16 = !{!"", !17, i64 0, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !7, i64 8, !17, i64 12, !8, i64 14, !8, i64 15}
!17 = !{!"short", !8, i64 0}
!18 = !{!14, !12, i64 24}
!19 = !{!12, !12, i64 0}
!20 = !{!21, !12, i64 80}
!21 = !{!"", !22, i64 0, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !12, i64 224, !12, i64 232, !12, i64 240, !12, i64 248, !12, i64 256, !12, i64 264, !12, i64 272, !12, i64 280, !12, i64 288, !12, i64 296, !12, i64 304, !12, i64 312, !12, i64 320, !12, i64 328, !12, i64 336, !12, i64 344, !12, i64 352, !12, i64 360, !12, i64 368}
!22 = !{!"", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!23 = !{!8, !8, i64 0}
!24 = !{!15, !7, i64 24}
!25 = !{!15, !12, i64 32}
!26 = !{!7, !7, i64 0}


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