/* This function will check if there're existing Guard pages of adjacent memory blocks, and try to use it as the Guard page of the memory to be allocated. */
UINT64 AdjustMemoryS(IN UINT64 Start, IN UINT64 Size, IN UINT64 SizeRequested)
/* This function will check if there're existing Guard pages of adjacent memory blocks, and try to use it as the Guard page of the memory to be allocated. */
UINT64 AdjustMemoryS(IN UINT64 Start, IN UINT64 Size, IN UINT64 SizeRequested)
{
  UINT64  Target;
  if ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0) {
    SizeRequested = ALIGN_VALUE (SizeRequested, 8);
  }
  Target = Start + Size - SizeRequested;
  ASSERT (Target >= Start);
  if (Target == 0) {
    return 0;
  }
  if (!IsGuardPage (Start + Size)) {
    Target -= EFI_PAGES_TO_SIZE (1);
  }
  if (Target < Start) {
    return 0;
  }
  if (Target == Start) {
    if (!IsGuardPage (Target - EFI_PAGES_TO_SIZE (1))) {
      return 0;
    }
  }
  return Target + SizeRequested - 1;
}