RtlpFcCalculateRequiredSizeForNewFeatureTable

NTSTATUS __fastcall RtlpFcCalculateRequiredSizeForNewFeatureTable(_DWORD *a1, _DWORD *a2, UINT64 a3, UINT64 *a4){
  UINT64 v4; 
  UINT64 v5; 
  UINT64 v6; 
  _DWORD *v10; 
  UINT64 v11; 
  _DWORD *v12; 
  int v13; 
  INT64 v14; 
  int v15; 
  CHAR IsUpdateModifyingOrAddingFeature; 
  UINT64 v17; 
  UINT64 v18; 
  _DWORD *v19; 
  UINT64 v20; 
  CHAR v21; 
  __int64 v22; 
  UINT64 v23; 
  UINT64 v24; 
  NTSTATUS result; 
  UINT64 v26; 
  UINT64 v27; 
  INT64 v28; 
  int v29; 
  v4 = 0i64;
  v5 = 0i64;
  v6 = 0i64;
  if( a1 )
  {
    v4 = (unsigned int)*a1;
    v10 = a1 + 1;
    v11 = v4;
    if( *a1 )
    {
      v12 = a2;
      do
      {
        if( v6 >= a3 )
          goto LABEL_22;
        v13 = RtlpFcCompareFeatureToUpdate(v10, v12);
        if( v13 )
        {
          if( v13 != 1 )
          {
            ++v5;
            v10 += 3;
            continue;
          }
          IsUpdateModifyingOrAddingFeature = RtlpFcIsUpdateModifyingOrAddingFeature((INT64)v12);
          v18 = v17 + 1;
          if( !IsUpdateModifyingOrAddingFeature )
            v18 = v17;
          v4 = v18;
        }
        else
        {
          if( (v12[7] & 4) != 0
            || (v15 = v10[2],
                v28 = *(_QWORD *)v10,
                v29 = v15,
                RtlpFcUpdateFeature((INT64)&v28, v14),
                !RtlpFcDoesFeatureHaveUniqueState(&v28)) )
          {
            --v4;
          }
          ++v5;
          v10 += 3;
        }
        ++v6;
        v12 += 8;
      }
      while( v5 < v11 );
    }
  }
  if( v6 < a3 )
  {
    v19 = &a2[8 * v6];
    v20 = a3 - v6;
    do
    {
      v21 = RtlpFcIsUpdateModifyingOrAddingFeature((INT64)v19);
      v24 = v23 + 1;
      if( !v21 )
        v24 = v23;
      v19 = (_DWORD *)(v22 + 32);
      v4 = v24;
      --v20;
    }
    while( v20 );
  }
LABEL_22:
  if( v4 )
  {
    result = RtlULongLongMult(v4, 0xCui64, a4);
    if( result >= 0 )
    {
      v26 = -1i64;
      v27 = *a4 + 4;
      if( v27 >= *a4 )
        v26 = *a4 + 4;
      result = v27 < *a4 ? 0xC0000095 : 0;
      *a4 = v26;
    }
  }
  else
  {
    *a4 = 0i64;
    return 0;
  }
  return result;
}

Referenced by:

RtlpFcUpdateFeatureConfiguration