static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,

                       VLCcode *codes, int flags)

{

    int table_size, table_index, index, code_prefix, symbol, subtable_bits;

    int i, j, k, n, nb, inc;

    uint32_t code;

    VLC_TYPE (*table)[2];



    table_size = 1 << table_nb_bits;

    if (table_nb_bits > 30)

       return -1;

    table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);

    av_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);

    if (table_index < 0)

        return table_index;

    table = &vlc->table[table_index];



    for (i = 0; i < table_size; i++) {

        table[i][1] = 0; //bits

        table[i][0] = -1; //codes

    }



    /* first pass: map codes and compute auxiliary table sizes */

    for (i = 0; i < nb_codes; i++) {

        n      = codes[i].bits;

        code   = codes[i].code;

        symbol = codes[i].symbol;

        av_dlog(NULL, "i=%d n=%d code=0x%x\n", i, n, code);

        if (n <= table_nb_bits) {

            /* no need to add another table */

            j = code >> (32 - table_nb_bits);

            nb = 1 << (table_nb_bits - n);

            inc = 1;

            if (flags & INIT_VLC_LE) {

                j = bitswap_32(code);

                inc = 1 << n;

            }

            for (k = 0; k < nb; k++) {

                av_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n);

                if (table[j][1] /*bits*/ != 0) {

                    av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");

                    return AVERROR_INVALIDDATA;

                }

                table[j][1] = n; //bits

                table[j][0] = symbol;

                j += inc;

            }

        } else {

            /* fill auxiliary table recursively */

            n -= table_nb_bits;

            code_prefix = code >> (32 - table_nb_bits);

            subtable_bits = n;

            codes[i].bits = n;

            codes[i].code = code << table_nb_bits;

            for (k = i+1; k < nb_codes; k++) {

                n = codes[k].bits - table_nb_bits;

                if (n <= 0)

                    break;

                code = codes[k].code;

                if (code >> (32 - table_nb_bits) != code_prefix)

                    break;

                codes[k].bits = n;

                codes[k].code = code << table_nb_bits;

                subtable_bits = FFMAX(subtable_bits, n);

            }

            subtable_bits = FFMIN(subtable_bits, table_nb_bits);

            j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;

            table[j][1] = -subtable_bits;

            av_dlog(NULL, "%4x: n=%d (subtable)\n",

                    j, codes[i].bits + table_nb_bits);

            index = build_table(vlc, subtable_bits, k-i, codes+i, flags);

            if (index < 0)

                return index;

            /* note: realloc has been done, so reload tables */

            table = &vlc->table[table_index];

            table[j][0] = index; //code


            i = k-1;

        }

    }

    return table_index;

}
static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,

                       VLCcode *codes, int flags)

{

    int table_size, table_index, index, code_prefix, symbol, subtable_bits;

    int i, j, k, n, nb, inc;

    uint32_t code;

    VLC_TYPE (*table)[2];



    table_size = 1 << table_nb_bits;

    if (table_nb_bits > 30)

       return -1;

    table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);

    av_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);

    if (table_index < 0)

        return table_index;

    table = &vlc->table[table_index];



    for (i = 0; i < table_size; i++) {

        table[i][1] = 0; 

        table[i][0] = -1; 

    }



    

    for (i = 0; i < nb_codes; i++) {

        n      = codes[i].bits;

        code   = codes[i].code;

        symbol = codes[i].symbol;

        av_dlog(NULL, "i=%d n=%d code=0x%x\n", i, n, code);

        if (n <= table_nb_bits) {

            

            j = code >> (32 - table_nb_bits);

            nb = 1 << (table_nb_bits - n);

            inc = 1;

            if (flags & INIT_VLC_LE) {

                j = bitswap_32(code);

                inc = 1 << n;

            }

            for (k = 0; k < nb; k++) {

                av_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n);

                if (table[j][1]  != 0) {

                    av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");

                    return AVERROR_INVALIDDATA;

                }

                table[j][1] = n; 

                table[j][0] = symbol;

                j += inc;

            }

        } else {

            

            n -= table_nb_bits;

            code_prefix = code >> (32 - table_nb_bits);

            subtable_bits = n;

            codes[i].bits = n;

            codes[i].code = code << table_nb_bits;

            for (k = i+1; k < nb_codes; k++) {

                n = codes[k].bits - table_nb_bits;

                if (n <= 0)

                    break;

                code = codes[k].code;

                if (code >> (32 - table_nb_bits) != code_prefix)

                    break;

                codes[k].bits = n;

                codes[k].code = code << table_nb_bits;

                subtable_bits = FFMAX(subtable_bits, n);

            }

            subtable_bits = FFMIN(subtable_bits, table_nb_bits);

            j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;

            table[j][1] = -subtable_bits;

            av_dlog(NULL, "%4x: n=%d (subtable)\n",

                    j, codes[i].bits + table_nb_bits);

            index = build_table(vlc, subtable_bits, k-i, codes+i, flags);

            if (index < 0)

                return index;

            

            table = &vlc->table[table_index];

            table[j][0] = index; 


            i = k-1;

        }

    }

    return table_index;

}
static int FUNC_0(VLC *VAR_0, int VAR_1, int VAR_2,

                       VLCcode *VAR_3, int VAR_4)

{

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10;

    int VAR_11, VAR_12, VAR_13, VAR_14, VAR_15, VAR_16;

    uint32_t code;

    VLC_TYPE (*table)[2];



    VAR_5 = 1 << VAR_1;

    if (VAR_1 > 30)

       return -1;

    VAR_6 = alloc_table(VAR_0, VAR_5, VAR_4 & INIT_VLC_USE_NEW_STATIC);

    av_dlog(NULL, "new table VAR_7=%d size=%d\VAR_14", VAR_6, VAR_5);

    if (VAR_6 < 0)

        return VAR_6;

    table = &VAR_0->table[VAR_6];



    for (VAR_11 = 0; VAR_11 < VAR_5; VAR_11++) {

        table[VAR_11][1] = 0; 

        table[VAR_11][0] = -1; 

    }



    

    for (VAR_11 = 0; VAR_11 < VAR_2; VAR_11++) {

        VAR_14      = VAR_3[VAR_11].bits;

        code   = VAR_3[VAR_11].code;

        VAR_9 = VAR_3[VAR_11].VAR_9;

        av_dlog(NULL, "VAR_11=%d VAR_14=%d code=0x%x\VAR_14", VAR_11, VAR_14, code);

        if (VAR_14 <= VAR_1) {

            

            VAR_12 = code >> (32 - VAR_1);

            VAR_15 = 1 << (VAR_1 - VAR_14);

            VAR_16 = 1;

            if (VAR_4 & INIT_VLC_LE) {

                VAR_12 = bitswap_32(code);

                VAR_16 = 1 << VAR_14;

            }

            for (VAR_13 = 0; VAR_13 < VAR_15; VAR_13++) {

                av_dlog(NULL, "%4x: code=%d VAR_14=%d\VAR_14", VAR_12, VAR_11, VAR_14);

                if (table[VAR_12][1]  != 0) {

                    av_log(NULL, AV_LOG_ERROR, "incorrect VAR_3\VAR_14");

                    return AVERROR_INVALIDDATA;

                }

                table[VAR_12][1] = VAR_14; 

                table[VAR_12][0] = VAR_9;

                VAR_12 += VAR_16;

            }

        } else {

            

            VAR_14 -= VAR_1;

            VAR_8 = code >> (32 - VAR_1);

            VAR_10 = VAR_14;

            VAR_3[VAR_11].bits = VAR_14;

            VAR_3[VAR_11].code = code << VAR_1;

            for (VAR_13 = VAR_11+1; VAR_13 < VAR_2; VAR_13++) {

                VAR_14 = VAR_3[VAR_13].bits - VAR_1;

                if (VAR_14 <= 0)

                    break;

                code = VAR_3[VAR_13].code;

                if (code >> (32 - VAR_1) != VAR_8)

                    break;

                VAR_3[VAR_13].bits = VAR_14;

                VAR_3[VAR_13].code = code << VAR_1;

                VAR_10 = FFMAX(VAR_10, VAR_14);

            }

            VAR_10 = FFMIN(VAR_10, VAR_1);

            VAR_12 = (VAR_4 & INIT_VLC_LE) ? bitswap_32(VAR_8) >> (32 - VAR_1) : VAR_8;

            table[VAR_12][1] = -VAR_10;

            av_dlog(NULL, "%4x: VAR_14=%d (subtable)\VAR_14",

                    VAR_12, VAR_3[VAR_11].bits + VAR_1);

            VAR_7 = FUNC_0(VAR_0, VAR_10, VAR_13-VAR_11, VAR_3+VAR_11, VAR_4);

            if (VAR_7 < 0)

                return VAR_7;

            

            table = &VAR_0->table[VAR_6];

            table[VAR_12][0] = VAR_7; 


            VAR_11 = VAR_13-1;

        }

    }

    return VAR_6;

}
static int FUNC_0(VLC *VAR_0, int VAR_1, int VAR_2,
VLCcode *VAR_3, int VAR_4)
{ int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; int VAR_11, VAR_12, VAR_13, VAR_14, VAR_15, VAR_16; uint32_t code; VLC_TYPE (*table)[2]; VAR_5 = 1 << VAR_1; if (VAR_1 > 30)
return -1; VAR_6 = alloc_table(VAR_0, VAR_5, VAR_4 & INIT_VLC_USE_NEW_STATIC); av_dlog(NULL, "new table VAR_7=%d size=%d\VAR_14", VAR_6, VAR_5); if (VAR_6 < 0)
return VAR_6; table = &VAR_0->table[VAR_6]; for (VAR_11 = 0; VAR_11 < VAR_5; VAR_11++) { table[VAR_11][1] = 0; table[VAR_11][0] = -1; } for (VAR_11 = 0; VAR_11 < VAR_2; VAR_11++) { VAR_14      = VAR_3[VAR_11].bits; code   = VAR_3[VAR_11].code; VAR_9 = VAR_3[VAR_11].VAR_9; av_dlog(NULL, "VAR_11=%d VAR_14=%d code=0x%x\VAR_14", VAR_11, VAR_14, code); if (VAR_14 <= VAR_1) { VAR_12 = code >> (32 - VAR_1); VAR_15 = 1 << (VAR_1 - VAR_14); VAR_16 = 1; if (VAR_4 & INIT_VLC_LE) { VAR_12 = bitswap_32(code); VAR_16 = 1 << VAR_14; } for (VAR_13 = 0; VAR_13 < VAR_15; VAR_13++) { av_dlog(NULL, "%4x: code=%d VAR_14=%d\VAR_14", VAR_12, VAR_11, VAR_14); if (table[VAR_12][1]  != 0) { av_log(NULL, AV_LOG_ERROR, "incorrect VAR_3\VAR_14"); return AVERROR_INVALIDDATA; } table[VAR_12][1] = VAR_14; table[VAR_12][0] = VAR_9; VAR_12 += VAR_16; } } else { VAR_14 -= VAR_1; VAR_8 = code >> (32 - VAR_1); VAR_10 = VAR_14; VAR_3[VAR_11].bits = VAR_14; VAR_3[VAR_11].code = code << VAR_1; for (VAR_13 = VAR_11+1; VAR_13 < VAR_2; VAR_13++) { VAR_14 = VAR_3[VAR_13].bits - VAR_1; if (VAR_14 <= 0)
break; code = VAR_3[VAR_13].code; if (code >> (32 - VAR_1) != VAR_8)
break; VAR_3[VAR_13].bits = VAR_14; VAR_3[VAR_13].code = code << VAR_1; VAR_10 = FFMAX(VAR_10, VAR_14); } VAR_10 = FFMIN(VAR_10, VAR_1); VAR_12 = (VAR_4 & INIT_VLC_LE) ? bitswap_32(VAR_8) >> (32 - VAR_1) : VAR_8; table[VAR_12][1] = -VAR_10; av_dlog(NULL, "%4x: VAR_14=%d (subtable)\VAR_14",
VAR_12, VAR_3[VAR_11].bits + VAR_1); VAR_7 = FUNC_0(VAR_0, VAR_10, VAR_13-VAR_11, VAR_3+VAR_11, VAR_4); if (VAR_7 < 0)
return VAR_7; table = &VAR_0->table[VAR_6]; table[VAR_12][0] = VAR_7; VAR_11 = VAR_13-1; } } return VAR_6; }