PnpFindBestConfigurationWorker

__int64 __fastcall PnpFindBestConfigurationWorker(
        INT64 RequestTable,
        UINT64 RequestTableCount,
        _LIST_ENTRY *ArbiterList,
        int a4){
  __int64 v4; 
  unsigned int v7; 
  __int64 v8; 
  unsigned int v9; 
  NTSTATUS v10; 
  _LIST_ENTRY v11; 
  unsigned int v13; 
  __int64 *v14; 
  __int64 v15; 
  __int64 v16; 
  INT64 v17; 
  __int64 v18; 
  unsigned int v19; 
  _LIST_ENTRY v20[3]; 

  v4 = (unsigned int)RequestTableCount;
  v20[0].Blink = v20;
  ArbiterList->Blink = ArbiterList;
  v20[0].Flink = v20;
  ArbiterList->Flink = ArbiterList;
  PnpSelectFirstConfiguration(RequestTable, RequestTableCount, ArbiterList, a4);
  v7 = -1;
  v8 = *(_QWORD *)&KUSER_SHARED_DATA.SystemTime.LowPart;
  v9 = PnpFindBestConfigurationTimeout;
  while( 1 )
  {
    v10 = IopTestConfiguration((_PNP_RESOURCE_REQUEST *)RequestTable, (unsigned int)v4, ArbiterList);
    if( v10 >= 0 )
    {
      v11 = *ArbiterList;
      v20[0] = *ArbiterList;
      if( (_DWORD)v4 == 1 )
        goto LABEL_4;
      v13 = 0;
      if( (_DWORD)v4 )
      {
        v14 = (__int64 *)(RequestTable + 32);
        v15 = v4;
        do
        {
          v16 = *v14;
          v14 += 8;
          v13 += ***(_DWORD ***)(v16 + 16);
          --v15;
        }
        while( v15 );
      }
      if( v13 < v7 )
      {
        v7 = v13;
        IopSaveRestoreConfiguration((_PNP_RESOURCE_REQUEST *)RequestTable, (unsigned int)v4, ArbiterList, 1u);
      }
    }
    if( (unsigned int)((*(_QWORD *)&KUSER_SHARED_DATA.SystemTime.LowPart - v8) / 10000) >= v9 )
      break;
    if( !IopSelectNextConfiguration((_PNP_RESOURCE_REQUEST *)RequestTable, (unsigned int)v4, ArbiterList) )
      goto LABEL_10;
  }
  if( (_DWORD)v4 )
  {
    v17 = RequestTable + 32;
    v18 = v4;
    do
    {
      IopAddRemoveReqDescs(
        (_REQ_DESC **)(**(_QWORD **)(*(_QWORD *)v17 + 16i64) + 24i64),
        *(unsigned int *)(**(_QWORD **)(*(_QWORD *)v17 + 16i64) + 20i64),
        0i64,
        0);
      v17 += 64i64;
      --v18;
    }
    while( v18 );
  }
LABEL_10:
  v11 = v20[0];
LABEL_4:
  if( v11.Flink == v20 )
  {
    if( v10 != -1073739512 )
      return(unsigned int)-1073741823;
  }
  else
  {
    v10 = 0;
    if( (_DWORD)v4 != 1 )
    {
      *ArbiterList = v11;
      IopSaveRestoreConfiguration((_PNP_RESOURCE_REQUEST *)RequestTable, (unsigned int)v4, ArbiterList, 0);
      IopRetestConfiguration(RequestTable, (unsigned int)v4);
      return v19;
    }
  }
  return(unsigned int)v10;
}

Referenced by:

PnpFindBestConfiguration