MiPrefetchVirtualMemory

INT64 __fastcall MiPrefetchVirtualMemory(UINT64 rcx0, INT64 a2, CHAR *a3, INT64 a4){
  int v4; 
  _ETHREAD *CurrentThread; 
  unsigned __int8 v8; 
  __int64 v9; 
  char v10; 
  __int64 v11; 
  __int64 v12; 
  ULONG_PTR *v13; 
  CHAR *v14; 
  _MMPTE *PteLimit; 
  unsigned __int64 v16; 
  _MMPTE *PteBase; 
  INT64 v18; 
  __int64 v19; 
  unsigned __int64 v20; 
  UINT64 LeafVa; 
  ULONG_PTR v22; 
  ULONG_PTR v23; 
  unsigned __int64 v24; 
  unsigned __int64 v25; 
  NTSTATUS v26; 
  __int64 v27; 
  __int64 v28; 
  int v29; 
  int v30; 
  NTSTATUS v31; 
  unsigned __int64 v33; 
  int v34; 
  int v35; 
  _LIST_ENTRY *p_IssuedSupportHead; 
  _LIST_ENTRY *Flink; 
  NTSTATUS v38; 
  int v39; 
  INT64 a1; 
  INT64 v41; 
  UINT64 v42; 
  unsigned __int64 v43; 
  unsigned __int64 v44; 
  _LIST_ENTRY IssuedSupportHead; 
  _LIST_ENTRY BuiltSupportHead; 
  unsigned __int64 v47; 
  int v48; 
  int v49; 
  __int64 v50; 
  INT64 v51[2]; 
  __int128 v52; 
  __int128 v53; 
  int v54; 
  _ETHREAD *v55; 
  int v56; 
  v56 = 0;
  a1 = 1i64;
  v4 = a4;
  v49 = 0;
  v43 = 0i64;
  v44 = 0i64;
  IssuedSupportHead.Blink = &IssuedSupportHead;
  IssuedSupportHead.Flink = &IssuedSupportHead;
  BuiltSupportHead.Blink = &BuiltSupportHead;
  BuiltSupportHead.Flink = &BuiltSupportHead;
  v41 = a2;
  v42 = rcx0;
  v47 = 0i64;
  v50 = 0i64;
  v48 = a4;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v54 = 0;
  v55 = CurrentThread;
  v8 = *((_BYTE *)CurrentThread + 1310);
  v9 = *((_QWORD *)CurrentThread + 23);
  if( v8 >= 2u )
    return 3221225626i64;
  if( a3 == (CHAR *)1 )
  {
    v13 = &MiSystemPartition;
LABEL_7:
    *((_BYTE *)CurrentThread + 1310) = v8 + 1;
    --*((_WORD *)CurrentThread + 242);
    *(_OWORD *)v51 = 0i64;
    v52 = 0i64;
    v53 = 0i64;
    if( v43 < v42 )
    {
      v14 = MiState;
      PteLimit = MmGetPteLimit();
      while( 1 )
      {
        v16 = 0xFFFF800000000000ui64;
        PteBase = MmGetPteBase();
        if( (v48 & 0x40000) != 0 && (*((_DWORD *)CurrentThread + 324) & 1) != 0 )
        {
          v30 = v54;
          v29 = -1073741749;
          goto LABEL_37;
        }
        v18 = a2 + 16 * v43;
        v19 = *(_QWORD *)(v18 + 8);
        if( v44 >= ((unsigned __int64)(*(_DWORD *)v18 & 0xFFF) + v19 + 4095) >> 12 )
          goto LABEL_63;
        if( !v19 )
        {
          v43 = v42;
          v44 = 0i64;
LABEL_82:
          CurrentThread = v55;
LABEL_36:
          v29 = v56;
          v30 = v54;
          goto LABEL_37;
        }
        if( (v20 = *(_QWORD *)v18 + (v44 << 12), LeafVa = v20, v20 >= qword_140C4F878) && v20 <= qword_140C4E0A8
          || v20 >= 0xFFFF800000000000ui64
          && (MiVaIsUltra(*(_QWORD *)v18 + (v44 << 12))
           || v14[((v20 >> 39) & 0x1FF) + 12296] == 1 && v20 >= qword_140C4DB20 && v20 < qword_140C4DB20 + 290816) )
        {
LABEL_63:
          MiAdvanceFaultList(&a1);
          goto LABEL_35;
        }
        if( v20 >= (unsigned __int64)PteBase && v20 <= (unsigned __int64)PteLimit )
        {
          if( v20 >= (unsigned __int64)PteBase + 0x4000000000i64 )
            goto LABEL_63;
          LeafVa = MiGetLeafVa(v20);
        }
        if( LeafVa < v16 )
          goto LABEL_16;
        if( v14[((LeafVa >> 39) & 0x1FF) + 12296] != 1 )
          break;
        if( a3 == (CHAR *)1 || (a3[184] & 7) != 1 )
          goto LABEL_63;
LABEL_18:
        if( (v48 & 0x80u) == 0 )
        {
          if( !(unsigned int)MiSufficientAvailablePages((INT64)v13, 0x120ui64) )
            goto LABEL_82;
          v22 = v13[949];
          v23 = v13[933];
          if( v23 > v22 || v22 - v23 < 0x1080 || (__int64)v13[896] < 288 )
            goto LABEL_82;
        }
        if( (v4 & 0x20000) != 0 )
          MiPrefetchPreallocatePages((INT64)v51, (INT64)&a1, (_MI_PARTITION *)v13, (INT64)a3, v18, v20);
        v24 = v43;
        v25 = v44;
        v26 = MmAccessFault(0i64, (PVOID)v20, 0, (char *)&a1 + 1);
        if( BYTE1(a1) == 2 )
        {
          if( (v48 & 0x80u) == 0 )
            goto LABEL_82;
        }
        else if( BYTE1(a1) != 1 )
        {
          if( v43 == v24 && v44 == v25 )
          {
            v27 = *(_QWORD *)(v41 + 16 * v43 + 8) + 4095i64;
            v28 = *(_DWORD *)(v41 + 16 * v43) & 0xFFF;
            if( ++v44 == (unsigned __int64)(v27 + v28) >> 12 )
            {
              v33 = v43 + 1;
              v43 = v33;
              v44 = 0i64;
              if( v33 < v42 && !*(_QWORD *)(v41 + 16 * v33 + 8) )
                v43 = v42;
            }
          }
          goto LABEL_30;
        }
        BYTE1(a1) = 0;
LABEL_30:
        if( v26 < 0 )
        {
          v54 = v26;
          v30 = v26;
          if( v26 != -1073741819 || v43 == v42 || !(unsigned int)MiLeapPrefetch(&a1, 0i64) )
          {
            CurrentThread = v55;
            v29 = v56;
            goto LABEL_37;
          }
        }
        if( v47 >= 0x200000 )
          MiPfCoalesceAndIssueIOs((union _MM_STORE_KEY *)&BuiltSupportHead, (union _SM_PAGE_KEY *)&IssuedSupportHead);
        if( (v48 & 0x400) != 0 )
        {
          v34 = 0;
          v35 = 0;
          while( 1 )
          {
            p_IssuedSupportHead = &IssuedSupportHead;
            if( !v35 )
              p_IssuedSupportHead = &BuiltSupportHead;
            Flink = p_IssuedSupportHead->Flink;
            if( p_IssuedSupportHead->Flink != p_IssuedSupportHead )
              break;
LABEL_70:
            if( (unsigned int)++v35 >= 2 )
              goto LABEL_34;
          }
          while( ++v34 != 4 )
          {
            Flink = Flink->Flink;
            if( Flink == p_IssuedSupportHead )
              goto LABEL_70;
          }
          v38 = MiPfCompletePrefetchIos(&IssuedSupportHead, &BuiltSupportHead, (_MMSUPPORT_INSTANCE *)a3);
          if( v38 < 0 )
          {
            v39 = v56;
            if( v56 >= 0 )
              v39 = v38;
            v56 = v39;
          }
          v47 = 0i64;
        }
LABEL_34:
        v14 = MiState;
        PteLimit = MmGetPteLimit();
LABEL_35:
        CurrentThread = v55;
        if( v43 >= v42 )
          goto LABEL_36;
      }
      if( LeafVa >= v16 )
      {
        if( a3 != (CHAR *)1 )
          goto LABEL_63;
        goto LABEL_18;
      }
LABEL_16:
      if( a3 == (CHAR *)1 || (a3[184] & 7) != 0 )
        goto LABEL_63;
      goto LABEL_18;
    }
    v29 = 0;
    v30 = 0;
LABEL_37:
    if( (v4 & 0x20000) != 0 )
      MiPrefetchReleasePreallocatedPages((INT64)v51, (INT64)&a1, (INT64)v13, 1i64);
    v31 = MiPfCompletePrefetchIos(&IssuedSupportHead, &BuiltSupportHead, (_MMSUPPORT_INSTANCE *)a3);
    if( v31 < 0 )
    {
      if( v29 < 0 )
      {
LABEL_42:
        KeLeaveCriticalRegionThread((__int64)CurrentThread);
        --*((_BYTE *)CurrentThread + 1310);
        return(unsigned int)v29;
      }
      v29 = v31;
    }
    if( v29 >= 0 && v30 < 0 && (v48 & 0x8000) != 0 )
      v29 = v30;
    goto LABEL_42;
  }
  v10 = a3[184] & 7;
  if( v10 == 1 )
  {
    v11 = *(_QWORD *)(v9 + 1368);
    if( v11 )
    {
      v12 = *(unsigned __int16 *)(v11 + 430);
LABEL_6:
      v13 = *(ULONG_PTR **)(qword_140C4E388 + 8 * v12);
      goto LABEL_7;
    }
  }
  else if( !v10 )
  {
    v12 = *(unsigned __int16 *)(v9 + 1838);
    goto LABEL_6;
  }
  return 3221225485i64;
}

Referenced by:

MiBuildForkPte
MiInPageSingleKernelStack
MiPrefetchDriverPages
MiPrefetchRestOfCluster
MmCopyMemory
MmPrefetchVirtualMemory
NtSetInformationVirtualMemory