static void find_best_tables(MpegEncContext * s)

{

    int i;

    int best       =-1, best_size       =9999999;

    int chroma_best=-1, best_chroma_size=9999999;



    for(i=0; i<3; i++){

        int level;

        int chroma_size=0;

        int size=0;



        if(i>0){// ;)

            size++;

            chroma_size++;

        }

        for(level=0; level<=MAX_LEVEL; level++){

            int run;

            for(run=0; run<=MAX_RUN; run++){

                int last;

                const int last_size= size + chroma_size;

                for(last=0; last<2; last++){

                    int inter_count       = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];

                    int intra_luma_count  = s->ac_stats[1][0][level][run][last];

                    int intra_chroma_count= s->ac_stats[1][1][level][run][last];



                    if(s->pict_type==AV_PICTURE_TYPE_I){

                        size       += intra_luma_count  *rl_length[i  ][level][run][last];

                        chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];

                    }else{

                        size+=        intra_luma_count  *rl_length[i  ][level][run][last]

                                     +intra_chroma_count*rl_length[i+3][level][run][last]

                                     +inter_count       *rl_length[i+3][level][run][last];

                    }

                }

                if(last_size == size+chroma_size) break;

            }

        }

        if(size<best_size){

            best_size= size;

            best= i;

        }

        if(chroma_size<best_chroma_size){

            best_chroma_size= chroma_size;

            chroma_best= i;

        }

    }



//    printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",

//           s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);



    if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;



    memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);



    s->rl_table_index       =        best;

    s->rl_chroma_table_index= chroma_best;



    if(s->pict_type != s->last_non_b_pict_type){

        s->rl_table_index= 2;

        if(s->pict_type==AV_PICTURE_TYPE_I)

            s->rl_chroma_table_index= 1;

        else

            s->rl_chroma_table_index= 2;

    }



}

static void find_best_tables(MpegEncContext * s)

{

    int i;

    int best       =-1, best_size       =9999999;

    int chroma_best=-1, best_chroma_size=9999999;



    for(i=0; i<3; i++){

        int level;

        int chroma_size=0;

        int size=0;



        if(i>0){

            size++;

            chroma_size++;

        }

        for(level=0; level<=MAX_LEVEL; level++){

            int run;

            for(run=0; run<=MAX_RUN; run++){

                int last;

                const int last_size= size + chroma_size;

                for(last=0; last<2; last++){

                    int inter_count       = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];

                    int intra_luma_count  = s->ac_stats[1][0][level][run][last];

                    int intra_chroma_count= s->ac_stats[1][1][level][run][last];



                    if(s->pict_type==AV_PICTURE_TYPE_I){

                        size       += intra_luma_count  *rl_length[i  ][level][run][last];

                        chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];

                    }else{

                        size+=        intra_luma_count  *rl_length[i  ][level][run][last]

                                     +intra_chroma_count*rl_length[i+3][level][run][last]

                                     +inter_count       *rl_length[i+3][level][run][last];

                    }

                }

                if(last_size == size+chroma_size) break;

            }

        }

        if(size<best_size){

            best_size= size;

            best= i;

        }

        if(chroma_size<best_chroma_size){

            best_chroma_size= chroma_size;

            chroma_best= i;

        }

    }









    if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;



    memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);



    s->rl_table_index       =        best;

    s->rl_chroma_table_index= chroma_best;



    if(s->pict_type != s->last_non_b_pict_type){

        s->rl_table_index= 2;

        if(s->pict_type==AV_PICTURE_TYPE_I)

            s->rl_chroma_table_index= 1;

        else

            s->rl_chroma_table_index= 2;

    }



}

static void FUNC_0(MpegEncContext * VAR_0)

{

    int VAR_1;

    int VAR_2       =-1, VAR_3       =9999999;

    int VAR_4=-1, VAR_5=9999999;



    for(VAR_1=0; VAR_1<3; VAR_1++){

        int VAR_6;

        int VAR_7=0;

        int VAR_8=0;



        if(VAR_1>0){

            VAR_8++;

            VAR_7++;

        }

        for(VAR_6=0; VAR_6<=MAX_LEVEL; VAR_6++){

            int run;

            for(run=0; run<=MAX_RUN; run++){

                int last;

                const int last_size= VAR_8 + VAR_7;

                for(last=0; last<2; last++){

                    int inter_count       = VAR_0->ac_stats[0][0][VAR_6][run][last] + VAR_0->ac_stats[0][1][VAR_6][run][last];

                    int intra_luma_count  = VAR_0->ac_stats[1][0][VAR_6][run][last];

                    int intra_chroma_count= VAR_0->ac_stats[1][1][VAR_6][run][last];



                    if(VAR_0->pict_type==AV_PICTURE_TYPE_I){

                        VAR_8       += intra_luma_count  *rl_length[VAR_1  ][VAR_6][run][last];

                        VAR_7+= intra_chroma_count*rl_length[VAR_1+3][VAR_6][run][last];

                    }else{

                        VAR_8+=        intra_luma_count  *rl_length[VAR_1  ][VAR_6][run][last]

                                     +intra_chroma_count*rl_length[VAR_1+3][VAR_6][run][last]

                                     +inter_count       *rl_length[VAR_1+3][VAR_6][run][last];

                    }

                }

                if(last_size == VAR_8+VAR_7) break;

            }

        }

        if(VAR_8<VAR_3){

            VAR_3= VAR_8;

            VAR_2= VAR_1;

        }

        if(VAR_7<VAR_5){

            VAR_5= VAR_7;

            VAR_4= VAR_1;

        }

    }









    if(VAR_0->pict_type==AV_PICTURE_TYPE_P) VAR_4= VAR_2;



    memset(VAR_0->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);



    VAR_0->rl_table_index       =        VAR_2;

    VAR_0->rl_chroma_table_index= VAR_4;



    if(VAR_0->pict_type != VAR_0->last_non_b_pict_type){

        VAR_0->rl_table_index= 2;

        if(VAR_0->pict_type==AV_PICTURE_TYPE_I)

            VAR_0->rl_chroma_table_index= 1;

        else

            VAR_0->rl_chroma_table_index= 2;

    }



}

static void FUNC_0(MpegEncContext * VAR_0)
{ int VAR_1; int VAR_2       =-1, VAR_3       =9999999; int VAR_4=-1, VAR_5=9999999; for(VAR_1=0; VAR_1<3; VAR_1++){ int VAR_6; int VAR_7=0; int VAR_8=0; if(VAR_1>0){ VAR_8++; VAR_7++; } for(VAR_6=0; VAR_6<=MAX_LEVEL; VAR_6++){ int run; for(run=0; run<=MAX_RUN; run++){ int last; const int last_size= VAR_8 + VAR_7; for(last=0; last<2; last++){ int inter_count       = VAR_0->ac_stats[0][0][VAR_6][run][last] + VAR_0->ac_stats[0][1][VAR_6][run][last]; int intra_luma_count  = VAR_0->ac_stats[1][0][VAR_6][run][last]; int intra_chroma_count= VAR_0->ac_stats[1][1][VAR_6][run][last]; if(VAR_0->pict_type==AV_PICTURE_TYPE_I){ VAR_8       += intra_luma_count  *rl_length[VAR_1  ][VAR_6][run][last]; VAR_7+= intra_chroma_count*rl_length[VAR_1+3][VAR_6][run][last]; }else{ VAR_8+=        intra_luma_count  *rl_length[VAR_1  ][VAR_6][run][last]
+intra_chroma_count*rl_length[VAR_1+3][VAR_6][run][last]
+inter_count       *rl_length[VAR_1+3][VAR_6][run][last]; } } if(last_size == VAR_8+VAR_7) break; } } if(VAR_8<VAR_3){ VAR_3= VAR_8; VAR_2= VAR_1; } if(VAR_7<VAR_5){ VAR_5= VAR_7; VAR_4= VAR_1; } } if(VAR_0->pict_type==AV_PICTURE_TYPE_P) VAR_4= VAR_2; memset(VAR_0->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2); VAR_0->rl_table_index       =        VAR_2; VAR_0->rl_chroma_table_index= VAR_4; if(VAR_0->pict_type != VAR_0->last_non_b_pict_type){ VAR_0->rl_table_index= 2; if(VAR_0->pict_type==AV_PICTURE_TYPE_I)
VAR_0->rl_chroma_table_index= 1; else
VAR_0->rl_chroma_table_index= 2; } }