// File: /workspace/github_c_makefile_star2_O2/akumrao[P]videoAnalyzer/encoder/macroblock.c
// Function: x264_cabac_mb_cbf_ctxidxinc(x264_macroblock_t*, int, int)
static int x264_cabac_mb_cbf_ctxidxinc(x264_macroblock_t *mb, int i_ctxBlockCat, int i_idx) {LOG_CALL;
    x264_mb_context_t *ctx = mb->context;
    x264_macroblock_t *a = NULL;
    x264_macroblock_t *b = NULL;
    int i_nza = -1;
    int i_nzb = -1;

    int i_ctxIdxInc = 0;

    if (i_ctxBlockCat == 0)
    {
        a = ctx->mba;
        b = ctx->mbb;

        if (a != NULL && a->i_type == I_16x16)
        {
            i_nza = array_non_zero_count(a->luma16x16_dc, 16);
        }
        if (b != NULL && b->i_type == I_16x16)
        {
            i_nzb = array_non_zero_count(b->luma16x16_dc, 16);
        }
    } else if (i_ctxBlockCat == 1 || i_ctxBlockCat == 2)
    {
        int i8x8a, i8x8b;
        int x, y;

        a = ctx->block[i_idx].mba;
        b = ctx->block[i_idx].mbb;

        x = block_idx_x[i_idx];
        y = block_idx_y[i_idx];

        i8x8a = block_idx_xy[(x - 1)&0x03][y] / 4;
        i8x8b = block_idx_xy[x][(y - 1)&0x03] / 4;

        /* FIXME is &0x01 correct ? */
        if (a != NULL && !IS_SKIP(a->i_type) && a->i_type != I_PCM &&
                ((a->i_cbp_luma >> i8x8a)) != 0)
        {
            i_nza = ctx->block[i_idx].bka->i_non_zero_count;
        }
        if (b != NULL && !IS_SKIP(b->i_type) && b->i_type != I_PCM &&
                ((b->i_cbp_luma >> i8x8b)) != 0)
        {
            i_nzb = ctx->block[i_idx].bkb->i_non_zero_count;
        }
    } else if (i_ctxBlockCat == 3)
    {
        a = ctx->mba;
        b = ctx->mbb;

        if (a != NULL && !IS_SKIP(a->i_type) && a->i_type != I_PCM &&
                a->i_cbp_chroma != 0)
        {
            i_nza = array_non_zero_count(a->chroma_dc[i_idx], 4);
        }
        if (b != NULL && !IS_SKIP(b->i_type) && b->i_type != I_PCM &&
                b->i_cbp_chroma != 0)
        {
            i_nzb = array_non_zero_count(b->chroma_dc[i_idx], 4);
        }
    } else if (i_ctxBlockCat == 4)
    {
        a = ctx->block[16 + i_idx].mba;
        b = ctx->block[16 + i_idx].mbb;

        if (a != NULL && !IS_SKIP(a->i_type) && a->i_type != I_PCM &&
                a->i_cbp_chroma == 2)
        {
            i_nza = ctx->block[16 + i_idx].bka->i_non_zero_count;
        }
        if (b != NULL && !IS_SKIP(b->i_type) && b->i_type != I_PCM &&
                b->i_cbp_chroma == 2)
        {
            i_nzb = ctx->block[16 + i_idx].bkb->i_non_zero_count;
        }
    }

    if ((a == NULL && IS_INTRA(mb->i_type)) || (a != NULL && a->i_type == I_PCM) || i_nza > 0)
    {
        i_ctxIdxInc++;
    }
    if ((b == NULL && IS_INTRA(mb->i_type)) || (b != NULL && b->i_type == I_PCM) || i_nzb > 0)
    {
        i_ctxIdxInc += 2;
    }

    return i_ctxIdxInc + 4 * i_ctxBlockCat;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r13d
movl %esi, %ebx
movq %rdi, %r14
leaq 0x73d0(%rip), %rdi      # 0x1b1b4
leaq 0xdb7d(%rip), %rsi      # 0x21968
leaq 0xe1a2(%rip), %rdx      # 0x21f94
xorl %eax, %eax
callq 0x39ba
movq %r14, %r11
movq %rbx, %r10
movq 0x10(%r14), %rax
testl %r10d, %r10d
je 0x13ed4
cmpl $0x2, %r10d
ja 0x13f45
movslq %r13d, %rcx
leaq 0xa690(%rip), %rdx      # 0x1e4b0
movzbl (%rcx,%rdx), %edx
leaq 0xa675(%rip), %rsi      # 0x1e4a0
movzbl (%rcx,%rsi), %esi
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x4e8, %rax            # imm = 0x4E8
movq (%rax), %rbx
movq 0x8(%rax), %r14
leaq 0x74b6(%rip), %rdi      # 0x1b300
pushq $-0x1
popq %r15
movl %r15d, %r12d
testq %rbx, %rbx
je 0x13e88
leal -0x1(%rdx), %ecx
andb $0x3, %cl
movzbl %cl, %ecx
leaq (%rdi,%rcx,4), %rcx
movzbl (%rsi,%rcx), %ecx
movl 0x18(%rbx), %r8d
cmpl $0x11, %r8d
ja 0x14081
movl $0x20024, %r9d          # imm = 0x20024
btl %r8d, %r9d
movl %r15d, %r12d
jae 0x14081
testq %r14, %r14
je 0x1402e
decb %sil
andb $0x3, %sil
movzbl %sil, %ecx
leaq (%rdi,%rdx,4), %rdx
movzbl (%rcx,%rdx), %ecx
movl 0x18(%r14), %edx
cmpl $0x11, %edx
ja 0x13ebb
movl $0x20024, %esi          # imm = 0x20024
btl %edx, %esi
jb 0x14031
shrl $0x2, %ecx
movl 0x2b8(%r14), %edx
sarl %cl, %edx
testl %edx, %edx
jne 0x14024
jmp 0x14031
movq (%rax), %rbx
movq 0x8(%rax), %r14
pushq $-0x1
popq %r15
movl %r15d, %r12d
testq %rbx, %rbx
je 0x13f0e
cmpl $0x1, 0x18(%rbx)
movl %r15d, %r12d
jne 0x13f0e
leaq 0x2c4(%rbx), %rdi
pushq $0x10
popq %rsi
movq %r10, %r12
movq %r11, %r13
callq 0x1145a
movq %r13, %r11
movq %r12, %r10
movl %eax, %r12d
testq %r14, %r14
je 0x1402e
cmpl $0x1, 0x18(%r14)
jne 0x14031
leaq 0x2c4(%r14), %rdi
pushq $0x10
popq %rsi
movq %r10, %r15
movq %r11, %r13
callq 0x1145a
movq %r13, %r11
movq %r15, %r10
movl %eax, %r15d
jmp 0x14031
cmpl $0x3, %r10d
jne 0x13fc2
movq (%rax), %rbx
movq 0x8(%rax), %r14
pushq $-0x1
popq %r15
movl %r15d, %r12d
testq %rbx, %rbx
je 0x13f7b
movl 0x18(%rbx), %eax
cmpl $0x11, %eax
ja 0x140a7
movl $0x20024, %ecx          # imm = 0x20024
btl %eax, %ecx
movl %r15d, %r12d
jae 0x140a7
testq %r14, %r14
je 0x1402e
movl 0x18(%r14), %eax
cmpl $0x11, %eax
ja 0x13f9b
movl $0x20024, %ecx          # imm = 0x20024
btl %eax, %ecx
jb 0x14031
cmpl $0x0, 0x2b4(%r14)
je 0x14031
movslq %r13d, %rax
shlq $0x4, %rax
leaq (%r14,%rax), %rdi
addq $0x304, %rdi            # imm = 0x304
pushq $0x4
jmp 0x13f2b
movslq %r13d, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x6e8, %rax            # imm = 0x6E8
movq (%rax), %rbx
movq 0x8(%rax), %r14
pushq $-0x1
popq %r15
movl %r15d, %r12d
testq %rbx, %rbx
je 0x14002
movl 0x18(%rbx), %ecx
cmpl $0x11, %ecx
ja 0x140e7
movl $0x20024, %edx          # imm = 0x20024
btl %ecx, %edx
movl %r15d, %r12d
jae 0x140e7
testq %r14, %r14
je 0x1402e
movl 0x18(%r14), %ecx
cmpl $0x11, %ecx
ja 0x1401a
movl $0x20024, %edx          # imm = 0x20024
btl %ecx, %edx
jb 0x14031
cmpl $0x2, 0x2b4(%r14)
jne 0x14031
movq 0x18(%rax), %rax
movl 0x4(%rax), %r15d
jmp 0x14031
xorl %r14d, %r14d
testq %rbx, %rbx
je 0x1403e
cmpl $0x2, 0x18(%rbx)
jne 0x14045
jmp 0x1404e
cmpl $0x2, 0x18(%r11)
jb 0x1404e
testl %r12d, %r12d
jg 0x1404e
xorl %eax, %eax
jmp 0x14051
pushq $0x1
popq %rax
testq %r14, %r14
je 0x1405f
cmpl $0x2, 0x18(%r14)
jne 0x14066
jmp 0x1406b
cmpl $0x2, 0x18(%r11)
jb 0x1406b
testl %r15d, %r15d
jle 0x1406e
orl $0x2, %eax
leal (%rax,%r10,4), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shrl $0x2, %ecx
movl 0x2b8(%rbx), %r8d
sarl %cl, %r8d
movl %r15d, %r12d
testl %r8d, %r8d
je 0x13e88
movq 0x10(%rax), %rcx
movl 0x4(%rcx), %r12d
jmp 0x13e88
cmpl $0x0, 0x2b4(%rbx)
movl %r15d, %r12d
je 0x13f7b
movslq %r13d, %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0x304, %rdi            # imm = 0x304
pushq $0x4
popq %rsi
movq %r10, -0x30(%rbp)
movq %r11, %r12
callq 0x1145a
movq %r12, %r11
movq -0x30(%rbp), %r10
movl %eax, %r12d
jmp 0x13f7b
cmpl $0x2, 0x2b4(%rbx)
movl %r15d, %r12d
jne 0x14002
movq 0x10(%rax), %rcx
movl 0x4(%rcx), %r12d
jmp 0x14002