/* Return the maximum number of new entries required to describe the code and data sections of all images covered by the input OldRecord. */
STATIC UINTN GetMaxSplitRecordCount(IN EFI_MEMORY_DESCRIPTOR *OldRecord, IN LIST_ENTRY *ImageRecordList)
/* Return the maximum number of new entries required to describe the code and data sections of all images covered by the input OldRecord. */
STATIC UINTN GetMaxSplitRecordCount(IN EFI_MEMORY_DESCRIPTOR *OldRecord, IN LIST_ENTRY *ImageRecordList)
{
  IMAGE_PROPERTIES_RECORD  *ImageRecord;
  UINTN                    SplitRecordCount;
  UINT64                   PhysicalStart;
  UINT64                   PhysicalEnd;
  SplitRecordCount = 0;
  PhysicalStart    = OldRecord->PhysicalStart;
  PhysicalEnd      = OldRecord->PhysicalStart + EfiPagesToSize (OldRecord->NumberOfPages);
  do {
    ImageRecord = GetImageRecordByAddress (PhysicalStart, PhysicalEnd - PhysicalStart, ImageRecordList);
    if (ImageRecord == NULL) {
      break;
    }
    SplitRecordCount += (2 * ImageRecord->CodeSegmentCount + 3);
    PhysicalStart     = ImageRecord->ImageBase + ImageRecord->ImageSize;
  } while ((ImageRecord != NULL) && (PhysicalStart < PhysicalEnd));
  if (SplitRecordCount != 0) {
    SplitRecordCount--;
  }
  return SplitRecordCount;
}