static void gmc1_motion(MpegEncContext *s,

                        uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,

                        uint8_t **ref_picture)

{

    uint8_t *ptr;

    int offset, src_x, src_y, linesize, uvlinesize;

    int motion_x, motion_y;

    int emu=0;



    motion_x= s->sprite_offset[0][0];

    motion_y= s->sprite_offset[0][1];

    src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1));

    src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1));

    motion_x<<=(3-s->sprite_warping_accuracy);

    motion_y<<=(3-s->sprite_warping_accuracy);

    src_x = av_clip(src_x, -16, s->width);

    if (src_x == s->width)

        motion_x =0;

    src_y = av_clip(src_y, -16, s->height);

    if (src_y == s->height)

        motion_y =0;



    linesize = s->linesize;

    uvlinesize = s->uvlinesize;



    ptr = ref_picture[0] + (src_y * linesize) + src_x;



    if(s->flags&CODEC_FLAG_EMU_EDGE){

        if(   (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0)

           || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){

            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);

            ptr= s->edge_emu_buffer;

        }

    }



    if((motion_x|motion_y)&7){

        s->dsp.gmc1(dest_y  , ptr  , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);

        s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);

    }else{

        int dxy;



        dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);

        if (s->no_rounding){

            s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);

        }else{

            s->hdsp.put_pixels_tab       [0][dxy](dest_y, ptr, linesize, 16);

        }

    }



    if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;



    motion_x= s->sprite_offset[1][0];

    motion_y= s->sprite_offset[1][1];

    src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1));

    src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1));

    motion_x<<=(3-s->sprite_warping_accuracy);

    motion_y<<=(3-s->sprite_warping_accuracy);

    src_x = av_clip(src_x, -8, s->width>>1);

    if (src_x == s->width>>1)

        motion_x =0;

    src_y = av_clip(src_y, -8, s->height>>1);

    if (src_y == s->height>>1)

        motion_y =0;



    offset = (src_y * uvlinesize) + src_x;

    ptr = ref_picture[1] + offset;

    if(s->flags&CODEC_FLAG_EMU_EDGE){

        if(   (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0)

           || (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){

            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);

            ptr= s->edge_emu_buffer;

            emu=1;

        }

    }

    s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);



    ptr = ref_picture[2] + offset;

    if(emu){

        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);

        ptr= s->edge_emu_buffer;

    }

    s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);



    return;

}

static void gmc1_motion(MpegEncContext *s,

                        uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,

                        uint8_t **ref_picture)

{

    uint8_t *ptr;

    int offset, src_x, src_y, linesize, uvlinesize;

    int motion_x, motion_y;

    int emu=0;



    motion_x= s->sprite_offset[0][0];

    motion_y= s->sprite_offset[0][1];

    src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1));

    src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1));

    motion_x<<=(3-s->sprite_warping_accuracy);

    motion_y<<=(3-s->sprite_warping_accuracy);

    src_x = av_clip(src_x, -16, s->width);

    if (src_x == s->width)

        motion_x =0;

    src_y = av_clip(src_y, -16, s->height);

    if (src_y == s->height)

        motion_y =0;



    linesize = s->linesize;

    uvlinesize = s->uvlinesize;



    ptr = ref_picture[0] + (src_y * linesize) + src_x;



    if(s->flags&CODEC_FLAG_EMU_EDGE){

        if(   (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0)

           || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){

            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);

            ptr= s->edge_emu_buffer;

        }

    }



    if((motion_x|motion_y)&7){

        s->dsp.gmc1(dest_y  , ptr  , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);

        s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);

    }else{

        int dxy;



        dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);

        if (s->no_rounding){

            s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);

        }else{

            s->hdsp.put_pixels_tab       [0][dxy](dest_y, ptr, linesize, 16);

        }

    }



    if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;



    motion_x= s->sprite_offset[1][0];

    motion_y= s->sprite_offset[1][1];

    src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1));

    src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1));

    motion_x<<=(3-s->sprite_warping_accuracy);

    motion_y<<=(3-s->sprite_warping_accuracy);

    src_x = av_clip(src_x, -8, s->width>>1);

    if (src_x == s->width>>1)

        motion_x =0;

    src_y = av_clip(src_y, -8, s->height>>1);

    if (src_y == s->height>>1)

        motion_y =0;



    offset = (src_y * uvlinesize) + src_x;

    ptr = ref_picture[1] + offset;

    if(s->flags&CODEC_FLAG_EMU_EDGE){

        if(   (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0)

           || (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){

            s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);

            ptr= s->edge_emu_buffer;

            emu=1;

        }

    }

    s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);



    ptr = ref_picture[2] + offset;

    if(emu){

        s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);

        ptr= s->edge_emu_buffer;

    }

    s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);



    return;

}

static void FUNC_0(MpegEncContext *VAR_0,

                        uint8_t *VAR_1, uint8_t *VAR_2, uint8_t *VAR_3,

                        uint8_t **VAR_4)

{

    uint8_t *ptr;

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9;

    int VAR_10, VAR_11;

    int VAR_12=0;



    VAR_10= VAR_0->sprite_offset[0][0];

    VAR_11= VAR_0->sprite_offset[0][1];

    VAR_6 = VAR_0->mb_x * 16 + (VAR_10 >> (VAR_0->sprite_warping_accuracy+1));

    VAR_7 = VAR_0->mb_y * 16 + (VAR_11 >> (VAR_0->sprite_warping_accuracy+1));

    VAR_10<<=(3-VAR_0->sprite_warping_accuracy);

    VAR_11<<=(3-VAR_0->sprite_warping_accuracy);

    VAR_6 = av_clip(VAR_6, -16, VAR_0->width);

    if (VAR_6 == VAR_0->width)

        VAR_10 =0;

    VAR_7 = av_clip(VAR_7, -16, VAR_0->height);

    if (VAR_7 == VAR_0->height)

        VAR_11 =0;



    VAR_8 = VAR_0->VAR_8;

    VAR_9 = VAR_0->VAR_9;



    ptr = VAR_4[0] + (VAR_7 * VAR_8) + VAR_6;



    if(VAR_0->flags&CODEC_FLAG_EMU_EDGE){

        if(   (unsigned)VAR_6 >= FFMAX(VAR_0->h_edge_pos - 17, 0)

           || (unsigned)VAR_7 >= FFMAX(VAR_0->v_edge_pos - 17, 0)){

            VAR_0->vdsp.emulated_edge_mc(VAR_0->edge_emu_buffer, ptr, VAR_8, 17, 17, VAR_6, VAR_7, VAR_0->h_edge_pos, VAR_0->v_edge_pos);

            ptr= VAR_0->edge_emu_buffer;

        }

    }



    if((VAR_10|VAR_11)&7){

        VAR_0->dsp.gmc1(VAR_1  , ptr  , VAR_8, 16, VAR_10&15, VAR_11&15, 128 - VAR_0->no_rounding);

        VAR_0->dsp.gmc1(VAR_1+8, ptr+8, VAR_8, 16, VAR_10&15, VAR_11&15, 128 - VAR_0->no_rounding);

    }else{

        int VAR_13;



        VAR_13= ((VAR_10>>3)&1) | ((VAR_11>>2)&2);

        if (VAR_0->no_rounding){

            VAR_0->hdsp.put_no_rnd_pixels_tab[0][VAR_13](VAR_1, ptr, VAR_8, 16);

        }else{

            VAR_0->hdsp.put_pixels_tab       [0][VAR_13](VAR_1, ptr, VAR_8, 16);

        }

    }



    if(CONFIG_GRAY && VAR_0->flags&CODEC_FLAG_GRAY) return;



    VAR_10= VAR_0->sprite_offset[1][0];

    VAR_11= VAR_0->sprite_offset[1][1];

    VAR_6 = VAR_0->mb_x * 8 + (VAR_10 >> (VAR_0->sprite_warping_accuracy+1));

    VAR_7 = VAR_0->mb_y * 8 + (VAR_11 >> (VAR_0->sprite_warping_accuracy+1));

    VAR_10<<=(3-VAR_0->sprite_warping_accuracy);

    VAR_11<<=(3-VAR_0->sprite_warping_accuracy);

    VAR_6 = av_clip(VAR_6, -8, VAR_0->width>>1);

    if (VAR_6 == VAR_0->width>>1)

        VAR_10 =0;

    VAR_7 = av_clip(VAR_7, -8, VAR_0->height>>1);

    if (VAR_7 == VAR_0->height>>1)

        VAR_11 =0;



    VAR_5 = (VAR_7 * VAR_9) + VAR_6;

    ptr = VAR_4[1] + VAR_5;

    if(VAR_0->flags&CODEC_FLAG_EMU_EDGE){

        if(   (unsigned)VAR_6 >= FFMAX((VAR_0->h_edge_pos>>1) - 9, 0)

           || (unsigned)VAR_7 >= FFMAX((VAR_0->v_edge_pos>>1) - 9, 0)){

            VAR_0->vdsp.emulated_edge_mc(VAR_0->edge_emu_buffer, ptr, VAR_9, 9, 9, VAR_6, VAR_7, VAR_0->h_edge_pos>>1, VAR_0->v_edge_pos>>1);

            ptr= VAR_0->edge_emu_buffer;

            VAR_12=1;

        }

    }

    VAR_0->dsp.gmc1(VAR_2, ptr, VAR_9, 8, VAR_10&15, VAR_11&15, 128 - VAR_0->no_rounding);



    ptr = VAR_4[2] + VAR_5;

    if(VAR_12){

        VAR_0->vdsp.emulated_edge_mc(VAR_0->edge_emu_buffer, ptr, VAR_9, 9, 9, VAR_6, VAR_7, VAR_0->h_edge_pos>>1, VAR_0->v_edge_pos>>1);

        ptr= VAR_0->edge_emu_buffer;

    }

    VAR_0->dsp.gmc1(VAR_3, ptr, VAR_9, 8, VAR_10&15, VAR_11&15, 128 - VAR_0->no_rounding);



    return;

}

static void FUNC_0(MpegEncContext *VAR_0,
uint8_t *VAR_1, uint8_t *VAR_2, uint8_t *VAR_3,
uint8_t **VAR_4)
{ uint8_t *ptr; int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9; int VAR_10, VAR_11; int VAR_12=0; VAR_10= VAR_0->sprite_offset[0][0]; VAR_11= VAR_0->sprite_offset[0][1]; VAR_6 = VAR_0->mb_x * 16 + (VAR_10 >> (VAR_0->sprite_warping_accuracy+1)); VAR_7 = VAR_0->mb_y * 16 + (VAR_11 >> (VAR_0->sprite_warping_accuracy+1)); VAR_10<<=(3-VAR_0->sprite_warping_accuracy); VAR_11<<=(3-VAR_0->sprite_warping_accuracy); VAR_6 = av_clip(VAR_6, -16, VAR_0->width); if (VAR_6 == VAR_0->width)
VAR_10 =0; VAR_7 = av_clip(VAR_7, -16, VAR_0->height); if (VAR_7 == VAR_0->height)
VAR_11 =0; VAR_8 = VAR_0->VAR_8; VAR_9 = VAR_0->VAR_9; ptr = VAR_4[0] + (VAR_7 * VAR_8) + VAR_6; if(VAR_0->flags&CODEC_FLAG_EMU_EDGE){ if(   (unsigned)VAR_6 >= FFMAX(VAR_0->h_edge_pos - 17, 0)
|| (unsigned)VAR_7 >= FFMAX(VAR_0->v_edge_pos - 17, 0)){ VAR_0->vdsp.emulated_edge_mc(VAR_0->edge_emu_buffer, ptr, VAR_8, 17, 17, VAR_6, VAR_7, VAR_0->h_edge_pos, VAR_0->v_edge_pos); ptr= VAR_0->edge_emu_buffer; } } if((VAR_10|VAR_11)&7){ VAR_0->dsp.gmc1(VAR_1  , ptr  , VAR_8, 16, VAR_10&15, VAR_11&15, 128 - VAR_0->no_rounding); VAR_0->dsp.gmc1(VAR_1+8, ptr+8, VAR_8, 16, VAR_10&15, VAR_11&15, 128 - VAR_0->no_rounding); }else{ int VAR_13; VAR_13= ((VAR_10>>3)&1) | ((VAR_11>>2)&2); if (VAR_0->no_rounding){ VAR_0->hdsp.put_no_rnd_pixels_tab[0][VAR_13](VAR_1, ptr, VAR_8, 16); }else{ VAR_0->hdsp.put_pixels_tab       [0][VAR_13](VAR_1, ptr, VAR_8, 16); } } if(CONFIG_GRAY && VAR_0->flags&CODEC_FLAG_GRAY) return; VAR_10= VAR_0->sprite_offset[1][0]; VAR_11= VAR_0->sprite_offset[1][1]; VAR_6 = VAR_0->mb_x * 8 + (VAR_10 >> (VAR_0->sprite_warping_accuracy+1)); VAR_7 = VAR_0->mb_y * 8 + (VAR_11 >> (VAR_0->sprite_warping_accuracy+1)); VAR_10<<=(3-VAR_0->sprite_warping_accuracy); VAR_11<<=(3-VAR_0->sprite_warping_accuracy); VAR_6 = av_clip(VAR_6, -8, VAR_0->width>>1); if (VAR_6 == VAR_0->width>>1)
VAR_10 =0; VAR_7 = av_clip(VAR_7, -8, VAR_0->height>>1); if (VAR_7 == VAR_0->height>>1)
VAR_11 =0; VAR_5 = (VAR_7 * VAR_9) + VAR_6; ptr = VAR_4[1] + VAR_5; if(VAR_0->flags&CODEC_FLAG_EMU_EDGE){ if(   (unsigned)VAR_6 >= FFMAX((VAR_0->h_edge_pos>>1) - 9, 0)
|| (unsigned)VAR_7 >= FFMAX((VAR_0->v_edge_pos>>1) - 9, 0)){ VAR_0->vdsp.emulated_edge_mc(VAR_0->edge_emu_buffer, ptr, VAR_9, 9, 9, VAR_6, VAR_7, VAR_0->h_edge_pos>>1, VAR_0->v_edge_pos>>1); ptr= VAR_0->edge_emu_buffer; VAR_12=1; } } VAR_0->dsp.gmc1(VAR_2, ptr, VAR_9, 8, VAR_10&15, VAR_11&15, 128 - VAR_0->no_rounding); ptr = VAR_4[2] + VAR_5; if(VAR_12){ VAR_0->vdsp.emulated_edge_mc(VAR_0->edge_emu_buffer, ptr, VAR_9, 9, 9, VAR_6, VAR_7, VAR_0->h_edge_pos>>1, VAR_0->v_edge_pos>>1); ptr= VAR_0->edge_emu_buffer; } VAR_0->dsp.gmc1(VAR_3, ptr, VAR_9, 8, VAR_10&15, VAR_11&15, 128 - VAR_0->no_rounding); return; }