// File: /workspace/github_c_makefile_star2_O1/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 0x1e3a4(%rip), %rdi     # 0x251b4
leaq 0x1ea19(%rip), %rsi     # 0x25830
leaq 0x1eae3(%rip), %rdx     # 0x25901
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x4c22
movl 0x1c(%rbx), %eax
cmpl $0xd, %eax
je 0x6e49
cmpl $0xf, %eax
je 0x6e43
cmpl $0xe, %eax
jne 0x6e3e
leal (%r15,%r15), %r14d
xorl %r9d, %r9d
jmp 0x6ead
leal (%r15,%r15), %r9d
jmp 0x6ead
movl %r15d, %r14d
shrl $0x1f, %r14d
addl %r15d, %r14d
andl $-0x2, %r14d
movl %r15d, %r9d
subl %r14d, %r9d
addl %r9d, %r9d
movslq %r15d, %rcx
movl 0x20(%rbx,%rcx,4), %ecx
cmpl $0xa, %ecx
ja 0x6ead
movl $0x111, %edx            # imm = 0x111
btl %ecx, %edx
jb 0x6e8f
movl $0x222, %edx            # imm = 0x222
btl %ecx, %edx
jb 0x6eaa
movl $0x444, %edx            # imm = 0x444
btl %ecx, %edx
jae 0x6ead
addl %r13d, %r9d
jmp 0x6ead
movl %r13d, %ecx
shrl $0x1f, %ecx
addl %r13d, %ecx
movl %ecx, %edx
andl $-0x2, %edx
subl %edx, %r13d
addl %r13d, %r9d
sarl %ecx
addl %ecx, %r14d
jmp 0x6ead
addl %r13d, %r14d
cmpl $0xd, %eax
je 0x6ec3
movl $0x4, %edx
cmpl $0xf, %eax
jne 0x6edf
movl $0x2, %edx
jmp 0x6edf
movslq %r15d, %rcx
movl 0x20(%rbx,%rcx,4), %ecx
movl $0x2, %edx
cmpq $0xa, %rcx
ja 0x6edf
leaq 0x1efc4(%rip), %rdx     # 0x25ea0
movl (%rdx,%rcx,4), %edx
movslq %r14d, %r10
leal -0x1(%r9), %edi
movl %edi, %r8d
movq %rbx, %rsi
testl %r9d, %r9d
jg 0x6efc
leal 0x3(%r9), %r8d
movq 0x10(%rbx), %rcx
movq (%rcx), %rsi
movslq %r9d, %rcx
leaq (%r10,%r10,4), %r13
movslq %r12d, %r11
movl $0x0, -0x2c(%rbp)
testq %rsi, %rsi
je 0x6f5e
movl $0xfffffffe, -0x48(%rbp) # imm = 0xFFFFFFFE
cmpl $0x2, 0x18(%rsi)
jb 0x6f65
movslq %r8d, %r8
leaq (%r8,%r8,4), %r8
shlq $0x5, %r8
addq %r8, %rsi
leaq (%rsi,%r13,8), %r8
movl 0x30(%r8,%r11,4), %r8d
movl $0x0, %r10d
cmpl $-0x1, %r8d
je 0x6f68
leaq (%rsi,%r13,8), %rsi
addq $0x30, %rsi
movl 0x8(%rsi,%r11,8), %r10d
movl %r10d, -0x2c(%rbp)
movl 0xc(%rsi,%r11,8), %r10d
movl %r8d, -0x48(%rbp)
jmp 0x6f68
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
xorl %r10d, %r10d
leaq (%rcx,%rcx,4), %r12
leal -0x1(%r14), %esi
movl %esi, %r8d
movq %rbx, %rcx
testl %r14d, %r14d
jg 0x6f87
leal 0x3(%r14), %r8d
movq 0x10(%rbx), %rcx
movq 0x8(%rcx), %rcx
movl %r10d, -0x44(%rbp)
shlq $0x5, %r12
movl $0x0, -0x38(%rbp)
movq %r15, %r10
testq %rcx, %rcx
je 0x6fea
movl $0xfffffffe, -0x34(%rbp) # imm = 0xFFFFFFFE
cmpl $0x2, 0x18(%rcx)
jb 0x6ff1
addq %r12, %rcx
movslq %r8d, %r8
leaq (%r8,%r8,4), %r15
leaq (%rcx,%r15,8), %r8
movl 0x30(%r8,%r11,4), %r8d
movl $0x0, -0x30(%rbp)
cmpl $-0x1, %r8d
je 0x6ff8
leaq (%rcx,%r15,8), %rcx
addq $0x30, %rcx
movl 0x8(%rcx,%r11,8), %r15d
movl %r15d, -0x38(%rbp)
movl 0xc(%rcx,%r11,8), %ecx
movl %ecx, -0x30(%rbp)
movl %r8d, -0x34(%rbp)
jmp 0x6ff8
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x30(%rbp)
addl %r9d, %edx
testl %r14d, %r14d
jg 0x701b
cmpl $0x4, %edx
jl 0x701b
movq 0x10(%rbx), %rcx
movq 0x10(%rcx), %r15
testq %r15, %r15
je 0x7025
addl $-0x4, %edx
leal 0x3(%r14), %r8d
jmp 0x7039
testl %r14d, %r14d
jle 0x702d
cmpl $0x3, %edx
jle 0x7092
xorl %r15d, %r15d
movl %esi, %r8d
jmp 0x7039
leal 0x3(%r14), %r8d
movq 0x10(%rbx), %rcx
movq 0x8(%rcx), %r15
movl %edx, %ecx
addq %rbx, %r12
testq %r15, %r15
jne 0x70e8
testl %r14d, %r14d
setg %cl
testl %r9d, %r9d
setg %dl
orb %cl, %dl
jne 0x707e
movq 0x10(%rbx), %rcx
cmpq $0x0, (%rcx)
je 0x70af
movq 0x8(%rcx), %r15
testq %r15, %r15
je 0x70af
addl $0x3, %r9d
addl $0x3, %r14d
addq $-0xf88, %r15           # imm = 0xF078
movl %r14d, %r8d
jmp 0x70e5
testl %r14d, %r14d
jle 0x70c4
testl %r9d, %r9d
jle 0x70d7
movl %esi, %r8d
movl %edi, %ecx
movq %rbx, %r15
jmp 0x70e8
cmpl $0x2, %edx
jne 0x70b7
movl $0x2, %ecx
movl %esi, %r8d
movq %rbx, %r15
testl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
jne 0x703b
jmp 0x7025
xorl %r15d, %r15d
movl %esi, %r8d
jmp 0x70d3
movl %esi, %r8d
movl %edx, %ecx
movq %rbx, %r15
jmp 0x703b
addl $0x3, %r14d
movq 0x10(%rbx), %rcx
movq 0x8(%rcx), %r15
movl %r14d, %r8d
movl %edi, %ecx
jmp 0x70e8
addl $0x3, %r9d
movq 0x10(%rbx), %rcx
movq (%rcx), %r15
movl %esi, %r8d
movl %r9d, %ecx
leaq (%r12,%r13,8), %rdi
xorl %edx, %edx
testq %r15, %r15
je 0x713f
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
cmpl $0x2, 0x18(%r15)
jb 0x7144
movslq %ecx, %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x5, %rcx
addq %rcx, %r15
movslq %r8d, %rcx
leaq (%rcx,%rcx,4), %r9
leaq (%r15,%r9,8), %rcx
movl 0x30(%rcx,%r11,4), %r8d
movl $0x0, %ecx
cmpl $-0x1, %r8d
je 0x7146
leaq (%r15,%r9,8), %rcx
addq $0x30, %rcx
movl 0x8(%rcx,%r11,8), %edx
movl 0xc(%rcx,%r11,8), %ecx
movl %r8d, %esi
jmp 0x7146
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl 0x30(%rdi,%r11,4), %r8d
testl %r10d, %r10d
jne 0x7169
cmpl $0xe, %eax
jne 0x7169
cmpl %r8d, -0x34(%rbp)
jne 0x7169
movq -0x40(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, (%rax)
movl -0x30(%rbp), %ecx
jmp 0x7198
cmpl $0x1, %r10d
movl -0x48(%rbp), %r11d
jne 0x717d
cmpl $0xe, %eax
jne 0x717d
cmpl %r8d, %r11d
je 0x718c
testl %r10d, %r10d
jne 0x71aa
cmpl $0xf, %eax
jne 0x71aa
cmpl %r8d, %r11d
jne 0x71aa
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 0x71c2
cmpl $0xf, %eax
jne 0x71c2
cmpl %r8d, %esi
jne 0x71c2
movq -0x40(%rbp), %rax
movl %edx, (%rax)
jmp 0x7198
xorl %eax, %eax
cmpl %r8d, %esi
sete %al
xorl %edi, %edi
cmpl %r8d, %r11d
sete %dil
leal 0x1(%rdi), %r9d
cmpl %r8d, -0x34(%rbp)
cmovnel %edi, %r9d
addl %r9d, %eax
cmpl $0x2, %eax
jb 0x725d
movl -0x2c(%rbp), %r8d
movl -0x38(%rbp), %r9d
cmpl %r8d, %r9d
movl %r8d, %eax
cmovll %r9d, %eax
movl %r8d, %esi
cmovgl %r9d, %esi
cmpl %edx, %esi
movl %edx, %edi
cmovgl %esi, %edi
cmpl %edx, %eax
cmovgel %edx, %eax
cmovgl %esi, %edi
addl %r8d, %r9d
addl %edx, %r9d
addl %eax, %edi
subl %edi, %r9d
movl -0x44(%rbp), %r8d
movl -0x30(%rbp), %r10d
cmpl %r8d, %r10d
movl %r8d, %eax
cmovll %r10d, %eax
movl %r8d, %edx
cmovgl %r10d, %edx
cmpl %ecx, %edx
movl %ecx, %esi
cmovgl %edx, %esi
cmpl %ecx, %eax
cmovgel %ecx, %eax
movq -0x40(%rbp), %rdi
movl %r9d, (%rdi)
cmovgl %edx, %esi
addl %r8d, %r10d
addl %ecx, %r10d
addl %eax, %esi
subl %esi, %r10d
movl %r10d, 0x4(%rdi)
jmp 0x719b
cmpl $0x1, %eax
movl -0x44(%rbp), %r9d
jne 0x727a
cmpl %r8d, %r11d
je 0x7288
cmpl %r8d, -0x34(%rbp)
je 0x715b
jmp 0x71ba
cmpl $-0x1, %r11d
je 0x729a
andl -0x34(%rbp), %esi
cmpl $-0x1, %esi
jne 0x729a
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
movl %r9d, 0x4(%rax)
jmp 0x719b
movl -0x2c(%rbp), %r8d
movl -0x38(%rbp), %r10d
cmpl %r8d, %r10d
movl %r8d, %eax
cmovll %r10d, %eax
movl %r8d, %esi
cmovgl %r10d, %esi
cmpl %edx, %esi
movl %edx, %edi
cmovgl %esi, %edi
cmpl %edx, %eax
cmovgel %edx, %eax
cmovgl %esi, %edi
addl %r8d, %r10d
addl %edx, %r10d
addl %eax, %edi
subl %edi, %r10d
movl -0x30(%rbp), %r8d
cmpl %r9d, %r8d
movl %r9d, %eax
cmovll %r8d, %eax
movl %r9d, %edx
cmovgl %r8d, %edx
cmpl %ecx, %edx
movl %ecx, %esi
cmovgl %edx, %esi
cmpl %ecx, %eax
cmovgel %ecx, %eax
movq -0x40(%rbp), %rdi
movl %r10d, (%rdi)
cmovgl %edx, %esi
addl %r9d, %r8d
addl %ecx, %r8d
addl %eax, %esi
subl %esi, %r8d
movl %r8d, 0x4(%rdi)
jmp 0x719b