// File: /workspace/github_c_makefile_star2_O0/akumrao[P]videoAnalyzer/encoder/analyse.c
// Function: x264_mb_analyse_inter_p(x264_t*, x264_macroblock_t*, x264_mb_analysis_t*)
static void x264_mb_analyse_inter_p( x264_t *h, x264_macroblock_t *mb, x264_mb_analysis_t *res )
{
    x264_mb_context_t *ctx = mb->context;

    int i_ref;

    /* int res */
    res->i_sad_p16x16 = -1;
    res->i_sad_p16x8  = -1;
    res->i_sad_p8x16  = -1;
    res->i_sad_p8x8   = -1;

    /* 16x16 Search on all ref frame */
    mb->i_type = P_L0;  /* beurk fix that */
    mb->i_partition = D_16x16;
    for( i_ref = 0; i_ref < h->i_ref0; i_ref++ )
    {
        int i_sad;
        int mvp[2];
        int mvx, mvy;

        /* Get the predicted MV */
        x264_mb_partition_set( mb, 0, 0, 0, i_ref, 0, 0 );
        x264_mb_predict_mv( mb, 0, 0, 0, mvp );

        mvx = mvp[0]; mvy = mvp[1];
        i_sad = h->me( h, ctx->p_fref0[i_ref][0], ctx->i_fref0[i_ref][0],
                          ctx->p_img[0],         ctx->i_img[0],
                          PIXEL_16x16, res->i_lambda, &mvx, &mvy );
        if( mvx == mvp[0] && mvy == mvp[1] )
        {
            i_sad -= 16 * res->i_lambda;
        }
        i_sad += res->i_lambda * bs_size_te( h->sh.i_num_ref_idx_l0_active - 1, i_ref );

        if( res->i_sad_p16x16 == -1 || i_sad < res->i_sad_p16x16 )
        {
            res->i_sad_p16x16   = i_sad;
            res->i_ref_p16x16   = i_ref;
            res->i_mv_p16x16[0] = mvx;
            res->i_mv_p16x16[1] = mvy;
        }
    }

    /* Now do the rafinement (using the ref found in 16x16 mode) */
    i_ref = res->i_ref_p16x16;
    x264_mb_partition_set( mb, 0, 0, 0, i_ref, 0, 0 );

    /* try 16x8 */
    /* XXX we test i_predict16x16 to try shape with the same direction than edge
     * We should do a better algo of course (the one with edge dectection to be used
     * for intra mode too)
     * */

    if( res->i_predict16x16 != I_PRED_16x16_V )
    {
        int mvp[2][2];

        mb->i_partition = D_16x8;

        res->i_ref_p16x8   = i_ref;
        x264_mb_predict_mv( mb, 0, 0, 0, mvp[0] );
        x264_mb_predict_mv( mb, 0, 1, 0, mvp[1] );

        res->i_mv_p16x8[0][0] = mvp[0][0]; res->i_mv_p16x8[0][1] = mvp[0][1];
        res->i_mv_p16x8[1][0] = mvp[1][0]; res->i_mv_p16x8[1][1] = mvp[1][1];

        res->i_sad_p16x8 = h->me( h,
                                  ctx->p_fref0[i_ref][0], ctx->i_fref0[i_ref][0],
                                  ctx->p_img[0],          ctx->i_img[0],
                                  PIXEL_16x8,
                                  res->i_lambda,
                                  &res->i_mv_p16x8[0][0], &res->i_mv_p16x8[0][1] ) +
                           h->me( h,
                                  &ctx->p_fref0[i_ref][0][8*ctx->i_fref0[i_ref][0]], ctx->i_fref0[i_ref][0],
                                  &ctx->p_img[0][8*ctx->i_img[0]],                   ctx->i_img[0],
                                  PIXEL_16x8,
                                  res->i_lambda,
                                  &res->i_mv_p16x8[1][0], &res->i_mv_p16x8[1][1] );

        res->i_sad_p16x8 += 2*res->i_lambda * bs_size_te( h->sh.i_num_ref_idx_l0_active - 1, i_ref );
    }

    /* try 8x16 */
    if( res->i_predict16x16 != I_PRED_16x16_H )
    {
        int mvp[2][2];

        mb->i_partition = D_8x16;

        res->i_ref_p8x16   = i_ref;
        x264_mb_predict_mv( mb, 0, 0, 0, mvp[0] );
        x264_mb_predict_mv( mb, 0, 1, 0, mvp[1] );

        res->i_mv_p8x16[0][0] = mvp[0][0]; res->i_mv_p8x16[0][1] = mvp[0][1];
        res->i_mv_p8x16[1][0] = mvp[1][0]; res->i_mv_p8x16[1][1] = mvp[1][1];

        res->i_sad_p8x16 = h->me( h,
                                  ctx->p_fref0[i_ref][0], ctx->i_fref0[i_ref][0],
                                  ctx->p_img[0],          ctx->i_img[0],
                                  PIXEL_8x16,
                                  res->i_lambda,
                                  &res->i_mv_p8x16[0][0], &res->i_mv_p8x16[0][1] ) +
                           h->me( h,
                                  &ctx->p_fref0[i_ref][0][8], ctx->i_fref0[i_ref][0],
                                  &ctx->p_img[0][8],          ctx->i_img[0],
                                  PIXEL_8x16,
                                  res->i_lambda,
                                  &res->i_mv_p8x16[1][0], &res->i_mv_p8x16[1][1] );

        res->i_sad_p8x16 += 2*res->i_lambda * bs_size_te( h->sh.i_num_ref_idx_l0_active - 1, i_ref );
    }

    /* a bit heuristique : if 4x4 is prefered, the block is probably not homegenous
     * for now disabled because too slow for too few bits saved */
    if( res->i_sad_i4x4 < res->i_sad_i16x16 )
    {
        x264_mb_analyse_inter_p_p8x8( h,mb, res );
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x88, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x5c(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x6c(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x84(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x9c(%rax) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movl $0x3, 0x18(%rax)
movq -0x18(%rbp), %rax
movl $0x10, 0x1c(%rax)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10f078(%rcx), %eax
jge 0x161d1
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %r8d
xorl %r9d, %r9d
movl %r9d, %esi
movl %r9d, %edx
movl %r9d, %ecx
movl $0x0, (%rsp)
callq 0x7a80
movq -0x18(%rbp), %rdi
leaq -0x38(%rbp), %r8
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x7ff0
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x10f390(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
addq $0x68, %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rsi
movq -0x28(%rbp), %rcx
addq $0x1e8, %rcx            # imm = 0x1E8
movslq -0x2c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %edx
movq -0x28(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x28(%rbp), %r8
movl 0x30(%r8), %r8d
movq -0x20(%rbp), %r9
movl (%r9), %ebx
xorl %r9d, %r9d
leaq -0x3c(%rbp), %r11
leaq -0x40(%rbp), %r10
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *%rax
movl %eax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0x16157
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x16157
movq -0x20(%rbp), %rax
movl (%rax), %ecx
shll $0x4, %ecx
movl -0x30(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movl 0x10db38(%rax), %edi
subl $0x1, %edi
movl -0x2c(%rbp), %esi
callq 0x17240
movl %eax, %ecx
movl -0x64(%rbp), %eax
imull %ecx, %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x5c(%rax)
je 0x16199
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x5c(%rcx), %eax
jge 0x161c1
movl -0x30(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x5c(%rax)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x60(%rax)
movl -0x3c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x64(%rax)
movl -0x40(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x68(%rax)
jmp 0x161c3
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x16073
movq -0x20(%rbp), %rax
movl 0x60(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %r8d
xorl %r9d, %r9d
movl %r9d, %esi
movl %r9d, %edx
movl %r9d, %ecx
movl $0x0, (%rsp)
callq 0x7a80
movq -0x20(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x163ea
movq -0x18(%rbp), %rax
movl $0xe, 0x1c(%rax)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x70(%rax)
movq -0x18(%rbp), %rdi
leaq -0x50(%rbp), %r8
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x7ff0
movq -0x18(%rbp), %rdi
leaq -0x50(%rbp), %r8
addq $0x8, %r8
xorl %ecx, %ecx
movl $0x1, %edx
movl %ecx, %esi
callq 0x7ff0
movl -0x50(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x74(%rax)
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x78(%rax)
movl -0x48(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x7c(%rax)
movl -0x44(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x10f390(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
addq $0x68, %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rsi
movq -0x28(%rbp), %rcx
addq $0x1e8, %rcx            # imm = 0x1E8
movslq -0x2c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %edx
movq -0x28(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x28(%rbp), %r8
movl 0x30(%r8), %r8d
movq -0x20(%rbp), %r9
movl (%r9), %ebx
movq -0x20(%rbp), %r11
addq $0x74, %r11
movq -0x20(%rbp), %r10
addq $0x74, %r10
addq $0x4, %r10
movl $0x1, %r9d
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *%rax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movq 0x10f390(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
addq $0x68, %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rsi
movq -0x28(%rbp), %rcx
addq $0x1e8, %rcx            # imm = 0x1E8
movslq -0x2c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
shll $0x3, %ecx
movslq %ecx, %rcx
addq %rcx, %rsi
movq -0x28(%rbp), %rcx
addq $0x1e8, %rcx            # imm = 0x1E8
movslq -0x2c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %edx
movq -0x28(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x28(%rbp), %r8
movl 0x30(%r8), %r8d
shll $0x3, %r8d
movslq %r8d, %r8
addq %r8, %rcx
movq -0x28(%rbp), %r8
movl 0x30(%r8), %r8d
movq -0x20(%rbp), %r9
movl (%r9), %ebx
movq -0x20(%rbp), %r11
addq $0x74, %r11
addq $0x8, %r11
movq -0x20(%rbp), %r10
addq $0x74, %r10
addq $0x8, %r10
addq $0x4, %r10
movl $0x1, %r9d
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *%rax
movl -0x6c(%rbp), %ecx
addl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
shll %eax
movl %eax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movl 0x10db38(%rax), %edi
subl $0x1, %edi
movl -0x2c(%rbp), %esi
callq 0x17240
movl -0x68(%rbp), %ecx
imull %eax, %ecx
movq -0x20(%rbp), %rax
addl 0x6c(%rax), %ecx
movl %ecx, 0x6c(%rax)
movq -0x20(%rbp), %rax
cmpl $0x1, 0xc(%rax)
je 0x165cf
movq -0x18(%rbp), %rax
movl $0xf, 0x1c(%rax)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x88(%rax)
movq -0x18(%rbp), %rdi
leaq -0x60(%rbp), %r8
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x7ff0
movq -0x18(%rbp), %rdi
leaq -0x60(%rbp), %r8
addq $0x8, %r8
xorl %ecx, %ecx
movl $0x1, %edx
movl %ecx, %esi
callq 0x7ff0
movl -0x60(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8c(%rax)
movl -0x5c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x90(%rax)
movl -0x58(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x94(%rax)
movl -0x54(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x98(%rax)
movq -0x10(%rbp), %rax
movq 0x10f390(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
addq $0x68, %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rsi
movq -0x28(%rbp), %rcx
addq $0x1e8, %rcx            # imm = 0x1E8
movslq -0x2c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %edx
movq -0x28(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x28(%rbp), %r8
movl 0x30(%r8), %r8d
movq -0x20(%rbp), %r9
movl (%r9), %ebx
movq -0x20(%rbp), %r11
addq $0x8c, %r11
movq -0x20(%rbp), %r10
addq $0x8c, %r10
addq $0x4, %r10
movl $0x2, %r9d
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *%rax
movl %eax, -0x74(%rbp)
movq -0x10(%rbp), %rax
movq 0x10f390(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
addq $0x68, %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rsi
addq $0x8, %rsi
movq -0x28(%rbp), %rcx
addq $0x1e8, %rcx            # imm = 0x1E8
movslq -0x2c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %edx
movq -0x28(%rbp), %rcx
movq 0x18(%rcx), %rcx
addq $0x8, %rcx
movq -0x28(%rbp), %r8
movl 0x30(%r8), %r8d
movq -0x20(%rbp), %r9
movl (%r9), %ebx
movq -0x20(%rbp), %r11
addq $0x8c, %r11
addq $0x8, %r11
movq -0x20(%rbp), %r10
addq $0x8c, %r10
addq $0x8, %r10
addq $0x4, %r10
movl $0x2, %r9d
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *%rax
movl -0x74(%rbp), %ecx
addl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x84(%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
shll %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movl 0x10db38(%rax), %edi
subl $0x1, %edi
movl -0x2c(%rbp), %esi
callq 0x17240
movl -0x70(%rbp), %ecx
imull %eax, %ecx
movq -0x20(%rbp), %rax
addl 0x84(%rax), %ecx
movl %ecx, 0x84(%rax)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x165f0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x172a0
addq $0x88, %rsp
popq %rbx
popq %rbp
retq
nopw (%rax,%rax)