static int decode_block_refinement(MJpegDecodeContext *s, DCTELEM *block, uint8_t *last_nnz,

                        int ac_index, int16_t *quant_matrix,

                        int ss, int se, int Al, int *EOBRUN)

{

    int code, i=ss, j, sign, val, run;

    int last = FFMIN(se, *last_nnz);



    OPEN_READER(re, &s->gb);

    if(*EOBRUN)

        (*EOBRUN)--;

    else {

        for(;;i++) {

            UPDATE_CACHE(re, &s->gb);

            GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2)

            /* Progressive JPEG use AC coeffs from zero and this decoder sets offset 16 by default */

            code -= 16;

            if(code & 0xF) {

                run = ((unsigned) code) >> 4;

                UPDATE_CACHE(re, &s->gb);

                val = SHOW_UBITS(re, &s->gb, 1);

                LAST_SKIP_BITS(re, &s->gb, 1);

                ZERO_RUN;

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

                val--;

                block[j] = ((quant_matrix[j]^val)-val) << Al;

                if(i == se) {

                    if(i > *last_nnz)

                        *last_nnz = i;

                    CLOSE_READER(re, &s->gb)

                    return 0;

                }

            }else{

                run = ((unsigned) code) >> 4;

                if(run == 0xF){

                    ZERO_RUN;

                }else{

                    val = run;

                    run = (1 << run);

                    if(val) {

                        UPDATE_CACHE(re, &s->gb);

                        run += SHOW_UBITS(re, &s->gb, val);

                        LAST_SKIP_BITS(re, &s->gb, val);

                    }

                    *EOBRUN = run - 1;

                    break;

                }

            }

        }



        if(i > *last_nnz)

            *last_nnz = i;

    }



    for(;i<=last;i++) {

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

        if(block[j])

            REFINE_BIT(j)

    }

    CLOSE_READER(re, &s->gb);



    return 0;

}

static int decode_block_refinement(MJpegDecodeContext *s, DCTELEM *block, uint8_t *last_nnz,

                        int ac_index, int16_t *quant_matrix,

                        int ss, int se, int Al, int *EOBRUN)

{

    int code, i=ss, j, sign, val, run;

    int last = FFMIN(se, *last_nnz);



    OPEN_READER(re, &s->gb);

    if(*EOBRUN)

        (*EOBRUN)--;

    else {

        for(;;i++) {

            UPDATE_CACHE(re, &s->gb);

            GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2)

            

            code -= 16;

            if(code & 0xF) {

                run = ((unsigned) code) >> 4;

                UPDATE_CACHE(re, &s->gb);

                val = SHOW_UBITS(re, &s->gb, 1);

                LAST_SKIP_BITS(re, &s->gb, 1);

                ZERO_RUN;

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

                val--;

                block[j] = ((quant_matrix[j]^val)-val) << Al;

                if(i == se) {

                    if(i > *last_nnz)

                        *last_nnz = i;

                    CLOSE_READER(re, &s->gb)

                    return 0;

                }

            }else{

                run = ((unsigned) code) >> 4;

                if(run == 0xF){

                    ZERO_RUN;

                }else{

                    val = run;

                    run = (1 << run);

                    if(val) {

                        UPDATE_CACHE(re, &s->gb);

                        run += SHOW_UBITS(re, &s->gb, val);

                        LAST_SKIP_BITS(re, &s->gb, val);

                    }

                    *EOBRUN = run - 1;

                    break;

                }

            }

        }



        if(i > *last_nnz)

            *last_nnz = i;

    }



    for(;i<=last;i++) {

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

        if(block[j])

            REFINE_BIT(j)

    }

    CLOSE_READER(re, &s->gb);



    return 0;

}

static int FUNC_0(MJpegDecodeContext *VAR_0, DCTELEM *VAR_1, uint8_t *VAR_2,

                        int VAR_3, int16_t *VAR_4,

                        int VAR_5, int VAR_6, int VAR_7, int *VAR_8)

{

    int VAR_9, VAR_10=VAR_5, VAR_11, VAR_12, VAR_13, VAR_14;

    int VAR_15 = FFMIN(VAR_6, *VAR_2);



    OPEN_READER(re, &VAR_0->gb);

    if(*VAR_8)

        (*VAR_8)--;

    else {

        for(;;VAR_10++) {

            UPDATE_CACHE(re, &VAR_0->gb);

            GET_VLC(VAR_9, re, &VAR_0->gb, VAR_0->vlcs[1][VAR_3].table, 9, 2)

            

            VAR_9 -= 16;

            if(VAR_9 & 0xF) {

                VAR_14 = ((unsigned) VAR_9) >> 4;

                UPDATE_CACHE(re, &VAR_0->gb);

                VAR_13 = SHOW_UBITS(re, &VAR_0->gb, 1);

                LAST_SKIP_BITS(re, &VAR_0->gb, 1);

                ZERO_RUN;

                VAR_11 = VAR_0->scantable.permutated[VAR_10];

                VAR_13--;

                VAR_1[VAR_11] = ((VAR_4[VAR_11]^VAR_13)-VAR_13) << VAR_7;

                if(VAR_10 == VAR_6) {

                    if(VAR_10 > *VAR_2)

                        *VAR_2 = VAR_10;

                    CLOSE_READER(re, &VAR_0->gb)

                    return 0;

                }

            }else{

                VAR_14 = ((unsigned) VAR_9) >> 4;

                if(VAR_14 == 0xF){

                    ZERO_RUN;

                }else{

                    VAR_13 = VAR_14;

                    VAR_14 = (1 << VAR_14);

                    if(VAR_13) {

                        UPDATE_CACHE(re, &VAR_0->gb);

                        VAR_14 += SHOW_UBITS(re, &VAR_0->gb, VAR_13);

                        LAST_SKIP_BITS(re, &VAR_0->gb, VAR_13);

                    }

                    *VAR_8 = VAR_14 - 1;

                    break;

                }

            }

        }



        if(VAR_10 > *VAR_2)

            *VAR_2 = VAR_10;

    }



    for(;VAR_10<=VAR_15;VAR_10++) {

        VAR_11 = VAR_0->scantable.permutated[VAR_10];

        if(VAR_1[VAR_11])

            REFINE_BIT(VAR_11)

    }

    CLOSE_READER(re, &VAR_0->gb);



    return 0;

}

static int FUNC_0(MJpegDecodeContext *VAR_0, DCTELEM *VAR_1, uint8_t *VAR_2,
int VAR_3, int16_t *VAR_4,
int VAR_5, int VAR_6, int VAR_7, int *VAR_8)
{ int VAR_9, VAR_10=VAR_5, VAR_11, VAR_12, VAR_13, VAR_14; int VAR_15 = FFMIN(VAR_6, *VAR_2); OPEN_READER(re, &VAR_0->gb); if(*VAR_8)
(*VAR_8)--; else { for(;;VAR_10++) { UPDATE_CACHE(re, &VAR_0->gb); GET_VLC(VAR_9, re, &VAR_0->gb, VAR_0->vlcs[1][VAR_3].table, 9, 2)
VAR_9 -= 16; if(VAR_9 & 0xF) { VAR_14 = ((unsigned) VAR_9) >> 4; UPDATE_CACHE(re, &VAR_0->gb); VAR_13 = SHOW_UBITS(re, &VAR_0->gb, 1); LAST_SKIP_BITS(re, &VAR_0->gb, 1); ZERO_RUN; VAR_11 = VAR_0->scantable.permutated[VAR_10]; VAR_13--; VAR_1[VAR_11] = ((VAR_4[VAR_11]^VAR_13)-VAR_13) << VAR_7; if(VAR_10 == VAR_6) { if(VAR_10 > *VAR_2)
*VAR_2 = VAR_10; CLOSE_READER(re, &VAR_0->gb)
return 0; } }else{ VAR_14 = ((unsigned) VAR_9) >> 4; if(VAR_14 == 0xF){ ZERO_RUN; }else{ VAR_13 = VAR_14; VAR_14 = (1 << VAR_14); if(VAR_13) { UPDATE_CACHE(re, &VAR_0->gb); VAR_14 += SHOW_UBITS(re, &VAR_0->gb, VAR_13); LAST_SKIP_BITS(re, &VAR_0->gb, VAR_13); } *VAR_8 = VAR_14 - 1; break; } } } if(VAR_10 > *VAR_2)
*VAR_2 = VAR_10; } for(;VAR_10<=VAR_15;VAR_10++) { VAR_11 = VAR_0->scantable.permutated[VAR_10]; if(VAR_1[VAR_11])
REFINE_BIT(VAR_11)
} CLOSE_READER(re, &VAR_0->gb); return 0; }