int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,

                              int n, int coded, const uint8_t *scan_table)

{

    int level, i, last, run, run_diff;

    int av_uninit(dc_pred_dir);

    RLTable *rl;

    RL_VLC_ELEM *rl_vlc;

    int qmul, qadd;



    if (s->mb_intra) {

        qmul=1;

        qadd=0;



        /* DC coef */

        level = msmpeg4_decode_dc(s, n, &dc_pred_dir);



        if (level < 0){

            av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);

            if(s->inter_intra_pred) level=0;

            else                    return -1;

        }

        if (n < 4) {

            rl = &ff_rl_table[s->rl_table_index];

            if(level > 256*s->y_dc_scale){

                av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);

                if(!s->inter_intra_pred) return -1;

            }

        } else {

            rl = &ff_rl_table[3 + s->rl_chroma_table_index];

            if(level > 256*s->c_dc_scale){

                av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);

                if(!s->inter_intra_pred) return -1;

            }

        }

        block[0] = level;



        run_diff = s->msmpeg4_version >= 4;

        i = 0;

        if (!coded) {

            goto not_coded;

        }

        if (s->ac_pred) {

            if (dc_pred_dir == 0)

                scan_table = s->intra_v_scantable.permutated; /* left */

            else

                scan_table = s->intra_h_scantable.permutated; /* top */

        } else {

            scan_table = s->intra_scantable.permutated;

        }

        rl_vlc= rl->rl_vlc[0];

    } else {

        qmul = s->qscale << 1;

        qadd = (s->qscale - 1) | 1;

        i = -1;

        rl = &ff_rl_table[3 + s->rl_table_index];



        if(s->msmpeg4_version==2)

            run_diff = 0;

        else

            run_diff = 1;



        if (!coded) {

            s->block_last_index[n] = i;

            return 0;

        }

        if(!scan_table)

            scan_table = s->inter_scantable.permutated;

        rl_vlc= rl->rl_vlc[s->qscale];

    }

  {

    OPEN_READER(re, &s->gb);

    for(;;) {

        UPDATE_CACHE(re, &s->gb);

        GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);

        if (level==0) {

            int cache;

            cache= GET_CACHE(re, &s->gb);

            /* escape */

            if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {

                if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {

                    /* third escape */

                    if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);

                    UPDATE_CACHE(re, &s->gb);

                    if(s->msmpeg4_version<=3){

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

                        run=   SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);

                        level= SHOW_SBITS(re, &s->gb, 8);

                        SKIP_COUNTER(re, &s->gb, 1+6+8);

                    }else{

                        int sign;

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

                        if(!s->esc3_level_length){

                            int ll;

                            av_dlog(s->avctx, "ESC-3 %X at %d %d\n",

                                    show_bits(&s->gb, 24), s->mb_x, s->mb_y);

                            if(s->qscale<8){

                                ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);

                                if(ll==0){

                                    ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);

                                }

                            }else{

                                ll=2;

                                while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){

                                    ll++;

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

                                }

                                if(ll<8) SKIP_BITS(re, &s->gb, 1);

                            }



                            s->esc3_level_length= ll;

                            s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);

                            UPDATE_CACHE(re, &s->gb);

                        }

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

                        SKIP_BITS(re, &s->gb, s->esc3_run_length);



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

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



                        level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);

                        SKIP_BITS(re, &s->gb, s->esc3_level_length);

                        if(sign) level= -level;

                    }



#if 0 // waste of time / this will detect very few errors

                    {

                        const int abs_level= FFABS(level);

                        const int run1= run - rl->max_run[last][abs_level] - run_diff;

                        if(abs_level<=MAX_LEVEL && run<=MAX_RUN){

                            if(abs_level <= rl->max_level[last][run]){

                                av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");

                                return DECODING_AC_LOST;

                            }

                            if(abs_level <= rl->max_level[last][run]*2){

                                av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");

                                return DECODING_AC_LOST;

                            }

                            if(run1>=0 && abs_level <= rl->max_level[last][run1]){

                                av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");

                                return DECODING_AC_LOST;

                            }

                        }

                    }

#endif

                    //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;

                    if (level>0) level= level * qmul + qadd;

                    else         level= level * qmul - qadd;

#if 0 // waste of time too :(

                    if(level>2048 || level<-2048){

                        av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n");

                        return DECODING_AC_LOST;

                    }

#endif

                    i+= run + 1;

                    if(last) i+=192;

#ifdef ERROR_DETAILS

                if(run==66)

                    av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level);

                else if((i>62 && i<192) || i>192+63)

                    av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level);

#endif

                } else {

                    /* second escape */

                    SKIP_BITS(re, &s->gb, 2);

                    GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);

                    i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing

                    level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);

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

#ifdef ERROR_DETAILS

                if(run==66)

                    av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level);

                else if((i>62 && i<192) || i>192+63)

                    av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level);

#endif

                }

            } else {

                /* first escape */

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

                GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);

                i+= run;

                level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing

                level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);

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

#ifdef ERROR_DETAILS

                if(run==66)

                    av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level);

                else if((i>62 && i<192) || i>192+63)

                    av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level);

#endif

            }

        } else {

            i+= run;

            level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);

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

#ifdef ERROR_DETAILS

                if(run==66)

                    av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level);

                else if((i>62 && i<192) || i>192+63)

                    av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level);

#endif

        }

        if (i > 62){

            i-= 192;

            if(i&(~63)){

                const int left= get_bits_left(&s->gb);

                if(((i+192 == 64 && level/qmul==-1) || !(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT))) && left>=0){

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

                    i = 63;

                    break;

                }else{

                    av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);

                    return -1;

                }

            }



            block[scan_table[i]] = level;

            break;

        }



        block[scan_table[i]] = level;

    }

    CLOSE_READER(re, &s->gb);

  }

 not_coded:

    if (s->mb_intra) {

        ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);

        if (s->ac_pred) {

            i = 63; /* XXX: not optimal */

        }

    }

    if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize

    s->block_last_index[n] = i;



    return 0;

}

int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,

                              int n, int coded, const uint8_t *scan_table)

{

    int level, i, last, run, run_diff;

    int av_uninit(dc_pred_dir);

    RLTable *rl;

    RL_VLC_ELEM *rl_vlc;

    int qmul, qadd;



    if (s->mb_intra) {

        qmul=1;

        qadd=0;



        

        level = msmpeg4_decode_dc(s, n, &dc_pred_dir);



        if (level < 0){

            av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d

            if(s->inter_intra_pred) level=0;

            else                    return -1;

        }

        if (n < 4) {

            rl = &ff_rl_table[s->rl_table_index];

            if(level > 256*s->y_dc_scale){

                av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d

                if(!s->inter_intra_pred) return -1;

            }

        } else {

            rl = &ff_rl_table[3 + s->rl_chroma_table_index];

            if(level > 256*s->c_dc_scale){

                av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d

                if(!s->inter_intra_pred) return -1;

            }

        }

        block[0] = level;



        run_diff = s->msmpeg4_version >= 4;

        i = 0;

        if (!coded) {

            goto not_coded;

        }

        if (s->ac_pred) {

            if (dc_pred_dir == 0)

                scan_table = s->intra_v_scantable.permutated; 

            else

                scan_table = s->intra_h_scantable.permutated; 

        } else {

            scan_table = s->intra_scantable.permutated;

        }

        rl_vlc= rl->rl_vlc[0];

    } else {

        qmul = s->qscale << 1;

        qadd = (s->qscale - 1) | 1;

        i = -1;

        rl = &ff_rl_table[3 + s->rl_table_index];



        if(s->msmpeg4_version==2)

            run_diff = 0;

        else

            run_diff = 1;



        if (!coded) {

            s->block_last_index[n] = i;

            return 0;

        }

        if(!scan_table)

            scan_table = s->inter_scantable.permutated;

        rl_vlc= rl->rl_vlc[s->qscale];

    }

  {

    OPEN_READER(re, &s->gb);

    for(;;) {

        UPDATE_CACHE(re, &s->gb);

        GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);

        if (level==0) {

            int cache;

            cache= GET_CACHE(re, &s->gb);

            

            if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {

                if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {

                    

                    if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);

                    UPDATE_CACHE(re, &s->gb);

                    if(s->msmpeg4_version<=3){

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

                        run=   SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);

                        level= SHOW_SBITS(re, &s->gb, 8);

                        SKIP_COUNTER(re, &s->gb, 1+6+8);

                    }else{

                        int sign;

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

                        if(!s->esc3_level_length){

                            int ll;

                            av_dlog(s->avctx, "ESC-3 %X at %d %d\n",

                                    show_bits(&s->gb, 24), s->mb_x, s->mb_y);

                            if(s->qscale<8){

                                ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);

                                if(ll==0){

                                    ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);

                                }

                            }else{

                                ll=2;

                                while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){

                                    ll++;

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

                                }

                                if(ll<8) SKIP_BITS(re, &s->gb, 1);

                            }



                            s->esc3_level_length= ll;

                            s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);

                            UPDATE_CACHE(re, &s->gb);

                        }

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

                        SKIP_BITS(re, &s->gb, s->esc3_run_length);



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

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



                        level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);

                        SKIP_BITS(re, &s->gb, s->esc3_level_length);

                        if(sign) level= -level;

                    }



#if 0 

                    {

                        const int abs_level= FFABS(level);

                        const int run1= run - rl->max_run[last][abs_level] - run_diff;

                        if(abs_level<=MAX_LEVEL && run<=MAX_RUN){

                            if(abs_level <= rl->max_level[last][run]){

                                av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");

                                return DECODING_AC_LOST;

                            }

                            if(abs_level <= rl->max_level[last][run]*2){

                                av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");

                                return DECODING_AC_LOST;

                            }

                            if(run1>=0 && abs_level <= rl->max_level[last][run1]){

                                av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");

                                return DECODING_AC_LOST;

                            }

                        }

                    }

#endif

                    

                    if (level>0) level= level * qmul + qadd;

                    else         level= level * qmul - qadd;

#if 0 

                    if(level>2048 || level<-2048){

                        av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n");

                        return DECODING_AC_LOST;

                    }

#endif

                    i+= run + 1;

                    if(last) i+=192;

#ifdef ERROR_DETAILS

                if(run==66)

                    av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level);

                else if((i>62 && i<192) || i>192+63)

                    av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level);

#endif

                } else {

                    

                    SKIP_BITS(re, &s->gb, 2);

                    GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);

                    i+= run + rl->max_run[run>>7][level/qmul] + run_diff; 

                    level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);

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

#ifdef ERROR_DETAILS

                if(run==66)

                    av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level);

                else if((i>62 && i<192) || i>192+63)

                    av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level);

#endif

                }

            } else {

                

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

                GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);

                i+= run;

                level = level + rl->max_level[run>>7][(run-1)&63] * qmul;

                level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);

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

#ifdef ERROR_DETAILS

                if(run==66)

                    av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level);

                else if((i>62 && i<192) || i>192+63)

                    av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level);

#endif

            }

        } else {

            i+= run;

            level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);

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

#ifdef ERROR_DETAILS

                if(run==66)

                    av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level);

                else if((i>62 && i<192) || i>192+63)

                    av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level);

#endif

        }

        if (i > 62){

            i-= 192;

            if(i&(~63)){

                const int left= get_bits_left(&s->gb);

                if(((i+192 == 64 && level/qmul==-1) || !(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT))) && left>=0){

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

                    i = 63;

                    break;

                }else{

                    av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);

                    return -1;

                }

            }



            block[scan_table[i]] = level;

            break;

        }



        block[scan_table[i]] = level;

    }

    CLOSE_READER(re, &s->gb);

  }

 not_coded:

    if (s->mb_intra) {

        ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);

        if (s->ac_pred) {

            i = 63; 

        }

    }

    if(s->msmpeg4_version>=4 && i>0) i=63; 

    s->block_last_index[n] = i;



    return 0;

}

            else                    return -1;
int FUNC_0(MpegEncContext * VAR_0, int16_t * VAR_1,

                              int VAR_2, int VAR_3, const uint8_t *VAR_4)

{

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9;

    int FUNC_1(dc_pred_dir);

    RLTable *rl;

    RL_VLC_ELEM *rl_vlc;

    int VAR_10, VAR_11;



    if (VAR_0->mb_intra) {

        VAR_10=1;

        VAR_11=0;



        

        VAR_5 = msmpeg4_decode_dc(VAR_0, VAR_2, &dc_pred_dir);



        if (VAR_5 < 0){

            av_log(VAR_0->avctx, AV_LOG_ERROR, "dc overflow- VAR_1: %d qscale: %d

            if(VAR_0->inter_intra_pred) VAR_5=0;

            else                    return -1;

        }

        if (VAR_2 < 4) {

            rl = &ff_rl_table[VAR_0->rl_table_index];

            if(VAR_5 > 256*VAR_0->y_dc_scale){

                av_log(VAR_0->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d

                if(!VAR_0->inter_intra_pred) return -1;

            }

        } else {

            rl = &ff_rl_table[3 + VAR_0->rl_chroma_table_index];

            if(VAR_5 > 256*VAR_0->c_dc_scale){

                av_log(VAR_0->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d

                if(!VAR_0->inter_intra_pred) return -1;

            }

        }

        VAR_1[0] = VAR_5;



        VAR_9 = VAR_0->msmpeg4_version >= 4;

        VAR_6 = 0;

        if (!VAR_3) {

            goto not_coded;

        }

        if (VAR_0->ac_pred) {

            if (dc_pred_dir == 0)

                VAR_4 = VAR_0->intra_v_scantable.permutated; 

            else

                VAR_4 = VAR_0->intra_h_scantable.permutated; 

        } else {

            VAR_4 = VAR_0->intra_scantable.permutated;

        }

        rl_vlc= rl->rl_vlc[0];

    } else {

        VAR_10 = VAR_0->qscale << 1;

        VAR_11 = (VAR_0->qscale - 1) | 1;

        VAR_6 = -1;

        rl = &ff_rl_table[3 + VAR_0->rl_table_index];



        if(VAR_0->msmpeg4_version==2)

            VAR_9 = 0;

        else

            VAR_9 = 1;



        if (!VAR_3) {

            VAR_0->block_last_index[VAR_2] = VAR_6;

            return 0;

        }

        if(!VAR_4)

            VAR_4 = VAR_0->inter_scantable.permutated;

        rl_vlc= rl->rl_vlc[VAR_0->qscale];

    }

  {

    OPEN_READER(re, &VAR_0->gb);

    for(;;) {

        UPDATE_CACHE(re, &VAR_0->gb);

        GET_RL_VLC(VAR_5, VAR_8, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 0);

        if (VAR_5==0) {

            int VAR_12;

            VAR_12= GET_CACHE(re, &VAR_0->gb);

            

            if (VAR_0->msmpeg4_version==1 || (VAR_12&0x80000000)==0) {

                if (VAR_0->msmpeg4_version==1 || (VAR_12&0x40000000)==0) {

                    

                    if(VAR_0->msmpeg4_version!=1) LAST_SKIP_BITS(re, &VAR_0->gb, 2);

                    UPDATE_CACHE(re, &VAR_0->gb);

                    if(VAR_0->msmpeg4_version<=3){

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

                        VAR_8=   SHOW_UBITS(re, &VAR_0->gb, 6); SKIP_CACHE(re, &VAR_0->gb, 6);

                        VAR_5= SHOW_SBITS(re, &VAR_0->gb, 8);

                        SKIP_COUNTER(re, &VAR_0->gb, 1+6+8);

                    }else{

                        int VAR_13;

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

                        if(!VAR_0->esc3_level_length){

                            int VAR_14;

                            av_dlog(VAR_0->avctx, "ESC-3 %X at %d %d\VAR_2",

                                    show_bits(&VAR_0->gb, 24), VAR_0->mb_x, VAR_0->mb_y);

                            if(VAR_0->qscale<8){

                                VAR_14= SHOW_UBITS(re, &VAR_0->gb, 3); SKIP_BITS(re, &VAR_0->gb, 3);

                                if(VAR_14==0){

                                    VAR_14= 8+SHOW_UBITS(re, &VAR_0->gb, 1); SKIP_BITS(re, &VAR_0->gb, 1);

                                }

                            }else{

                                VAR_14=2;

                                while(VAR_14<8 && SHOW_UBITS(re, &VAR_0->gb, 1)==0){

                                    VAR_14++;

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

                                }

                                if(VAR_14<8) SKIP_BITS(re, &VAR_0->gb, 1);

                            }



                            VAR_0->esc3_level_length= VAR_14;

                            VAR_0->esc3_run_length= SHOW_UBITS(re, &VAR_0->gb, 2) + 3; SKIP_BITS(re, &VAR_0->gb, 2);

                            UPDATE_CACHE(re, &VAR_0->gb);

                        }

                        VAR_8=   SHOW_UBITS(re, &VAR_0->gb, VAR_0->esc3_run_length);

                        SKIP_BITS(re, &VAR_0->gb, VAR_0->esc3_run_length);



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

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



                        VAR_5= SHOW_UBITS(re, &VAR_0->gb, VAR_0->esc3_level_length);

                        SKIP_BITS(re, &VAR_0->gb, VAR_0->esc3_level_length);

                        if(VAR_13) VAR_5= -VAR_5;

                    }



#if 0 

                    {

                        const int abs_level= FFABS(VAR_5);

                        const int run1= VAR_8 - rl->max_run[VAR_7][abs_level] - VAR_9;

                        if(abs_level<=MAX_LEVEL && VAR_8<=MAX_RUN){

                            if(abs_level <= rl->max_level[VAR_7][VAR_8]){

                                av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\VAR_2");

                                return DECODING_AC_LOST;

                            }

                            if(abs_level <= rl->max_level[VAR_7][VAR_8]*2){

                                av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\VAR_2");

                                return DECODING_AC_LOST;

                            }

                            if(run1>=0 && abs_level <= rl->max_level[VAR_7][run1]){

                                av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\VAR_2");

                                return DECODING_AC_LOST;

                            }

                        }

                    }

#endif

                    

                    if (VAR_5>0) VAR_5= VAR_5 * VAR_10 + VAR_11;

                    else         VAR_5= VAR_5 * VAR_10 - VAR_11;

#if 0 

                    if(VAR_5>2048 || VAR_5<-2048){

                        av_log(VAR_0->avctx, AV_LOG_ERROR, "|VAR_5| overflow in 3. esc\VAR_2");

                        return DECODING_AC_LOST;

                    }

#endif

                    VAR_6+= VAR_8 + 1;

                    if(VAR_7) VAR_6+=192;

#ifdef ERROR_DETAILS

                if(VAR_8==66)

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 VAR_5=%d\VAR_2", VAR_5);

                else if((VAR_6>62 && VAR_6<192) || VAR_6>192+63)

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 overflow in ESC3 VAR_6=%d VAR_8=%d VAR_5=%d\VAR_2", VAR_6, VAR_8, VAR_5);

#endif

                } else {

                    

                    SKIP_BITS(re, &VAR_0->gb, 2);

                    GET_RL_VLC(VAR_5, VAR_8, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 1);

                    VAR_6+= VAR_8 + rl->max_run[VAR_8>>7][VAR_5/VAR_10] + VAR_9; 

                    VAR_5 = (VAR_5 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1);

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

#ifdef ERROR_DETAILS

                if(VAR_8==66)

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 VAR_5=%d\VAR_2", VAR_5);

                else if((VAR_6>62 && VAR_6<192) || VAR_6>192+63)

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 overflow in ESC2 VAR_6=%d VAR_8=%d VAR_5=%d\VAR_2", VAR_6, VAR_8, VAR_5);

#endif

                }

            } else {

                

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

                GET_RL_VLC(VAR_5, VAR_8, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 1);

                VAR_6+= VAR_8;

                VAR_5 = VAR_5 + rl->max_level[VAR_8>>7][(VAR_8-1)&63] * VAR_10;

                VAR_5 = (VAR_5 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1);

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

#ifdef ERROR_DETAILS

                if(VAR_8==66)

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 VAR_5=%d\VAR_2", VAR_5);

                else if((VAR_6>62 && VAR_6<192) || VAR_6>192+63)

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 overflow in ESC1 VAR_6=%d VAR_8=%d VAR_5=%d\VAR_2", VAR_6, VAR_8, VAR_5);

#endif

            }

        } else {

            VAR_6+= VAR_8;

            VAR_5 = (VAR_5 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1);

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

#ifdef ERROR_DETAILS

                if(VAR_8==66)

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal vlc code VAR_5=%d\VAR_2", VAR_5);

                else if((VAR_6>62 && VAR_6<192) || VAR_6>192+63)

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 overflow VAR_6=%d VAR_8=%d VAR_5=%d\VAR_2", VAR_6, VAR_8, VAR_5);

#endif

        }

        if (VAR_6 > 62){

            VAR_6-= 192;

            if(VAR_6&(~63)){

                const int VAR_15= get_bits_left(&VAR_0->gb);

                if(((VAR_6+192 == 64 && VAR_5/VAR_10==-1) || !(VAR_0->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT))) && VAR_15>=0){

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\VAR_2", VAR_0->mb_x, VAR_0->mb_y);

                    VAR_6 = 63;

                    break;

                }else{

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\VAR_2", VAR_0->mb_x, VAR_0->mb_y);

                    return -1;

                }

            }



            VAR_1[VAR_4[VAR_6]] = VAR_5;

            break;

        }



        VAR_1[VAR_4[VAR_6]] = VAR_5;

    }

    CLOSE_READER(re, &VAR_0->gb);

  }

 not_coded:

    if (VAR_0->mb_intra) {

        ff_mpeg4_pred_ac(VAR_0, VAR_1, VAR_2, dc_pred_dir);

        if (VAR_0->ac_pred) {

            VAR_6 = 63; 

        }

    }

    if(VAR_0->msmpeg4_version>=4 && VAR_6>0) VAR_6=63; 

    VAR_0->block_last_index[VAR_2] = VAR_6;



    return 0;

}

int FUNC_0(MpegEncContext * VAR_0, int16_t * VAR_1,
int VAR_2, int VAR_3, const uint8_t *VAR_4)
{ int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9; int FUNC_1(dc_pred_dir); RLTable *rl; RL_VLC_ELEM *rl_vlc; int VAR_10, VAR_11; if (VAR_0->mb_intra) { VAR_10=1; VAR_11=0; VAR_5 = msmpeg4_decode_dc(VAR_0, VAR_2, &dc_pred_dir); if (VAR_5 < 0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "dc overflow- VAR_1: %d qscale: %d
if(VAR_0->inter_intra_pred) VAR_5=0; else                    return -1; } if (VAR_2 < 4) { rl = &ff_rl_table[VAR_0->rl_table_index]; if(VAR_5 > 256*VAR_0->y_dc_scale){ av_log(VAR_0->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d
if(!VAR_0->inter_intra_pred) return -1; } } else { rl = &ff_rl_table[3 + VAR_0->rl_chroma_table_index]; if(VAR_5 > 256*VAR_0->c_dc_scale){ av_log(VAR_0->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d
if(!VAR_0->inter_intra_pred) return -1; } } VAR_1[0] = VAR_5; VAR_9 = VAR_0->msmpeg4_version >= 4; VAR_6 = 0; if (!VAR_3) { goto not_coded; } if (VAR_0->ac_pred) { if (dc_pred_dir == 0)
VAR_4 = VAR_0->intra_v_scantable.permutated; else
VAR_4 = VAR_0->intra_h_scantable.permutated; } else { VAR_4 = VAR_0->intra_scantable.permutated; } rl_vlc= rl->rl_vlc[0]; } else { VAR_10 = VAR_0->qscale << 1; VAR_11 = (VAR_0->qscale - 1) | 1; VAR_6 = -1; rl = &ff_rl_table[3 + VAR_0->rl_table_index]; if(VAR_0->msmpeg4_version==2)
VAR_9 = 0; else
VAR_9 = 1; if (!VAR_3) { VAR_0->block_last_index[VAR_2] = VAR_6; return 0; } if(!VAR_4)
VAR_4 = VAR_0->inter_scantable.permutated; rl_vlc= rl->rl_vlc[VAR_0->qscale]; } { OPEN_READER(re, &VAR_0->gb); for(;;) { UPDATE_CACHE(re, &VAR_0->gb); GET_RL_VLC(VAR_5, VAR_8, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 0); if (VAR_5==0) { int VAR_12; VAR_12= GET_CACHE(re, &VAR_0->gb); if (VAR_0->msmpeg4_version==1 || (VAR_12&0x80000000)==0) { if (VAR_0->msmpeg4_version==1 || (VAR_12&0x40000000)==0) { if(VAR_0->msmpeg4_version!=1) LAST_SKIP_BITS(re, &VAR_0->gb, 2); UPDATE_CACHE(re, &VAR_0->gb); if(VAR_0->msmpeg4_version<=3){ VAR_7=  SHOW_UBITS(re, &VAR_0->gb, 1); SKIP_CACHE(re, &VAR_0->gb, 1); VAR_8=   SHOW_UBITS(re, &VAR_0->gb, 6); SKIP_CACHE(re, &VAR_0->gb, 6); VAR_5= SHOW_SBITS(re, &VAR_0->gb, 8); SKIP_COUNTER(re, &VAR_0->gb, 1+6+8); }else{ int VAR_13; VAR_7=  SHOW_UBITS(re, &VAR_0->gb, 1); SKIP_BITS(re, &VAR_0->gb, 1); if(!VAR_0->esc3_level_length){ int VAR_14; av_dlog(VAR_0->avctx, "ESC-3 %X at %d %d\VAR_2",
show_bits(&VAR_0->gb, 24), VAR_0->mb_x, VAR_0->mb_y); if(VAR_0->qscale<8){ VAR_14= SHOW_UBITS(re, &VAR_0->gb, 3); SKIP_BITS(re, &VAR_0->gb, 3); if(VAR_14==0){ VAR_14= 8+SHOW_UBITS(re, &VAR_0->gb, 1); SKIP_BITS(re, &VAR_0->gb, 1); } }else{ VAR_14=2; while(VAR_14<8 && SHOW_UBITS(re, &VAR_0->gb, 1)==0){ VAR_14++; SKIP_BITS(re, &VAR_0->gb, 1); } if(VAR_14<8) SKIP_BITS(re, &VAR_0->gb, 1); } VAR_0->esc3_level_length= VAR_14; VAR_0->esc3_run_length= SHOW_UBITS(re, &VAR_0->gb, 2) + 3; SKIP_BITS(re, &VAR_0->gb, 2); UPDATE_CACHE(re, &VAR_0->gb); } VAR_8=   SHOW_UBITS(re, &VAR_0->gb, VAR_0->esc3_run_length); SKIP_BITS(re, &VAR_0->gb, VAR_0->esc3_run_length); VAR_13=  SHOW_UBITS(re, &VAR_0->gb, 1); SKIP_BITS(re, &VAR_0->gb, 1); VAR_5= SHOW_UBITS(re, &VAR_0->gb, VAR_0->esc3_level_length); SKIP_BITS(re, &VAR_0->gb, VAR_0->esc3_level_length); if(VAR_13) VAR_5= -VAR_5; } #if 0
{ const int abs_level= FFABS(VAR_5); const int run1= VAR_8 - rl->max_run[VAR_7][abs_level] - VAR_9; if(abs_level<=MAX_LEVEL && VAR_8<=MAX_RUN){ if(abs_level <= rl->max_level[VAR_7][VAR_8]){ av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\VAR_2"); return DECODING_AC_LOST; } if(abs_level <= rl->max_level[VAR_7][VAR_8]*2){ av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\VAR_2"); return DECODING_AC_LOST; } if(run1>=0 && abs_level <= rl->max_level[VAR_7][run1]){ av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\VAR_2"); return DECODING_AC_LOST; } } } #endif
if (VAR_5>0) VAR_5= VAR_5 * VAR_10 + VAR_11; else         VAR_5= VAR_5 * VAR_10 - VAR_11; #if 0
if(VAR_5>2048 || VAR_5<-2048){ av_log(VAR_0->avctx, AV_LOG_ERROR, "|VAR_5| overflow in 3. esc\VAR_2"); return DECODING_AC_LOST; } #endif
VAR_6+= VAR_8 + 1; if(VAR_7) VAR_6+=192; #ifdef ERROR_DETAILS
if(VAR_8==66)
av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 VAR_5=%d\VAR_2", VAR_5); else if((VAR_6>62 && VAR_6<192) || VAR_6>192+63)
av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 overflow in ESC3 VAR_6=%d VAR_8=%d VAR_5=%d\VAR_2", VAR_6, VAR_8, VAR_5); #endif
} else { SKIP_BITS(re, &VAR_0->gb, 2); GET_RL_VLC(VAR_5, VAR_8, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 1); VAR_6+= VAR_8 + rl->max_run[VAR_8>>7][VAR_5/VAR_10] + VAR_9; VAR_5 = (VAR_5 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1); LAST_SKIP_BITS(re, &VAR_0->gb, 1); #ifdef ERROR_DETAILS
if(VAR_8==66)
av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 VAR_5=%d\VAR_2", VAR_5); else if((VAR_6>62 && VAR_6<192) || VAR_6>192+63)
av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 overflow in ESC2 VAR_6=%d VAR_8=%d VAR_5=%d\VAR_2", VAR_6, VAR_8, VAR_5); #endif
} } else { SKIP_BITS(re, &VAR_0->gb, 1); GET_RL_VLC(VAR_5, VAR_8, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 1); VAR_6+= VAR_8; VAR_5 = VAR_5 + rl->max_level[VAR_8>>7][(VAR_8-1)&63] * VAR_10; VAR_5 = (VAR_5 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1); LAST_SKIP_BITS(re, &VAR_0->gb, 1); #ifdef ERROR_DETAILS
if(VAR_8==66)
av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 VAR_5=%d\VAR_2", VAR_5); else if((VAR_6>62 && VAR_6<192) || VAR_6>192+63)
av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 overflow in ESC1 VAR_6=%d VAR_8=%d VAR_5=%d\VAR_2", VAR_6, VAR_8, VAR_5); #endif
} } else { VAR_6+= VAR_8; VAR_5 = (VAR_5 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1); LAST_SKIP_BITS(re, &VAR_0->gb, 1); #ifdef ERROR_DETAILS
if(VAR_8==66)
av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal vlc code VAR_5=%d\VAR_2", VAR_5); else if((VAR_6>62 && VAR_6<192) || VAR_6>192+63)
av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 overflow VAR_6=%d VAR_8=%d VAR_5=%d\VAR_2", VAR_6, VAR_8, VAR_5); #endif
} if (VAR_6 > 62){ VAR_6-= 192; if(VAR_6&(~63)){ const int VAR_15= get_bits_left(&VAR_0->gb); if(((VAR_6+192 == 64 && VAR_5/VAR_10==-1) || !(VAR_0->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT))) && VAR_15>=0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\VAR_2", VAR_0->mb_x, VAR_0->mb_y); VAR_6 = 63; break; }else{ av_log(VAR_0->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\VAR_2", VAR_0->mb_x, VAR_0->mb_y); return -1; } } VAR_1[VAR_4[VAR_6]] = VAR_5; break; } VAR_1[VAR_4[VAR_6]] = VAR_5; } CLOSE_READER(re, &VAR_0->gb); } not_coded:
if (VAR_0->mb_intra) { ff_mpeg4_pred_ac(VAR_0, VAR_1, VAR_2, dc_pred_dir); if (VAR_0->ac_pred) { VAR_6 = 63; } } if(VAR_0->msmpeg4_version>=4 && VAR_6>0) VAR_6=63; VAR_0->block_last_index[VAR_2] = VAR_6; return 0; }