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

; 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._UDP4_RXDATA_WRAP_ = type { %struct._LIST_ENTRY, ptr, i32, %struct.EFI_UDP4_RECEIVE_DATA }
%struct.EFI_UDP4_RECEIVE_DATA = type { %struct.EFI_TIME, ptr, %struct.EFI_UDP4_SESSION_DATA, i32, i32, [1 x %struct.EFI_UDP4_FRAGMENT_DATA] }
%struct.EFI_TIME = type { i16, i8, i8, i8, i8, i8, i8, i32, i16, i8, i8 }
%struct.EFI_UDP4_SESSION_DATA = type { %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct.EFI_UDP4_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 }
%struct._UDP4_INSTANCE_DATA_ = type { i32, %struct._LIST_ENTRY, ptr, %struct._EFI_UDP4_PROTOCOL, %struct.EFI_UDP4_CONFIG_DATA, ptr, i8, i8, %struct.NET_MAP, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i16, i64, ptr, i8 }
%struct._EFI_UDP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_UDP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, i8, i32, i32, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16 }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }

@gBS = external global ptr, align 8

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

declare ptr @InitializeListHead(ptr noundef) #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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 void @Udp4RecycleRxDataWrap(ptr noundef, ptr noundef) #2

declare void @FreePool(ptr noundef) #1

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

21:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %53

22:                                               ; preds = %3
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._UDP4_RXDATA_WRAP_, ptr %23, i32 0, i32 0
  %25 = call ptr @InitializeListHead(ptr noundef %24)
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._UDP4_RXDATA_WRAP_, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call ptr @CopyMem(ptr noundef %27, ptr noundef %28, i64 noundef 64)
  %30 = load ptr, ptr @gBS, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %30, i32 0, i32 8
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._UDP4_RXDATA_WRAP_, ptr %34, i32 0, i32 3
  %36 = getelementptr inbounds %struct.EFI_UDP4_RECEIVE_DATA, ptr %35, i32 0, i32 1
  %37 = call i64 %32(i32 noundef 512, i64 noundef 16, ptr noundef @Udp4RecycleRxDataWrap, ptr noundef %33, ptr noundef %36)
  store i64 %37, ptr %8, align 8, !tbaa !17
  %38 = load i64, ptr %8, align 8, !tbaa !17
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %22
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  call void @FreePool(ptr noundef %41)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %53

42:                                               ; preds = %22
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._UDP4_RXDATA_WRAP_, ptr %44, i32 0, i32 1
  store ptr %43, ptr %45, align 8, !tbaa !18
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %46, i32 0, i32 4
  %48 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %47, i32 0, i32 7
  %49 = load i32, ptr %48, align 8, !tbaa !25
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._UDP4_RXDATA_WRAP_, ptr %50, i32 0, i32 2
  store i32 %49, ptr %51, align 8, !tbaa !30
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %52, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %53

53:                                               ; preds = %42, %40, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %54 = load ptr, ptr %4, align 8
  ret ptr %54
}

declare ptr @AllocatePool(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 = { 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 80}
!15 = !{!"", !16, 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}
!16 = !{!"", !12, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!17 = !{!12, !12, i64 0}
!18 = !{!19, !6, i64 16}
!19 = !{!"_UDP4_RXDATA_WRAP_", !13, i64 0, !6, i64 16, !11, i64 24, !20, i64 32}
!20 = !{!"", !21, i64 0, !6, i64 16, !23, i64 24, !11, i64 36, !11, i64 40, !7, i64 48}
!21 = !{!"", !22, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !11, i64 8, !22, i64 12, !7, i64 14, !7, i64 15}
!22 = !{!"short", !7, i64 0}
!23 = !{!"", !24, i64 0, !22, i64 4, !24, i64 6, !22, i64 10}
!24 = !{!"", !7, i64 0}
!25 = !{!26, !11, i64 104}
!26 = !{!"_UDP4_INSTANCE_DATA_", !11, i64 0, !13, i64 8, !6, i64 24, !27, i64 32, !28, i64 96, !6, i64 136, !7, i64 144, !7, i64 145, !29, i64 152, !29, i64 192, !29, i64 232, !13, i64 272, !13, i64 288, !22, i64 304, !12, i64 312, !6, i64 320, !7, i64 328}
!27 = !{!"_EFI_UDP4_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!28 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !11, i64 8, !11, i64 12, !7, i64 16, !24, i64 17, !24, i64 21, !22, i64 26, !24, i64 28, !22, i64 32}
!29 = !{!"", !13, i64 0, !13, i64 16, !12, i64 32}
!30 = !{!19, !11, i64 24}


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

@gBS = external local_unnamed_addr global ptr, align 8

declare ptr @InitializeListHead(ptr noundef) local_unnamed_addr #0

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

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

declare void @FreePool(ptr noundef) local_unnamed_addr #0

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

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

22:                                               ; preds = %12
  tail call void @FreePool(ptr noundef nonnull %10) #2
  br label %28

23:                                               ; preds = %12
  %24 = getelementptr inbounds i8, ptr %10, i64 16
  store ptr %1, ptr %24, align 8, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %0, i64 104
  %26 = load i32, ptr %25, align 8, !tbaa !24
  %27 = getelementptr inbounds i8, ptr %10, i64 24
  store i32 %26, ptr %27, align 8, !tbaa !29
  br label %28

28:                                               ; preds = %3, %23, %22
  %.0 = phi ptr [ null, %22 ], [ %10, %23 ], [ null, %3 ]
  ret ptr %.0
}

declare ptr @AllocatePool(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 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 = !{!12, !12, i64 0}
!14 = !{!15, !12, i64 80}
!15 = !{!"", !16, 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}
!16 = !{!"", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!17 = !{!18, !12, i64 16}
!18 = !{!"_UDP4_RXDATA_WRAP_", !11, i64 0, !12, i64 16, !7, i64 24, !19, i64 32}
!19 = !{!"", !20, i64 0, !12, i64 16, !22, i64 24, !7, i64 36, !7, i64 40, !8, i64 48}
!20 = !{!"", !21, i64 0, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !7, i64 8, !21, i64 12, !8, i64 14, !8, i64 15}
!21 = !{!"short", !8, i64 0}
!22 = !{!"", !23, i64 0, !21, i64 4, !23, i64 6, !21, i64 10}
!23 = !{!"", !8, i64 0}
!24 = !{!25, !7, i64 104}
!25 = !{!"_UDP4_INSTANCE_DATA_", !7, i64 0, !11, i64 8, !12, i64 24, !26, i64 32, !27, i64 96, !12, i64 136, !8, i64 144, !8, i64 145, !28, i64 152, !28, i64 192, !28, i64 232, !11, i64 272, !11, i64 288, !21, i64 304, !10, i64 312, !12, i64 320, !8, i64 328}
!26 = !{!"_EFI_UDP4_PROTOCOL", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56}
!27 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6, !7, i64 8, !7, i64 12, !8, i64 16, !23, i64 17, !23, i64 21, !21, i64 26, !23, i64 28, !21, i64 32}
!28 = !{!"", !11, i64 0, !11, i64 16, !10, i64 32}
!29 = !{!18, !7, i64 24}


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