// File: /workspace/github_c_makefile_star2_O3/akumrao[P]videoAnalyzer/core/macroblock.c
// Function: x264_mb_predict_mv(x264_macroblock_t*, int, int, int, int*)
void x264_mb_predict_mv(x264_macroblock_t *mb, int i_list, int i_part, int i_subpart, int mv[2]) {LOG_CALL;
    int x, y, xn, yn;
    int w, h;
    int i_ref;

    int i_refa = -1;
    int i_refb = -1;
    int i_refc = -1;

    int mvxa = 0, mvxb = 0, mvxc = 0;
    int mvya = 0, mvyb = 0, mvyc = 0;

    x264_macroblock_t *mbn;


    x264_mb_partition_getxy(mb, i_part, i_subpart, &x, &y);
    x264_mb_partition_size(mb, i_part, i_subpart, &w, &h);
    i_ref = mb->partition[x][y].i_ref[i_list];

    /* Left  pixel (-1,0)*/
    xn = x - 1;
    mbn = mb;
    if (xn < 0)
    {
        xn += 4;
        mbn = mb->context->mba;
    }
    if (mbn)
    {
        i_refa = -2;
        if (!IS_INTRA(mbn->i_type) && mbn->partition[xn][y].i_ref[i_list] != -1)
        {
            i_refa = mbn->partition[xn][y].i_ref[i_list];
            mvxa = mbn->partition[xn][y].mv[i_list][0];
            mvya = mbn->partition[xn][y].mv[i_list][1];
        }
    }

    /* Up ( pixel(0,-1)*/
    yn = y - 1;
    mbn = mb;
    if (yn < 0)
    {
        yn += 4;
        mbn = mb->context->mbb;
    }
    if (mbn)
    {
        i_refb = -2;
        if (!IS_INTRA(mbn->i_type) && mbn->partition[x][yn].i_ref[i_list] != -1)
        {
            i_refb = mbn->partition[x][yn].i_ref[i_list];
            mvxb = mbn->partition[x][yn].mv[i_list][0];
            mvyb = mbn->partition[x][yn].mv[i_list][1];
        }
    }

    /* Up right pixel(width,-1)*/
    xn = x + w;
    yn = y - 1;

    mbn = mb;
    if (yn < 0 && xn >= 4)
    {
        if (mb->context->mbc)
        {
            xn -= 4;
            yn += 4;
            mbn = mb->context->mbc;
        } else
        {
            mbn = NULL;
        }
    } else if (yn < 0)
    {
        yn += 4;
        mbn = mb->context->mbb;
    } else if (xn >= 4 || (xn == 2 && (yn == 0 || yn == 2)))
    {
        mbn = NULL; /* not yet decoded */
    }

    if (mbn == NULL)
    {
        /* load top left pixel(-1,-1) */
        xn = x - 1;
        yn = y - 1;

        mbn = mb;
        if (yn < 0 && xn < 0)
        {
            if (mb->context->mba && mb->context->mbb)
            {
                xn += 4;
                yn += 4;
                mbn = mb->context->mbb - 1;
            } else
            {
                mbn = NULL;
            }
        } else if (yn < 0)
        {
            yn += 4;
            mbn = mb->context->mbb;
        } else if (xn < 0)
        {
            xn += 4;
            mbn = mb->context->mba;
        }
    }

    if (mbn)
    {
        i_refc = -2;
        if (!IS_INTRA(mbn->i_type) && mbn->partition[xn][yn].i_ref[i_list] != -1)
        {
            i_refc = mbn->partition[xn][yn].i_ref[i_list];
            mvxc = mbn->partition[xn][yn].mv[i_list][0];
            mvyc = mbn->partition[xn][yn].mv[i_list][1];
        }
    }

    if (mb->i_partition == D_16x8 && i_part == 0 && i_refb == i_ref)
    {
        mv[0] = mvxb;
        mv[1] = mvyb;
    } else if (mb->i_partition == D_16x8 && i_part == 1 && i_refa == i_ref)
    {
        mv[0] = mvxa;
        mv[1] = mvya;
    } else if (mb->i_partition == D_8x16 && i_part == 0 && i_refa == i_ref)
    {
        mv[0] = mvxa;
        mv[1] = mvya;
    } else if (mb->i_partition == D_8x16 && i_part == 1 && i_refc == i_ref)
    {
        mv[0] = mvxc;
        mv[1] = mvyc;
    } else
    {
        int i_count;

        i_count = 0;
        if (i_refa == i_ref) i_count++;
        if (i_refb == i_ref) i_count++;
        if (i_refc == i_ref) i_count++;

        if (i_count > 1)
        {
            mv[0] = x264_median(mvxa, mvxb, mvxc);
            mv[1] = x264_median(mvya, mvyb, mvyc);
        } else if (i_count == 1)
        {
            if (i_refa == i_ref)
            {
                mv[0] = mvxa;
                mv[1] = mvya;
            } else if (i_refb == i_ref)
            {
                mv[0] = mvxb;
                mv[1] = mvyb;
            } else
            {
                mv[0] = mvxc;
                mv[1] = mvyc;
            }
        } else if (i_refb == -1 && i_refc == -1 && i_refa != -1)
        {
            mv[0] = mvxa;
            mv[1] = mvya;
        } else
        {
            mv[0] = x264_median(mvxa, mvxb, mvxc);
            mv[1] = x264_median(mvya, mvyb, mvyc);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, -0x40(%rbp)
movl %ecx, %r13d
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %rbx
leaq 0x2057c(%rip), %rdi     # 0x271b4
leaq 0x20bf1(%rip), %rsi     # 0x27830
leaq 0x20cbb(%rip), %rdx     # 0x27901
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x4a56
movl 0x1c(%rbx), %eax
cmpl $0xd, %eax
je 0x6c7d
cmpl $0xf, %eax
je 0x6c74
movl $0x4, %r13d
cmpl $0xe, %eax
jne 0x6c6c
leal (%r15,%r15), %r14d
xorl %r11d, %r11d
jmp 0x6d04
leal (%r15,%r15), %r11d
jmp 0x6cfe
movl %r15d, %r14d
shrl $0x1f, %r14d
addl %r15d, %r14d
andl $-0x2, %r14d
movl %r15d, %r11d
subl %r14d, %r11d
addl %r11d, %r11d
movslq %r15d, %rcx
movl 0x20(%rbx,%rcx,4), %ecx
cmpl $0xa, %ecx
ja 0x6ce1
movl $0x111, %edx            # imm = 0x111
btl %ecx, %edx
jb 0x6cc3
movl $0x222, %edx            # imm = 0x222
btl %ecx, %edx
jb 0x6cde
movl $0x444, %edx            # imm = 0x444
btl %ecx, %edx
jae 0x6ce1
addl %r13d, %r11d
jmp 0x6ce1
movl %r13d, %edx
shrl $0x1f, %edx
addl %r13d, %edx
movl %edx, %esi
andl $-0x2, %esi
subl %esi, %r13d
addl %r13d, %r11d
sarl %edx
addl %edx, %r14d
jmp 0x6ce1
addl %r13d, %r14d
cmpl $0xa, %ecx
ja 0x6cfe
movl $0x1, %r13d
movl $0x555, %edx            # imm = 0x555
btl %ecx, %edx
jb 0x6d04
movl $0x222, %edx            # imm = 0x222
btl %ecx, %edx
movl $0x2, %r13d
movslq %r11d, %r10
leaq (%r10,%r10,4), %rsi
shlq $0x5, %rsi
leaq (%rbx,%rsi), %rcx
movslq %r14d, %rdx
leaq (%rdx,%rdx,4), %rdi
leaq (%rcx,%rdi,8), %rdx
movslq %r12d, %r12
leal -0x1(%r10), %ecx
movq %rbx, %r8
movl %ecx, %r9d
testl %r10d, %r10d
jg 0x6d40
movq 0x10(%rbx), %r8
movq (%r8), %r8
testq %r8, %r8
je 0x6d9c
leal 0x3(%r11), %r9d
movl $0x0, -0x2c(%rbp)
movl $0xfffffffe, -0x30(%rbp) # imm = 0xFFFFFFFE
cmpl $0x2, 0x18(%r8)
jae 0x6d5a
movq %r15, %r10
jmp 0x6dad
movq %r15, %r10
movslq %r9d, %r9
leaq (%r9,%r9,4), %r9
shlq $0x5, %r9
addq %r9, %r8
leaq (%r8,%rdi,8), %r9
movl 0x30(%r9,%r12,4), %r9d
movl $0x0, %r15d
cmpl $-0x1, %r9d
je 0x6db0
leaq (%r8,%rdi,8), %rdi
addq $0x30, %rdi
movl 0x8(%rdi,%r12,8), %r8d
movl %r8d, -0x2c(%rbp)
movl 0xc(%rdi,%r12,8), %r15d
movl %r9d, -0x30(%rbp)
jmp 0x6db0
movq %r15, %r10
movl $0x0, -0x2c(%rbp)
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movl %r15d, -0x44(%rbp)
movl 0x30(%rdx,%r12,4), %r9d
leal -0x1(%r14), %edi
movq %rbx, %r15
movl %edi, %edx
testl %r14d, %r14d
jg 0x6ddc
leal 0x3(%r14), %edx
movq 0x10(%rbx), %r8
movq 0x8(%r8), %r15
testq %r15, %r15
je 0x6e9a
movl $0x0, -0x34(%rbp)
movl $0xfffffffe, -0x38(%rbp) # imm = 0xFFFFFFFE
cmpl $0x2, 0x18(%r15)
jae 0x6df5
xorl %esi, %esi
jmp 0x6e2b
addq %rsi, %r15
movslq %edx, %rdx
leaq (%rdx,%rdx,4), %r8
leaq (%r15,%r8,8), %rdx
movl 0x30(%rdx,%r12,4), %edx
movl $0x0, %esi
cmpl $-0x1, %edx
je 0x6e2b
leaq (%r15,%r8,8), %rsi
addq $0x30, %rsi
movl 0x8(%rsi,%r12,8), %r8d
movl %r8d, -0x34(%rbp)
movl 0xc(%rsi,%r12,8), %esi
movl %edx, -0x38(%rbp)
addl %r11d, %r13d
testl %r14d, %r14d
jg 0x6e56
cmpl $0x4, %r13d
jl 0x6e56
movq 0x10(%rbx), %r8
movq 0x10(%r8), %rbx
testq %rbx, %rbx
je 0x6e73
addl $-0x4, %r13d
addl $0x3, %r14d
movl %r14d, %edi
jmp 0x6eeb
testl %r14d, %r14d
jle 0x6e85
cmpl $0x3, %r13d
jle 0x6ed3
testl %r11d, %r11d
jg 0x6ece
addl $0x3, %r11d
movq 0x10(%rbx), %r8
movl %r11d, %ecx
jmp 0x6ec2
testl %r11d, %r11d
jle 0x6fab
addl $0x3, %r14d
movl %r14d, %edx
jmp 0x6ebc
movq 0x10(%rbx), %r8
movq 0x8(%r8), %rbx
leal 0x3(%r14), %edx
movl %edx, %edi
testq %rbx, %rbx
jne 0x6eeb
jmp 0x6eb3
addl %r11d, %r13d
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
xorl %esi, %esi
movl $0x0, -0x34(%rbp)
cmpl $0x4, %r13d
jge 0x6e3d
testl %r11d, %r11d
jle 0x6fab
addq $0x8, %r8
movl %edx, %edi
movq (%r8), %rbx
testq %rbx, %rbx
je 0x6fe0
movl %ecx, %r13d
jmp 0x6eeb
cmpl $0x2, %r13d
jne 0x6eeb
movl $0x2, %r13d
testl $0xfffffffd, %edi       # imm = 0xFFFFFFFD
je 0x6e61
xorl %ecx, %ecx
cmpl $0x2, 0x18(%rbx)
jb 0x6f2a
movslq %r13d, %rdx
leaq (%rdx,%rdx,4), %rdx
shlq $0x5, %rdx
addq %rdx, %rbx
movslq %edi, %rdx
leaq (%rdx,%rdx,4), %rdi
leaq (%rbx,%rdi,8), %rdx
movl 0x30(%rdx,%r12,4), %edx
cmpl $-0x1, %edx
je 0x6f2a
leaq (%rbx,%rdi,8), %rdi
addq $0x30, %rdi
movl 0x8(%rdi,%r12,8), %ecx
movl 0xc(%rdi,%r12,8), %r11d
jmp 0x6f32
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
xorl %r11d, %r11d
testl %r10d, %r10d
jne 0x6f50
cmpl $0xe, %eax
jne 0x6f50
cmpl %r9d, -0x38(%rbp)
jne 0x6f50
movq -0x40(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, (%rax)
movl %esi, 0x4(%rax)
jmp 0x6f80
cmpl $0x1, %r10d
jne 0x6f61
cmpl $0xe, %eax
jne 0x6f61
cmpl %r9d, -0x30(%rbp)
je 0x6f71
testl %r10d, %r10d
jne 0x6f8f
cmpl $0xf, %eax
jne 0x6f8f
cmpl %r9d, -0x30(%rbp)
jne 0x6f8f
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
movl -0x44(%rbp), %ecx
movl %ecx, 0x4(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1, %r10d
jne 0x6fec
cmpl $0xf, %eax
jne 0x6fec
cmpl %r9d, %edx
jne 0x6fec
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movl %r11d, 0x4(%rax)
jmp 0x6f80
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq $0x0, (%r8)
je 0x6f2f
movq 0x8(%r8), %rbx
testq %rbx, %rbx
je 0x6f2f
addl $0x3, %r11d
addl $0x3, %r14d
addq $-0xf88, %rbx           # imm = 0xF078
movl %r11d, %r13d
jmp 0x6e4e
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x6f2f
xorl %eax, %eax
cmpl %r9d, %edx
sete %al
xorl %edi, %edi
cmpl %r9d, -0x30(%rbp)
sete %dil
leal 0x1(%rdi), %r8d
cmpl %r9d, -0x38(%rbp)
cmovnel %edi, %r8d
addl %r8d, %eax
cmpl $0x2, %eax
jb 0x7084
movl -0x2c(%rbp), %r8d
movl -0x34(%rbp), %r9d
cmpl %r8d, %r9d
movl %r8d, %eax
cmovll %r9d, %eax
movl %r8d, %edx
cmovgl %r9d, %edx
cmpl %ecx, %edx
movl %ecx, %edi
cmovgl %edx, %edi
cmpl %ecx, %eax
cmovgel %ecx, %eax
cmovgl %edx, %edi
addl %r8d, %r9d
addl %ecx, %r9d
addl %eax, %edi
subl %edi, %r9d
movl -0x44(%rbp), %r8d
cmpl %r8d, %esi
movl %r8d, %eax
cmovll %esi, %eax
movl %r8d, %ecx
cmovgl %esi, %ecx
cmpl %r11d, %ecx
movl %r11d, %edx
cmovgl %ecx, %edx
cmpl %r11d, %eax
cmovgel %r11d, %eax
movq -0x40(%rbp), %rdi
movl %r9d, (%rdi)
cmovgl %ecx, %edx
addl %r8d, %esi
addl %r11d, %esi
addl %eax, %edx
subl %edx, %esi
movl %esi, 0x4(%rdi)
jmp 0x6f80
cmpl $0x1, %eax
movl -0x44(%rbp), %r8d
jne 0x70a2
cmpl %r9d, -0x30(%rbp)
je 0x70b0
cmpl %r9d, -0x38(%rbp)
je 0x6f42
jmp 0x6f9f
cmpl $-0x1, -0x30(%rbp)
je 0x70c2
andl -0x38(%rbp), %edx
cmpl $-0x1, %edx
jne 0x70c2
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
movl %r8d, 0x4(%rax)
jmp 0x6f80
movl -0x2c(%rbp), %r9d
movl -0x34(%rbp), %r10d
cmpl %r9d, %r10d
movl %r9d, %eax
cmovll %r10d, %eax
movl %r9d, %edx
cmovgl %r10d, %edx
cmpl %ecx, %edx
movl %ecx, %edi
cmovgl %edx, %edi
cmpl %ecx, %eax
cmovgel %ecx, %eax
cmovgl %edx, %edi
addl %r9d, %r10d
addl %ecx, %r10d
addl %eax, %edi
subl %edi, %r10d
cmpl %r8d, %esi
movl %r8d, %eax
cmovll %esi, %eax
movl %r8d, %ecx
cmovgl %esi, %ecx
cmpl %r11d, %ecx
movl %r11d, %edx
cmovgl %ecx, %edx
cmpl %r11d, %eax
cmovgel %r11d, %eax
movq -0x40(%rbp), %rdi
movl %r10d, (%rdi)
jmp 0x706f