static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,

                              int n, int coded, int intra, int rvlc)

{

    int level, i, last, run;

    int dc_pred_dir;

    RLTable * rl;

    RL_VLC_ELEM * rl_vlc;

    const uint8_t * scan_table;

    int qmul, qadd;



    //Note intra & rvlc should be optimized away if this is inlined



    if(intra) {

      if(s->qscale < s->intra_dc_threshold){

        /* DC coef */

        if(s->partitioned_frame){

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

            if(n<4) level= FASTDIV((level + (s->y_dc_scale>>1)), s->y_dc_scale);

            else    level= FASTDIV((level + (s->c_dc_scale>>1)), s->c_dc_scale);

            dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_stride]<<n)&32;

        }else{

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

            if (level < 0)

                return -1;

        }

        block[0] = level;

        i = 0;

      }else{

            i = -1;

            ff_mpeg4_pred_dc(s, n, 0, &dc_pred_dir, 0);

      }

        if (!coded)

            goto not_coded;



        if(rvlc){

            rl = &rvlc_rl_intra;

            rl_vlc = rvlc_rl_intra.rl_vlc[0];

        }else{

            rl = &rl_intra;

            rl_vlc = rl_intra.rl_vlc[0];

        }

        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;

        }

        qmul=1;

        qadd=0;

    } else {

        i = -1;

        if (!coded) {

            s->block_last_index[n] = i;

            return 0;

        }

        if(rvlc) rl = &rvlc_rl_inter;

        else     rl = &rl_inter;



        scan_table = s->intra_scantable.permutated;



        if(s->mpeg_quant){

            qmul=1;

            qadd=0;

            if(rvlc){

                rl_vlc = rvlc_rl_inter.rl_vlc[0];

            }else{

                rl_vlc = rl_inter.rl_vlc[0];

            }

        }else{

            qmul = s->qscale << 1;

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

            if(rvlc){

                rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale];

            }else{

                rl_vlc = rl_inter.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) {

          /* escape */

          if(rvlc){

                if(SHOW_UBITS(re, &s->gb, 1)==0){

                    av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in rvlc esc\n");

                    return -1;

                }; SKIP_CACHE(re, &s->gb, 1);



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

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

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

                UPDATE_CACHE(re, &s->gb);



                if(SHOW_UBITS(re, &s->gb, 1)==0){

                    av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in rvlc esc\n");

                    return -1;

                }; SKIP_CACHE(re, &s->gb, 1);



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



                if(SHOW_UBITS(re, &s->gb, 5)!=0x10){

                    av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n");

                    return -1;

                }; SKIP_CACHE(re, &s->gb, 5);



                level=  level * qmul + qadd;

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

                SKIP_COUNTER(re, &s->gb, 1+11+5+1);



                i+= run + 1;

                if(last) i+=192;

          }else{

            int cache;

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



            if(IS_3IV1)

                cache ^= 0xC0000000;



            if (cache&0x80000000) {

                if (cache&0x40000000) {

                    /* third escape */

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

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

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

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

                    UPDATE_CACHE(re, &s->gb);



                    if(IS_3IV1){

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

                    }else{

                        if(SHOW_UBITS(re, &s->gb, 1)==0){

                            av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\n");

                            return -1;

                        }; SKIP_CACHE(re, &s->gb, 1);



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



                        if(SHOW_UBITS(re, &s->gb, 1)==0){

                            av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n");

                            return -1;

                        }; LAST_SKIP_CACHE(re, &s->gb, 1);



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

                    }



#if 0

                    if(s->error_resilience >= FF_ER_COMPLIANT){

                        const int abs_level= ABS(level);

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

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

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

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

                                return -1;

                            }

                            if(s->error_resilience > FF_ER_COMPLIANT){

                                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 -1;

                                }

                                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 -1;

                                }

                            }

                        }

                    }

#endif

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

                    else         level= level * qmul - qadd;



                    if((unsigned)(level + 2048) > 4095){

                        if(s->error_resilience > FF_ER_COMPLIANT){

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

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

                                return -1;

                            }

                        }

                        level= level<0 ? -2048 : 2047;

                    }



                    i+= run + 1;

                    if(last) i+=192;

                } else {

                    /* second escape */

#if MIN_CACHE_BITS < 20

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

                    UPDATE_CACHE(re, &s->gb);

#else

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

#endif

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

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

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

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

                }

            } else {

                /* first escape */

#if MIN_CACHE_BITS < 19

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

                UPDATE_CACHE(re, &s->gb);

#else

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

#endif

                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);

            }

          }

        } else {

            i+= run;

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

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

        }

        if (i > 62){

            i-= 192;

            if(i&(~63)){

                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 (intra) {

        if(s->qscale >= s->intra_dc_threshold){

            block[0] = ff_mpeg4_pred_dc(s, n, block[0], &dc_pred_dir, 0);



            i -= i>>31; //if(i == -1) i=0;

        }



        mpeg4_pred_ac(s, block, n, dc_pred_dir);

        if (s->ac_pred) {

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

        }

    }

    s->block_last_index[n] = i;

    return 0;

}

static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,

                              int n, int coded, int intra, int rvlc)

{

    int level, i, last, run;

    int dc_pred_dir;

    RLTable * rl;

    RL_VLC_ELEM * rl_vlc;

    const uint8_t * scan_table;

    int qmul, qadd;



    



    if(intra) {

      if(s->qscale < s->intra_dc_threshold){

        

        if(s->partitioned_frame){

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

            if(n<4) level= FASTDIV((level + (s->y_dc_scale>>1)), s->y_dc_scale);

            else    level= FASTDIV((level + (s->c_dc_scale>>1)), s->c_dc_scale);

            dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_stride]<<n)&32;

        }else{

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

            if (level < 0)

                return -1;

        }

        block[0] = level;

        i = 0;

      }else{

            i = -1;

            ff_mpeg4_pred_dc(s, n, 0, &dc_pred_dir, 0);

      }

        if (!coded)

            goto not_coded;



        if(rvlc){

            rl = &rvlc_rl_intra;

            rl_vlc = rvlc_rl_intra.rl_vlc[0];

        }else{

            rl = &rl_intra;

            rl_vlc = rl_intra.rl_vlc[0];

        }

        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;

        }

        qmul=1;

        qadd=0;

    } else {

        i = -1;

        if (!coded) {

            s->block_last_index[n] = i;

            return 0;

        }

        if(rvlc) rl = &rvlc_rl_inter;

        else     rl = &rl_inter;



        scan_table = s->intra_scantable.permutated;



        if(s->mpeg_quant){

            qmul=1;

            qadd=0;

            if(rvlc){

                rl_vlc = rvlc_rl_inter.rl_vlc[0];

            }else{

                rl_vlc = rl_inter.rl_vlc[0];

            }

        }else{

            qmul = s->qscale << 1;

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

            if(rvlc){

                rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale];

            }else{

                rl_vlc = rl_inter.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) {

          

          if(rvlc){

                if(SHOW_UBITS(re, &s->gb, 1)==0){

                    av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in rvlc esc\n");

                    return -1;

                }; SKIP_CACHE(re, &s->gb, 1);



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

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

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

                UPDATE_CACHE(re, &s->gb);



                if(SHOW_UBITS(re, &s->gb, 1)==0){

                    av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in rvlc esc\n");

                    return -1;

                }; SKIP_CACHE(re, &s->gb, 1);



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



                if(SHOW_UBITS(re, &s->gb, 5)!=0x10){

                    av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n");

                    return -1;

                }; SKIP_CACHE(re, &s->gb, 5);



                level=  level * qmul + qadd;

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

                SKIP_COUNTER(re, &s->gb, 1+11+5+1);



                i+= run + 1;

                if(last) i+=192;

          }else{

            int cache;

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



            if(IS_3IV1)

                cache ^= 0xC0000000;



            if (cache&0x80000000) {

                if (cache&0x40000000) {

                    

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

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

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

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

                    UPDATE_CACHE(re, &s->gb);



                    if(IS_3IV1){

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

                    }else{

                        if(SHOW_UBITS(re, &s->gb, 1)==0){

                            av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\n");

                            return -1;

                        }; SKIP_CACHE(re, &s->gb, 1);



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



                        if(SHOW_UBITS(re, &s->gb, 1)==0){

                            av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n");

                            return -1;

                        }; LAST_SKIP_CACHE(re, &s->gb, 1);



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

                    }



#if 0

                    if(s->error_resilience >= FF_ER_COMPLIANT){

                        const int abs_level= ABS(level);

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

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

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

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

                                return -1;

                            }

                            if(s->error_resilience > FF_ER_COMPLIANT){

                                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 -1;

                                }

                                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 -1;

                                }

                            }

                        }

                    }

#endif

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

                    else         level= level * qmul - qadd;



                    if((unsigned)(level + 2048) > 4095){

                        if(s->error_resilience > FF_ER_COMPLIANT){

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

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

                                return -1;

                            }

                        }

                        level= level<0 ? -2048 : 2047;

                    }



                    i+= run + 1;

                    if(last) i+=192;

                } else {

                    

#if MIN_CACHE_BITS < 20

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

                    UPDATE_CACHE(re, &s->gb);

#else

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

#endif

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

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

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

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

                }

            } else {

                

#if MIN_CACHE_BITS < 19

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

                UPDATE_CACHE(re, &s->gb);

#else

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

#endif

                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);

            }

          }

        } else {

            i+= run;

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

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

        }

        if (i > 62){

            i-= 192;

            if(i&(~63)){

                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 (intra) {

        if(s->qscale >= s->intra_dc_threshold){

            block[0] = ff_mpeg4_pred_dc(s, n, block[0], &dc_pred_dir, 0);



            i -= i>>31; 

        }



        mpeg4_pred_ac(s, block, n, dc_pred_dir);

        if (s->ac_pred) {

            i = 63; 

        }

    }

    s->block_last_index[n] = i;

    return 0;

}

static inline int FUNC_0(MpegEncContext * VAR_0, DCTELEM * VAR_1,

                              int VAR_2, int VAR_3, int VAR_4, int VAR_5)

{

    int VAR_6, VAR_7, VAR_8, VAR_9;

    int VAR_10;

    RLTable * rl;

    RL_VLC_ELEM * rl_vlc;

    const uint8_t * VAR_11;

    int VAR_12, VAR_13;



    



    if(VAR_4) {

      if(VAR_0->qscale < VAR_0->intra_dc_threshold){

        

        if(VAR_0->partitioned_frame){

            VAR_6 = VAR_0->dc_val[0][ VAR_0->block_index[VAR_2] ];

            if(VAR_2<4) VAR_6= FASTDIV((VAR_6 + (VAR_0->y_dc_scale>>1)), VAR_0->y_dc_scale);

            else    VAR_6= FASTDIV((VAR_6 + (VAR_0->c_dc_scale>>1)), VAR_0->c_dc_scale);

            VAR_10= (VAR_0->pred_dir_table[VAR_0->mb_x + VAR_0->mb_y*VAR_0->mb_stride]<<VAR_2)&32;

        }else{

            VAR_6 = mpeg4_decode_dc(VAR_0, VAR_2, &VAR_10);

            if (VAR_6 < 0)

                return -1;

        }

        VAR_1[0] = VAR_6;

        VAR_7 = 0;

      }else{

            VAR_7 = -1;

            ff_mpeg4_pred_dc(VAR_0, VAR_2, 0, &VAR_10, 0);

      }

        if (!VAR_3)

            goto not_coded;



        if(VAR_5){

            rl = &rvlc_rl_intra;

            rl_vlc = rvlc_rl_intra.rl_vlc[0];

        }else{

            rl = &rl_intra;

            rl_vlc = rl_intra.rl_vlc[0];

        }

        if (VAR_0->ac_pred) {

            if (VAR_10 == 0)

                VAR_11 = VAR_0->intra_v_scantable.permutated; 

            else

                VAR_11 = VAR_0->intra_h_scantable.permutated; 

        } else {

            VAR_11 = VAR_0->intra_scantable.permutated;

        }

        VAR_12=1;

        VAR_13=0;

    } else {

        VAR_7 = -1;

        if (!VAR_3) {

            VAR_0->block_last_index[VAR_2] = VAR_7;

            return 0;

        }

        if(VAR_5) rl = &rvlc_rl_inter;

        else     rl = &rl_inter;



        VAR_11 = VAR_0->intra_scantable.permutated;



        if(VAR_0->mpeg_quant){

            VAR_12=1;

            VAR_13=0;

            if(VAR_5){

                rl_vlc = rvlc_rl_inter.rl_vlc[0];

            }else{

                rl_vlc = rl_inter.rl_vlc[0];

            }

        }else{

            VAR_12 = VAR_0->qscale << 1;

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

            if(VAR_5){

                rl_vlc = rvlc_rl_inter.rl_vlc[VAR_0->qscale];

            }else{

                rl_vlc = rl_inter.rl_vlc[VAR_0->qscale];

            }

        }

    }

  {

    OPEN_READER(re, &VAR_0->gb);

    for(;;) {

        UPDATE_CACHE(re, &VAR_0->gb);

        GET_RL_VLC(VAR_6, VAR_9, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 0);

        if (VAR_6==0) {

          

          if(VAR_5){

                if(SHOW_UBITS(re, &VAR_0->gb, 1)==0){

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "1. marker bit missing in VAR_5 esc\VAR_2");

                    return -1;

                }; SKIP_CACHE(re, &VAR_0->gb, 1);



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

                VAR_9=   SHOW_UBITS(re, &VAR_0->gb, 6); LAST_SKIP_CACHE(re, &VAR_0->gb, 6);

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

                UPDATE_CACHE(re, &VAR_0->gb);



                if(SHOW_UBITS(re, &VAR_0->gb, 1)==0){

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "2. marker bit missing in VAR_5 esc\VAR_2");

                    return -1;

                }; SKIP_CACHE(re, &VAR_0->gb, 1);



                VAR_6= SHOW_UBITS(re, &VAR_0->gb, 11); SKIP_CACHE(re, &VAR_0->gb, 11);



                if(SHOW_UBITS(re, &VAR_0->gb, 5)!=0x10){

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "reverse esc missing\VAR_2");

                    return -1;

                }; SKIP_CACHE(re, &VAR_0->gb, 5);



                VAR_6=  VAR_6 * VAR_12 + VAR_13;

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

                SKIP_COUNTER(re, &VAR_0->gb, 1+11+5+1);



                VAR_7+= VAR_9 + 1;

                if(VAR_8) VAR_7+=192;

          }else{

            int VAR_14;

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



            if(IS_3IV1)

                VAR_14 ^= 0xC0000000;



            if (VAR_14&0x80000000) {

                if (VAR_14&0x40000000) {

                    

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

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

                    VAR_9=   SHOW_UBITS(re, &VAR_0->gb, 6); LAST_SKIP_CACHE(re, &VAR_0->gb, 6);

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

                    UPDATE_CACHE(re, &VAR_0->gb);



                    if(IS_3IV1){

                        VAR_6= SHOW_SBITS(re, &VAR_0->gb, 12); LAST_SKIP_BITS(re, &VAR_0->gb, 12);

                    }else{

                        if(SHOW_UBITS(re, &VAR_0->gb, 1)==0){

                            av_log(VAR_0->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\VAR_2");

                            return -1;

                        }; SKIP_CACHE(re, &VAR_0->gb, 1);



                        VAR_6= SHOW_SBITS(re, &VAR_0->gb, 12); SKIP_CACHE(re, &VAR_0->gb, 12);



                        if(SHOW_UBITS(re, &VAR_0->gb, 1)==0){

                            av_log(VAR_0->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\VAR_2");

                            return -1;

                        }; LAST_SKIP_CACHE(re, &VAR_0->gb, 1);



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

                    }



#if 0

                    if(VAR_0->error_resilience >= FF_ER_COMPLIANT){

                        const int abs_level= ABS(VAR_6);

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

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

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

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

                                return -1;

                            }

                            if(VAR_0->error_resilience > FF_ER_COMPLIANT){

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

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

                                    return -1;

                                }

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

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

                                    return -1;

                                }

                            }

                        }

                    }

#endif

                    if (VAR_6>0) VAR_6= VAR_6 * VAR_12 + VAR_13;

                    else         VAR_6= VAR_6 * VAR_12 - VAR_13;



                    if((unsigned)(VAR_6 + 2048) > 4095){

                        if(VAR_0->error_resilience > FF_ER_COMPLIANT){

                            if(VAR_6 > 2560 || VAR_6<-2560){

                                av_log(VAR_0->avctx, AV_LOG_ERROR, "|VAR_6| overflow in 3. esc, qp=%d\VAR_2", VAR_0->qscale);

                                return -1;

                            }

                        }

                        VAR_6= VAR_6<0 ? -2048 : 2047;

                    }



                    VAR_7+= VAR_9 + 1;

                    if(VAR_8) VAR_7+=192;

                } else {

                    

#if MIN_CACHE_BITS < 20

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

                    UPDATE_CACHE(re, &VAR_0->gb);

#else

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

#endif

                    GET_RL_VLC(VAR_6, VAR_9, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 1);

                    VAR_7+= VAR_9 + rl->max_run[VAR_9>>7][VAR_6/VAR_12] +1; 

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

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

                }

            } else {

                

#if MIN_CACHE_BITS < 19

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

                UPDATE_CACHE(re, &VAR_0->gb);

#else

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

#endif

                GET_RL_VLC(VAR_6, VAR_9, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 1);

                VAR_7+= VAR_9;

                VAR_6 = VAR_6 + rl->max_level[VAR_9>>7][(VAR_9-1)&63] * VAR_12;

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

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

            }

          }

        } else {

            VAR_7+= VAR_9;

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

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

        }

        if (VAR_7 > 62){

            VAR_7-= 192;

            if(VAR_7&(~63)){

                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_11[VAR_7]] = VAR_6;

            break;

        }



        VAR_1[VAR_11[VAR_7]] = VAR_6;

    }

    CLOSE_READER(re, &VAR_0->gb);

  }

 not_coded:

    if (VAR_4) {

        if(VAR_0->qscale >= VAR_0->intra_dc_threshold){

            VAR_1[0] = ff_mpeg4_pred_dc(VAR_0, VAR_2, VAR_1[0], &VAR_10, 0);



            VAR_7 -= VAR_7>>31; 

        }



        mpeg4_pred_ac(VAR_0, VAR_1, VAR_2, VAR_10);

        if (VAR_0->ac_pred) {

            VAR_7 = 63; 

        }

    }

    VAR_0->block_last_index[VAR_2] = VAR_7;

    return 0;

}

static inline int FUNC_0(MpegEncContext * VAR_0, DCTELEM * VAR_1,
int VAR_2, int VAR_3, int VAR_4, int VAR_5)
{ int VAR_6, VAR_7, VAR_8, VAR_9; int VAR_10; RLTable * rl; RL_VLC_ELEM * rl_vlc; const uint8_t * VAR_11; int VAR_12, VAR_13; if(VAR_4) { if(VAR_0->qscale < VAR_0->intra_dc_threshold){ if(VAR_0->partitioned_frame){ VAR_6 = VAR_0->dc_val[0][ VAR_0->block_index[VAR_2] ]; if(VAR_2<4) VAR_6= FASTDIV((VAR_6 + (VAR_0->y_dc_scale>>1)), VAR_0->y_dc_scale); else    VAR_6= FASTDIV((VAR_6 + (VAR_0->c_dc_scale>>1)), VAR_0->c_dc_scale); VAR_10= (VAR_0->pred_dir_table[VAR_0->mb_x + VAR_0->mb_y*VAR_0->mb_stride]<<VAR_2)&32; }else{ VAR_6 = mpeg4_decode_dc(VAR_0, VAR_2, &VAR_10); if (VAR_6 < 0)
return -1; } VAR_1[0] = VAR_6; VAR_7 = 0; }else{ VAR_7 = -1; ff_mpeg4_pred_dc(VAR_0, VAR_2, 0, &VAR_10, 0); } if (!VAR_3)
goto not_coded; if(VAR_5){ rl = &rvlc_rl_intra; rl_vlc = rvlc_rl_intra.rl_vlc[0]; }else{ rl = &rl_intra; rl_vlc = rl_intra.rl_vlc[0]; } if (VAR_0->ac_pred) { if (VAR_10 == 0)
VAR_11 = VAR_0->intra_v_scantable.permutated; else
VAR_11 = VAR_0->intra_h_scantable.permutated; } else { VAR_11 = VAR_0->intra_scantable.permutated; } VAR_12=1; VAR_13=0; } else { VAR_7 = -1; if (!VAR_3) { VAR_0->block_last_index[VAR_2] = VAR_7; return 0; } if(VAR_5) rl = &rvlc_rl_inter; else     rl = &rl_inter; VAR_11 = VAR_0->intra_scantable.permutated; if(VAR_0->mpeg_quant){ VAR_12=1; VAR_13=0; if(VAR_5){ rl_vlc = rvlc_rl_inter.rl_vlc[0]; }else{ rl_vlc = rl_inter.rl_vlc[0]; } }else{ VAR_12 = VAR_0->qscale << 1; VAR_13 = (VAR_0->qscale - 1) | 1; if(VAR_5){ rl_vlc = rvlc_rl_inter.rl_vlc[VAR_0->qscale]; }else{ rl_vlc = rl_inter.rl_vlc[VAR_0->qscale]; } } } { OPEN_READER(re, &VAR_0->gb); for(;;) { UPDATE_CACHE(re, &VAR_0->gb); GET_RL_VLC(VAR_6, VAR_9, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 0); if (VAR_6==0) { if(VAR_5){ if(SHOW_UBITS(re, &VAR_0->gb, 1)==0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "1. marker bit missing in VAR_5 esc\VAR_2"); return -1; }; SKIP_CACHE(re, &VAR_0->gb, 1); VAR_8=  SHOW_UBITS(re, &VAR_0->gb, 1); SKIP_CACHE(re, &VAR_0->gb, 1); VAR_9=   SHOW_UBITS(re, &VAR_0->gb, 6); LAST_SKIP_CACHE(re, &VAR_0->gb, 6); SKIP_COUNTER(re, &VAR_0->gb, 1+1+6); UPDATE_CACHE(re, &VAR_0->gb); if(SHOW_UBITS(re, &VAR_0->gb, 1)==0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "2. marker bit missing in VAR_5 esc\VAR_2"); return -1; }; SKIP_CACHE(re, &VAR_0->gb, 1); VAR_6= SHOW_UBITS(re, &VAR_0->gb, 11); SKIP_CACHE(re, &VAR_0->gb, 11); if(SHOW_UBITS(re, &VAR_0->gb, 5)!=0x10){ av_log(VAR_0->avctx, AV_LOG_ERROR, "reverse esc missing\VAR_2"); return -1; }; SKIP_CACHE(re, &VAR_0->gb, 5); VAR_6=  VAR_6 * VAR_12 + VAR_13; VAR_6 = (VAR_6 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1); LAST_SKIP_CACHE(re, &VAR_0->gb, 1); SKIP_COUNTER(re, &VAR_0->gb, 1+11+5+1); VAR_7+= VAR_9 + 1; if(VAR_8) VAR_7+=192; }else{ int VAR_14; VAR_14= GET_CACHE(re, &VAR_0->gb); if(IS_3IV1)
VAR_14 ^= 0xC0000000; if (VAR_14&0x80000000) { if (VAR_14&0x40000000) { SKIP_CACHE(re, &VAR_0->gb, 2); VAR_8=  SHOW_UBITS(re, &VAR_0->gb, 1); SKIP_CACHE(re, &VAR_0->gb, 1); VAR_9=   SHOW_UBITS(re, &VAR_0->gb, 6); LAST_SKIP_CACHE(re, &VAR_0->gb, 6); SKIP_COUNTER(re, &VAR_0->gb, 2+1+6); UPDATE_CACHE(re, &VAR_0->gb); if(IS_3IV1){ VAR_6= SHOW_SBITS(re, &VAR_0->gb, 12); LAST_SKIP_BITS(re, &VAR_0->gb, 12); }else{ if(SHOW_UBITS(re, &VAR_0->gb, 1)==0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\VAR_2"); return -1; }; SKIP_CACHE(re, &VAR_0->gb, 1); VAR_6= SHOW_SBITS(re, &VAR_0->gb, 12); SKIP_CACHE(re, &VAR_0->gb, 12); if(SHOW_UBITS(re, &VAR_0->gb, 1)==0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\VAR_2"); return -1; }; LAST_SKIP_CACHE(re, &VAR_0->gb, 1); SKIP_COUNTER(re, &VAR_0->gb, 1+12+1); } #if 0
if(VAR_0->error_resilience >= FF_ER_COMPLIANT){ const int abs_level= ABS(VAR_6); if(abs_level<=MAX_LEVEL && VAR_9<=MAX_RUN){ const int run1= VAR_9 - rl->max_run[VAR_8][abs_level] - 1; if(abs_level <= rl->max_level[VAR_8][VAR_9]){ av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\VAR_2"); return -1; } if(VAR_0->error_resilience > FF_ER_COMPLIANT){ if(abs_level <= rl->max_level[VAR_8][VAR_9]*2){ av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\VAR_2"); return -1; } if(run1 >= 0 && abs_level <= rl->max_level[VAR_8][run1]){ av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\VAR_2"); return -1; } } } } #endif
if (VAR_6>0) VAR_6= VAR_6 * VAR_12 + VAR_13; else         VAR_6= VAR_6 * VAR_12 - VAR_13; if((unsigned)(VAR_6 + 2048) > 4095){ if(VAR_0->error_resilience > FF_ER_COMPLIANT){ if(VAR_6 > 2560 || VAR_6<-2560){ av_log(VAR_0->avctx, AV_LOG_ERROR, "|VAR_6| overflow in 3. esc, qp=%d\VAR_2", VAR_0->qscale); return -1; } } VAR_6= VAR_6<0 ? -2048 : 2047; } VAR_7+= VAR_9 + 1; if(VAR_8) VAR_7+=192; } else { #if MIN_CACHE_BITS < 20
LAST_SKIP_BITS(re, &VAR_0->gb, 2); UPDATE_CACHE(re, &VAR_0->gb); #else
SKIP_BITS(re, &VAR_0->gb, 2); #endif
GET_RL_VLC(VAR_6, VAR_9, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 1); VAR_7+= VAR_9 + rl->max_run[VAR_9>>7][VAR_6/VAR_12] +1; VAR_6 = (VAR_6 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1); LAST_SKIP_BITS(re, &VAR_0->gb, 1); } } else { #if MIN_CACHE_BITS < 19
LAST_SKIP_BITS(re, &VAR_0->gb, 1); UPDATE_CACHE(re, &VAR_0->gb); #else
SKIP_BITS(re, &VAR_0->gb, 1); #endif
GET_RL_VLC(VAR_6, VAR_9, re, &VAR_0->gb, rl_vlc, TEX_VLC_BITS, 2, 1); VAR_7+= VAR_9; VAR_6 = VAR_6 + rl->max_level[VAR_9>>7][(VAR_9-1)&63] * VAR_12; VAR_6 = (VAR_6 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1); LAST_SKIP_BITS(re, &VAR_0->gb, 1); } } } else { VAR_7+= VAR_9; VAR_6 = (VAR_6 ^ SHOW_SBITS(re, &VAR_0->gb, 1)) - SHOW_SBITS(re, &VAR_0->gb, 1); LAST_SKIP_BITS(re, &VAR_0->gb, 1); } if (VAR_7 > 62){ VAR_7-= 192; if(VAR_7&(~63)){ 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_11[VAR_7]] = VAR_6; break; } VAR_1[VAR_11[VAR_7]] = VAR_6; } CLOSE_READER(re, &VAR_0->gb); } not_coded:
if (VAR_4) { if(VAR_0->qscale >= VAR_0->intra_dc_threshold){ VAR_1[0] = ff_mpeg4_pred_dc(VAR_0, VAR_2, VAR_1[0], &VAR_10, 0); VAR_7 -= VAR_7>>31; } mpeg4_pred_ac(VAR_0, VAR_1, VAR_2, VAR_10); if (VAR_0->ac_pred) { VAR_7 = 63; } } VAR_0->block_last_index[VAR_2] = VAR_7; return 0; }