MiFlushTbAsNeeded

void __fastcall MiFlushTbAsNeeded(ULONG_PTR BugCheckParameter2, unsigned __int64 a2, int a3, int a4){
  int v8; 
  int v9; 
  unsigned __int64 v10; 
  ULONG_PTR BugCheckParameter4; 
  ULONG_PTR v12; 
  INT64 v13[4]; 
  INT64 result[20]; 
  memset((INT64)result, 0i64);
  v13[1] = 20i64;
  v13[0] = (unsigned int)a3;
  v8 = 0;
  v9 = 0;
  v13[2] = 0i64;
  v10 = 0i64;
  for( v13[3] = 0i64; v10 < a2; BugCheckParameter2 += 8i64 )
  {
    BugCheckParameter4 = *(_QWORD *)BugCheckParameter2;
    if( (*(_QWORD *)BugCheckParameter2 & 0xC01i64) == 0 && (*(_QWORD *)BugCheckParameter2 & 0x3E0i64) == 0 )
    {
      if( qword_140C4DC80 && (BugCheckParameter4 & 0x10) == 0 )
        BugCheckParameter4 &= ~qword_140C4DC80;
      v12 = HIDWORD(BugCheckParameter4);
      *(_QWORD *)BugCheckParameter2 = ZeroPte;
      if( (_DWORD)v12 )
      {
        if( (_DWORD)v12 == v8 )
        {
          if( v9 == 1 )
            MiInsertTbFlushEntry(
              (INT64)v13,
              (__int64)((BugCheckParameter2 << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16,
              1i64,
              0i64);
        }
        else
        {
          if( MiCompareTbFlushTimeStamp((unsigned int)v12, 0xFFFFFFFFui64) )
          {
            MiInsertTbFlushEntry(
              (INT64)v13,
              (__int64)((BugCheckParameter2 << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16,
              1i64,
              0i64);
            v9 = 1;
          }
          else
          {
            v9 = 0;
          }
          v8 = v12;
        }
      }
      else
      {
        v9 = 0;
        v8 = 0;
      }
    }
    else if( !a4 )
    {
      KeBugCheckEx(0x1Au, 0x5100ui64, BugCheckParameter2, a2 - v10, BugCheckParameter4);
    }
    ++v10;
  }
  MiFlushTbList((__int64)v13);
}

Referenced by:

MiLinkPoolCommitChain
MiReservePtes