// File: /workspace/github_c_makefile_star2_O1/akumrao[P]videoAnalyzer/encoder/macroblock.c
// Function: x264_cabac_mb_ref(x264_t*, x264_macroblock_t*, int, int)
static void x264_cabac_mb_ref(x264_t *h, x264_macroblock_t *mb, int i_list, int i_part) {LOG_CALL;
    x264_macroblock_t *a;
    x264_macroblock_t *b;

    int i_ctxIdxInc = 0;
    int i_ref;
    int i_refa = -1;
    int i_refb = -1;

    int x, y, xn, yn;

    x264_mb_partition_getxy(mb, i_part, 0, &x, &y);
    i_ref = mb->partition[x][y].i_ref[i_list];


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

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

    /* FIXME not complete for B frame (B_DIRECT and B_DIRECT 8x8 sub */
    if (i_refa > 0 && !IS_SKIP(a->i_type))
    {
        i_ctxIdxInc++;
    }
    if (i_refb > 0 && !IS_SKIP(b->i_type))
    {
        i_ctxIdxInc += 2;
    }

    while (i_ref > 0)
    {
        x264_cabac_encode_decision(&h->cabac, 54 + i_ctxIdxInc, 1);
        if (i_ctxIdxInc < 4)
        {
            i_ctxIdxInc = 4;
        } else
        {
            i_ctxIdxInc = 5;
        }
        i_ref--;
    }
    x264_cabac_encode_decision(&h->cabac, 54 + i_ctxIdxInc, 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xa6f2(%rip), %rdi      # 0x251b4
leaq 0x10f4f(%rip), %rsi     # 0x2ba18
leaq 0x114dd(%rip), %rdx     # 0x2bfad
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x4c22
movl 0x1c(%r14), %eax
cmpl $0xd, %eax
je 0x1aaf7
cmpl $0xf, %eax
je 0x1ab08
cmpl $0xe, %eax
jne 0x1ab10
addl %r15d, %r15d
xorl %eax, %eax
movl %r15d, %r12d
jmp 0x1ab12
movl %r15d, %r12d
shrl $0x1f, %r12d
addl %r15d, %r12d
andl $-0x2, %r12d
subl %r12d, %r15d
addl %r15d, %r15d
movl %r15d, %eax
jmp 0x1ab12
xorl %eax, %eax
movslq %r12d, %rdx
testl %eax, %eax
jle 0x1ab21
leal -0x1(%rax), %edi
movq %r14, %rcx
jmp 0x1ab2b
leal 0x3(%rax), %edi
movq 0x10(%r14), %rcx
movq (%rcx), %rcx
movslq %eax, %rsi
leaq (%rdx,%rdx,4), %rax
testq %rcx, %rcx
je 0x1ab3d
cmpl $0x2, 0x18(%rcx)
jae 0x1ab41
xorl %edx, %edx
jmp 0x1ab57
movslq %edi, %rdx
leaq (%rdx,%rdx,4), %rdx
shlq $0x5, %rdx
addq %rcx, %rdx
cmpl $0x0, 0x30(%rdx,%rax,8)
setg %dl
leaq (%rsi,%rsi,4), %rdi
testl %r12d, %r12d
jle 0x1ab68
decl %r12d
movq %r14, %rsi
jmp 0x1ab74
addl $0x3, %r12d
movq 0x10(%r14), %rsi
movq 0x8(%rsi), %rsi
shlq $0x5, %rdi
xorl %r15d, %r15d
testq %rsi, %rsi
je 0x1ab86
cmpl $0x2, 0x18(%rsi)
jae 0x1ab8b
xorl %r8d, %r8d
jmp 0x1aba0
leaq (%rsi,%rdi), %r8
movslq %r12d, %r9
leaq (%r9,%r9,4), %r9
cmpl $0x0, 0x30(%r8,%r9,8)
setg %r8b
addq %rdi, %r14
testb %dl, %dl
je 0x1abbc
movl 0x18(%rcx), %ecx
cmpl $0x5, %ecx
setne %dl
cmpl $0x11, %ecx
setne %cl
andb %dl, %cl
movzbl %cl, %r15d
movl 0x30(%r14,%rax,8), %r12d
testb %r8b, %r8b
je 0x1abd7
movl 0x18(%rsi), %eax
cmpl $0x5, %eax
je 0x1abd7
cmpl $0x11, %eax
je 0x1abd7
orl $0x2, %r15d
testl %r12d, %r12d
jle 0x1ac0e
leaq 0x10db60(%rbx), %r14
incl %r12d
leal 0x36(%r15), %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x40ca
cmpl $0x4, %r15d
movl $0x5, %r15d
sbbl $0x0, %r15d
decl %r12d
cmpl $0x1, %r12d
jg 0x1abe6
addq $0x10db60, %rbx         # imm = 0x10DB60
addl $0x36, %r15d
movq %rbx, %rdi
movl %r15d, %esi
xorl %edx, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x40ca