matroska_ebmlnum_uint (uint8_t  *data,

                       uint32_t  size,

                       uint64_t *num)

{

    int len_mask = 0x80, read = 1, n = 1, num_ffs = 0;

    uint64_t total;



    if (size <= 0)

        return AVERROR_INVALIDDATA;



    total = data[0];

    while (read <= 8 && !(total & len_mask)) {

        read++;

        len_mask >>= 1;

    }

    if (read > 8)

        return AVERROR_INVALIDDATA;



    if ((total &= (len_mask - 1)) == len_mask - 1)

        num_ffs++;

    if (size < read)

        return AVERROR_INVALIDDATA;

    while (n < read) {

        if (data[n] == 0xff)

            num_ffs++;

        total = (total << 8) | data[n];

        n++;

    }



    if (!total)

        return AVERROR_INVALIDDATA;



    if (read == num_ffs)

        *num = (uint64_t)-1;

    else

        *num = total;



    return read;

}

matroska_ebmlnum_uint (uint8_t  *data,

                       uint32_t  size,

                       uint64_t *num)

{

    int len_mask = 0x80, read = 1, n = 1, num_ffs = 0;

    uint64_t total;



    if (size <= 0)

        return AVERROR_INVALIDDATA;



    total = data[0];

    while (read <= 8 && !(total & len_mask)) {

        read++;

        len_mask >>= 1;

    }

    if (read > 8)

        return AVERROR_INVALIDDATA;



    if ((total &= (len_mask - 1)) == len_mask - 1)

        num_ffs++;

    if (size < read)

        return AVERROR_INVALIDDATA;

    while (n < read) {

        if (data[n] == 0xff)

            num_ffs++;

        total = (total << 8) | data[n];

        n++;

    }



    if (!total)

        return AVERROR_INVALIDDATA;



    if (read == num_ffs)

        *num = (uint64_t)-1;

    else

        *num = total;



    return read;

}

FUNC_0 (uint8_t  *VAR_0,

                       uint32_t  VAR_1,

                       uint64_t *VAR_2)

{

    int VAR_3 = 0x80, VAR_4 = 1, VAR_5 = 1, VAR_6 = 0;

    uint64_t total;



    if (VAR_1 <= 0)

        return AVERROR_INVALIDDATA;



    total = VAR_0[0];

    while (VAR_4 <= 8 && !(total & VAR_3)) {

        VAR_4++;

        VAR_3 >>= 1;

    }

    if (VAR_4 > 8)

        return AVERROR_INVALIDDATA;



    if ((total &= (VAR_3 - 1)) == VAR_3 - 1)

        VAR_6++;

    if (VAR_1 < VAR_4)

        return AVERROR_INVALIDDATA;

    while (VAR_5 < VAR_4) {

        if (VAR_0[VAR_5] == 0xff)

            VAR_6++;

        total = (total << 8) | VAR_0[VAR_5];

        VAR_5++;

    }



    if (!total)

        return AVERROR_INVALIDDATA;



    if (VAR_4 == VAR_6)

        *VAR_2 = (uint64_t)-1;

    else

        *VAR_2 = total;



    return VAR_4;

}

FUNC_0 (uint8_t  *VAR_0,
uint32_t  VAR_1,
uint64_t *VAR_2)
{ int VAR_3 = 0x80, VAR_4 = 1, VAR_5 = 1, VAR_6 = 0; uint64_t total; if (VAR_1 <= 0)
return AVERROR_INVALIDDATA; total = VAR_0[0]; while (VAR_4 <= 8 && !(total & VAR_3)) { VAR_4++; VAR_3 >>= 1; } if (VAR_4 > 8)
return AVERROR_INVALIDDATA; if ((total &= (VAR_3 - 1)) == VAR_3 - 1)
VAR_6++; if (VAR_1 < VAR_4)
return AVERROR_INVALIDDATA; while (VAR_5 < VAR_4) { if (VAR_0[VAR_5] == 0xff)
VAR_6++; total = (total << 8) | VAR_0[VAR_5]; VAR_5++; } if (!total)
return AVERROR_INVALIDDATA; if (VAR_4 == VAR_6)
*VAR_2 = (uint64_t)-1; else
*VAR_2 = total; return VAR_4; }