int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, unsigned num)

{

    uint32_t exit_at_level[33] = { 404 };

    unsigned i, j, p, code;



    for (p = 0; (bits[p] == 0) && (p < num); ++p)

        ;

    if (p == num)

        return 0;



    codes[p] = 0;

    if (bits[p] > 32)

        return AVERROR_INVALIDDATA;

    for (i = 0; i < bits[p]; ++i)

        exit_at_level[i+1] = 1 << i;



    ++p;



    for (i = p; (bits[i] == 0) && (i < num); ++i)

        ;

    if (i == num)

        return 0;



    for (; p < num; ++p) {

        if (bits[p] > 32)

             return AVERROR_INVALIDDATA;

        if (bits[p] == 0)

             continue;

        // find corresponding exit(node which the tree can grow further from)

        for (i = bits[p]; i > 0; --i)

            if (exit_at_level[i])

                break;

        if (!i) // overspecified tree

             return AVERROR_INVALIDDATA;

        code = exit_at_level[i];

        exit_at_level[i] = 0;

        // construct code (append 0s to end) and introduce new exits

        for (j = i + 1 ;j <= bits[p]; ++j)

            exit_at_level[j] = code + (1 << (j - 1));

        codes[p] = code;

    }



    //no exits should be left (underspecified tree - ie. unused valid vlcs - not allowed by SPEC)

    for (p = 1; p < 33; p++)

        if (exit_at_level[p])

            return AVERROR_INVALIDDATA;



    return 0;

}

int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, unsigned num)

{

    uint32_t exit_at_level[33] = { 404 };

    unsigned i, j, p, code;



    for (p = 0; (bits[p] == 0) && (p < num); ++p)

        ;

    if (p == num)

        return 0;



    codes[p] = 0;

    if (bits[p] > 32)

        return AVERROR_INVALIDDATA;

    for (i = 0; i < bits[p]; ++i)

        exit_at_level[i+1] = 1 << i;



    ++p;



    for (i = p; (bits[i] == 0) && (i < num); ++i)

        ;

    if (i == num)

        return 0;



    for (; p < num; ++p) {

        if (bits[p] > 32)

             return AVERROR_INVALIDDATA;

        if (bits[p] == 0)

             continue;

        

        for (i = bits[p]; i > 0; --i)

            if (exit_at_level[i])

                break;

        if (!i) 

             return AVERROR_INVALIDDATA;

        code = exit_at_level[i];

        exit_at_level[i] = 0;

        

        for (j = i + 1 ;j <= bits[p]; ++j)

            exit_at_level[j] = code + (1 << (j - 1));

        codes[p] = code;

    }



    

    for (p = 1; p < 33; p++)

        if (exit_at_level[p])

            return AVERROR_INVALIDDATA;



    return 0;

}

    for (p = 0; (bits[p] == 0) && (p < num); ++p)     for (i = p; (bits[i] == 0) && (i < num); ++i)
int FUNC_0(uint8_t *VAR_0, uint32_t *VAR_1, unsigned VAR_2)

{

    uint32_t exit_at_level[33] = { 404 };

    unsigned VAR_3, VAR_4, VAR_5, VAR_6;



    for (VAR_5 = 0; (VAR_0[VAR_5] == 0) && (VAR_5 < VAR_2); ++VAR_5)

        ;

    if (VAR_5 == VAR_2)

        return 0;



    VAR_1[VAR_5] = 0;

    if (VAR_0[VAR_5] > 32)

        return AVERROR_INVALIDDATA;

    for (VAR_3 = 0; VAR_3 < VAR_0[VAR_5]; ++VAR_3)

        exit_at_level[VAR_3+1] = 1 << VAR_3;



    ++VAR_5;



    for (VAR_3 = VAR_5; (VAR_0[VAR_3] == 0) && (VAR_3 < VAR_2); ++VAR_3)

        ;

    if (VAR_3 == VAR_2)

        return 0;



    for (; VAR_5 < VAR_2; ++VAR_5) {

        if (VAR_0[VAR_5] > 32)

             return AVERROR_INVALIDDATA;

        if (VAR_0[VAR_5] == 0)

             continue;

        

        for (VAR_3 = VAR_0[VAR_5]; VAR_3 > 0; --VAR_3)

            if (exit_at_level[VAR_3])

                break;

        if (!VAR_3) 

             return AVERROR_INVALIDDATA;

        VAR_6 = exit_at_level[VAR_3];

        exit_at_level[VAR_3] = 0;

        

        for (VAR_4 = VAR_3 + 1 ;VAR_4 <= VAR_0[VAR_5]; ++VAR_4)

            exit_at_level[VAR_4] = VAR_6 + (1 << (VAR_4 - 1));

        VAR_1[VAR_5] = VAR_6;

    }



    

    for (VAR_5 = 1; VAR_5 < 33; VAR_5++)

        if (exit_at_level[VAR_5])

            return AVERROR_INVALIDDATA;



    return 0;

}

int FUNC_0(uint8_t *VAR_0, uint32_t *VAR_1, unsigned VAR_2)
{ uint32_t exit_at_level[33] = { 404 }; unsigned VAR_3, VAR_4, VAR_5, VAR_6; for (VAR_5 = 0; (VAR_0[VAR_5] == 0) && (VAR_5 < VAR_2); ++VAR_5) ; if (VAR_5 == VAR_2)
return 0; VAR_1[VAR_5] = 0; if (VAR_0[VAR_5] > 32)
return AVERROR_INVALIDDATA; for (VAR_3 = 0; VAR_3 < VAR_0[VAR_5]; ++VAR_3) exit_at_level[VAR_3+1] = 1 << VAR_3; ++VAR_5; for (VAR_3 = VAR_5; (VAR_0[VAR_3] == 0) && (VAR_3 < VAR_2); ++VAR_3) ; if (VAR_3 == VAR_2)
return 0; for (; VAR_5 < VAR_2; ++VAR_5) { if (VAR_0[VAR_5] > 32)
return AVERROR_INVALIDDATA; if (VAR_0[VAR_5] == 0)
continue; for (VAR_3 = VAR_0[VAR_5]; VAR_3 > 0; --VAR_3) if (exit_at_level[VAR_3])
break; if (!VAR_3)
return AVERROR_INVALIDDATA; VAR_6 = exit_at_level[VAR_3]; exit_at_level[VAR_3] = 0; for (VAR_4 = VAR_3 + 1 ;VAR_4 <= VAR_0[VAR_5]; ++VAR_4) exit_at_level[VAR_4] = VAR_6 + (1 << (VAR_4 - 1)); VAR_1[VAR_5] = VAR_6; } for (VAR_5 = 1; VAR_5 < 33; VAR_5++) if (exit_at_level[VAR_5])
return AVERROR_INVALIDDATA; return 0; }