/* This function remove duplicate and invalid offsets in Offsets. Invalid offset means MAX_UINT64 in Offsets. */
VOID RemoveDuplicateAndInvalidOffset(IN UINT64 *Offsets, IN OUT UINTN *Count)
/* This function remove duplicate and invalid offsets in Offsets. Invalid offset means MAX_UINT64 in Offsets. */
VOID RemoveDuplicateAndInvalidOffset(IN UINT64 *Offsets, IN OUT UINTN *Count)
{
  UINTN   Index;
  UINTN   NewCount;
  UINT64  LastOffset;
  UINT64  QuickSortBuffer;
  QuickSort (
    Offsets,
    *Count,
    sizeof (UINT64),
    MicrocodePatchOffsetCompareFunction,
    (VOID *)&QuickSortBuffer
    );
  NewCount   = 0;
  LastOffset = MAX_UINT64;
  for (Index = 0; Index < *Count; Index++) {
    if (Offsets[Index] == MAX_UINT64) {
      break;
    }
    if (Offsets[Index] != LastOffset) {
      LastOffset        = Offsets[Index];
      Offsets[NewCount] = Offsets[Index];
      NewCount++;
    }
  }
  *Count = NewCount;
}