KeFlushMultipleRangeTb

VOID __fastcall KeFlushMultipleRangeTb(UINT64 a1, UINT64 *a2, UINT64 a3, UINT64 a4){
  int v4; 
  unsigned int v5; 
  unsigned int v6; 
  __int64 v7; 
  char v9; 
  unsigned __int8 CurrentIrql; 
  struct _KPRCB *CurrentPrcb; 
  int v12; 
  unsigned __int16 *v13; 
  __int64 v14; 
  unsigned __int16 v15; 
  __int64 v16; 
  unsigned __int16 v17; 
  __int64 v18; 
  unsigned int v19; 
  __int64 v20; 
  __int64 v21; 
  unsigned int v22; 
  __int64 v23; 
  unsigned __int16 v24; 
  __int64 v25; 
  volatile _KAFFINITY_EX *v26; 
  unsigned __int8 v27; 
  char v28; 
  UINT64 *v29; 
  __int64 v30; 
  unsigned __int8 v31; 
  int v32[8]; 
  unsigned __int8 *v33; 
  char v34[8]; 
  UINT64 v35; 
  __int128 v36; 
  BYTE v37; 
  unsigned __int8 v38; 
  v4 = 0;
  v5 = a3;
  v6 = a4;
  v7 = (unsigned int)a1;
  v35 = 0i64;
  v37 = 0;
  v34[0] = 0;
  v38 = 0;
  v33 = &v38;
  v9 = 0;
  if( KiPreprocessFlushTb(0i64, (unsigned int)a3, (unsigned int)a4, &v37) )
  {
    if( (_DWORD)v7 )
    {
      v29 = a2;
      v30 = v7;
      do
      {
        KiFlushRangeTb(*v29++, v5);
        --v30;
      }
      while( v30 );
    }
    __writecr8(v38);
    v9 = 1;
  }
  if( v5 == 1 && *a2 <= 0x7FFFFFFEFFFFi64 && *(_QWORD *)(*((_QWORD *)KeGetCurrentThread() + 23) + 992i64) || v37 )
  {
    KiPrepareFlushParameters(v5, &v35, v34);
    v26 = KiFlushAffinity(v6);
    v9 |= HvlFlushRangeListTb(v35, (__int64)v26, v34[0], v27, v28, v7, a2);
  }
  if( !v9 )
  {
    *(_QWORD *)&v36 = a2;
    *((_QWORD *)&v36 + 1) = __PAIR64__(v5, v7);
    CurrentIrql = KeGetCurrentIrql();
    __writecr8(0xCui64);
    CurrentPrcb = KeGetCurrentPrcb();
    if( v6 )
    {
      v12 = 1;
      v13 = 0i64;
      if( (unsigned int)KeNumberProcessors_0 > 1 )
      {
LABEL_9:
        v14 = 2147483652i64;
        if( v6 != 1 )
          v14 = 4i64;
        KiIpiSendRequest((__int64)CurrentPrcb, v12, v13, &v36, v14);
        KiFlushRangeWorker((INT64)&v36);
        while( *((_DWORD *)CurrentPrcb + 2912) )
        {
          ++v4;
          _mm_pause();
        }
        goto LABEL_23;
      }
    }
    else
    {
      _InterlockedOr(v32, 0);
      v13 = (unsigned __int16 *)((char *)CurrentPrcb + 11704);
      v15 = 0;
      v16 = *(_QWORD *)(*((_QWORD *)CurrentPrcb + 1) + 184i64);
      v17 = *(_WORD *)(v16 + 368);
      *((_WORD *)CurrentPrcb + 5852) = v17;
      *((_WORD *)CurrentPrcb + 5853) = *(_WORD *)(v16 + 370);
      *((_DWORD *)CurrentPrcb + 2927) = 0;
      if( *(_WORD *)(v16 + 368) )
      {
        do
        {
          v18 = v15++;
          *(_QWORD *)&v13[4 * v18 + 4] = *(_QWORD *)(8 * v18 + v16 + 376);
        }
        while( v15 < *(_WORD *)(v16 + 368) );
        v17 = *v13;
      }
      v19 = v17;
      v20 = *((unsigned int *)CurrentPrcb + 9);
      v21 = (unsigned int)KiProcessorIndexToNumberMappingTable[v20] >> 6;
      v22 = KiProcessorIndexToNumberMappingTable[v20] & 0x3F;
      if( v19 > (unsigned int)v21 )
      {
        v23 = *(_QWORD *)&v13[4 * v21 + 4];
        _bittestandreset64(&v23, v22);
        *(_QWORD *)&v13[4 * v21 + 4] = v23;
        LOWORD(v19) = *v13;
      }
      v12 = 0;
      v24 = 0;
      if( (_WORD)v19 )
      {
        do
        {
          v25 = *(_QWORD *)&v13[4 * v24 + 4];
          if( v25 )
          {
            if( v24 != *((unsigned __int8 *)CurrentPrcb + 208) || v25 != *((_QWORD *)CurrentPrcb + 25) )
              goto LABEL_9;
          }
        }
        while( ++v24 < *v13 );
      }
    }
    KiFlushRangeWorker((INT64)&v36);
LABEL_23:
    __writecr8(CurrentIrql);
    goto LABEL_24;
  }
  if( v5 == 4 )
    KeFlushProcessWriteBuffers(1u);
LABEL_24:
  if( VmTbFlushEnabled )
    VmFlushTb(v7, a2, v5);
  if( ExTbFlushActive )
  {
    v31 = KeGetCurrentIrql();
    __writecr8(0xFui64);
    ExFlushTb(v7, (__int64)a2, v5);
    __writecr8(v31);
  }
}

Referenced by:

MiAgeWorkingSetTail
MiFlushTbList