static void find_block_motion(DeshakeContext *deshake, uint8_t *src1,

                              uint8_t *src2, int cx, int cy, int stride,

                              MotionVector *mv)

{

    int x, y;

    int diff;

    int smallest = INT_MAX;

    int tmp, tmp2;



    #define CMP(i, j) deshake->c.sad[0](deshake, src1 + cy * stride + cx, \

                                        src2 + (j) * stride + (i), stride, \

                                        deshake->blocksize)



    if (deshake->search == EXHAUSTIVE) {

        // Compare every possible position - this is sloooow!

        for (y = -deshake->ry; y <= deshake->ry; y++) {

            for (x = -deshake->rx; x <= deshake->rx; x++) {

                diff = CMP(cx - x, cy - y);

                if (diff < smallest) {

                    smallest = diff;

                    mv->x = x;

                    mv->y = y;

                }

            }

        }

    } else if (deshake->search == SMART_EXHAUSTIVE) {

        // Compare every other possible position and find the best match

        for (y = -deshake->ry + 1; y < deshake->ry - 2; y += 2) {

            for (x = -deshake->rx + 1; x < deshake->rx - 2; x += 2) {

                diff = CMP(cx - x, cy - y);

                if (diff < smallest) {

                    smallest = diff;

                    mv->x = x;

                    mv->y = y;

                }

            }

        }



        // Hone in on the specific best match around the match we found above

        tmp = mv->x;

        tmp2 = mv->y;



        for (y = tmp2 - 1; y <= tmp2 + 1; y++) {

            for (x = tmp - 1; x <= tmp + 1; x++) {

                if (x == tmp && y == tmp2)

                    continue;



                diff = CMP(cx - x, cy - y);

                if (diff < smallest) {

                    smallest = diff;

                    mv->x = x;

                    mv->y = y;

                }

            }

        }

    }



    if (smallest > 512) {

        mv->x = -1;

        mv->y = -1;

    }

    emms_c();

    //av_log(NULL, AV_LOG_ERROR, "%d\n", smallest);

    //av_log(NULL, AV_LOG_ERROR, "Final: (%d, %d) = %d x %d\n", cx, cy, mv->x, mv->y);

}

static void find_block_motion(DeshakeContext *deshake, uint8_t *src1,

                              uint8_t *src2, int cx, int cy, int stride,

                              MotionVector *mv)

{

    int x, y;

    int diff;

    int smallest = INT_MAX;

    int tmp, tmp2;



    #define CMP(i, j) deshake->c.sad[0](deshake, src1 + cy * stride + cx, \

                                        src2 + (j) * stride + (i), stride, \

                                        deshake->blocksize)



    if (deshake->search == EXHAUSTIVE) {

        

        for (y = -deshake->ry; y <= deshake->ry; y++) {

            for (x = -deshake->rx; x <= deshake->rx; x++) {

                diff = CMP(cx - x, cy - y);

                if (diff < smallest) {

                    smallest = diff;

                    mv->x = x;

                    mv->y = y;

                }

            }

        }

    } else if (deshake->search == SMART_EXHAUSTIVE) {

        

        for (y = -deshake->ry + 1; y < deshake->ry - 2; y += 2) {

            for (x = -deshake->rx + 1; x < deshake->rx - 2; x += 2) {

                diff = CMP(cx - x, cy - y);

                if (diff < smallest) {

                    smallest = diff;

                    mv->x = x;

                    mv->y = y;

                }

            }

        }



        

        tmp = mv->x;

        tmp2 = mv->y;



        for (y = tmp2 - 1; y <= tmp2 + 1; y++) {

            for (x = tmp - 1; x <= tmp + 1; x++) {

                if (x == tmp && y == tmp2)

                    continue;



                diff = CMP(cx - x, cy - y);

                if (diff < smallest) {

                    smallest = diff;

                    mv->x = x;

                    mv->y = y;

                }

            }

        }

    }



    if (smallest > 512) {

        mv->x = -1;

        mv->y = -1;

    }

    emms_c();

    

    

}

                              MotionVector *mv)
static void FUNC_0(DeshakeContext *VAR_0, uint8_t *VAR_1,

                              uint8_t *VAR_2, int VAR_3, int VAR_4, int VAR_5,

                              MotionVector *VAR_6)

{

    int VAR_7, VAR_8;

    int VAR_9;

    int VAR_10 = INT_MAX;

    int VAR_11, VAR_12;



    #define CMP(i, j) VAR_0->c.sad[0](VAR_0, VAR_1 + VAR_4 * VAR_5 + VAR_3, \

                                        VAR_2 + (j) * VAR_5 + (i), VAR_5, \

                                        VAR_0->blocksize)



    if (VAR_0->search == EXHAUSTIVE) {

        

        for (VAR_8 = -VAR_0->ry; VAR_8 <= VAR_0->ry; VAR_8++) {

            for (VAR_7 = -VAR_0->rx; VAR_7 <= VAR_0->rx; VAR_7++) {

                VAR_9 = CMP(VAR_3 - VAR_7, VAR_4 - VAR_8);

                if (VAR_9 < VAR_10) {

                    VAR_10 = VAR_9;

                    VAR_6->VAR_7 = VAR_7;

                    VAR_6->VAR_8 = VAR_8;

                }

            }

        }

    } else if (VAR_0->search == SMART_EXHAUSTIVE) {

        

        for (VAR_8 = -VAR_0->ry + 1; VAR_8 < VAR_0->ry - 2; VAR_8 += 2) {

            for (VAR_7 = -VAR_0->rx + 1; VAR_7 < VAR_0->rx - 2; VAR_7 += 2) {

                VAR_9 = CMP(VAR_3 - VAR_7, VAR_4 - VAR_8);

                if (VAR_9 < VAR_10) {

                    VAR_10 = VAR_9;

                    VAR_6->VAR_7 = VAR_7;

                    VAR_6->VAR_8 = VAR_8;

                }

            }

        }



        

        VAR_11 = VAR_6->VAR_7;

        VAR_12 = VAR_6->VAR_8;



        for (VAR_8 = VAR_12 - 1; VAR_8 <= VAR_12 + 1; VAR_8++) {

            for (VAR_7 = VAR_11 - 1; VAR_7 <= VAR_11 + 1; VAR_7++) {

                if (VAR_7 == VAR_11 && VAR_8 == VAR_12)

                    continue;



                VAR_9 = CMP(VAR_3 - VAR_7, VAR_4 - VAR_8);

                if (VAR_9 < VAR_10) {

                    VAR_10 = VAR_9;

                    VAR_6->VAR_7 = VAR_7;

                    VAR_6->VAR_8 = VAR_8;

                }

            }

        }

    }



    if (VAR_10 > 512) {

        VAR_6->VAR_7 = -1;

        VAR_6->VAR_8 = -1;

    }

    emms_c();

    

    

}

static void FUNC_0(DeshakeContext *VAR_0, uint8_t *VAR_1,
uint8_t *VAR_2, int VAR_3, int VAR_4, int VAR_5,
MotionVector *VAR_6)
{ int VAR_7, VAR_8; int VAR_9; int VAR_10 = INT_MAX; int VAR_11, VAR_12; #define CMP(i, j) VAR_0->c.sad[0](VAR_0, VAR_1 + VAR_4 * VAR_5 + VAR_3, \
VAR_2 + (j) * VAR_5 + (i), VAR_5, \
VAR_0->blocksize)
if (VAR_0->search == EXHAUSTIVE) { for (VAR_8 = -VAR_0->ry; VAR_8 <= VAR_0->ry; VAR_8++) { for (VAR_7 = -VAR_0->rx; VAR_7 <= VAR_0->rx; VAR_7++) { VAR_9 = CMP(VAR_3 - VAR_7, VAR_4 - VAR_8); if (VAR_9 < VAR_10) { VAR_10 = VAR_9; VAR_6->VAR_7 = VAR_7; VAR_6->VAR_8 = VAR_8; } } } } else if (VAR_0->search == SMART_EXHAUSTIVE) { for (VAR_8 = -VAR_0->ry + 1; VAR_8 < VAR_0->ry - 2; VAR_8 += 2) { for (VAR_7 = -VAR_0->rx + 1; VAR_7 < VAR_0->rx - 2; VAR_7 += 2) { VAR_9 = CMP(VAR_3 - VAR_7, VAR_4 - VAR_8); if (VAR_9 < VAR_10) { VAR_10 = VAR_9; VAR_6->VAR_7 = VAR_7; VAR_6->VAR_8 = VAR_8; } } } VAR_11 = VAR_6->VAR_7; VAR_12 = VAR_6->VAR_8; for (VAR_8 = VAR_12 - 1; VAR_8 <= VAR_12 + 1; VAR_8++) { for (VAR_7 = VAR_11 - 1; VAR_7 <= VAR_11 + 1; VAR_7++) { if (VAR_7 == VAR_11 && VAR_8 == VAR_12)
continue; VAR_9 = CMP(VAR_3 - VAR_7, VAR_4 - VAR_8); if (VAR_9 < VAR_10) { VAR_10 = VAR_9; VAR_6->VAR_7 = VAR_7; VAR_6->VAR_8 = VAR_8; } } } } if (VAR_10 > 512) { VAR_6->VAR_7 = -1; VAR_6->VAR_8 = -1; } emms_c(); }