static av_always_inline int dnxhd_decode_dct_block(const DNXHDContext *ctx,

                                                   RowContext *row,

                                                   int n,

                                                   int index_bits,

                                                   int level_bias,

                                                   int level_shift,

                                                   int dc_shift)

{

    int i, j, index1, index2, len, flags;

    int level, component, sign;

    const int *scale;

    const uint8_t *weight_matrix;

    const uint8_t *ac_info = ctx->cid_table->ac_info;

    int16_t *block = row->blocks[n];

    const int eob_index     = ctx->cid_table->eob_index;

    int ret = 0;

    OPEN_READER(bs, &row->gb);



    ctx->bdsp.clear_block(block);



    if (!ctx->is_444) {

        if (n & 2) {

            component     = 1 + (n & 1);

            scale = row->chroma_scale;

            weight_matrix = ctx->cid_table->chroma_weight;

        } else {

            component     = 0;

            scale = row->luma_scale;

            weight_matrix = ctx->cid_table->luma_weight;

        }

    } else {

        component = (n >> 1) % 3;

        if (component) {

            scale = row->chroma_scale;

            weight_matrix = ctx->cid_table->chroma_weight;

        } else {

            scale = row->luma_scale;

            weight_matrix = ctx->cid_table->luma_weight;

        }

    }



    UPDATE_CACHE(bs, &row->gb);

    GET_VLC(len, bs, &row->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1);

    if (len) {

        level = GET_CACHE(bs, &row->gb);

        LAST_SKIP_BITS(bs, &row->gb, len);

        sign  = ~level >> 31;

        level = (NEG_USR32(sign ^ level, len) ^ sign) - sign;

        row->last_dc[component] += level << dc_shift;

    }

    block[0] = row->last_dc[component];



    i = 0;



    UPDATE_CACHE(bs, &row->gb);

    GET_VLC(index1, bs, &row->gb, ctx->ac_vlc.table,

            DNXHD_VLC_BITS, 2);



    while (index1 != eob_index) {

        level = ac_info[2*index1+0];

        flags = ac_info[2*index1+1];



        sign = SHOW_SBITS(bs, &row->gb, 1);

        SKIP_BITS(bs, &row->gb, 1);



        if (flags & 1) {

            level += SHOW_UBITS(bs, &row->gb, index_bits) << 7;

            SKIP_BITS(bs, &row->gb, index_bits);

        }



        if (flags & 2) {

            UPDATE_CACHE(bs, &row->gb);

            GET_VLC(index2, bs, &row->gb, ctx->run_vlc.table,

                    DNXHD_VLC_BITS, 2);

            i += ctx->cid_table->run[index2];

        }



        if (++i > 63) {

            av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, i);

            ret = -1;

            break;

        }



        j     = ctx->scantable.permutated[i];

        level *= scale[i];

        level += scale[i] >> 1;

        if (level_bias < 32 || weight_matrix[i] != level_bias)

            level += level_bias; // 1<<(level_shift-1)

        level >>= level_shift;



        block[j] = (level ^ sign) - sign;



        UPDATE_CACHE(bs, &row->gb);

        GET_VLC(index1, bs, &row->gb, ctx->ac_vlc.table,

                DNXHD_VLC_BITS, 2);

    }



    CLOSE_READER(bs, &row->gb);

    return ret;

}

static av_always_inline int dnxhd_decode_dct_block(const DNXHDContext *ctx,

                                                   RowContext *row,

                                                   int n,

                                                   int index_bits,

                                                   int level_bias,

                                                   int level_shift,

                                                   int dc_shift)

{

    int i, j, index1, index2, len, flags;

    int level, component, sign;

    const int *scale;

    const uint8_t *weight_matrix;

    const uint8_t *ac_info = ctx->cid_table->ac_info;

    int16_t *block = row->blocks[n];

    const int eob_index     = ctx->cid_table->eob_index;

    int ret = 0;

    OPEN_READER(bs, &row->gb);



    ctx->bdsp.clear_block(block);



    if (!ctx->is_444) {

        if (n & 2) {

            component     = 1 + (n & 1);

            scale = row->chroma_scale;

            weight_matrix = ctx->cid_table->chroma_weight;

        } else {

            component     = 0;

            scale = row->luma_scale;

            weight_matrix = ctx->cid_table->luma_weight;

        }

    } else {

        component = (n >> 1) % 3;

        if (component) {

            scale = row->chroma_scale;

            weight_matrix = ctx->cid_table->chroma_weight;

        } else {

            scale = row->luma_scale;

            weight_matrix = ctx->cid_table->luma_weight;

        }

    }



    UPDATE_CACHE(bs, &row->gb);

    GET_VLC(len, bs, &row->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1);

    if (len) {

        level = GET_CACHE(bs, &row->gb);

        LAST_SKIP_BITS(bs, &row->gb, len);

        sign  = ~level >> 31;

        level = (NEG_USR32(sign ^ level, len) ^ sign) - sign;

        row->last_dc[component] += level << dc_shift;

    }

    block[0] = row->last_dc[component];



    i = 0;



    UPDATE_CACHE(bs, &row->gb);

    GET_VLC(index1, bs, &row->gb, ctx->ac_vlc.table,

            DNXHD_VLC_BITS, 2);



    while (index1 != eob_index) {

        level = ac_info[2*index1+0];

        flags = ac_info[2*index1+1];



        sign = SHOW_SBITS(bs, &row->gb, 1);

        SKIP_BITS(bs, &row->gb, 1);



        if (flags & 1) {

            level += SHOW_UBITS(bs, &row->gb, index_bits) << 7;

            SKIP_BITS(bs, &row->gb, index_bits);

        }



        if (flags & 2) {

            UPDATE_CACHE(bs, &row->gb);

            GET_VLC(index2, bs, &row->gb, ctx->run_vlc.table,

                    DNXHD_VLC_BITS, 2);

            i += ctx->cid_table->run[index2];

        }



        if (++i > 63) {

            av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, i);

            ret = -1;

            break;

        }



        j     = ctx->scantable.permutated[i];

        level *= scale[i];

        level += scale[i] >> 1;

        if (level_bias < 32 || weight_matrix[i] != level_bias)

            level += level_bias; 

        level >>= level_shift;



        block[j] = (level ^ sign) - sign;



        UPDATE_CACHE(bs, &row->gb);

        GET_VLC(index1, bs, &row->gb, ctx->ac_vlc.table,

                DNXHD_VLC_BITS, 2);

    }



    CLOSE_READER(bs, &row->gb);

    return ret;

}

static av_always_inline int FUNC_0(const DNXHDContext *ctx,

                                                   RowContext *row,

                                                   int n,

                                                   int index_bits,

                                                   int level_bias,

                                                   int level_shift,

                                                   int dc_shift)

{

    int VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5;

    int VAR_6, VAR_7, VAR_8;

    const int *VAR_9;

    const uint8_t *VAR_10;

    const uint8_t *VAR_11 = ctx->cid_table->VAR_11;

    int16_t *block = row->blocks[n];

    const int VAR_12     = ctx->cid_table->VAR_12;

    int VAR_13 = 0;

    OPEN_READER(bs, &row->gb);



    ctx->bdsp.clear_block(block);



    if (!ctx->is_444) {

        if (n & 2) {

            VAR_7     = 1 + (n & 1);

            VAR_9 = row->chroma_scale;

            VAR_10 = ctx->cid_table->chroma_weight;

        } else {

            VAR_7     = 0;

            VAR_9 = row->luma_scale;

            VAR_10 = ctx->cid_table->luma_weight;

        }

    } else {

        VAR_7 = (n >> 1) % 3;

        if (VAR_7) {

            VAR_9 = row->chroma_scale;

            VAR_10 = ctx->cid_table->chroma_weight;

        } else {

            VAR_9 = row->luma_scale;

            VAR_10 = ctx->cid_table->luma_weight;

        }

    }



    UPDATE_CACHE(bs, &row->gb);

    GET_VLC(VAR_4, bs, &row->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1);

    if (VAR_4) {

        VAR_6 = GET_CACHE(bs, &row->gb);

        LAST_SKIP_BITS(bs, &row->gb, VAR_4);

        VAR_8  = ~VAR_6 >> 31;

        VAR_6 = (NEG_USR32(VAR_8 ^ VAR_6, VAR_4) ^ VAR_8) - VAR_8;

        row->last_dc[VAR_7] += VAR_6 << dc_shift;

    }

    block[0] = row->last_dc[VAR_7];



    VAR_0 = 0;



    UPDATE_CACHE(bs, &row->gb);

    GET_VLC(VAR_2, bs, &row->gb, ctx->ac_vlc.table,

            DNXHD_VLC_BITS, 2);



    while (VAR_2 != VAR_12) {

        VAR_6 = VAR_11[2*VAR_2+0];

        VAR_5 = VAR_11[2*VAR_2+1];



        VAR_8 = SHOW_SBITS(bs, &row->gb, 1);

        SKIP_BITS(bs, &row->gb, 1);



        if (VAR_5 & 1) {

            VAR_6 += SHOW_UBITS(bs, &row->gb, index_bits) << 7;

            SKIP_BITS(bs, &row->gb, index_bits);

        }



        if (VAR_5 & 2) {

            UPDATE_CACHE(bs, &row->gb);

            GET_VLC(VAR_3, bs, &row->gb, ctx->run_vlc.table,

                    DNXHD_VLC_BITS, 2);

            VAR_0 += ctx->cid_table->run[VAR_3];

        }



        if (++VAR_0 > 63) {

            av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, VAR_0);

            VAR_13 = -1;

            break;

        }



        VAR_1     = ctx->scantable.permutated[VAR_0];

        VAR_6 *= VAR_9[VAR_0];

        VAR_6 += VAR_9[VAR_0] >> 1;

        if (level_bias < 32 || VAR_10[VAR_0] != level_bias)

            VAR_6 += level_bias; 

        VAR_6 >>= level_shift;



        block[VAR_1] = (VAR_6 ^ VAR_8) - VAR_8;



        UPDATE_CACHE(bs, &row->gb);

        GET_VLC(VAR_2, bs, &row->gb, ctx->ac_vlc.table,

                DNXHD_VLC_BITS, 2);

    }



    CLOSE_READER(bs, &row->gb);

    return VAR_13;

}

static av_always_inline int FUNC_0(const DNXHDContext *ctx,
RowContext *row,
int n,
int index_bits,
int level_bias,
int level_shift,
int dc_shift)
{ int VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5; int VAR_6, VAR_7, VAR_8; const int *VAR_9; const uint8_t *VAR_10; const uint8_t *VAR_11 = ctx->cid_table->VAR_11; int16_t *block = row->blocks[n]; const int VAR_12     = ctx->cid_table->VAR_12; int VAR_13 = 0; OPEN_READER(bs, &row->gb); ctx->bdsp.clear_block(block); if (!ctx->is_444) { if (n & 2) { VAR_7     = 1 + (n & 1); VAR_9 = row->chroma_scale; VAR_10 = ctx->cid_table->chroma_weight; } else { VAR_7     = 0; VAR_9 = row->luma_scale; VAR_10 = ctx->cid_table->luma_weight; } } else { VAR_7 = (n >> 1) % 3; if (VAR_7) { VAR_9 = row->chroma_scale; VAR_10 = ctx->cid_table->chroma_weight; } else { VAR_9 = row->luma_scale; VAR_10 = ctx->cid_table->luma_weight; } } UPDATE_CACHE(bs, &row->gb); GET_VLC(VAR_4, bs, &row->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1); if (VAR_4) { VAR_6 = GET_CACHE(bs, &row->gb); LAST_SKIP_BITS(bs, &row->gb, VAR_4); VAR_8  = ~VAR_6 >> 31; VAR_6 = (NEG_USR32(VAR_8 ^ VAR_6, VAR_4) ^ VAR_8) - VAR_8; row->last_dc[VAR_7] += VAR_6 << dc_shift; } block[0] = row->last_dc[VAR_7]; VAR_0 = 0; UPDATE_CACHE(bs, &row->gb); GET_VLC(VAR_2, bs, &row->gb, ctx->ac_vlc.table,
DNXHD_VLC_BITS, 2); while (VAR_2 != VAR_12) { VAR_6 = VAR_11[2*VAR_2+0]; VAR_5 = VAR_11[2*VAR_2+1]; VAR_8 = SHOW_SBITS(bs, &row->gb, 1); SKIP_BITS(bs, &row->gb, 1); if (VAR_5 & 1) { VAR_6 += SHOW_UBITS(bs, &row->gb, index_bits) << 7; SKIP_BITS(bs, &row->gb, index_bits); } if (VAR_5 & 2) { UPDATE_CACHE(bs, &row->gb); GET_VLC(VAR_3, bs, &row->gb, ctx->run_vlc.table,
DNXHD_VLC_BITS, 2); VAR_0 += ctx->cid_table->run[VAR_3]; } if (++VAR_0 > 63) { av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, VAR_0); VAR_13 = -1; break; } VAR_1     = ctx->scantable.permutated[VAR_0]; VAR_6 *= VAR_9[VAR_0]; VAR_6 += VAR_9[VAR_0] >> 1; if (level_bias < 32 || VAR_10[VAR_0] != level_bias)
VAR_6 += level_bias; VAR_6 >>= level_shift; block[VAR_1] = (VAR_6 ^ VAR_8) - VAR_8; UPDATE_CACHE(bs, &row->gb); GET_VLC(VAR_2, bs, &row->gb, ctx->ac_vlc.table,
DNXHD_VLC_BITS, 2); } CLOSE_READER(bs, &row->gb); return VAR_13; }