scantable= s->intra_scantable;
scantable= s->intra_scantable.permutated;
static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n){    int level, run, last, i, j, last_index;    int last_non_zero, sign, slevel;    int code, run_diff, dc_pred_dir;    const RLTable *rl;    const UINT8 *scantable;    if (s->mb_intra) {        set_stat(ST_DC);        msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);        i = 1;        if (n < 4) {            rl = &rl_table[s->rl_table_index];        } else {            rl = &rl_table[3 + s->rl_chroma_table_index];        }        run_diff = 0;        scantable= s->intra_scantable;        set_stat(ST_INTRA_AC);    } else {        i = 0;        rl = &rl_table[3 + s->rl_table_index];        if(s->msmpeg4_version<=2)            run_diff = 0;        else            run_diff = 1;        scantable= s->inter_scantable;        set_stat(ST_INTER_AC);    }    /* recalculate block_last_index for M$ wmv1 */    if(scantable!=zigzag_direct && s->block_last_index[n]>0){        for(last_index=63; last_index>=0; last_index--){            if(block[scantable[last_index]]) break;        }    }else        last_index = s->block_last_index[n];    /* AC coefs */    last_non_zero = i - 1;    for (; i <= last_index; i++) {	j = scantable[i];	level = block[j];	if (level) {	    run = i - last_non_zero - 1;	    last = (i == last_index);	    sign = 0;	    slevel = level;	    if (level < 0) {		sign = 1;		level = -level;	    }            if(level<=MAX_LEVEL && run<=MAX_RUN){                s->ac_stats[s->mb_intra][n>3][level][run][last]++;            }#if 0else    s->ac_stats[s->mb_intra][n>3][40][63][0]++; //esc3 like#endif            code = get_rl_index(rl, last, run, level);            put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);            if (code == rl->n) {                int level1, run1;                level1 = level - rl->max_level[last][run];                if (level1 < 1)                     goto esc2;                code = get_rl_index(rl, last, run, level1);                if (code == rl->n) {                esc2:                    put_bits(&s->pb, 1, 0);                    if (level > MAX_LEVEL)                        goto esc3;                    run1 = run - rl->max_run[last][level] - run_diff;                    if (run1 < 0)                        goto esc3;                    code = get_rl_index(rl, last, run1, level);                    if (code == rl->n) {                    esc3:                        /* third escape */                        put_bits(&s->pb, 1, 0);                        put_bits(&s->pb, 1, last);                        if(s->msmpeg4_version==4){                            if(s->esc3_level_length==0){                                s->esc3_level_length=8;                                s->esc3_run_length= 6;                                if(s->qscale<8)                                    put_bits(&s->pb, 6, 3);                                else                                    put_bits(&s->pb, 8, 3);                            }                            put_bits(&s->pb, s->esc3_run_length, run);                            put_bits(&s->pb, 1, sign);                            put_bits(&s->pb, s->esc3_level_length, level);                        }else{                            put_bits(&s->pb, 6, run);                            put_bits(&s->pb, 8, slevel & 0xff);                        }                    } else {                        /* second escape */                        put_bits(&s->pb, 1, 1);                        put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);                        put_bits(&s->pb, 1, sign);                    }                } else {                    /* first escape */                    put_bits(&s->pb, 1, 1);                    put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);                    put_bits(&s->pb, 1, sign);                }            } else {                put_bits(&s->pb, 1, sign);            }	    last_non_zero = i;	}    }}