static int mpeg2_decode_block_non_intra(MpegEncContext *s, 

                                        DCTELEM *block, 

                                        int n)

{

    int level, i, j, run;

    int code;

    RLTable *rl = &rl_mpeg1;

    const UINT8 *scan_table;

    const UINT16 *matrix;

    int mismatch;



    if (s->alternate_scan)

        scan_table = ff_alternate_vertical_scan;

    else

        scan_table = zigzag_direct;

    mismatch = 1;



    {

        int bit_cnt, v;

        UINT32 bit_buf;

        UINT8 *buf_ptr;

        i = 0;

        if (n < 4) 

            matrix = s->non_intra_matrix;

        else

            matrix = s->chroma_non_intra_matrix;

            

        /* special case for the first coef. no need to add a second vlc table */

        SAVE_BITS(&s->gb);

        SHOW_BITS(&s->gb, v, 2);

        if (v & 2) {

            run = 0;

            level = 1 - ((v & 1) << 1);

            FLUSH_BITS(2);

            RESTORE_BITS(&s->gb);

            goto add_coef;

        }

        RESTORE_BITS(&s->gb);

    }



    /* now quantify & encode AC coefs */

    for(;;) {

        code = get_vlc(&s->gb, &rl->vlc);

        if (code < 0)

            return -1;

        if (code == 112) {

            break;

        } else if (code == 111) {

            /* escape */

            run = get_bits(&s->gb, 6);

            level = get_bits(&s->gb, 12);

            level = (level << 20) >> 20;

        } else {

            run = rl->table_run[code];

            level = rl->table_level[code];

            if (get_bits1(&s->gb))

                level = -level;

        }

        i += run;

        if (i >= 64)

            return -1;

    add_coef:

	j = scan_table[i];

        dprintf("%d: run=%d level=%d\n", n, run, level);

        /* XXX: optimize */

        if (level > 0) {

            level = ((level * 2 + 1) * s->qscale * matrix[j]) >> 5;

        } else {

            level = ((-level * 2 + 1) * s->qscale * matrix[j]) >> 5;

            level = -level;

        }

        /* XXX: is it really necessary to saturate since the encoder

           knows whats going on ? */

        mismatch ^= level;

        block[j] = level;

        i++;

    }

    block[63] ^= (mismatch & 1);

    s->block_last_index[n] = i;

    return 0;

}

static int mpeg2_decode_block_non_intra(MpegEncContext *s, 

                                        DCTELEM *block, 

                                        int n)

{

    int level, i, j, run;

    int code;

    RLTable *rl = &rl_mpeg1;

    const UINT8 *scan_table;

    const UINT16 *matrix;

    int mismatch;



    if (s->alternate_scan)

        scan_table = ff_alternate_vertical_scan;

    else

        scan_table = zigzag_direct;

    mismatch = 1;



    {

        int bit_cnt, v;

        UINT32 bit_buf;

        UINT8 *buf_ptr;

        i = 0;

        if (n < 4) 

            matrix = s->non_intra_matrix;

        else

            matrix = s->chroma_non_intra_matrix;

            

        

        SAVE_BITS(&s->gb);

        SHOW_BITS(&s->gb, v, 2);

        if (v & 2) {

            run = 0;

            level = 1 - ((v & 1) << 1);

            FLUSH_BITS(2);

            RESTORE_BITS(&s->gb);

            goto add_coef;

        }

        RESTORE_BITS(&s->gb);

    }



    

    for(;;) {

        code = get_vlc(&s->gb, &rl->vlc);

        if (code < 0)

            return -1;

        if (code == 112) {

            break;

        } else if (code == 111) {

            

            run = get_bits(&s->gb, 6);

            level = get_bits(&s->gb, 12);

            level = (level << 20) >> 20;

        } else {

            run = rl->table_run[code];

            level = rl->table_level[code];

            if (get_bits1(&s->gb))

                level = -level;

        }

        i += run;

        if (i >= 64)

            return -1;

    add_coef:

	j = scan_table[i];

        dprintf("%d: run=%d level=%d\n", n, run, level);

        

        if (level > 0) {

            level = ((level * 2 + 1) * s->qscale * matrix[j]) >> 5;

        } else {

            level = ((-level * 2 + 1) * s->qscale * matrix[j]) >> 5;

            level = -level;

        }

        



        mismatch ^= level;

        block[j] = level;

        i++;

    }

    block[63] ^= (mismatch & 1);

    s->block_last_index[n] = i;

    return 0;

}

        } else {         i = 0;             matrix = s->non_intra_matrix;             matrix = s->chroma_non_intra_matrix;         } else {         } else {
static int FUNC_0(MpegEncContext *VAR_0, 

                                        DCTELEM *VAR_1, 

                                        int VAR_2)

{

    int VAR_3, VAR_4, VAR_5, VAR_6;

    int VAR_7;

    RLTable *rl = &rl_mpeg1;

    const UINT8 *VAR_8;

    const UINT16 *VAR_9;

    int VAR_10;



    if (VAR_0->alternate_scan)

        VAR_8 = ff_alternate_vertical_scan;

    else

        VAR_8 = zigzag_direct;

    VAR_10 = 1;



    {

        int VAR_11, VAR_12;

        UINT32 bit_buf;

        UINT8 *buf_ptr;

        VAR_4 = 0;

        if (VAR_2 < 4) 

            VAR_9 = VAR_0->non_intra_matrix;

        else

            VAR_9 = VAR_0->chroma_non_intra_matrix;

            

        

        SAVE_BITS(&VAR_0->gb);

        SHOW_BITS(&VAR_0->gb, VAR_12, 2);

        if (VAR_12 & 2) {

            VAR_6 = 0;

            VAR_3 = 1 - ((VAR_12 & 1) << 1);

            FLUSH_BITS(2);

            RESTORE_BITS(&VAR_0->gb);

            goto add_coef;

        }

        RESTORE_BITS(&VAR_0->gb);

    }



    

    for(;;) {

        VAR_7 = get_vlc(&VAR_0->gb, &rl->vlc);

        if (VAR_7 < 0)

            return -1;

        if (VAR_7 == 112) {

            break;

        } else if (VAR_7 == 111) {

            

            VAR_6 = get_bits(&VAR_0->gb, 6);

            VAR_3 = get_bits(&VAR_0->gb, 12);

            VAR_3 = (VAR_3 << 20) >> 20;

        } else {

            VAR_6 = rl->table_run[VAR_7];

            VAR_3 = rl->table_level[VAR_7];

            if (get_bits1(&VAR_0->gb))

                VAR_3 = -VAR_3;

        }

        VAR_4 += VAR_6;

        if (VAR_4 >= 64)

            return -1;

    add_coef:

	VAR_5 = VAR_8[VAR_4];

        dprintf("%d: VAR_6=%d VAR_3=%d\VAR_2", VAR_2, VAR_6, VAR_3);

        

        if (VAR_3 > 0) {

            VAR_3 = ((VAR_3 * 2 + 1) * VAR_0->qscale * VAR_9[VAR_5]) >> 5;

        } else {

            VAR_3 = ((-VAR_3 * 2 + 1) * VAR_0->qscale * VAR_9[VAR_5]) >> 5;

            VAR_3 = -VAR_3;

        }

        



        VAR_10 ^= VAR_3;

        VAR_1[VAR_5] = VAR_3;

        VAR_4++;

    }

    VAR_1[63] ^= (VAR_10 & 1);

    VAR_0->block_last_index[VAR_2] = VAR_4;

    return 0;

}

static int FUNC_0(MpegEncContext *VAR_0,
DCTELEM *VAR_1,
int VAR_2)
{ int VAR_3, VAR_4, VAR_5, VAR_6; int VAR_7; RLTable *rl = &rl_mpeg1; const UINT8 *VAR_8; const UINT16 *VAR_9; int VAR_10; if (VAR_0->alternate_scan)
VAR_8 = ff_alternate_vertical_scan; else
VAR_8 = zigzag_direct; VAR_10 = 1; { int VAR_11, VAR_12; UINT32 bit_buf; UINT8 *buf_ptr; VAR_4 = 0; if (VAR_2 < 4)
VAR_9 = VAR_0->non_intra_matrix; else
VAR_9 = VAR_0->chroma_non_intra_matrix; SAVE_BITS(&VAR_0->gb); SHOW_BITS(&VAR_0->gb, VAR_12, 2); if (VAR_12 & 2) { VAR_6 = 0; VAR_3 = 1 - ((VAR_12 & 1) << 1); FLUSH_BITS(2); RESTORE_BITS(&VAR_0->gb); goto add_coef; } RESTORE_BITS(&VAR_0->gb); } for(;;) { VAR_7 = get_vlc(&VAR_0->gb, &rl->vlc); if (VAR_7 < 0)
return -1; if (VAR_7 == 112) { break; } else if (VAR_7 == 111) { VAR_6 = get_bits(&VAR_0->gb, 6); VAR_3 = get_bits(&VAR_0->gb, 12); VAR_3 = (VAR_3 << 20) >> 20; } else { VAR_6 = rl->table_run[VAR_7]; VAR_3 = rl->table_level[VAR_7]; if (get_bits1(&VAR_0->gb))
VAR_3 = -VAR_3; } VAR_4 += VAR_6; if (VAR_4 >= 64)
return -1; add_coef:
VAR_5 = VAR_8[VAR_4]; dprintf("%d: VAR_6=%d VAR_3=%d\VAR_2", VAR_2, VAR_6, VAR_3); if (VAR_3 > 0) { VAR_3 = ((VAR_3 * 2 + 1) * VAR_0->qscale * VAR_9[VAR_5]) >> 5; } else { VAR_3 = ((-VAR_3 * 2 + 1) * VAR_0->qscale * VAR_9[VAR_5]) >> 5; VAR_3 = -VAR_3; } VAR_10 ^= VAR_3; VAR_1[VAR_5] = VAR_3; VAR_4++; } VAR_1[63] ^= (VAR_10 & 1); VAR_0->block_last_index[VAR_2] = VAR_4; return 0; }