// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
leaq 0x9ae3(%rip), %rdi      # 0x28eb0
leaq 0x10700(%rip), %rsi     # 0x2fad4
leaq 0x10ca9(%rip), %rdx     # 0x30084
movb $0x0, %al
callq 0x4d20
movl $0x0, -0x2c(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
xorl %edx, %edx
leaq -0x3c(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x1ab20
movq -0x10(%rbp), %rax
addq $0x30, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x1f467
movl -0x44(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1f4ad
movq -0x20(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x1f4ad
movq -0x20(%rbp), %rax
cmpl $0x1, 0x18(%rax)
je 0x1f4ad
movq -0x20(%rbp), %rax
addq $0x30, %rax
movslq -0x44(%rbp), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x48(%rbp)
jge 0x1f4dd
movl -0x48(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x1f523
movq -0x28(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x1f523
movq -0x28(%rbp), %rax
cmpl $0x1, 0x18(%rax)
je 0x1f523
movq -0x28(%rbp), %rax
addq $0x30, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movslq -0x48(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x1f546
movq -0x20(%rbp), %rax
cmpl $0x5, 0x18(%rax)
je 0x1f546
movq -0x20(%rbp), %rax
cmpl $0x11, 0x18(%rax)
je 0x1f546
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x38(%rbp)
jle 0x1f569
movq -0x28(%rbp), %rax
cmpl $0x5, 0x18(%rax)
je 0x1f569
movq -0x28(%rbp), %rax
cmpl $0x11, 0x18(%rax)
je 0x1f569
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1f56b
cmpl $0x0, -0x30(%rbp)
jle 0x1f5ad
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movl -0x2c(%rbp), %esi
addl $0x36, %esi
movl $0x1, %edx
callq 0x3970
cmpl $0x4, -0x2c(%rbp)
jge 0x1f59b
movl $0x4, -0x2c(%rbp)
jmp 0x1f5a2
movl $0x5, -0x2c(%rbp)
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1f56b
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movl -0x2c(%rbp), %esi
addl $0x36, %esi
xorl %edx, %edx
callq 0x3970
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)