static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding)

{

    int a, b, c, wrap, pred, scale, ret;

    int16_t *dc_val;



    /* find prediction */

    if (n < 4) {

        scale = s->y_dc_scale;

    } else {

        scale = s->c_dc_scale;

    }

    if(IS_3IV1)

        scale= 8;



    wrap= s->block_wrap[n];

    dc_val = s->dc_val[0] + s->block_index[n];



    /* B C

     * A X

     */

    a = dc_val[ - 1];

    b = dc_val[ - 1 - wrap];

    c = dc_val[ - wrap];



    /* outside slice handling (we can't do that by memset as we need the dc for error resilience) */

    if(s->first_slice_line && n!=3){

        if(n!=2) b=c= 1024;

        if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024;

    }

    if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){

        if(n==0 || n==4 || n==5)

            b=1024;

    }



    if (abs(a - b) < abs(b - c)) {

        pred = c;

        *dir_ptr = 1; /* top */

    } else {

        pred = a;

        *dir_ptr = 0; /* left */

    }

    /* we assume pred is positive */

    pred = FASTDIV((pred + (scale >> 1)), scale);



    if(encoding){

        ret = level - pred;

    }else{

        level += pred;

        ret= level;

        if(s->error_recognition>=3){

            if(level<0){

                av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y);

                return -1;

            }

            if(level*scale > 2048 + scale){

                av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y);

                return -1;

            }

        }

    }

    level *=scale;

    if(level&(~2047)){

        if(level<0)

            level=0;

        else if(!(s->workaround_bugs&FF_BUG_DC_CLIP))

            level=2047;

    }

    dc_val[0]= level;



    return ret;

}

static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding)

{

    int a, b, c, wrap, pred, scale, ret;

    int16_t *dc_val;



    

    if (n < 4) {

        scale = s->y_dc_scale;

    } else {

        scale = s->c_dc_scale;

    }

    if(IS_3IV1)

        scale= 8;



    wrap= s->block_wrap[n];

    dc_val = s->dc_val[0] + s->block_index[n];



    





    a = dc_val[ - 1];

    b = dc_val[ - 1 - wrap];

    c = dc_val[ - wrap];



    

    if(s->first_slice_line && n!=3){

        if(n!=2) b=c= 1024;

        if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024;

    }

    if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){

        if(n==0 || n==4 || n==5)

            b=1024;

    }



    if (abs(a - b) < abs(b - c)) {

        pred = c;

        *dir_ptr = 1; 

    } else {

        pred = a;

        *dir_ptr = 0; 

    }

    

    pred = FASTDIV((pred + (scale >> 1)), scale);



    if(encoding){

        ret = level - pred;

    }else{

        level += pred;

        ret= level;

        if(s->error_recognition>=3){

            if(level<0){

                av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y);

                return -1;

            }

            if(level*scale > 2048 + scale){

                av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y);

                return -1;

            }

        }

    }

    level *=scale;

    if(level&(~2047)){

        if(level<0)

            level=0;

        else if(!(s->workaround_bugs&FF_BUG_DC_CLIP))

            level=2047;

    }

    dc_val[0]= level;



    return ret;

}

static inline int FUNC_0(MpegEncContext * VAR_0, int VAR_1, int VAR_2, int *VAR_3, int VAR_4)

{

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;

    int16_t *dc_val;



    

    if (VAR_1 < 4) {

        VAR_10 = VAR_0->y_dc_scale;

    } else {

        VAR_10 = VAR_0->c_dc_scale;

    }

    if(IS_3IV1)

        VAR_10= 8;



    VAR_8= VAR_0->block_wrap[VAR_1];

    dc_val = VAR_0->dc_val[0] + VAR_0->block_index[VAR_1];



    





    VAR_5 = dc_val[ - 1];

    VAR_6 = dc_val[ - 1 - VAR_8];

    VAR_7 = dc_val[ - VAR_8];



    

    if(VAR_0->first_slice_line && VAR_1!=3){

        if(VAR_1!=2) VAR_6=VAR_7= 1024;

        if(VAR_1!=1 && VAR_0->mb_x == VAR_0->resync_mb_x) VAR_6=VAR_5= 1024;

    }

    if(VAR_0->mb_x == VAR_0->resync_mb_x && VAR_0->mb_y == VAR_0->resync_mb_y+1){

        if(VAR_1==0 || VAR_1==4 || VAR_1==5)

            VAR_6=1024;

    }



    if (abs(VAR_5 - VAR_6) < abs(VAR_6 - VAR_7)) {

        VAR_9 = VAR_7;

        *VAR_3 = 1; 

    } else {

        VAR_9 = VAR_5;

        *VAR_3 = 0; 

    }

    

    VAR_9 = FASTDIV((VAR_9 + (VAR_10 >> 1)), VAR_10);



    if(VAR_4){

        VAR_11 = VAR_2 - VAR_9;

    }else{

        VAR_2 += VAR_9;

        VAR_11= VAR_2;

        if(VAR_0->error_recognition>=3){

            if(VAR_2<0){

                av_log(VAR_0->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\VAR_1", VAR_0->mb_x, VAR_0->mb_y);

                return -1;

            }

            if(VAR_2*VAR_10 > 2048 + VAR_10){

                av_log(VAR_0->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\VAR_1", VAR_0->mb_x, VAR_0->mb_y);

                return -1;

            }

        }

    }

    VAR_2 *=VAR_10;

    if(VAR_2&(~2047)){

        if(VAR_2<0)

            VAR_2=0;

        else if(!(VAR_0->workaround_bugs&FF_BUG_DC_CLIP))

            VAR_2=2047;

    }

    dc_val[0]= VAR_2;



    return VAR_11;

}

static inline int FUNC_0(MpegEncContext * VAR_0, int VAR_1, int VAR_2, int *VAR_3, int VAR_4)
{ int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; int16_t *dc_val; if (VAR_1 < 4) { VAR_10 = VAR_0->y_dc_scale; } else { VAR_10 = VAR_0->c_dc_scale; } if(IS_3IV1)
VAR_10= 8; VAR_8= VAR_0->block_wrap[VAR_1]; dc_val = VAR_0->dc_val[0] + VAR_0->block_index[VAR_1]; VAR_5 = dc_val[ - 1]; VAR_6 = dc_val[ - 1 - VAR_8]; VAR_7 = dc_val[ - VAR_8]; if(VAR_0->first_slice_line && VAR_1!=3){ if(VAR_1!=2) VAR_6=VAR_7= 1024; if(VAR_1!=1 && VAR_0->mb_x == VAR_0->resync_mb_x) VAR_6=VAR_5= 1024; } if(VAR_0->mb_x == VAR_0->resync_mb_x && VAR_0->mb_y == VAR_0->resync_mb_y+1){ if(VAR_1==0 || VAR_1==4 || VAR_1==5)
VAR_6=1024; } if (abs(VAR_5 - VAR_6) < abs(VAR_6 - VAR_7)) { VAR_9 = VAR_7; *VAR_3 = 1; } else { VAR_9 = VAR_5; *VAR_3 = 0; } VAR_9 = FASTDIV((VAR_9 + (VAR_10 >> 1)), VAR_10); if(VAR_4){ VAR_11 = VAR_2 - VAR_9; }else{ VAR_2 += VAR_9; VAR_11= VAR_2; if(VAR_0->error_recognition>=3){ if(VAR_2<0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\VAR_1", VAR_0->mb_x, VAR_0->mb_y); return -1; } if(VAR_2*VAR_10 > 2048 + VAR_10){ av_log(VAR_0->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\VAR_1", VAR_0->mb_x, VAR_0->mb_y); return -1; } } } VAR_2 *=VAR_10; if(VAR_2&(~2047)){ if(VAR_2<0)
VAR_2=0; else if(!(VAR_0->workaround_bugs&FF_BUG_DC_CLIP))
VAR_2=2047; } dc_val[0]= VAR_2; return VAR_11; }