static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){

    MpegEncContext * const s = &h->s;

    int b8_stride = 2;

    int b4_stride = h->b_stride;

    int mb_xy = h->mb_xy, mb_y = s->mb_y;

    int mb_type_col[2];

    const int16_t (*l1mv0)[2], (*l1mv1)[2];

    const int8_t *l1ref0, *l1ref1;

    const int is_b8x8 = IS_8X8(*mb_type);

    unsigned int sub_mb_type= MB_TYPE_L0L1;

    int i8, i4;

    int ref[2];

    int mv[2];

    int list;



    assert(h->ref_list[1][0].f.reference & 3);



    await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));



#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)





    /* ref = min(neighbors) */

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

        int left_ref = h->ref_cache[list][scan8[0] - 1];

        int top_ref  = h->ref_cache[list][scan8[0] - 8];

        int refc = h->ref_cache[list][scan8[0] - 8 + 4];

        const int16_t *C= h->mv_cache[list][ scan8[0] - 8 + 4];

        if(refc == PART_NOT_AVAILABLE){

            refc = h->ref_cache[list][scan8[0] - 8 - 1];

            C    = h-> mv_cache[list][scan8[0] - 8 - 1];


        ref[list] = FFMIN3((unsigned)left_ref, (unsigned)top_ref, (unsigned)refc);

        if(ref[list] >= 0){

            //this is just pred_motion() but with the cases removed that cannot happen for direct blocks

            const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ];

            const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];



            int match_count= (left_ref==ref[list]) + (top_ref==ref[list]) + (refc==ref[list]);

            if(match_count > 1){ //most common

                mv[list]= pack16to32(mid_pred(A[0], B[0], C[0]),

                                     mid_pred(A[1], B[1], C[1]) );

            }else {

                assert(match_count==1);

                if(left_ref==ref[list]){

                    mv[list]= AV_RN32A(A);

                }else if(top_ref==ref[list]){

                    mv[list]= AV_RN32A(B);

                }else{

                    mv[list]= AV_RN32A(C);



        }else{

            int mask= ~(MB_TYPE_L0 << (2*list));

            mv[list] = 0;

            ref[list] = -1;

            if(!is_b8x8)

                *mb_type &= mask;

            sub_mb_type &= mask;



    if(ref[0] < 0 && ref[1] < 0){

        ref[0] = ref[1] = 0;

        if(!is_b8x8)

            *mb_type |= MB_TYPE_L0L1;

        sub_mb_type |= MB_TYPE_L0L1;




    if(!(is_b8x8|mv[0]|mv[1])){

        fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);

        fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);

        fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);

        fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);

        *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;

        return;




    if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL

        if (!IS_INTERLACED(*mb_type)) {                          //     AFR/FR    -> AFL/FL

            mb_y = (s->mb_y&~1) + h->col_parity;

            mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;

            b8_stride = 0;

        }else{

            mb_y  += h->col_fieldoff;

            mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity


        goto single_col;

    }else{                                               // AFL/AFR/FR/FL -> AFR/FR

        if(IS_INTERLACED(*mb_type)){                     // AFL       /FL -> AFR/FR

            mb_y = s->mb_y&~1;

            mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;

            mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy];

            mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride];

            b8_stride = 2+4*s->mb_stride;

            b4_stride *= 6;







            sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_SUB_8x8 */

            if(    (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)

                && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)

                && !is_b8x8){

                *mb_type   |= MB_TYPE_16x8 |MB_TYPE_DIRECT2; /* B_16x8 */

            }else{

                *mb_type   |= MB_TYPE_8x8;


        }else{                                           //     AFR/FR    -> AFR/FR

single_col:

            mb_type_col[0] =

            mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy];



            sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_SUB_8x8 */

            if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){

                *mb_type   |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_16x16 */

            }else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){

                *mb_type   |= MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16));

            }else{

                if(!h->sps.direct_8x8_inference_flag){

                    /* FIXME save sub mb types from previous frames (or derive from MVs)

                    * so we know exactly what block size to use */

                    sub_mb_type += (MB_TYPE_8x8-MB_TYPE_16x16); /* B_SUB_4x4 */


                *mb_type   |= MB_TYPE_8x8;






    await_reference_mb_row(h, &h->ref_list[1][0], mb_y);



    l1mv0  = &h->ref_list[1][0].f.motion_val[0][h->mb2b_xy [mb_xy]];

    l1mv1  = &h->ref_list[1][0].f.motion_val[1][h->mb2b_xy [mb_xy]];

    l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy];

    l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy];

    if(!b8_stride){

        if(s->mb_y&1){

            l1ref0 += 2;

            l1ref1 += 2;

            l1mv0  +=  2*b4_stride;

            l1mv1  +=  2*b4_stride;







        if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){

            int n=0;

            for(i8=0; i8<4; i8++){

                int x8 = i8&1;

                int y8 = i8>>1;

                int xy8 = x8+y8*b8_stride;

                int xy4 = 3*x8+y8*b4_stride;

                int a,b;



                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))

                    continue;

                h->sub_mb_type[i8] = sub_mb_type;



                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);

                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);

                if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref

                   && (   (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)

                       || (l1ref0[xy8]  < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){

                    a=b=0;

                    if(ref[0] > 0)

                        a= mv[0];

                    if(ref[1] > 0)

                        b= mv[1];

                    n++;

                }else{

                    a= mv[0];

                    b= mv[1];


                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);

                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);


            if(!is_b8x8 && !(n&3))

                *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;

        }else if(IS_16X16(*mb_type)){

            int a,b;



            fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);

            fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);

            if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref

               && (   (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)

                   || (l1ref0[0]  < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1

                       && h->x264_build>33U))){

                a=b=0;

                if(ref[0] > 0)

                    a= mv[0];

                if(ref[1] > 0)

                    b= mv[1];

            }else{

                a= mv[0];

                b= mv[1];


            fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);

            fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);

        }else{

            int n=0;

            for(i8=0; i8<4; i8++){

                const int x8 = i8&1;

                const int y8 = i8>>1;



                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))

                    continue;

                h->sub_mb_type[i8] = sub_mb_type;



                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, mv[0], 4);

                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, mv[1], 4);

                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);

                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);



                assert(b8_stride==2);

                /* col_zero_flag */

                if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && (   l1ref0[i8] == 0

                                              || (l1ref0[i8] < 0 && l1ref1[i8] == 0

                                                  && h->x264_build>33U))){

                    const int16_t (*l1mv)[2]= l1ref0[i8] == 0 ? l1mv0 : l1mv1;

                    if(IS_SUB_8X8(sub_mb_type)){

                        const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];

                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){

                            if(ref[0] == 0)

                                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);

                            if(ref[1] == 0)

                                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);

                            n+=4;


                    }else{

                        int m=0;

                    for(i4=0; i4<4; i4++){

                        const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];

                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){

                            if(ref[0] == 0)

                                AV_ZERO32(h->mv_cache[0][scan8[i8*4+i4]]);

                            if(ref[1] == 0)

                                AV_ZERO32(h->mv_cache[1][scan8[i8*4+i4]]);

                            m++;



                    if(!(m&3))

                        h->sub_mb_type[i8]+= MB_TYPE_16x16 - MB_TYPE_8x8;

                    n+=m;




            if(!is_b8x8 && !(n&15))

                *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;


static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){

    MpegEncContext * const s = &h->s;

    int b8_stride = 2;

    int b4_stride = h->b_stride;

    int mb_xy = h->mb_xy, mb_y = s->mb_y;

    int mb_type_col[2];

    const int16_t (*l1mv0)[2], (*l1mv1)[2];

    const int8_t *l1ref0, *l1ref1;

    const int is_b8x8 = IS_8X8(*mb_type);

    unsigned int sub_mb_type= MB_TYPE_L0L1;

    int i8, i4;

    int ref[2];

    int mv[2];

    int list;



    assert(h->ref_list[1][0].f.reference & 3);



    await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));



#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)





    

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

        int left_ref = h->ref_cache[list][scan8[0] - 1];

        int top_ref  = h->ref_cache[list][scan8[0] - 8];

        int refc = h->ref_cache[list][scan8[0] - 8 + 4];

        const int16_t *C= h->mv_cache[list][ scan8[0] - 8 + 4];

        if(refc == PART_NOT_AVAILABLE){

            refc = h->ref_cache[list][scan8[0] - 8 - 1];

            C    = h-> mv_cache[list][scan8[0] - 8 - 1];


        ref[list] = FFMIN3((unsigned)left_ref, (unsigned)top_ref, (unsigned)refc);

        if(ref[list] >= 0){

            

            const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ];

            const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];



            int match_count= (left_ref==ref[list]) + (top_ref==ref[list]) + (refc==ref[list]);

            if(match_count > 1){ 

                mv[list]= pack16to32(mid_pred(A[0], B[0], C[0]),

                                     mid_pred(A[1], B[1], C[1]) );

            }else {

                assert(match_count==1);

                if(left_ref==ref[list]){

                    mv[list]= AV_RN32A(A);

                }else if(top_ref==ref[list]){

                    mv[list]= AV_RN32A(B);

                }else{

                    mv[list]= AV_RN32A(C);



        }else{

            int mask= ~(MB_TYPE_L0 << (2*list));

            mv[list] = 0;

            ref[list] = -1;

            if(!is_b8x8)

                *mb_type &= mask;

            sub_mb_type &= mask;



    if(ref[0] < 0 && ref[1] < 0){

        ref[0] = ref[1] = 0;

        if(!is_b8x8)

            *mb_type |= MB_TYPE_L0L1;

        sub_mb_type |= MB_TYPE_L0L1;




    if(!(is_b8x8|mv[0]|mv[1])){

        fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);

        fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);

        fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);

        fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);

        *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;

        return;




    if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { 

        if (!IS_INTERLACED(*mb_type)) {                          

            mb_y = (s->mb_y&~1) + h->col_parity;

            mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;

            b8_stride = 0;

        }else{

            mb_y  += h->col_fieldoff;

            mb_xy += s->mb_stride*h->col_fieldoff; 


        goto single_col;

    }else{                                               

        if(IS_INTERLACED(*mb_type)){                     

            mb_y = s->mb_y&~1;

            mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;

            mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy];

            mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride];

            b8_stride = 2+4*s->mb_stride;

            b4_stride *= 6;







            sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; 

            if(    (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)

                && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)

                && !is_b8x8){

                *mb_type   |= MB_TYPE_16x8 |MB_TYPE_DIRECT2; 

            }else{

                *mb_type   |= MB_TYPE_8x8;


        }else{                                           

single_col:

            mb_type_col[0] =

            mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy];



            sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; 

            if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){

                *mb_type   |= MB_TYPE_16x16|MB_TYPE_DIRECT2; 

            }else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){

                *mb_type   |= MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16));

            }else{

                if(!h->sps.direct_8x8_inference_flag){

                    



                    sub_mb_type += (MB_TYPE_8x8-MB_TYPE_16x16); 


                *mb_type   |= MB_TYPE_8x8;






    await_reference_mb_row(h, &h->ref_list[1][0], mb_y);



    l1mv0  = &h->ref_list[1][0].f.motion_val[0][h->mb2b_xy [mb_xy]];

    l1mv1  = &h->ref_list[1][0].f.motion_val[1][h->mb2b_xy [mb_xy]];

    l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy];

    l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy];

    if(!b8_stride){

        if(s->mb_y&1){

            l1ref0 += 2;

            l1ref1 += 2;

            l1mv0  +=  2*b4_stride;

            l1mv1  +=  2*b4_stride;







        if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){

            int n=0;

            for(i8=0; i8<4; i8++){

                int x8 = i8&1;

                int y8 = i8>>1;

                int xy8 = x8+y8*b8_stride;

                int xy4 = 3*x8+y8*b4_stride;

                int a,b;



                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))

                    continue;

                h->sub_mb_type[i8] = sub_mb_type;



                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);

                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);

                if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref

                   && (   (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)

                       || (l1ref0[xy8]  < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){

                    a=b=0;

                    if(ref[0] > 0)

                        a= mv[0];

                    if(ref[1] > 0)

                        b= mv[1];

                    n++;

                }else{

                    a= mv[0];

                    b= mv[1];


                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);

                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);


            if(!is_b8x8 && !(n&3))

                *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;

        }else if(IS_16X16(*mb_type)){

            int a,b;



            fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);

            fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);

            if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref

               && (   (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)

                   || (l1ref0[0]  < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1

                       && h->x264_build>33U))){

                a=b=0;

                if(ref[0] > 0)

                    a= mv[0];

                if(ref[1] > 0)

                    b= mv[1];

            }else{

                a= mv[0];

                b= mv[1];


            fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);

            fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);

        }else{

            int n=0;

            for(i8=0; i8<4; i8++){

                const int x8 = i8&1;

                const int y8 = i8>>1;



                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))

                    continue;

                h->sub_mb_type[i8] = sub_mb_type;



                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, mv[0], 4);

                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, mv[1], 4);

                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);

                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);



                assert(b8_stride==2);

                

                if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && (   l1ref0[i8] == 0

                                              || (l1ref0[i8] < 0 && l1ref1[i8] == 0

                                                  && h->x264_build>33U))){

                    const int16_t (*l1mv)[2]= l1ref0[i8] == 0 ? l1mv0 : l1mv1;

                    if(IS_SUB_8X8(sub_mb_type)){

                        const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];

                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){

                            if(ref[0] == 0)

                                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);

                            if(ref[1] == 0)

                                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);

                            n+=4;


                    }else{

                        int m=0;

                    for(i4=0; i4<4; i4++){

                        const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];

                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){

                            if(ref[0] == 0)

                                AV_ZERO32(h->mv_cache[0][scan8[i8*4+i4]]);

                            if(ref[1] == 0)

                                AV_ZERO32(h->mv_cache[1][scan8[i8*4+i4]]);

                            m++;



                    if(!(m&3))

                        h->sub_mb_type[i8]+= MB_TYPE_16x16 - MB_TYPE_8x8;

                    n+=m;




            if(!is_b8x8 && !(n&15))

                *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;


static void FUNC_0(H264Context * const VAR_0, int *VAR_1){

    MpegEncContext * const s = &VAR_0->s;

    int VAR_2 = 2;

    int VAR_3 = VAR_0->b_stride;

    int VAR_4 = VAR_0->VAR_4, VAR_5 = s->VAR_5;

    int VAR_6[2];

    const FUNC_1 (*l1mv0)[2], (*l1mv1)[2];

    const int8_t *VAR_7, *l1ref1;

    const int VAR_8 = IS_8X8(*VAR_1);

    unsigned int VAR_9= MB_TYPE_L0L1;

    int VAR_10, VAR_11;

    int VAR_12[2];

    int VAR_13[2];

    int VAR_14;



    assert(VAR_0->ref_list[1][0].f.reference & 3);



    await_reference_mb_row(VAR_0, &VAR_0->ref_list[1][0], s->VAR_5 + !!IS_INTERLACED(*VAR_1));



#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)





    

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

        int VAR_15 = VAR_0->ref_cache[VAR_14][scan8[0] - 1];

        int VAR_16  = VAR_0->ref_cache[VAR_14][scan8[0] - 8];

        int VAR_17 = VAR_0->ref_cache[VAR_14][scan8[0] - 8 + 4];

        const FUNC_1 *VAR_18= VAR_0->mv_cache[VAR_14][ scan8[0] - 8 + 4];

        if(VAR_17 == PART_NOT_AVAILABLE){

            VAR_17 = VAR_0->ref_cache[VAR_14][scan8[0] - 8 - 1];

            VAR_18    = VAR_0-> mv_cache[VAR_14][scan8[0] - 8 - 1];


        VAR_12[VAR_14] = FFMIN3((unsigned)VAR_15, (unsigned)VAR_16, (unsigned)VAR_17);

        if(VAR_12[VAR_14] >= 0){

            

            const FUNC_1 * const VAR_19= VAR_0->mv_cache[VAR_14][ scan8[0] - 1 ];

            const FUNC_1 * const VAR_20= VAR_0->mv_cache[VAR_14][ scan8[0] - 8 ];



            int VAR_21= (VAR_15==VAR_12[VAR_14]) + (VAR_16==VAR_12[VAR_14]) + (VAR_17==VAR_12[VAR_14]);

            if(VAR_21 > 1){ 

                VAR_13[VAR_14]= pack16to32(mid_pred(VAR_19[0], VAR_20[0], VAR_18[0]),

                                     mid_pred(VAR_19[1], VAR_20[1], VAR_18[1]) );

            }else {

                assert(VAR_21==1);

                if(VAR_15==VAR_12[VAR_14]){

                    VAR_13[VAR_14]= AV_RN32A(VAR_19);

                }else if(VAR_16==VAR_12[VAR_14]){

                    VAR_13[VAR_14]= AV_RN32A(VAR_20);

                }else{

                    VAR_13[VAR_14]= AV_RN32A(VAR_18);



        }else{

            int mask= ~(MB_TYPE_L0 << (2*VAR_14));

            VAR_13[VAR_14] = 0;

            VAR_12[VAR_14] = -1;

            if(!VAR_8)

                *VAR_1 &= mask;

            VAR_9 &= mask;



    if(VAR_12[0] < 0 && VAR_12[1] < 0){

        VAR_12[0] = VAR_12[1] = 0;

        if(!VAR_8)

            *VAR_1 |= MB_TYPE_L0L1;

        VAR_9 |= MB_TYPE_L0L1;




    if(!(VAR_8|VAR_13[0]|VAR_13[1])){

        fill_rectangle(&VAR_0->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)VAR_12[0], 1);

        fill_rectangle(&VAR_0->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)VAR_12[1], 1);

        fill_rectangle(&VAR_0->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);

        fill_rectangle(&VAR_0->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);

        *VAR_1= (*VAR_1 & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;

        return;




    if (IS_INTERLACED(VAR_0->ref_list[1][0].f.VAR_1[VAR_4])) { 

        if (!IS_INTERLACED(*VAR_1)) {                          

            VAR_5 = (s->VAR_5&~1) + VAR_0->col_parity;

            VAR_4= s->mb_x + ((s->VAR_5&~1) + VAR_0->col_parity)*s->mb_stride;

            VAR_2 = 0;

        }else{

            VAR_5  += VAR_0->col_fieldoff;

            VAR_4 += s->mb_stride*VAR_0->col_fieldoff; 


        goto single_col;

    }else{                                               

        if(IS_INTERLACED(*VAR_1)){                     

            VAR_5 = s->VAR_5&~1;

            VAR_4= s->mb_x + (s->VAR_5&~1)*s->mb_stride;

            VAR_6[0] = VAR_0->ref_list[1][0].f.VAR_1[VAR_4];

            VAR_6[1] = VAR_0->ref_list[1][0].f.VAR_1[VAR_4 + s->mb_stride];

            VAR_2 = 2+4*s->mb_stride;

            VAR_3 *= 6;







            VAR_9 |= MB_TYPE_16x16|MB_TYPE_DIRECT2; 

            if(    (VAR_6[0] & MB_TYPE_16x16_OR_INTRA)

                && (VAR_6[1] & MB_TYPE_16x16_OR_INTRA)

                && !VAR_8){

                *VAR_1   |= MB_TYPE_16x8 |MB_TYPE_DIRECT2; 

            }else{

                *VAR_1   |= MB_TYPE_8x8;


        }else{                                           

single_col:

            VAR_6[0] =

            VAR_6[1] = VAR_0->ref_list[1][0].f.VAR_1[VAR_4];



            VAR_9 |= MB_TYPE_16x16|MB_TYPE_DIRECT2; 

            if(!VAR_8 && (VAR_6[0] & MB_TYPE_16x16_OR_INTRA)){

                *VAR_1   |= MB_TYPE_16x16|MB_TYPE_DIRECT2; 

            }else if(!VAR_8 && (VAR_6[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){

                *VAR_1   |= MB_TYPE_DIRECT2 | (VAR_6[0] & (MB_TYPE_16x8|MB_TYPE_8x16));

            }else{

                if(!VAR_0->sps.direct_8x8_inference_flag){

                    



                    VAR_9 += (MB_TYPE_8x8-MB_TYPE_16x16); 


                *VAR_1   |= MB_TYPE_8x8;






    await_reference_mb_row(VAR_0, &VAR_0->ref_list[1][0], VAR_5);



    l1mv0  = &VAR_0->ref_list[1][0].f.motion_val[0][VAR_0->mb2b_xy [VAR_4]];

    l1mv1  = &VAR_0->ref_list[1][0].f.motion_val[1][VAR_0->mb2b_xy [VAR_4]];

    VAR_7 = &VAR_0->ref_list[1][0].f.ref_index [0][4 * VAR_4];

    l1ref1 = &VAR_0->ref_list[1][0].f.ref_index [1][4 * VAR_4];

    if(!VAR_2){

        if(s->VAR_5&1){

            VAR_7 += 2;

            l1ref1 += 2;

            l1mv0  +=  2*VAR_3;

            l1mv1  +=  2*VAR_3;







        if(IS_INTERLACED(*VAR_1) != IS_INTERLACED(VAR_6[0])){

            int n=0;

            for(VAR_10=0; VAR_10<4; VAR_10++){

                int x8 = VAR_10&1;

                int y8 = VAR_10>>1;

                int xy8 = x8+y8*VAR_2;

                int xy4 = 3*x8+y8*VAR_3;

                int a,b;



                if(VAR_8 && !IS_DIRECT(VAR_0->VAR_9[VAR_10]))

                    continue;

                VAR_0->VAR_9[VAR_10] = VAR_9;



                fill_rectangle(&VAR_0->ref_cache[0][scan8[VAR_10*4]], 2, 2, 8, (uint8_t)VAR_12[0], 1);

                fill_rectangle(&VAR_0->ref_cache[1][scan8[VAR_10*4]], 2, 2, 8, (uint8_t)VAR_12[1], 1);

                if(!IS_INTRA(VAR_6[y8]) && !VAR_0->ref_list[1][0].long_ref

                   && (   (VAR_7[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)

                       || (VAR_7[xy8]  < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){

                    a=b=0;

                    if(VAR_12[0] > 0)

                        a= VAR_13[0];

                    if(VAR_12[1] > 0)

                        b= VAR_13[1];

                    n++;

                }else{

                    a= VAR_13[0];

                    b= VAR_13[1];


                fill_rectangle(&VAR_0->mv_cache[0][scan8[VAR_10*4]], 2, 2, 8, a, 4);

                fill_rectangle(&VAR_0->mv_cache[1][scan8[VAR_10*4]], 2, 2, 8, b, 4);


            if(!VAR_8 && !(n&3))

                *VAR_1= (*VAR_1 & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;

        }else if(IS_16X16(*VAR_1)){

            int a,b;



            fill_rectangle(&VAR_0->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)VAR_12[0], 1);

            fill_rectangle(&VAR_0->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)VAR_12[1], 1);

            if(!IS_INTRA(VAR_6[0]) && !VAR_0->ref_list[1][0].long_ref

               && (   (VAR_7[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)

                   || (VAR_7[0]  < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1

                       && VAR_0->x264_build>33U))){

                a=b=0;

                if(VAR_12[0] > 0)

                    a= VAR_13[0];

                if(VAR_12[1] > 0)

                    b= VAR_13[1];

            }else{

                a= VAR_13[0];

                b= VAR_13[1];


            fill_rectangle(&VAR_0->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);

            fill_rectangle(&VAR_0->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);

        }else{

            int n=0;

            for(VAR_10=0; VAR_10<4; VAR_10++){

                const int x8 = VAR_10&1;

                const int y8 = VAR_10>>1;



                if(VAR_8 && !IS_DIRECT(VAR_0->VAR_9[VAR_10]))

                    continue;

                VAR_0->VAR_9[VAR_10] = VAR_9;



                fill_rectangle(&VAR_0->mv_cache[0][scan8[VAR_10*4]], 2, 2, 8, VAR_13[0], 4);

                fill_rectangle(&VAR_0->mv_cache[1][scan8[VAR_10*4]], 2, 2, 8, VAR_13[1], 4);

                fill_rectangle(&VAR_0->ref_cache[0][scan8[VAR_10*4]], 2, 2, 8, (uint8_t)VAR_12[0], 1);

                fill_rectangle(&VAR_0->ref_cache[1][scan8[VAR_10*4]], 2, 2, 8, (uint8_t)VAR_12[1], 1);



                assert(VAR_2==2);

                

                if(!IS_INTRA(VAR_6[0]) && !VAR_0->ref_list[1][0].long_ref && (   VAR_7[VAR_10] == 0

                                              || (VAR_7[VAR_10] < 0 && l1ref1[VAR_10] == 0

                                                  && VAR_0->x264_build>33U))){

                    const FUNC_1 (*l1mv)[2]= VAR_7[VAR_10] == 0 ? l1mv0 : l1mv1;

                    if(IS_SUB_8X8(VAR_9)){

                        const FUNC_1 *mv_col = l1mv[x8*3 + y8*3*VAR_3];

                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){

                            if(VAR_12[0] == 0)

                                fill_rectangle(&VAR_0->mv_cache[0][scan8[VAR_10*4]], 2, 2, 8, 0, 4);

                            if(VAR_12[1] == 0)

                                fill_rectangle(&VAR_0->mv_cache[1][scan8[VAR_10*4]], 2, 2, 8, 0, 4);

                            n+=4;


                    }else{

                        int m=0;

                    for(VAR_11=0; VAR_11<4; VAR_11++){

                        const FUNC_1 *mv_col = l1mv[x8*2 + (VAR_11&1) + (y8*2 + (VAR_11>>1))*VAR_3];

                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){

                            if(VAR_12[0] == 0)

                                AV_ZERO32(VAR_0->mv_cache[0][scan8[VAR_10*4+VAR_11]]);

                            if(VAR_12[1] == 0)

                                AV_ZERO32(VAR_0->mv_cache[1][scan8[VAR_10*4+VAR_11]]);

                            m++;



                    if(!(m&3))

                        VAR_0->VAR_9[VAR_10]+= MB_TYPE_16x16 - MB_TYPE_8x8;

                    n+=m;




            if(!VAR_8 && !(n&15))

                *VAR_1= (*VAR_1 & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;


static void FUNC_0(H264Context * const VAR_0, int *VAR_1){ MpegEncContext * const s = &VAR_0->s; int VAR_2 = 2; int VAR_3 = VAR_0->b_stride; int VAR_4 = VAR_0->VAR_4, VAR_5 = s->VAR_5; int VAR_6[2]; const FUNC_1 (*l1mv0)[2], (*l1mv1)[2]; const int8_t *VAR_7, *l1ref1; const int VAR_8 = IS_8X8(*VAR_1); unsigned int VAR_9= MB_TYPE_L0L1; int VAR_10, VAR_11; int VAR_12[2]; int VAR_13[2]; int VAR_14; assert(VAR_0->ref_list[1][0].f.reference & 3); await_reference_mb_row(VAR_0, &VAR_0->ref_list[1][0], s->VAR_5 + !!IS_INTERLACED(*VAR_1)); #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
for(VAR_14=0; VAR_14<2; VAR_14++){ int VAR_15 = VAR_0->ref_cache[VAR_14][scan8[0] - 1]; int VAR_16  = VAR_0->ref_cache[VAR_14][scan8[0] - 8]; int VAR_17 = VAR_0->ref_cache[VAR_14][scan8[0] - 8 + 4]; const FUNC_1 *VAR_18= VAR_0->mv_cache[VAR_14][ scan8[0] - 8 + 4]; if(VAR_17 == PART_NOT_AVAILABLE){ VAR_17 = VAR_0->ref_cache[VAR_14][scan8[0] - 8 - 1]; VAR_18    = VAR_0-> mv_cache[VAR_14][scan8[0] - 8 - 1]; VAR_12[VAR_14] = FFMIN3((unsigned)VAR_15, (unsigned)VAR_16, (unsigned)VAR_17); if(VAR_12[VAR_14] >= 0){ const FUNC_1 * const VAR_19= VAR_0->mv_cache[VAR_14][ scan8[0] - 1 ]; const FUNC_1 * const VAR_20= VAR_0->mv_cache[VAR_14][ scan8[0] - 8 ]; int VAR_21= (VAR_15==VAR_12[VAR_14]) + (VAR_16==VAR_12[VAR_14]) + (VAR_17==VAR_12[VAR_14]); if(VAR_21 > 1){ VAR_13[VAR_14]= pack16to32(mid_pred(VAR_19[0], VAR_20[0], VAR_18[0]),
mid_pred(VAR_19[1], VAR_20[1], VAR_18[1]) ); }else { assert(VAR_21==1); if(VAR_15==VAR_12[VAR_14]){ VAR_13[VAR_14]= AV_RN32A(VAR_19); }else if(VAR_16==VAR_12[VAR_14]){ VAR_13[VAR_14]= AV_RN32A(VAR_20); }else{ VAR_13[VAR_14]= AV_RN32A(VAR_18); }else{ int mask= ~(MB_TYPE_L0 << (2*VAR_14)); VAR_13[VAR_14] = 0; VAR_12[VAR_14] = -1; if(!VAR_8)
*VAR_1 &= mask; VAR_9 &= mask; if(VAR_12[0] < 0 && VAR_12[1] < 0){ VAR_12[0] = VAR_12[1] = 0; if(!VAR_8)
*VAR_1 |= MB_TYPE_L0L1; VAR_9 |= MB_TYPE_L0L1; if(!(VAR_8|VAR_13[0]|VAR_13[1])){ fill_rectangle(&VAR_0->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)VAR_12[0], 1); fill_rectangle(&VAR_0->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)VAR_12[1], 1); fill_rectangle(&VAR_0->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); fill_rectangle(&VAR_0->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); *VAR_1= (*VAR_1 & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2; return; if (IS_INTERLACED(VAR_0->ref_list[1][0].f.VAR_1[VAR_4])) { if (!IS_INTERLACED(*VAR_1)) { VAR_5 = (s->VAR_5&~1) + VAR_0->col_parity; VAR_4= s->mb_x + ((s->VAR_5&~1) + VAR_0->col_parity)*s->mb_stride; VAR_2 = 0; }else{ VAR_5  += VAR_0->col_fieldoff; VAR_4 += s->mb_stride*VAR_0->col_fieldoff; goto single_col; }else{ if(IS_INTERLACED(*VAR_1)){ VAR_5 = s->VAR_5&~1; VAR_4= s->mb_x + (s->VAR_5&~1)*s->mb_stride; VAR_6[0] = VAR_0->ref_list[1][0].f.VAR_1[VAR_4]; VAR_6[1] = VAR_0->ref_list[1][0].f.VAR_1[VAR_4 + s->mb_stride]; VAR_2 = 2+4*s->mb_stride; VAR_3 *= 6; VAR_9 |= MB_TYPE_16x16|MB_TYPE_DIRECT2; if(    (VAR_6[0] & MB_TYPE_16x16_OR_INTRA)
&& (VAR_6[1] & MB_TYPE_16x16_OR_INTRA)
&& !VAR_8){ *VAR_1   |= MB_TYPE_16x8 |MB_TYPE_DIRECT2; }else{ *VAR_1   |= MB_TYPE_8x8; }else{ single_col:
VAR_6[0] =
VAR_6[1] = VAR_0->ref_list[1][0].f.VAR_1[VAR_4]; VAR_9 |= MB_TYPE_16x16|MB_TYPE_DIRECT2; if(!VAR_8 && (VAR_6[0] & MB_TYPE_16x16_OR_INTRA)){ *VAR_1   |= MB_TYPE_16x16|MB_TYPE_DIRECT2; }else if(!VAR_8 && (VAR_6[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){ *VAR_1   |= MB_TYPE_DIRECT2 | (VAR_6[0] & (MB_TYPE_16x8|MB_TYPE_8x16)); }else{ if(!VAR_0->sps.direct_8x8_inference_flag){ VAR_9 += (MB_TYPE_8x8-MB_TYPE_16x16); *VAR_1   |= MB_TYPE_8x8; await_reference_mb_row(VAR_0, &VAR_0->ref_list[1][0], VAR_5); l1mv0  = &VAR_0->ref_list[1][0].f.motion_val[0][VAR_0->mb2b_xy [VAR_4]]; l1mv1  = &VAR_0->ref_list[1][0].f.motion_val[1][VAR_0->mb2b_xy [VAR_4]]; VAR_7 = &VAR_0->ref_list[1][0].f.ref_index [0][4 * VAR_4]; l1ref1 = &VAR_0->ref_list[1][0].f.ref_index [1][4 * VAR_4]; if(!VAR_2){ if(s->VAR_5&1){ VAR_7 += 2; l1ref1 += 2; l1mv0  +=  2*VAR_3; l1mv1  +=  2*VAR_3; if(IS_INTERLACED(*VAR_1) != IS_INTERLACED(VAR_6[0])){ int n=0; for(VAR_10=0; VAR_10<4; VAR_10++){ int x8 = VAR_10&1; int y8 = VAR_10>>1; int xy8 = x8+y8*VAR_2; int xy4 = 3*x8+y8*VAR_3; int a,b; if(VAR_8 && !IS_DIRECT(VAR_0->VAR_9[VAR_10]))
continue; VAR_0->VAR_9[VAR_10] = VAR_9; fill_rectangle(&VAR_0->ref_cache[0][scan8[VAR_10*4]], 2, 2, 8, (uint8_t)VAR_12[0], 1); fill_rectangle(&VAR_0->ref_cache[1][scan8[VAR_10*4]], 2, 2, 8, (uint8_t)VAR_12[1], 1); if(!IS_INTRA(VAR_6[y8]) && !VAR_0->ref_list[1][0].long_ref
&& (   (VAR_7[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)
|| (VAR_7[xy8]  < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){ a=b=0; if(VAR_12[0] > 0)
a= VAR_13[0]; if(VAR_12[1] > 0)
b= VAR_13[1]; n++; }else{ a= VAR_13[0]; b= VAR_13[1]; fill_rectangle(&VAR_0->mv_cache[0][scan8[VAR_10*4]], 2, 2, 8, a, 4); fill_rectangle(&VAR_0->mv_cache[1][scan8[VAR_10*4]], 2, 2, 8, b, 4); if(!VAR_8 && !(n&3))
*VAR_1= (*VAR_1 & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2; }else if(IS_16X16(*VAR_1)){ int a,b; fill_rectangle(&VAR_0->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)VAR_12[0], 1); fill_rectangle(&VAR_0->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)VAR_12[1], 1); if(!IS_INTRA(VAR_6[0]) && !VAR_0->ref_list[1][0].long_ref
&& (   (VAR_7[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
|| (VAR_7[0]  < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
&& VAR_0->x264_build>33U))){ a=b=0; if(VAR_12[0] > 0)
a= VAR_13[0]; if(VAR_12[1] > 0)
b= VAR_13[1]; }else{ a= VAR_13[0]; b= VAR_13[1]; fill_rectangle(&VAR_0->mv_cache[0][scan8[0]], 4, 4, 8, a, 4); fill_rectangle(&VAR_0->mv_cache[1][scan8[0]], 4, 4, 8, b, 4); }else{ int n=0; for(VAR_10=0; VAR_10<4; VAR_10++){ const int x8 = VAR_10&1; const int y8 = VAR_10>>1; if(VAR_8 && !IS_DIRECT(VAR_0->VAR_9[VAR_10]))
continue; VAR_0->VAR_9[VAR_10] = VAR_9; fill_rectangle(&VAR_0->mv_cache[0][scan8[VAR_10*4]], 2, 2, 8, VAR_13[0], 4); fill_rectangle(&VAR_0->mv_cache[1][scan8[VAR_10*4]], 2, 2, 8, VAR_13[1], 4); fill_rectangle(&VAR_0->ref_cache[0][scan8[VAR_10*4]], 2, 2, 8, (uint8_t)VAR_12[0], 1); fill_rectangle(&VAR_0->ref_cache[1][scan8[VAR_10*4]], 2, 2, 8, (uint8_t)VAR_12[1], 1); assert(VAR_2==2); if(!IS_INTRA(VAR_6[0]) && !VAR_0->ref_list[1][0].long_ref && (   VAR_7[VAR_10] == 0
|| (VAR_7[VAR_10] < 0 && l1ref1[VAR_10] == 0
&& VAR_0->x264_build>33U))){ const FUNC_1 (*l1mv)[2]= VAR_7[VAR_10] == 0 ? l1mv0 : l1mv1; if(IS_SUB_8X8(VAR_9)){ const FUNC_1 *mv_col = l1mv[x8*3 + y8*3*VAR_3]; if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){ if(VAR_12[0] == 0)
fill_rectangle(&VAR_0->mv_cache[0][scan8[VAR_10*4]], 2, 2, 8, 0, 4); if(VAR_12[1] == 0)
fill_rectangle(&VAR_0->mv_cache[1][scan8[VAR_10*4]], 2, 2, 8, 0, 4); n+=4; }else{ int m=0; for(VAR_11=0; VAR_11<4; VAR_11++){ const FUNC_1 *mv_col = l1mv[x8*2 + (VAR_11&1) + (y8*2 + (VAR_11>>1))*VAR_3]; if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){ if(VAR_12[0] == 0)
AV_ZERO32(VAR_0->mv_cache[0][scan8[VAR_10*4+VAR_11]]); if(VAR_12[1] == 0)
AV_ZERO32(VAR_0->mv_cache[1][scan8[VAR_10*4+VAR_11]]); m++; if(!(m&3))
VAR_0->VAR_9[VAR_10]+= MB_TYPE_16x16 - MB_TYPE_8x8; n+=m; if(!VAR_8 && !(n&15))
*VAR_1= (*VAR_1 & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;