KiSelectIdealProcessorForProcess

NTSTATUS __stdcall KiSelectIdealProcessorForProcess(INT64 a1, INT64 *a2){
  INT64 v2; 
  __int64 v3; 
  int v4; 
  unsigned __int64 v5; 
  __int64 v6; 
  __int64 v7; 
  __int64 v8; 

  v2 = *a2;
  v3 = *(_QWORD *)(a1 + 376);
  v4 = *((unsigned __int16 *)a2 + 4);
  v5 = *a2 & *(_QWORD *)(a1 + 136);
  if( v3 )
  {
    LOWORD(v6) = *(_WORD *)(a1 + 110) & 0x3F;
    v7 = ~((1i64 << (*(_WORD *)(a1 + 110) & 0x3F)) - 1) & v3;
    do
    {
      v8 = v7 & ~(1i64 << v6);
      v7 = *(_QWORD *)(a1 + 376);
      if( v8 )
        v7 = v8;
      _BitScanForward64((unsigned __int64 *)&v6, v7);
      v5 = (unsigned __int64)*(&KiProcessorBlock
                             + (unsigned int)KiProcessorNumberToIndexMappingTable[(unsigned int)((v4 << 6) + v6)]);
    }
    while( (v2 & *(_QWORD *)(v5 + 33896)) == 0 );
    _BitScanForward64(&v5, v2 & *(_QWORD *)(v5 + 33896));
    *(_WORD *)(a1 + 110) = v5;
  }
  else
  {
    _BitScanForward64(&v5, v5);
  }
  return LOWORD(KiProcessorNumberToIndexMappingTable[(unsigned int)(v5 + (v4 << 6))]);
}

Referenced by:

KiSetIdealNodeProcessByGroup