static int dct_quantize_c(MpegEncContext *s, 

                        DCTELEM *block, int n,

                        int qscale, int *overflow)

{

    int i, j, level, last_non_zero, q;

    const int *qmat;

    int bias;

    int max=0;

    unsigned int threshold1, threshold2;



    av_fdct (block);



    /* we need this permutation so that we correct the IDCT

       permutation. will be moved into DCT code */

    block_permute(block);



    if (s->mb_intra) {

        if (!s->h263_aic) {

            if (n < 4)

                q = s->y_dc_scale;

            else

                q = s->c_dc_scale;

            q = q << 3;

        } else

            /* For AIC we skip quant/dequant of INTRADC */

            q = 1 << 3;

            

        /* note: block[0] is assumed to be positive */

        block[0] = (block[0] + (q >> 1)) / q;

        i = 1;

        last_non_zero = 0;

        qmat = s->q_intra_matrix[qscale];

        bias= s->intra_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT);

    } else {

        i = 0;

        last_non_zero = -1;

        qmat = s->q_inter_matrix[qscale];

        bias= s->inter_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT);

    }

    threshold1= (1<<(QMAT_SHIFT - 3)) - bias - 1;

    threshold2= threshold1<<1;



    for(;i<64;i++) {

        j = zigzag_direct[i];

        level = block[j];

        level = level * qmat[j];



//        if(   bias+level >= (1<<(QMAT_SHIFT - 3))

//           || bias-level >= (1<<(QMAT_SHIFT - 3))){

        if(((unsigned)(level+threshold1))>threshold2){

            if(level>0){

                level= (bias + level)>>(QMAT_SHIFT - 3);

                block[j]= level;

            }else{

                level= (bias - level)>>(QMAT_SHIFT - 3);

                block[j]= -level;

            }

            max |=level;

            last_non_zero = i;

        }else{

            block[j]=0;

        }

    }

    *overflow= s->max_qcoeff < max; //overflow might have happend

    

    return last_non_zero;

}

static int dct_quantize_c(MpegEncContext *s, 

                        DCTELEM *block, int n,

                        int qscale, int *overflow)

{

    int i, j, level, last_non_zero, q;

    const int *qmat;

    int bias;

    int max=0;

    unsigned int threshold1, threshold2;



    av_fdct (block);



    



    block_permute(block);



    if (s->mb_intra) {

        if (!s->h263_aic) {

            if (n < 4)

                q = s->y_dc_scale;

            else

                q = s->c_dc_scale;

            q = q << 3;

        } else

            

            q = 1 << 3;

            

        

        block[0] = (block[0] + (q >> 1)) / q;

        i = 1;

        last_non_zero = 0;

        qmat = s->q_intra_matrix[qscale];

        bias= s->intra_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT);

    } else {

        i = 0;

        last_non_zero = -1;

        qmat = s->q_inter_matrix[qscale];

        bias= s->inter_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT);

    }

    threshold1= (1<<(QMAT_SHIFT - 3)) - bias - 1;

    threshold2= threshold1<<1;



    for(;i<64;i++) {

        j = zigzag_direct[i];

        level = block[j];

        level = level * qmat[j];







        if(((unsigned)(level+threshold1))>threshold2){

            if(level>0){

                level= (bias + level)>>(QMAT_SHIFT - 3);

                block[j]= level;

            }else{

                level= (bias - level)>>(QMAT_SHIFT - 3);

                block[j]= -level;

            }

            max |=level;

            last_non_zero = i;

        }else{

            block[j]=0;

        }

    }

    *overflow= s->max_qcoeff < max; 

    

    return last_non_zero;

}

static int FUNC_0(MpegEncContext *VAR_0, 

                        DCTELEM *VAR_1, int VAR_2,

                        int VAR_3, int *VAR_4)

{

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9;

    const int *VAR_10;

    int VAR_11;

    int VAR_12=0;

    unsigned int VAR_13, VAR_14;



    av_fdct (VAR_1);



    



    block_permute(VAR_1);



    if (VAR_0->mb_intra) {

        if (!VAR_0->h263_aic) {

            if (VAR_2 < 4)

                VAR_9 = VAR_0->y_dc_scale;

            else

                VAR_9 = VAR_0->c_dc_scale;

            VAR_9 = VAR_9 << 3;

        } else

            

            VAR_9 = 1 << 3;

            

        

        VAR_1[0] = (VAR_1[0] + (VAR_9 >> 1)) / VAR_9;

        VAR_5 = 1;

        VAR_8 = 0;

        VAR_10 = VAR_0->q_intra_matrix[VAR_3];

        VAR_11= VAR_0->intra_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT);

    } else {

        VAR_5 = 0;

        VAR_8 = -1;

        VAR_10 = VAR_0->q_inter_matrix[VAR_3];

        VAR_11= VAR_0->inter_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT);

    }

    VAR_13= (1<<(QMAT_SHIFT - 3)) - VAR_11 - 1;

    VAR_14= VAR_13<<1;



    for(;VAR_5<64;VAR_5++) {

        VAR_6 = zigzag_direct[VAR_5];

        VAR_7 = VAR_1[VAR_6];

        VAR_7 = VAR_7 * VAR_10[VAR_6];







        if(((unsigned)(VAR_7+VAR_13))>VAR_14){

            if(VAR_7>0){

                VAR_7= (VAR_11 + VAR_7)>>(QMAT_SHIFT - 3);

                VAR_1[VAR_6]= VAR_7;

            }else{

                VAR_7= (VAR_11 - VAR_7)>>(QMAT_SHIFT - 3);

                VAR_1[VAR_6]= -VAR_7;

            }

            VAR_12 |=VAR_7;

            VAR_8 = VAR_5;

        }else{

            VAR_1[VAR_6]=0;

        }

    }

    *VAR_4= VAR_0->max_qcoeff < VAR_12; 

    

    return VAR_8;

}

static int FUNC_0(MpegEncContext *VAR_0,
DCTELEM *VAR_1, int VAR_2,
int VAR_3, int *VAR_4)
{ int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9; const int *VAR_10; int VAR_11; int VAR_12=0; unsigned int VAR_13, VAR_14; av_fdct (VAR_1); block_permute(VAR_1); if (VAR_0->mb_intra) { if (!VAR_0->h263_aic) { if (VAR_2 < 4)
VAR_9 = VAR_0->y_dc_scale; else
VAR_9 = VAR_0->c_dc_scale; VAR_9 = VAR_9 << 3; } else VAR_9 = 1 << 3; VAR_1[0] = (VAR_1[0] + (VAR_9 >> 1)) / VAR_9; VAR_5 = 1; VAR_8 = 0; VAR_10 = VAR_0->q_intra_matrix[VAR_3]; VAR_11= VAR_0->intra_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT); } else { VAR_5 = 0; VAR_8 = -1; VAR_10 = VAR_0->q_inter_matrix[VAR_3]; VAR_11= VAR_0->inter_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT); } VAR_13= (1<<(QMAT_SHIFT - 3)) - VAR_11 - 1; VAR_14= VAR_13<<1; for(;VAR_5<64;VAR_5++) { VAR_6 = zigzag_direct[VAR_5]; VAR_7 = VAR_1[VAR_6]; VAR_7 = VAR_7 * VAR_10[VAR_6]; if(((unsigned)(VAR_7+VAR_13))>VAR_14){ if(VAR_7>0){ VAR_7= (VAR_11 + VAR_7)>>(QMAT_SHIFT - 3); VAR_1[VAR_6]= VAR_7; }else{ VAR_7= (VAR_11 - VAR_7)>>(QMAT_SHIFT - 3); VAR_1[VAR_6]= -VAR_7; } VAR_12 |=VAR_7; VAR_8 = VAR_5; }else{ VAR_1[VAR_6]=0; } } *VAR_4= VAR_0->max_qcoeff < VAR_12; return VAR_8; }