static int dnxhd_init_vlc(DNXHDEncContext *ctx)

{

    int i, j, level, run;

    int max_level = 1<<(ctx->cid_table->bit_depth+2);



    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes), fail);

    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits,  max_level*4*sizeof(*ctx->vlc_bits) , fail);

    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2,                                fail);

    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits,  63,                                  fail);



    ctx->vlc_codes += max_level*2;

    ctx->vlc_bits  += max_level*2;

    for (level = -max_level; level < max_level; level++) {

        for (run = 0; run < 2; run++) {

            int index = (level<<1)|run;

            int sign, offset = 0, alevel = level;



            MASK_ABS(sign, alevel);

            if (alevel > 64) {

                offset = (alevel-1)>>6;

                alevel -= offset<<6;

            }

            for (j = 0; j < 257; j++) {

                if (ctx->cid_table->ac_level[j] >> 1 == alevel &&

                    (!offset || (ctx->cid_table->ac_index_flag[j] && offset)) &&

                    (!run    || (ctx->cid_table->ac_run_flag  [j] && run))) {

                    assert(!ctx->vlc_codes[index]);

                    if (alevel) {

                        ctx->vlc_codes[index] = (ctx->cid_table->ac_codes[j]<<1)|(sign&1);

                        ctx->vlc_bits [index] = ctx->cid_table->ac_bits[j]+1;

                    } else {

                        ctx->vlc_codes[index] = ctx->cid_table->ac_codes[j];

                        ctx->vlc_bits [index] = ctx->cid_table->ac_bits [j];

                    }

                    break;

                }

            }

            assert(!alevel || j < 257);

            if (offset) {

                ctx->vlc_codes[index] = (ctx->vlc_codes[index]<<ctx->cid_table->index_bits)|offset;

                ctx->vlc_bits [index]+= ctx->cid_table->index_bits;

            }

        }

    }

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

        int run = ctx->cid_table->run[i];

        assert(run < 63);

        ctx->run_codes[run] = ctx->cid_table->run_codes[i];

        ctx->run_bits [run] = ctx->cid_table->run_bits[i];

    }

    return 0;

 fail:

    return -1;

}

static int dnxhd_init_vlc(DNXHDEncContext *ctx)

{

    int i, j, level, run;

    int max_level = 1<<(ctx->cid_table->bit_depth+2);



    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes), fail);

    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits,  max_level*4*sizeof(*ctx->vlc_bits) , fail);

    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2,                                fail);

    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits,  63,                                  fail);



    ctx->vlc_codes += max_level*2;

    ctx->vlc_bits  += max_level*2;

    for (level = -max_level; level < max_level; level++) {

        for (run = 0; run < 2; run++) {

            int index = (level<<1)|run;

            int sign, offset = 0, alevel = level;



            MASK_ABS(sign, alevel);

            if (alevel > 64) {

                offset = (alevel-1)>>6;

                alevel -= offset<<6;

            }

            for (j = 0; j < 257; j++) {

                if (ctx->cid_table->ac_level[j] >> 1 == alevel &&

                    (!offset || (ctx->cid_table->ac_index_flag[j] && offset)) &&

                    (!run    || (ctx->cid_table->ac_run_flag  [j] && run))) {

                    assert(!ctx->vlc_codes[index]);

                    if (alevel) {

                        ctx->vlc_codes[index] = (ctx->cid_table->ac_codes[j]<<1)|(sign&1);

                        ctx->vlc_bits [index] = ctx->cid_table->ac_bits[j]+1;

                    } else {

                        ctx->vlc_codes[index] = ctx->cid_table->ac_codes[j];

                        ctx->vlc_bits [index] = ctx->cid_table->ac_bits [j];

                    }

                    break;

                }

            }

            assert(!alevel || j < 257);

            if (offset) {

                ctx->vlc_codes[index] = (ctx->vlc_codes[index]<<ctx->cid_table->index_bits)|offset;

                ctx->vlc_bits [index]+= ctx->cid_table->index_bits;

            }

        }

    }

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

        int run = ctx->cid_table->run[i];

        assert(run < 63);

        ctx->run_codes[run] = ctx->cid_table->run_codes[i];

        ctx->run_bits [run] = ctx->cid_table->run_bits[i];

    }

    return 0;

 fail:

    return -1;

}

static int FUNC_0(DNXHDEncContext *VAR_0)

{

    int VAR_1, VAR_2, VAR_3, VAR_10;

    int VAR_5 = 1<<(VAR_0->cid_table->bit_depth+2);



    FF_ALLOCZ_OR_GOTO(VAR_0->m.avctx, VAR_0->vlc_codes, VAR_5*4*sizeof(*VAR_0->vlc_codes), fail);

    FF_ALLOCZ_OR_GOTO(VAR_0->m.avctx, VAR_0->vlc_bits,  VAR_5*4*sizeof(*VAR_0->vlc_bits) , fail);

    FF_ALLOCZ_OR_GOTO(VAR_0->m.avctx, VAR_0->run_codes, 63*2,                                fail);

    FF_ALLOCZ_OR_GOTO(VAR_0->m.avctx, VAR_0->run_bits,  63,                                  fail);



    VAR_0->vlc_codes += VAR_5*2;

    VAR_0->vlc_bits  += VAR_5*2;

    for (VAR_3 = -VAR_5; VAR_3 < VAR_5; VAR_3++) {

        for (VAR_10 = 0; VAR_10 < 2; VAR_10++) {

            int VAR_6 = (VAR_3<<1)|VAR_10;

            int VAR_7, VAR_8 = 0, VAR_9 = VAR_3;



            MASK_ABS(VAR_7, VAR_9);

            if (VAR_9 > 64) {

                VAR_8 = (VAR_9-1)>>6;

                VAR_9 -= VAR_8<<6;

            }

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

                if (VAR_0->cid_table->ac_level[VAR_2] >> 1 == VAR_9 &&

                    (!VAR_8 || (VAR_0->cid_table->ac_index_flag[VAR_2] && VAR_8)) &&

                    (!VAR_10    || (VAR_0->cid_table->ac_run_flag  [VAR_2] && VAR_10))) {

                    assert(!VAR_0->vlc_codes[VAR_6]);

                    if (VAR_9) {

                        VAR_0->vlc_codes[VAR_6] = (VAR_0->cid_table->ac_codes[VAR_2]<<1)|(VAR_7&1);

                        VAR_0->vlc_bits [VAR_6] = VAR_0->cid_table->ac_bits[VAR_2]+1;

                    } else {

                        VAR_0->vlc_codes[VAR_6] = VAR_0->cid_table->ac_codes[VAR_2];

                        VAR_0->vlc_bits [VAR_6] = VAR_0->cid_table->ac_bits [VAR_2];

                    }

                    break;

                }

            }

            assert(!VAR_9 || VAR_2 < 257);

            if (VAR_8) {

                VAR_0->vlc_codes[VAR_6] = (VAR_0->vlc_codes[VAR_6]<<VAR_0->cid_table->index_bits)|VAR_8;

                VAR_0->vlc_bits [VAR_6]+= VAR_0->cid_table->index_bits;

            }

        }

    }

    for (VAR_1 = 0; VAR_1 < 62; VAR_1++) {

        int VAR_10 = VAR_0->cid_table->VAR_10[VAR_1];

        assert(VAR_10 < 63);

        VAR_0->run_codes[VAR_10] = VAR_0->cid_table->run_codes[VAR_1];

        VAR_0->run_bits [VAR_10] = VAR_0->cid_table->run_bits[VAR_1];

    }

    return 0;

 fail:

    return -1;

}

static int FUNC_0(DNXHDEncContext *VAR_0)
{ int VAR_1, VAR_2, VAR_3, VAR_10; int VAR_5 = 1<<(VAR_0->cid_table->bit_depth+2); FF_ALLOCZ_OR_GOTO(VAR_0->m.avctx, VAR_0->vlc_codes, VAR_5*4*sizeof(*VAR_0->vlc_codes), fail); FF_ALLOCZ_OR_GOTO(VAR_0->m.avctx, VAR_0->vlc_bits,  VAR_5*4*sizeof(*VAR_0->vlc_bits) , fail); FF_ALLOCZ_OR_GOTO(VAR_0->m.avctx, VAR_0->run_codes, 63*2,                                fail); FF_ALLOCZ_OR_GOTO(VAR_0->m.avctx, VAR_0->run_bits,  63,                                  fail); VAR_0->vlc_codes += VAR_5*2; VAR_0->vlc_bits  += VAR_5*2; for (VAR_3 = -VAR_5; VAR_3 < VAR_5; VAR_3++) { for (VAR_10 = 0; VAR_10 < 2; VAR_10++) { int VAR_6 = (VAR_3<<1)|VAR_10; int VAR_7, VAR_8 = 0, VAR_9 = VAR_3; MASK_ABS(VAR_7, VAR_9); if (VAR_9 > 64) { VAR_8 = (VAR_9-1)>>6; VAR_9 -= VAR_8<<6; } for (VAR_2 = 0; VAR_2 < 257; VAR_2++) { if (VAR_0->cid_table->ac_level[VAR_2] >> 1 == VAR_9 &&
(!VAR_8 || (VAR_0->cid_table->ac_index_flag[VAR_2] && VAR_8)) &&
(!VAR_10    || (VAR_0->cid_table->ac_run_flag  [VAR_2] && VAR_10))) { assert(!VAR_0->vlc_codes[VAR_6]); if (VAR_9) { VAR_0->vlc_codes[VAR_6] = (VAR_0->cid_table->ac_codes[VAR_2]<<1)|(VAR_7&1); VAR_0->vlc_bits [VAR_6] = VAR_0->cid_table->ac_bits[VAR_2]+1; } else { VAR_0->vlc_codes[VAR_6] = VAR_0->cid_table->ac_codes[VAR_2]; VAR_0->vlc_bits [VAR_6] = VAR_0->cid_table->ac_bits [VAR_2]; } break; } } assert(!VAR_9 || VAR_2 < 257); if (VAR_8) { VAR_0->vlc_codes[VAR_6] = (VAR_0->vlc_codes[VAR_6]<<VAR_0->cid_table->index_bits)|VAR_8; VAR_0->vlc_bits [VAR_6]+= VAR_0->cid_table->index_bits; } } } for (VAR_1 = 0; VAR_1 < 62; VAR_1++) { int VAR_10 = VAR_0->cid_table->VAR_10[VAR_1]; assert(VAR_10 < 63); VAR_0->run_codes[VAR_10] = VAR_0->cid_table->run_codes[VAR_1]; VAR_0->run_bits [VAR_10] = VAR_0->cid_table->run_bits[VAR_1]; } return 0; fail:
return -1; }