// File: /workspace/github_c_makefile_star2_O3/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 0xb9f0(%rip), %rdi      # 0x271b4
leaq 0x11f99(%rip), %rsi     # 0x2d764
leaq 0x12527(%rip), %rdx     # 0x2dcf9
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x4a56
movl 0x1c(%r14), %eax
cmpl $0xd, %eax
je 0x1b807
cmpl $0xf, %eax
je 0x1b818
cmpl $0xe, %eax
jne 0x1b7f5
addl %r15d, %r15d
movl %r15d, %r13d
movslq %r13d, %rdx
leaq (%rdx,%rdx,4), %rax
movl 0x30(%r14,%rax,8), %r12d
xorl %eax, %eax
xorl %esi, %esi
jmp 0x1b848
movl %r15d, %r13d
shrl $0x1f, %r13d
addl %r15d, %r13d
andl $-0x2, %r13d
subl %r13d, %r15d
leal (%r15,%r15), %esi
movslq %esi, %rax
leaq (%rax,%rax,4), %rcx
shlq $0x5, %rcx
addq %r14, %rcx
movslq %r13d, %rdx
leaq (%rdx,%rdx,4), %rdi
movl 0x30(%rcx,%rdi,8), %r12d
testl %r15d, %r15d
jle 0x1b848
leal -0x1(,%r15,2), %esi
movq %r14, %rcx
jmp 0x1b857
movq 0x10(%r14), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x1b879
addl $0x3, %esi
cmpl $0x2, 0x18(%rcx)
jb 0x1b87b
movslq %esi, %rsi
leaq (%rsi,%rsi,4), %rsi
shlq $0x5, %rsi
addq %rcx, %rsi
leaq (%rdx,%rdx,4), %rdx
cmpl $0x0, 0x30(%rsi,%rdx,8)
setg %dl
jmp 0x1b87d
xorl %ecx, %ecx
xorl %edx, %edx
testl %r13d, %r13d
jle 0x1b887
decl %r13d
jmp 0x1b898
movq 0x10(%r14), %rsi
movq 0x8(%rsi), %r14
testq %r14, %r14
je 0x1b8bb
addl $0x3, %r13d
cmpl $0x2, 0x18(%r14)
jb 0x1b8be
leaq (%rax,%rax,4), %rax
shlq $0x5, %rax
addq %r14, %rax
movslq %r13d, %rsi
leaq (%rsi,%rsi,4), %rsi
cmpl $0x0, 0x30(%rax,%rsi,8)
setg %al
jmp 0x1b8c0
xorl %r14d, %r14d
xorl %eax, %eax
xorl %r15d, %r15d
testb %dl, %dl
je 0x1b8dc
movl 0x18(%rcx), %ecx
cmpl $0x5, %ecx
setne %dl
cmpl $0x11, %ecx
setne %cl
andb %dl, %cl
movzbl %cl, %r15d
testb %al, %al
je 0x1b8f2
movl 0x18(%r14), %eax
cmpl $0x5, %eax
je 0x1b8f2
cmpl $0x11, %eax
je 0x1b8f2
orl $0x2, %r15d
testl %r12d, %r12d
jle 0x1b929
leaq 0x10db60(%rbx), %r14
incl %r12d
leal 0x36(%r15), %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x3efb
cmpl $0x4, %r15d
movl $0x5, %r15d
sbbl $0x0, %r15d
decl %r12d
cmpl $0x1, %r12d
ja 0x1b901
addq $0x10db60, %rbx         # imm = 0x10DB60
addl $0x36, %r15d
movq %rbx, %rdi
movl %r15d, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3efb