void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,

                enum cavs_mv_pred mode, enum cavs_block size, int ref)

{

    cavs_vector *mvP = &h->mv[nP];

    cavs_vector *mvA = &h->mv[nP-1];

    cavs_vector *mvB = &h->mv[nP-4];

    cavs_vector *mvC = &h->mv[nC];

    const cavs_vector *mvP2 = NULL;



    mvP->ref  = ref;

    mvP->dist = h->dist[mvP->ref];

    if (mvC->ref == NOT_AVAIL || (nP == MV_FWD_X3) || (nP == MV_BWD_X3 ))

        mvC = &h->mv[nP - 5];  // set to top-left (mvD)

    if (mode == MV_PRED_PSKIP &&

        (mvA->ref == NOT_AVAIL ||

         mvB->ref == NOT_AVAIL ||

         (mvA->x | mvA->y | mvA->ref) == 0 ||

         (mvB->x | mvB->y | mvB->ref) == 0)) {

        mvP2 = &un_mv;

    /* if there is only one suitable candidate, take it */

    } else if (mvA->ref >= 0 && mvB->ref < 0  && mvC->ref < 0) {

        mvP2 = mvA;

    } else if (mvA->ref < 0  && mvB->ref >= 0 && mvC->ref < 0) {

        mvP2 = mvB;

    } else if (mvA->ref < 0  && mvB->ref < 0  && mvC->ref >= 0) {

        mvP2 = mvC;

    } else if (mode == MV_PRED_LEFT     && mvA->ref == ref) {

        mvP2 = mvA;

    } else if (mode == MV_PRED_TOP      && mvB->ref == ref) {

        mvP2 = mvB;

    } else if (mode == MV_PRED_TOPRIGHT && mvC->ref == ref) {

        mvP2 = mvC;

    }

    if (mvP2) {

        mvP->x = mvP2->x;

        mvP->y = mvP2->y;

    } else

        mv_pred_median(h, mvP, mvA, mvB, mvC);



    if (mode < MV_PRED_PSKIP) {

        mvP->x += get_se_golomb(&h->gb);

        mvP->y += get_se_golomb(&h->gb);

    }

    set_mvs(mvP, size);

}

void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,

                enum cavs_mv_pred mode, enum cavs_block size, int ref)

{

    cavs_vector *mvP = &h->mv[nP];

    cavs_vector *mvA = &h->mv[nP-1];

    cavs_vector *mvB = &h->mv[nP-4];

    cavs_vector *mvC = &h->mv[nC];

    const cavs_vector *mvP2 = NULL;



    mvP->ref  = ref;

    mvP->dist = h->dist[mvP->ref];

    if (mvC->ref == NOT_AVAIL || (nP == MV_FWD_X3) || (nP == MV_BWD_X3 ))

        mvC = &h->mv[nP - 5];  

    if (mode == MV_PRED_PSKIP &&

        (mvA->ref == NOT_AVAIL ||

         mvB->ref == NOT_AVAIL ||

         (mvA->x | mvA->y | mvA->ref) == 0 ||

         (mvB->x | mvB->y | mvB->ref) == 0)) {

        mvP2 = &un_mv;

    

    } else if (mvA->ref >= 0 && mvB->ref < 0  && mvC->ref < 0) {

        mvP2 = mvA;

    } else if (mvA->ref < 0  && mvB->ref >= 0 && mvC->ref < 0) {

        mvP2 = mvB;

    } else if (mvA->ref < 0  && mvB->ref < 0  && mvC->ref >= 0) {

        mvP2 = mvC;

    } else if (mode == MV_PRED_LEFT     && mvA->ref == ref) {

        mvP2 = mvA;

    } else if (mode == MV_PRED_TOP      && mvB->ref == ref) {

        mvP2 = mvB;

    } else if (mode == MV_PRED_TOPRIGHT && mvC->ref == ref) {

        mvP2 = mvC;

    }

    if (mvP2) {

        mvP->x = mvP2->x;

        mvP->y = mvP2->y;

    } else

        mv_pred_median(h, mvP, mvA, mvB, mvC);



    if (mode < MV_PRED_PSKIP) {

        mvP->x += get_se_golomb(&h->gb);

        mvP->y += get_se_golomb(&h->gb);

    }

    set_mvs(mvP, size);

}

        mvP->x += get_se_golomb(&h->gb);         mvP->y += get_se_golomb(&h->gb);
void FUNC_0(AVSContext *VAR_0, enum cavs_mv_loc VAR_1, enum cavs_mv_loc VAR_2,

                enum cavs_mv_pred VAR_3, enum cavs_block VAR_4, int VAR_5)

{

    cavs_vector *mvP = &VAR_0->mv[VAR_1];

    cavs_vector *mvA = &VAR_0->mv[VAR_1-1];

    cavs_vector *mvB = &VAR_0->mv[VAR_1-4];

    cavs_vector *mvC = &VAR_0->mv[VAR_2];

    const cavs_vector *VAR_6 = NULL;



    mvP->VAR_5  = VAR_5;

    mvP->dist = VAR_0->dist[mvP->VAR_5];

    if (mvC->VAR_5 == NOT_AVAIL || (VAR_1 == MV_FWD_X3) || (VAR_1 == MV_BWD_X3 ))

        mvC = &VAR_0->mv[VAR_1 - 5];  

    if (VAR_3 == MV_PRED_PSKIP &&

        (mvA->VAR_5 == NOT_AVAIL ||

         mvB->VAR_5 == NOT_AVAIL ||

         (mvA->x | mvA->y | mvA->VAR_5) == 0 ||

         (mvB->x | mvB->y | mvB->VAR_5) == 0)) {

        VAR_6 = &un_mv;

    

    } else if (mvA->VAR_5 >= 0 && mvB->VAR_5 < 0  && mvC->VAR_5 < 0) {

        VAR_6 = mvA;

    } else if (mvA->VAR_5 < 0  && mvB->VAR_5 >= 0 && mvC->VAR_5 < 0) {

        VAR_6 = mvB;

    } else if (mvA->VAR_5 < 0  && mvB->VAR_5 < 0  && mvC->VAR_5 >= 0) {

        VAR_6 = mvC;

    } else if (VAR_3 == MV_PRED_LEFT     && mvA->VAR_5 == VAR_5) {

        VAR_6 = mvA;

    } else if (VAR_3 == MV_PRED_TOP      && mvB->VAR_5 == VAR_5) {

        VAR_6 = mvB;

    } else if (VAR_3 == MV_PRED_TOPRIGHT && mvC->VAR_5 == VAR_5) {

        VAR_6 = mvC;

    }

    if (VAR_6) {

        mvP->x = VAR_6->x;

        mvP->y = VAR_6->y;

    } else

        mv_pred_median(VAR_0, mvP, mvA, mvB, mvC);



    if (VAR_3 < MV_PRED_PSKIP) {

        mvP->x += get_se_golomb(&VAR_0->gb);

        mvP->y += get_se_golomb(&VAR_0->gb);

    }

    set_mvs(mvP, VAR_4);

}

void FUNC_0(AVSContext *VAR_0, enum cavs_mv_loc VAR_1, enum cavs_mv_loc VAR_2,
enum cavs_mv_pred VAR_3, enum cavs_block VAR_4, int VAR_5)
{ cavs_vector *mvP = &VAR_0->mv[VAR_1]; cavs_vector *mvA = &VAR_0->mv[VAR_1-1]; cavs_vector *mvB = &VAR_0->mv[VAR_1-4]; cavs_vector *mvC = &VAR_0->mv[VAR_2]; const cavs_vector *VAR_6 = NULL; mvP->VAR_5  = VAR_5; mvP->dist = VAR_0->dist[mvP->VAR_5]; if (mvC->VAR_5 == NOT_AVAIL || (VAR_1 == MV_FWD_X3) || (VAR_1 == MV_BWD_X3 ))
mvC = &VAR_0->mv[VAR_1 - 5]; if (VAR_3 == MV_PRED_PSKIP &&
(mvA->VAR_5 == NOT_AVAIL ||
mvB->VAR_5 == NOT_AVAIL ||
(mvA->x | mvA->y | mvA->VAR_5) == 0 ||
(mvB->x | mvB->y | mvB->VAR_5) == 0)) { VAR_6 = &un_mv; } else if (mvA->VAR_5 >= 0 && mvB->VAR_5 < 0  && mvC->VAR_5 < 0) { VAR_6 = mvA; } else if (mvA->VAR_5 < 0  && mvB->VAR_5 >= 0 && mvC->VAR_5 < 0) { VAR_6 = mvB; } else if (mvA->VAR_5 < 0  && mvB->VAR_5 < 0  && mvC->VAR_5 >= 0) { VAR_6 = mvC; } else if (VAR_3 == MV_PRED_LEFT     && mvA->VAR_5 == VAR_5) { VAR_6 = mvA; } else if (VAR_3 == MV_PRED_TOP      && mvB->VAR_5 == VAR_5) { VAR_6 = mvB; } else if (VAR_3 == MV_PRED_TOPRIGHT && mvC->VAR_5 == VAR_5) { VAR_6 = mvC; } if (VAR_6) { mvP->x = VAR_6->x; mvP->y = VAR_6->y; } else mv_pred_median(VAR_0, mvP, mvA, mvB, mvC); if (VAR_3 < MV_PRED_PSKIP) { mvP->x += get_se_golomb(&VAR_0->gb); mvP->y += get_se_golomb(&VAR_0->gb); } set_mvs(mvP, VAR_4); }