IopSetupArbiterAndTranslators

INT64 __fastcall IopSetupArbiterAndTranslators(INT64 a1){
  __int64 v2; 
  char v3; 
  char v4; 
  __int64 v5; 
  __int64 v6; 
  unsigned __int8 v7; 
  int v8; 
  char v9; 
  __int64 *LegacyBusDeviceNode; 
  __int64 v11; 
  unsigned __int8 v12; 
  INT64 v13; 
  unsigned __int8 v14; 
  __int64 v15; 
  __int64 *v16; 
  INT64 result; 
  __int16 v18; 
  int v19; 
  __int16 v20; 
  int v21; 
  char *v22; 
  __int64 v23; 
  _QWORD *v24; 
  _QWORD *v25; 
  __int64 **v26; 
  __int64 v27; 
  unsigned __int8 v28; 
  char v29; 
  __int64 v30; 
  unsigned __int64 PoolWithTag; 
  __int64 **v32; 
  __int64 v33; 
  __int64 v34; 
  __int64 v35; 
  __int64 v36; 
  char v37; 
  char v38; 
  __int64 v39; 
  INT64 v40; 
  v2 = *(_QWORD *)(a1 + 72);
  v3 = 0;
  v40 = 0i64;
  v4 = 0;
  v36 = v2;
  v5 = *(_QWORD *)(a1 + 32);
  v35 = 0i64;
  v38 = 1;
  v34 = 0i64;
  v6 = *(_QWORD *)(v5 + 64);
  v39 = 0i64;
  v7 = *(_BYTE *)(v6 + 1);
  v8 = *(_DWORD *)(a1 + 80);
  if( v7 == 7 )
    v7 = 3;
  if( v8 != 1 || (v9 = 1, *(_DWORD *)a1) )
    v9 = 0;
  v37 = v9;
  if( !v2 || v8 == 1 )
    LegacyBusDeviceNode = (__int64 *)IopRootDeviceNode;
  else
    LegacyBusDeviceNode = *(__int64 **)(*(_QWORD *)(v2 + 312) + 40i64);
  if( !LegacyBusDeviceNode )
    return 3221225610i64;
  while( 1 )
  {
    if( LegacyBusDeviceNode != IopRootDeviceNode || v4 || v9 )
    {
      if( v3 )
        goto LABEL_17;
      v11 = LegacyBusDeviceNode[4];
      if( v11 == v2 )
        goto LABEL_17;
      if( IopFindResourceHandlerInfo(2, LegacyBusDeviceNode, v7, &v40) )
        goto LABEL_13;
      if( v7 > 0xFu )
        v20 = 0;
      else
        v20 = 1 << v7;
      v21 = IopQueryResourceHandlerInterface(2, v11, v12, &v39);
      *((_WORD *)LegacyBusDeviceNode + 263) |= v20;
      if( v21 >= 0 )
      {
        v33 = v39;
      }
      else
      {
        *((_WORD *)LegacyBusDeviceNode + 262) |= v20;
        if( v7 <= 0xFu )
        {
LABEL_13:
          v13 = v40;
LABEL_14:
          if( v13 )
          {
            v3 = 1;
            if( (*(_DWORD *)(*(_QWORD *)(v13 + 24) + 40i64) & 1) != 0
              && (int)IopCallArbiter(v13, 7i64, *(_QWORD *)(a1 + 32)) < 0 )
            {
              v3 = 0;
            }
            else
            {
              *(_QWORD *)(a1 + 288) = v13;
              *(_WORD *)(v13 + 104) = 0;
            }
          }
LABEL_17:
          if( !v38 )
          {
LABEL_24:
            LegacyBusDeviceNode = (__int64 *)LegacyBusDeviceNode[2];
            v9 = v37;
            goto LABEL_25;
          }
          if( IopFindResourceHandlerInfo(1, LegacyBusDeviceNode, v7, &v34) )
            goto LABEL_19;
          if( v7 > 0xFu )
            v18 = 0;
          else
            v18 = 1 << v7;
          v19 = IopQueryResourceHandlerInterface(1, LegacyBusDeviceNode[4], v14, &v39);
          *((_WORD *)LegacyBusDeviceNode + 261) |= v18;
          if( v19 >= 0 )
          {
            v30 = v39;
          }
          else
          {
            *((_WORD *)LegacyBusDeviceNode + 260) |= v18;
            if( v7 <= 0xFu )
            {
LABEL_19:
              v15 = v34;
LABEL_20:
              if( v15 )
                v4 = 1;
              if( !v3 && v15 )
              {
                result = IopTranslateAndAdjustReqDesc(*(_QWORD *)(a1 + 32), v15, &v35);
                if( (int)result < 0 )
                  return result;
                v27 = v35;
                v28 = *(_BYTE *)(*(_QWORD *)(v35 + 64) + 1i64);
                *(_QWORD *)(v35 + 32) = *(_QWORD *)(a1 + 32);
                v7 = v28;
                if( v28 == 7 )
                  v7 = 3;
                v29 = v38;
                *(_QWORD *)(a1 + 32) = v27;
                if( (_DWORD)result == 288 )
                  v29 = 0;
                v38 = v29;
              }
              goto LABEL_24;
            }
            v30 = 0i64;
            v39 = 0i64;
          }
          PoolWithTag = (unsigned __int64)ExAllocatePoolWithTag(PagedPool, 0x28ui64, 0x20207050ui64);
          if( !PoolWithTag )
            return 3221225626i64;
          *(_BYTE *)(PoolWithTag + 16) = v7;
          *(_QWORD *)(PoolWithTag + 8) = PoolWithTag;
          *(_QWORD *)PoolWithTag = PoolWithTag;
          *(_QWORD *)(PoolWithTag + 24) = v30;
          *(_QWORD *)(PoolWithTag + 32) = LegacyBusDeviceNode;
          v32 = (__int64 **)LegacyBusDeviceNode[64];
          if( *v32 != LegacyBusDeviceNode + 63 )
            goto LABEL_68;
          *(_QWORD *)(PoolWithTag + 8) = v32;
          *(_QWORD *)PoolWithTag = LegacyBusDeviceNode + 63;
          *v32 = (__int64 *)PoolWithTag;
          v15 = PoolWithTag & -(__int64)(v30 != 0);
          LegacyBusDeviceNode[64] = PoolWithTag;
          v34 = v15;
          goto LABEL_20;
        }
        v33 = 0i64;
        v39 = 0i64;
      }
      v22 = (char *)ExAllocatePoolWithTag(PagedPool, 0x70ui64, 0x20207050ui64);
      v23 = (__int64)v22;
      if( !v22 )
        return 3221225626i64;
      *((_WORD *)v22 + 52) = 0;
      *((_QWORD *)v22 + 12) = v22 + 88;
      *((_QWORD *)v22 + 11) = v22 + 88;
      *((_QWORD *)v22 + 10) = v22 + 72;
      *((_QWORD *)v22 + 9) = v22 + 72;
      v24 = v22 + 40;
      *((_QWORD *)v22 + 6) = v22 + 40;
      v25 = v22 + 56;
      *v24 = v24;
      v25[1] = v25;
      *v25 = v25;
      *(_QWORD *)(v23 + 8) = v23;
      *(_QWORD *)v23 = v23;
      *(_BYTE *)(v23 + 16) = v7;
      *(_QWORD *)(v23 + 32) = LegacyBusDeviceNode;
      v26 = (__int64 **)LegacyBusDeviceNode[62];
      if( *v26 != LegacyBusDeviceNode + 61 )
LABEL_68:
        __fastfail(3u);
      *(_QWORD *)v23 = LegacyBusDeviceNode + 61;
      *(_QWORD *)(v23 + 8) = v26;
      *v26 = (__int64 *)v23;
      LegacyBusDeviceNode[62] = v23;
      *(_QWORD *)(v23 + 24) = v33;
      v13 = v23 & -(__int64)(v33 != 0);
      v40 = v13;
      goto LABEL_14;
    }
    v37 = 1;
    LegacyBusDeviceNode = IopFindLegacyBusDeviceNode(*(_DWORD *)a1, *(_DWORD *)(a1 + 4));
    if( LegacyBusDeviceNode == v16 && !**(_DWORD **)(*(_QWORD *)(a1 + 16) + 8i64) )
      LegacyBusDeviceNode = IopFindLegacyBusDeviceNode(1u, 0);
LABEL_25:
    if( !LegacyBusDeviceNode )
      break;
    v2 = v36;
  }
  if( !v3 )
    return 3221225610i64;
  return 0i64;
}

Referenced by:

IopResourceRequirementsListToReqList