// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x7c5d(%rip), %rdi      # 0x1b1b4
leaq 0xe40a(%rip), %rsi      # 0x21968
leaq 0xe998(%rip), %rdx      # 0x21efd
xorl %eax, %eax
callq 0x39ba
leaq -0x30(%rbp), %r12
leaq -0x2c(%rbp), %r13
movq %r14, %rdi
movl %r15d, %esi
xorl %edx, %edx
movq %r12, %rcx
movq %r13, %r8
callq 0x104ec
movslq (%r12), %rsi
movslq (%r13), %rdx
imulq $0x28, %rdx, %rax
testq %rsi, %rsi
jle 0x135a0
leal -0x1(%rsi), %edi
movq %r14, %rcx
jmp 0x135af
movq 0x10(%r14), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x135cd
leal 0x3(%rsi), %edi
cmpl $0x2, 0x18(%rcx)
jb 0x135cf
movslq %edi, %rdi
imulq $0xa0, %rdi, %rdi
addq %rcx, %rdi
cmpl $0x0, 0x30(%rax,%rdi)
setg %dil
jmp 0x135d1
xorl %ecx, %ecx
xorl %edi, %edi
imulq $0xa0, %rsi, %rsi
testl %edx, %edx
jle 0x135e3
decl %edx
movq %r14, %r8
jmp 0x135f3
movq 0x10(%r14), %r8
movq 0x8(%r8), %r8
testq %r8, %r8
je 0x13610
addl $0x3, %edx
cmpl $0x2, 0x18(%r8)
jb 0x13613
leaq (%r8,%rsi), %r9
movslq %edx, %rdx
imulq $0x28, %rdx, %rdx
cmpl $0x0, 0x30(%rdx,%r9)
setg %dl
jmp 0x13615
xorl %r8d, %r8d
xorl %edx, %edx
xorl %r15d, %r15d
testb %dil, %dil
je 0x13634
movl 0x18(%rcx), %ecx
cmpl $0x5, %ecx
setne %dil
cmpl $0x11, %ecx
setne %cl
andb %dil, %cl
movzbl %cl, %r15d
addq %rsi, %r14
testb %dl, %dl
je 0x1364d
movl 0x18(%r8), %ecx
cmpl $0x5, %ecx
je 0x1364d
cmpl $0x11, %ecx
je 0x1364d
orl $0x2, %r15d
movl 0x30(%rax,%r14), %r12d
addq $0x10db60, %rbx         # imm = 0x10DB60
pushq $0x1
popq %r14
pushq $0x5
popq %r13
leal 0x36(%r15), %esi
testl %r12d, %r12d
jle 0x13685
movq %rbx, %rdi
movl %r14d, %edx
callq 0x30bc
cmpl $0x4, %r15d
movl %r13d, %r15d
sbbl $0x0, %r15d
decl %r12d
jmp 0x13661
movq %rbx, %rdi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30bc