MmPrefetchPagesEx

NTSTATUS __stdcall MmPrefetchPagesEx(UINT64 NumberOfLists, _READ_LIST **ReadLists, UINT64 *PrefetchPagesMax){
  __int64 v3; 
  void *v5; 
  __int64 v6; 
  void *v7; 
  _ETHREAD *CurrentThread; 
  int v9; 
  NTSTATUS v10; 
  _QWORD *v11; 
  INT64 *v12; 
  char *v13; 
  __int64 v14; 
  int List; 
  int v16; 
  char v18; 
  NTSTATUS v19; 
  unsigned int v20; 
  INT64 *v21; 
  int v22; 
  INT64 v23; 
  __int64 v24; 
  INT64 *v25; 
  __int64 v26; 
  PVOID *v27; 
  struct _SLIST_ENTRY **v28; 
  struct _SLIST_ENTRY *v29; 
  _SLIST_ENTRY *Next; 
  const char *a5; 
  int v32; 
  void *v34; 
  v3 = (unsigned int)NumberOfLists;
  if( (unsigned int)NumberOfLists > 0x1FFFFFFF )
    return -1073741585;
  LODWORD(v5) = MiAllocatePool((struct _SLIST_ENTRY *)0x40);
  v34 = v5;
  v7 = v5;
  if( !v5 )
    return -1073741670;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v9 = 0;
  v10 = 0;
  a5 = (const char *)CurrentThread;
  --*((_WORD *)CurrentThread + 242);
  if( (_DWORD)v3 )
  {
    v11 = v5;
    v12 = (INT64 *)v5;
    v13 = (char *)((char *)ReadLists - (_BYTE *)v5);
    v14 = (unsigned int)v3;
    do
    {
      List = MiPfPrepareReadList(*(UINT64 **)((char *)v11 + (_QWORD)v13), v12, PrefetchPagesMax);
      if( List < 0 )
      {
        v10 = List;
      }
      else
      {
        v16 = v9 | 1;
        if( !*v11 )
          v16 = v9;
        v9 = v16;
      }
      ++v12;
      ++v11;
      --v14;
    }
    while( v14 );
    v7 = v34;
    CurrentThread = (_ETHREAD *)a5;
  }
  if( (v9 & 1) == 0 )
  {
    KeLeaveCriticalRegionThread((__int64)CurrentThread);
    ExFreePoolWithTag(v7, 0);
    return v10;
  }
  ++*((_BYTE *)CurrentThread + 1310);
  v18 = v9 & 0xFE;
  v19 = 0;
  v20 = 0;
  if( !(_DWORD)v3 )
    goto LABEL_20;
  v21 = (INT64 *)v7;
  while( !*v21 )
  {
LABEL_19:
    ++v20;
    ++v21;
    if( v20 >= (unsigned int)v3 )
      goto LABEL_20;
  }
  *(_DWORD *)(*v21 + 104) = 0;
  MiPfPutPagesInTransition(*v21, PrefetchPagesMax, 0, v6, (const char *__ptr32)a5, v32);
  if( v22 >= 0 )
  {
    v23 = *v21;
    if( *(_QWORD *)(*v21 + 120) == *v21 + 120 )
    {
      MiReleaseReadListResources(v23);
      ExFreePoolWithTag((PVOID)*v21, 0);
      *v21 = 0i64;
    }
    else
    {
      v18 |= 1u;
      MiPfExecuteReadList(v23, 0, 0xFFFFFFFFui64, 0i64);
    }
    goto LABEL_19;
  }
  v19 = v22;
  while( v20 < (unsigned int)v3 )
  {
    if( *((_QWORD *)v7 + v20) )
    {
      while( 1 )
      {
        v28 = (struct _SLIST_ENTRY **)(*((_QWORD *)v7 + v20) + 120i64);
        v29 = *v28;
        if( *v28 == (struct _SLIST_ENTRY *)v28 )
          break;
        if( *((struct _SLIST_ENTRY ***)&v29->Next + 1) != v28 || (Next = v29->Next, *(&v29->Next->Next + 1) != v29) )
          __fastfail(3u);
        *v28 = Next;
        *((_QWORD *)&Next->Next + 1) = v28;
        MiFreeInPageSupportBlock(v29);
      }
      MiReleaseReadListResources(*((_QWORD *)v7 + v20));
      ExFreePoolWithTag(*((PVOID *)v7 + v20), 0);
      *((_QWORD *)v7 + v20) = 0i64;
    }
    ++v20;
  }
LABEL_20:
  v24 = v3;
  if( (v18 & 1) != 0 )
  {
    v19 = 0;
    if( (_DWORD)v3 )
    {
      v25 = (INT64 *)v7;
      v26 = v3;
      do
      {
        if( *v25 )
        {
          MiPfCompletePrefetchIos((_LIST_ENTRY *)(*v25 + 120), 0i64, 0i64);
          MiReleaseReadListResources(*v25);
        }
        ++v25;
        --v26;
      }
      while( v26 );
    }
  }
  KeLeaveCriticalRegionThread((__int64)CurrentThread);
  --*((_BYTE *)CurrentThread + 1310);
  if( (_DWORD)v3 )
  {
    v27 = (PVOID *)v7;
    do
    {
      if( *v27 )
        ExFreePoolWithTag(*v27, 0);
      ++v27;
      --v24;
    }
    while( v24 );
  }
  ExFreePoolWithTag(v7, 0);
  return v19;
}

Referenced by:

MmPrefetchPages
PfSnPrefetchSections
PfpPrefetchFiles
PfpPrefetchFilesTrickle