HalGetMessageRoutingInfo

__int64 __fastcall HalGetMessageRoutingInfo(int *a1, _DWORD *a2){
  unsigned __int64 v4; 
  char v5; 
  unsigned __int16 v6; 
  char v7; 
  unsigned __int64 v8; 
  int v9; 
  int v10; 
  UINT64 v11; 
  int v12; 
  int v14; 
  int v15; 
  int v16; 
  char v17; 
  int v18; 
  int v19; 
  int v20; 
  int v21; 
  _KAFFINITY_ENUMERATION_CONTEXT Context; 
  __int128 v23; 
  UINT64 ProcIndex; 

  *(_DWORD *)(&Context.CurrentIndex + 1) = 0;
  *(&Context.CurrentIndex + 3) = 0;
  LODWORD(ProcIndex) = 0;
  v23 = 0i64;
  if( (unsigned int)*a1 > 1 )
    goto LABEL_53;
  v4 = *((_QWORD *)a1 + 2);
  if( !v4 || (v5 = 1, (v4 & (v4 ^ (v4 - 1))) != v4) )
    v5 = 0;
  v6 = *((_WORD *)a1 + 12);
  v7 = 0;
  if( !v6 )
  {
    v8 = 0i64;
    if( KeActiveProcessors.Count )
      v8 = KeActiveProcessors.Bitmap[0];
    if( v4 == v8 )
      v7 = 1;
  }
  v9 = a1[8];
  Context.CurrentIndex = v6;
  Context.CurrentMask = v4;
  Context.Affinity = 0i64;
  if( v9 == 1 )
  {
    if( v5 || v7 )
    {
      KeEnumerateNextProcessor(&ProcIndex, &Context);
      if( v10 >= 0 )
      {
        if( v7 )
        {
          while( 1 )
          {
            v11 = (unsigned int)ProcIndex;
            if( (unsigned int)ProcIndex >= (unsigned int)qword_140C50640 )
              break;
            KeEnumerateNextProcessor(&ProcIndex, &Context);
            if( v10 < 0 )
            {
              v11 = (unsigned int)ProcIndex;
              goto LABEL_49;
            }
          }
          v10 = -1073741811;
LABEL_49:
          if( (unsigned int)v11 < (unsigned int)qword_140C50640 )
            v10 = 0;
        }
        else
        {
          v11 = (unsigned int)ProcIndex;
        }
        if( v10 >= 0 && (int)HalGetProcessorIdByNtNumber(v11, &ProcIndex) >= 0 )
          goto LABEL_16;
      }
    }
    goto LABEL_44;
  }
  if( v9 == 2 )
  {
    if( !*(&CmpDummyThreadEvent + 7160) )
    {
      KeEnumerateNextProcessor(&ProcIndex, &Context);
      if( v14 < 0 )
        return 3221225485i64;
      v15 = DWORD2(v23);
      while( (unsigned int)ProcIndex < (unsigned int)qword_140C50640 )
      {
        if( *(_DWORD *)(qword_140C50630 + 24i64 * (unsigned int)ProcIndex) != 5 )
          goto LABEL_53;
        v15 |= *(_DWORD *)(qword_140C50630 + 24i64 * (unsigned int)ProcIndex + 8);
        KeEnumerateNextProcessor(&ProcIndex, &Context);
        if( v16 < 0 )
        {
          if( v15 )
            goto LABEL_16;
          return 3221225485i64;
        }
      }
LABEL_44:
      *(&CmpDummyThreadEvent + 1789) = 21;
      return 3221225485i64;
    }
LABEL_53:
    *(&CmpDummyThreadEvent + 1789) = 20;
    return 3221225485i64;
  }
  if( v9 != 3 || !*(&CmpDummyThreadEvent + 7160) )
    goto LABEL_53;
  v17 = 0;
  KeEnumerateNextProcessor(&ProcIndex, &Context);
  if( v18 >= 0 )
  {
    v19 = HIDWORD(v23);
    v20 = DWORD2(v23);
    while( (unsigned int)ProcIndex < (unsigned int)qword_140C50640 )
    {
      if( *(_DWORD *)(qword_140C50630 + 24i64 * (unsigned int)ProcIndex) != 6 )
        goto LABEL_53;
      if( v17 )
      {
        if( v20 != *(_DWORD *)(qword_140C50630 + 24i64 * (unsigned int)ProcIndex + 8) )
        {
          if( !v7 )
            goto LABEL_53;
          v19 = *(_DWORD *)(qword_140C50630 + 24i64 * (unsigned int)ProcIndex + 12);
          v20 = *(_DWORD *)(qword_140C50630 + 24i64 * (unsigned int)ProcIndex + 8);
        }
        v19 |= *(_DWORD *)(qword_140C50630 + 24i64 * (unsigned int)ProcIndex + 12);
      }
      else
      {
        v19 = *(_DWORD *)(qword_140C50630 + 24i64 * (unsigned int)ProcIndex + 12);
        v20 = *(_DWORD *)(qword_140C50630 + 24i64 * (unsigned int)ProcIndex + 8);
        v17 = 1;
      }
      KeEnumerateNextProcessor(&ProcIndex, &Context);
      if( v21 < 0 )
        goto LABEL_16;
    }
    goto LABEL_44;
  }
LABEL_16:
  v12 = *a1;
  *a2 = 1;
  if( v12 )
  {
    a2[2] = 3;
    a2[20] = v9;
  }
  else
  {
    a2[2] = 1;
    a2[21] = a1[10];
    a2[20] = a1[11];
    a2[22] = *((unsigned __int16 *)a1 + 24);
  }
  return 0i64;
}

Referenced by:

IopConnectMessageBasedInterrupt