static inline int get_p_cbp(MpegEncContext * s,
                      DCTELEM block[6][64],
                      int motion_x, int motion_y){
    int cbp, i;
    if(s->flags & CODEC_FLAG_CBP_RD){
        int best_cbpy_score= INT_MAX;
        int best_cbpc_score= INT_MAX;
        int cbpc = (-1), cbpy= (-1);
        const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0);
        const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
        for(i=0; i<4; i++){
            int score= inter_MCBPC_bits[i + offset] * lambda;
            if(i&1) score += s->coded_score[5];
            if(i&2) score += s->coded_score[4];
            if(score < best_cbpc_score){
                best_cbpc_score= score;
                cbpc= i;
            }
        }
        for(i=0; i<16; i++){
            int score= cbpy_tab[i ^ 0xF][1] * lambda;
            if(i&1) score += s->coded_score[3];
            if(i&2) score += s->coded_score[2];
            if(i&4) score += s->coded_score[1];
            if(i&8) score += s->coded_score[0];
            if(score < best_cbpy_score){
                best_cbpy_score= score;
                cbpy= i;
            }
        }
        cbp= cbpc + 4*cbpy;
        if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){
            if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0)
                cbp= 0;
        }
        for (i = 0; i < 6; i++) {
            if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){
                s->block_last_index[i]= -1;
                memset(s->block[i], 0, sizeof(DCTELEM)*64);
            }
        }
    }else{
        cbp= 0;
        for (i = 0; i < 6; i++) {
            if (s->block_last_index[i] >= 0)
                cbp |= 1 << (5 - i);
        }
    }
    return cbp;
}
['static inline int get_p_cbp(MpegEncContext * s,\n                      DCTELEM block[6][64],\n                      int motion_x, int motion_y){\n    int cbp, i;\n    if(s->flags & CODEC_FLAG_CBP_RD){\n        int best_cbpy_score= INT_MAX;\n        int best_cbpc_score= INT_MAX;\n        int cbpc = (-1), cbpy= (-1);\n        const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0);\n        const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);\n        for(i=0; i<4; i++){\n            int score= inter_MCBPC_bits[i + offset] * lambda;\n            if(i&1) score += s->coded_score[5];\n            if(i&2) score += s->coded_score[4];\n            if(score < best_cbpc_score){\n                best_cbpc_score= score;\n                cbpc= i;\n            }\n        }\n        for(i=0; i<16; i++){\n            int score= cbpy_tab[i ^ 0xF][1] * lambda;\n            if(i&1) score += s->coded_score[3];\n            if(i&2) score += s->coded_score[2];\n            if(i&4) score += s->coded_score[1];\n            if(i&8) score += s->coded_score[0];\n            if(score < best_cbpy_score){\n                best_cbpy_score= score;\n                cbpy= i;\n            }\n        }\n        cbp= cbpc + 4*cbpy;\n        if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){\n            if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0)\n                cbp= 0;\n        }\n        for (i = 0; i < 6; i++) {\n            if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){\n                s->block_last_index[i]= -1;\n                memset(s->block[i], 0, sizeof(DCTELEM)*64);\n            }\n        }\n    }else{\n        cbp= 0;\n        for (i = 0; i < 6; i++) {\n            if (s->block_last_index[i] >= 0)\n                cbp |= 1 << (5 - i);\n        }\n    }\n    return cbp;\n}']