/* If FirstEntry is NULL, then ASSERT(). If SecondEntry is NULL, then ASSERT(). If PcdVerifyNodeInList is TRUE and SecondEntry and FirstEntry are not in the same linked list, then ASSERT(). If PcdMaximumLinkedListLength is not zero, and the number of nodes in the linked list containing the FirstEntry and SecondEntry nodes, including the FirstEntry and SecondEntry nodes, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT(). */
LIST_ENTRY* EFIAPI SwapListEntries(IN OUT LIST_ENTRY *FirstEntry, IN OUT LIST_ENTRY *SecondEntry)
/* If FirstEntry is NULL, then ASSERT(). If SecondEntry is NULL, then ASSERT(). If PcdVerifyNodeInList is TRUE and SecondEntry and FirstEntry are not in the same linked list, then ASSERT(). If PcdMaximumLinkedListLength is not zero, and the number of nodes in the linked list containing the FirstEntry and SecondEntry nodes, including the FirstEntry and SecondEntry nodes, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT(). */
LIST_ENTRY* EFIAPI SwapListEntries(IN OUT LIST_ENTRY *FirstEntry, IN OUT LIST_ENTRY *SecondEntry)
{
  LIST_ENTRY  *Ptr;
  if (FirstEntry == SecondEntry) {
    return SecondEntry;
  }
  ASSERT_VERIFY_NODE_IN_VALID_LIST (FirstEntry, SecondEntry, TRUE);
  Ptr = RemoveEntryList (FirstEntry);
  if (Ptr->BackLink == SecondEntry) {
    return InsertTailList (SecondEntry, FirstEntry);
  }
  if (Ptr == InsertHeadList (SecondEntry, FirstEntry)) {
    return Ptr;
  }
  RemoveEntryList (SecondEntry);
  InsertTailList (Ptr, SecondEntry);
  return SecondEntry;
}