// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %rbx
leaq 0x9ea8(%rip), %rdi      # 0x251b4
leaq 0x10705(%rip), %rsi     # 0x2ba18
leaq 0x10d2a(%rip), %rdx     # 0x2c044
xorl %eax, %eax
callq 0x4c22
movq %rbx, %r10
movq 0x10(%rbx), %rax
testl %r15d, %r15d
je 0x1b3fc
cmpl $0x2, %r15d
ja 0x1b4b8
movslq %r14d, %rcx
leaq 0xc9ab(%rip), %rdx      # 0x27cf0
movzbl (%rcx,%rdx), %edx
leaq 0xc990(%rip), %rsi      # 0x27ce0
movzbl (%rcx,%rsi), %esi
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x4e8, %rax            # imm = 0x4E8
movq (%rax), %r13
movq 0x8(%rax), %r12
leaq 0x9f91(%rip), %rdi      # 0x25300
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x1b3ae
leal -0x1(%rdx), %ecx
andb $0x3, %cl
movzbl %cl, %ecx
leaq (%rdi,%rcx,4), %rcx
movzbl (%rsi,%rcx), %ecx
movl 0x18(%r13), %r8d
cmpl $0x11, %r8d
ja 0x1b65c
movl $0x20024, %r9d          # imm = 0x20024
btl %r8d, %r9d
jae 0x1b65c
testq %r12, %r12
je 0x1b57a
decb %sil
andb $0x3, %sil
movzbl %sil, %ecx
leaq (%rdi,%rdx,4), %rdx
movzbl (%rcx,%rdx), %ecx
movl 0x18(%r12), %edx
cmpl $0x11, %edx
ja 0x1b3e2
movl $0x20024, %esi          # imm = 0x20024
btl %edx, %esi
jb 0x1b57a
shrl $0x2, %ecx
movl 0x2b8(%r12), %edx
sarl %cl, %edx
testl %edx, %edx
jne 0x1b647
jmp 0x1b57a
movq %r15, -0x30(%rbp)
movq (%rax), %r13
movq 0x8(%rax), %r12
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x1b45a
cmpl $0x1, 0x18(%r13)
jne 0x1b45a
leaq 0x9d8f(%rip), %rdi      # 0x251b4
leaq 0x105ec(%rip), %rsi     # 0x2ba18
leaq 0x109c7(%rip), %rdx     # 0x2bdfa
xorl %r15d, %r15d
xorl %eax, %eax
movq %r10, %rbx
callq 0x4c22
movq %rbx, %r10
xorl %ebx, %ebx
cmpl $0x1, 0x2c4(%r13,%r15,4)
sbbl $-0x1, %ebx
incq %r15
cmpq $0x10, %r15
jne 0x1b445
testq %r12, %r12
je 0x1b573
cmpl $0x1, 0x18(%r12)
jne 0x1b576
movq %r10, -0x38(%rbp)
leaq 0x9d3a(%rip), %rdi      # 0x251b4
leaq 0x10597(%rip), %rsi     # 0x2ba18
leaq 0x10972(%rip), %rdx     # 0x2bdfa
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x4c22
movl $0xb1, %eax
cmpl $0x1, (%r12,%rax,4)
sbbl $-0x1, %r14d
incq %rax
cmpq $0xc1, %rax
jne 0x1b497
movq -0x30(%rbp), %r15
movq -0x38(%rbp), %r10
jmp 0x1b57a
cmpl $0x3, %r15d
jne 0x1b5d9
movl %r14d, -0x3c(%rbp)
movq %r15, -0x30(%rbp)
movq (%rax), %r13
movq 0x8(%rax), %r12
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x1b4fc
movl 0x18(%r13), %eax
cmpl $0x11, %eax
ja 0x1b67e
movl $0x20024, %ecx          # imm = 0x20024
btl %eax, %ecx
jae 0x1b67e
testq %r12, %r12
je 0x1b573
movl 0x18(%r12), %eax
cmpl $0x11, %eax
ja 0x1b515
movl $0x20024, %ecx          # imm = 0x20024
btl %eax, %ecx
jb 0x1b576
cmpl $0x0, 0x2b4(%r12)
je 0x1b576
movq %r10, -0x38(%rbp)
movslq -0x3c(%rbp), %rax
shlq $0x4, %rax
leaq (%r12,%rax), %r14
addq $0x304, %r14            # imm = 0x304
leaq 0x9c76(%rip), %rdi      # 0x251b4
leaq 0x104d3(%rip), %rsi     # 0x2ba18
leaq 0x108ae(%rip), %rdx     # 0x2bdfa
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x4c22
movq %r14, %rax
xorl %r14d, %r14d
cmpl $0x1, (%rax,%r15,4)
sbbl $-0x1, %r14d
incq %r15
cmpq $0x4, %r15
jne 0x1b55c
jmp 0x1b4ab
xorl %r12d, %r12d
movq -0x30(%rbp), %r15
testq %r13, %r13
je 0x1b58e
cmpl $0x2, 0x18(%r13)
je 0x1b595
testl %ebx, %ebx
jg 0x1b595
xorl %eax, %eax
jmp 0x1b59a
cmpl $0x2, 0x18(%r10)
jae 0x1b5cb
movl $0x1, %eax
testq %r12, %r12
je 0x1b5ae
cmpl $0x2, 0x18(%r12)
je 0x1b5b5
testl %r14d, %r14d
jle 0x1b5b8
jmp 0x1b5b5
cmpl $0x2, 0x18(%r10)
jae 0x1b5d2
orl $0x2, %eax
leal (%rax,%r15,4), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r13, %r13
jne 0x1b57f
jmp 0x1b586
testq %r12, %r12
jne 0x1b59f
jmp 0x1b5a7
movslq %r14d, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x6e8, %rax            # imm = 0x6E8
movq (%rax), %r13
movq 0x8(%rax), %r12
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x1b61b
movl 0x18(%r13), %ecx
cmpl $0x11, %ecx
ja 0x1b6e2
movl $0x20024, %edx          # imm = 0x20024
btl %ecx, %edx
jae 0x1b6e2
testq %r12, %r12
je 0x1b654
movl 0x18(%r12), %ecx
cmpl $0x11, %ecx
ja 0x1b638
movl $0x20024, %edx          # imm = 0x20024
btl %ecx, %edx
jb 0x1b57a
cmpl $0x2, 0x2b4(%r12)
jne 0x1b57a
movq 0x18(%rax), %rax
movl 0x4(%rax), %r14d
jmp 0x1b57a
xorl %r12d, %r12d
jmp 0x1b57a
shrl $0x2, %ecx
movl 0x2b8(%r13), %r8d
sarl %cl, %r8d
testl %r8d, %r8d
je 0x1b3ae
movq 0x10(%rax), %rcx
movl 0x4(%rcx), %ebx
jmp 0x1b3ae
cmpl $0x0, 0x2b4(%r13)
je 0x1b4fc
movslq -0x3c(%rbp), %rax
shlq $0x4, %rax
addq %r13, %rax
addq $0x304, %rax            # imm = 0x304
movq %rax, -0x38(%rbp)
leaq 0x9b0c(%rip), %rdi      # 0x251b4
leaq 0x10369(%rip), %rsi     # 0x2ba18
leaq 0x10744(%rip), %rdx     # 0x2bdfa
xorl %r15d, %r15d
xorl %eax, %eax
movq %r10, %rbx
callq 0x4c22
movq -0x38(%rbp), %rax
movq %rbx, %r10
xorl %ebx, %ebx
cmpl $0x1, (%rax,%r15,4)
sbbl $-0x1, %ebx
incq %r15
cmpq $0x4, %r15
jne 0x1b6cc
jmp 0x1b4fc
cmpl $0x2, 0x2b4(%r13)
jne 0x1b61b
movq 0x10(%rax), %rcx
movl 0x4(%rcx), %ebx
jmp 0x1b61b