KeSetAffinityProcess

__int64 __fastcall KeSetAffinityProcess(__int64 a1, char a2, unsigned __int16 *a3){
  char v6; 
  char v7; 
  UINT16 v8; 
  UINT64 *v9; 
  unsigned int v10; 
  unsigned int v11; 
  unsigned __int16 *v12; 
  unsigned __int8 CurrentIrql; 
  INT64 *v14; 
  char v15; 
  unsigned __int16 *v16; 
  unsigned __int16 v17; 
  _QWORD *i; 
  _GROUP_AFFINITY *p_Affinity; 
  unsigned __int16 v21; 
  unsigned __int16 v22; 
  unsigned __int16 *v23; 
  char v24; 
  __int64 v25; 
  bool v26; 
  __int128 v27; 
  __int128 v28; 
  __int128 v29; 
  __int128 v30; 
  __int128 v31; 
  __int128 v32; 
  __int128 v33; 
  __int128 v34; 
  __int64 v35; 
  char v36; 
  signed __int32 v37; 
  int v38; 
  _SINGLE_LIST_ENTRY ReadyList; 
  struct _KPRCB *CurrentPrcb; 
  _GROUP_AFFINITY Affinity; 
  __int128 Base; 
  _OWORD v43[10]; 
  __int64 v44; 
  Base = 0i64;
  memset((INT64)v43 + 8, 0i64);
  LODWORD(v43[0]) = 1310721;
  v36 = 0;
  ReadyList.Next = 0i64;
  v6 = 0;
  v7 = 0;
  v38 = 1;
  memset((INT64)v43 + 4, 0i64);
  if( (a2 & 3) != 0 )
  {
    if( (a2 & 1) != 0 )
      v7 = 1;
    else
      v36 = 1;
  }
  KeFirstGroupAffinityEx(&Base, (UINT8)a3, v8, v9);
  v10 = *a3;
  v11 = 0;
  v37 = 0;
  if( v10 )
  {
    v12 = a3 + 4;
    do
    {
      if( *(_QWORD *)v12 )
        _bittestandset(&v37, v11);
      ++v11;
      v12 += 4;
    }
    while( v11 < v10 );
  }
  Affinity = 0i64;
  CurrentIrql = KeGetCurrentIrql();
  __writecr8(2ui64);
  v14 = (INT64 *)(a1 + 64);
  CurrentPrcb = KeGetCurrentPrcb();
  ExAcquireSpinLockExclusiveAtDpcLevel((INT64 *)(a1 + 64));
  if( !v7 || ((*(_DWORD *)(a1 + 636) - 1) & *(_DWORD *)(a1 + 636)) == 0 )
  {
    v15 = v36;
    v16 = (unsigned __int16 *)(a1 + 80);
    if( v36 )
    {
      v21 = *v16;
      v22 = 0;
      if( !*v16 )
        goto LABEL_22;
      v23 = a3 + 4;
      v24 = 0;
      do
      {
        v25 = *(_QWORD *)((char *)v23 + a1 - (_QWORD)a3 + 80);
        if( v25 )
        {
          if( v22 < *a3 && (v25 | *(_QWORD *)v23) != v25 )
          {
            v25 |= *(_QWORD *)v23;
            v24 = 1;
          }
          if( LOWORD(v43[0]) <= v22 )
            LOWORD(v43[0]) = v38 + v22;
          *(_QWORD *)((char *)v23 + (char *)v43 - (char *)a3) |= v25;
        }
        ++v22;
        v23 += 4;
      }
      while( v22 < v21 );
      v26 = v24 == 0;
      v14 = (INT64 *)(a1 + 64);
      if( v26 )
        goto LABEL_22;
      v27 = v43[1];
      *(_OWORD *)v16 = v43[0];
      v28 = v43[2];
      *(_OWORD *)(a1 + 96) = v27;
      v29 = v43[3];
      *(_OWORD *)(a1 + 112) = v28;
      v30 = v43[4];
      *(_OWORD *)(a1 + 128) = v29;
      v31 = v43[5];
      *(_OWORD *)(a1 + 144) = v30;
      v32 = v43[6];
      *(_OWORD *)(a1 + 160) = v31;
      v33 = v43[8];
      *(_OWORD *)(a1 + 176) = v32;
      *(_OWORD *)(a1 + 192) = v43[7];
      v34 = v43[9];
      v35 = v44;
      *(_OWORD *)(a1 + 208) = v33;
      *(_OWORD *)(a1 + 224) = v34;
      *(_QWORD *)(a1 + 240) = v35;
    }
    else
    {
      v17 = 0;
      *(_OWORD *)v16 = *(_OWORD *)a3;
      *(_OWORD *)(a1 + 96) = *((_OWORD *)a3 + 1);
      *(_OWORD *)(a1 + 112) = *((_OWORD *)a3 + 2);
      *(_OWORD *)(a1 + 128) = *((_OWORD *)a3 + 3);
      *(_OWORD *)(a1 + 144) = *((_OWORD *)a3 + 4);
      *(_OWORD *)(a1 + 160) = *((_OWORD *)a3 + 5);
      *(_OWORD *)(a1 + 176) = *((_OWORD *)a3 + 6);
      *(_OWORD *)(a1 + 192) = *((_OWORD *)a3 + 7);
      *(_OWORD *)(a1 + 208) = *((_OWORD *)a3 + 8);
      *(_OWORD *)(a1 + 224) = *((_OWORD *)a3 + 9);
      *(_QWORD *)(a1 + 240) = *((_QWORD *)a3 + 20);
      if( *a3 )
      {
        do
        {
          if( *(_QWORD *)&a3[4 * v17 + 4] )
          {
            KiSetIdealNodeProcessByGroup((_EPROCESS *)a1, 0i64, v17);
            if( !v6 )
            {
              v6 = 1;
              *(_WORD *)(a1 + 836) = *(_WORD *)(a1 + 2i64 * v17 + 772);
            }
          }
          ++v17;
        }
        while( v17 < *a3 );
        v15 = 0;
        v14 = (INT64 *)(a1 + 64);
      }
    }
    for( i = *(_QWORD **)(a1 + 48); i != (_QWORD *)(a1 + 48); i = (_QWORD *)*i )
    {
      Affinity.Group = *((_WORD *)i - 100);
      p_Affinity = &Affinity;
      Affinity.Mask = *(_QWORD *)(a1 + 8i64 * Affinity.Group + 88);
      if( !Affinity.Mask )
        p_Affinity = (_GROUP_AFFINITY *)&Base;
      KiSetAffinityThread((_ETHREAD *)(i - 95), &ReadyList, p_Affinity);
    }
    if( !v15 )
      *(_DWORD *)(a1 + 636) = v37;
LABEL_22:
    ExReleaseSpinLockExclusiveFromDpcLevel(v14);
    KiProcessDeferredReadyList((__int64)CurrentPrcb, &ReadyList, CurrentIrql);
    return 0i64;
  }
  ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(a1 + 64));
  __writecr8(CurrentIrql);
  return 3221225485i64;
}

Referenced by:

KiInitializeDynamicProcessorDpc
Phase1InitializationDiscard
PspSetProcessAffinitySafe