run1 = run - rl->max_run[last][abs_level] - 1;
static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,                              int n, int coded){    int code, level, i, j, last, run;    int dc_pred_dir;    RLTable *rl;    const UINT8 *scan_table;    if (s->mb_intra) {	/* DC coef */        if(s->data_partitioning && s->pict_type!=B_TYPE){            level = s->dc_val[0][ s->block_index[n] ];            if(n<4) level= (level + (s->y_dc_scale>>1))/s->y_dc_scale; //FIXME optimizs            else    level= (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_width]<<n)&32;        }else{            level = mpeg4_decode_dc(s, n, &dc_pred_dir);            if (level < 0)                return DECODING_ACDC_LOST;        }        block[0] = level;        i = 1;        if (!coded)             goto not_coded;        rl = &rl_intra;        if (s->ac_pred) {            if (dc_pred_dir == 0)                 scan_table = ff_alternate_vertical_scan; /* left */            else                scan_table = ff_alternate_horizontal_scan; /* top */        } else {            scan_table = zigzag_direct;        }    } else {	i = 0;        if (!coded) {            s->block_last_index[n] = i - 1;            return 0;        }        rl = &rl_inter;        scan_table = zigzag_direct;    }    for(;;) {        code = get_vlc(&s->gb, &rl->vlc);        if (code < 0)            return DECODING_AC_LOST;        if (code == rl->n) {            /* escape */            if (get_bits1(&s->gb) != 0) {                if (get_bits1(&s->gb) != 0) {                    /* third escape */                    last = get_bits1(&s->gb);                    run = get_bits(&s->gb, 6);                    if(get_bits1(&s->gb)==0){                        fprintf(stderr, "1. marker bit missing in 3. esc\n");                        return DECODING_AC_LOST;                    }                    level = get_bits(&s->gb, 12);                    level = (level << 20) >> 20; /* sign extend */                    if(get_bits1(&s->gb)==0){                        fprintf(stderr, "2. marker bit missing in 3. esc\n");                        return DECODING_AC_LOST;                    }                    if(level>512 || level<-512){ //FIXME check that QP=1 is ok with this too                        fprintf(stderr, "|level| overflow in 3. esc\n");                        return DECODING_AC_LOST;                    }#if 1                     {                        const int abs_level= ABS(level);                        const int run1= run - rl->max_run[last][abs_level] - 1;                        if(abs_level<=MAX_LEVEL && run<=MAX_RUN && s->error_resilience>=0){                            if(abs_level <= rl->max_level[last][run]){                                fprintf(stderr, "illegal 3. esc, vlc encoding possible\n");                                return DECODING_AC_LOST;                            }                            if(abs_level <= rl->max_level[last][run]*2){                                fprintf(stderr, "illegal 3. esc, esc 1 encoding possible\n");                                return DECODING_AC_LOST;                            }                            if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){                                fprintf(stderr, "illegal 3. esc, esc 2 encoding possible\n");                                return DECODING_AC_LOST;                            }                        }                    }#endif                } else {                    /* second escape */                    code = get_vlc(&s->gb, &rl->vlc);                    if (code < 0 || code >= rl->n)                        return DECODING_AC_LOST;                    run = rl->table_run[code];                    level = rl->table_level[code];                    last = code >= rl->last;                    run += rl->max_run[last][level] + 1;                    if (get_bits1(&s->gb))                        level = -level;                }            } else {                /* first escape */                code = get_vlc(&s->gb, &rl->vlc);                if (code < 0 || code >= rl->n)                    return DECODING_AC_LOST;                run = rl->table_run[code];                level = rl->table_level[code];                last = code >= rl->last;                level += rl->max_level[last][run];                if (get_bits1(&s->gb))                    level = -level;            }        } else {            run = rl->table_run[code];            level = rl->table_level[code];            last = code >= rl->last;            if (get_bits1(&s->gb))                level = -level;        }        i += run;        if (i >= 64)            return DECODING_AC_LOST;	j = scan_table[i];        block[j] = level;        i++;        if (last)            break;    } not_coded:    if (s->mb_intra) {        mpeg4_pred_ac(s, block, n, dc_pred_dir);        if (s->ac_pred) {            i = 64; /* XXX: not optimal */        }    }    s->block_last_index[n] = i - 1;    return 0;}