CmpValueEnumStackAdvance

__int64 __fastcall CmpValueEnumStackAdvance(__int64 a1){
  INT16 v2; 
  unsigned int v3; 
  INT64 *EntryAtLayerHeight; 
  __int16 v5; 
  int v6; 
  INT64 v8; 
  UINT16 *v9; 
  __int64 v10; 
  int v11; 
  CHAR v12; 
  __int64 v13; 

  v13 = 0xFFFFFFFFi64;
  v12 = 0;
  if( *(_BYTE *)(a1 + 4) )
  {
    if( *(_DWORD *)a1 == -1 )
      return(unsigned int)-2147483622;
    ++*(_DWORD *)(a1 + 8);
    v2 = *(_WORD *)(a1 + 6);
  }
  else
  {
    *(_DWORD *)(a1 + 8) = 0;
    *(_BYTE *)(a1 + 4) = 1;
    v2 = *(_WORD *)(a1 + 12);
    *(_WORD *)(a1 + 6) = v2;
  }
  *(_DWORD *)a1 = -1;
  if( v2 >= 0 )
  {
    do
    {
      EntryAtLayerHeight = (INT64 *)CmpValueEnumStackGetEntryAtLayerHeight(a1, v2);
      while( v3 < *((_DWORD *)EntryAtLayerHeight + 6) )
      {
        v8 = (*(__int64(__fastcall **)(INT64, _QWORD, __int64 *))(*EntryAtLayerHeight + 8))(
               *EntryAtLayerHeight,
               *(unsigned int *)(EntryAtLayerHeight[1] + 4i64 * v3),
               &v13);
        if( CmpIsValueTombstone(*EntryAtLayerHeight, v8) )
        {
          (*(void(__fastcall **)(__int64, __int64 *))(v10 + 16))(v10, &v13);
          v3 = ++*(_DWORD *)(a1 + 8);
        }
        else
        {
          v6 = CmpValueEnumStackMatchingValueInUpperLayer(a1, *(_WORD *)(a1 + 6), v9, &v12);
          (*(void(__fastcall **)(INT64, __int64 *))(*EntryAtLayerHeight + 16))(*EntryAtLayerHeight, &v13);
          if( v6 < 0 )
            return(unsigned int)v6;
          v11 = *(_DWORD *)(a1 + 8);
          if( !v12 )
          {
            v6 = 0;
            *(_DWORD *)a1 = *(_DWORD *)(EntryAtLayerHeight[1] + 4i64 * *(unsigned int *)(a1 + 8));
            return(unsigned int)v6;
          }
          v3 = v11 + 1;
          *(_DWORD *)(a1 + 8) = v11 + 1;
        }
      }
      v5 = *(_WORD *)(a1 + 6) - 1;
      *(_DWORD *)(a1 + 8) = 0;
      v2 = v5;
      *(_WORD *)(a1 + 6) = v5;
    }
    while( v5 >= 0 );
  }
  return(unsigned int)-2147483622;
}

Referenced by:

CmEnumerateValueFromLayeredKey
CmpFullPromoteSingleKeyFromKeyNodeStacks
CmpGetValueCountForKeyNodeStack