// File: /workspace/github_c_makefile_star2_O3/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 0xb1a1(%rip), %rdi      # 0x271b4
leaq 0x1174a(%rip), %rsi     # 0x2d764
leaq 0x11d6f(%rip), %rdx     # 0x2dd90
xorl %eax, %eax
callq 0x4a56
movq %rbx, %r10
movq 0x10(%rbx), %rax
testl %r15d, %r15d
je 0x1c103
cmpl $0x2, %r15d
ja 0x1c1bf
movslq %r14d, %rcx
leaq 0xdff4(%rip), %rdx      # 0x2a040
movzbl (%rcx,%rdx), %edx
leaq 0xdfd9(%rip), %rsi      # 0x2a030
movzbl (%rcx,%rsi), %esi
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x4e8, %rax            # imm = 0x4E8
movq (%rax), %r13
movq 0x8(%rax), %r12
leaq 0xb28a(%rip), %rdi      # 0x27300
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x1c0b5
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 0x1c349
movl $0x20024, %r9d          # imm = 0x20024
btl %r8d, %r9d
jae 0x1c349
testq %r12, %r12
je 0x1c2f3
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 0x1c0e9
movl $0x20024, %esi          # imm = 0x20024
btl %edx, %esi
jb 0x1c2f6
shrl $0x2, %ecx
movl 0x2b8(%r12), %edx
sarl %cl, %edx
testl %edx, %edx
jne 0x1c2e9
jmp 0x1c2f6
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 0x1c161
cmpl $0x1, 0x18(%r13)
jne 0x1c161
leaq 0xb088(%rip), %rdi      # 0x271b4
leaq 0x11631(%rip), %rsi     # 0x2d764
leaq 0x11a0c(%rip), %rdx     # 0x2db46
xorl %r15d, %r15d
xorl %eax, %eax
movq %r10, %rbx
callq 0x4a56
movq %rbx, %r10
xorl %ebx, %ebx
cmpl $0x1, 0x2c4(%r13,%r15,4)
sbbl $-0x1, %ebx
incq %r15
cmpq $0x10, %r15
jne 0x1c14c
testq %r12, %r12
je 0x1c27a
cmpl $0x1, 0x18(%r12)
jne 0x1c27d
movq %r10, -0x38(%rbp)
leaq 0xb033(%rip), %rdi      # 0x271b4
leaq 0x115dc(%rip), %rsi     # 0x2d764
leaq 0x119b7(%rip), %rdx     # 0x2db46
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x4a56
movl $0xb1, %eax
cmpl $0x1, (%r12,%rax,4)
sbbl $-0x1, %r14d
incq %rax
cmpq $0xc1, %rax
jne 0x1c19e
movq -0x30(%rbp), %r15
movq -0x38(%rbp), %r10
jmp 0x1c2f6
cmpl $0x3, %r15d
jne 0x1c283
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 0x1c203
movl 0x18(%r13), %eax
cmpl $0x11, %eax
ja 0x1c36b
movl $0x20024, %ecx          # imm = 0x20024
btl %eax, %ecx
jae 0x1c36b
testq %r12, %r12
je 0x1c27a
movl 0x18(%r12), %eax
cmpl $0x11, %eax
ja 0x1c21c
movl $0x20024, %ecx          # imm = 0x20024
btl %eax, %ecx
jb 0x1c27d
cmpl $0x0, 0x2b4(%r12)
je 0x1c27d
movq %r10, -0x38(%rbp)
movslq -0x3c(%rbp), %rax
shlq $0x4, %rax
leaq (%r12,%rax), %r14
addq $0x304, %r14            # imm = 0x304
leaq 0xaf6f(%rip), %rdi      # 0x271b4
leaq 0x11518(%rip), %rsi     # 0x2d764
leaq 0x118f3(%rip), %rdx     # 0x2db46
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x4a56
movq %r14, %rax
xorl %r14d, %r14d
cmpl $0x1, (%rax,%r15,4)
sbbl $-0x1, %r14d
incq %r15
cmpq $0x4, %r15
jne 0x1c263
jmp 0x1c1b2
xorl %r12d, %r12d
movq -0x30(%rbp), %r15
jmp 0x1c2f6
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 0x1c2c5
movl 0x18(%r13), %ecx
cmpl $0x11, %ecx
ja 0x1c3cf
movl $0x20024, %edx          # imm = 0x20024
btl %ecx, %edx
jae 0x1c3cf
testq %r12, %r12
je 0x1c2f3
movl 0x18(%r12), %ecx
cmpl $0x11, %ecx
ja 0x1c2de
movl $0x20024, %edx          # imm = 0x20024
btl %ecx, %edx
jb 0x1c2f6
cmpl $0x2, 0x2b4(%r12)
jne 0x1c2f6
movq 0x18(%rax), %rax
movl 0x4(%rax), %r14d
jmp 0x1c2f6
xorl %r12d, %r12d
testq %r13, %r13
je 0x1c304
cmpl $0x2, 0x18(%r13)
jne 0x1c30b
jmp 0x1c313
cmpl $0x2, 0x18(%r10)
jb 0x1c313
testl %ebx, %ebx
jg 0x1c313
xorl %eax, %eax
jmp 0x1c318
movl $0x1, %eax
testq %r12, %r12
je 0x1c327
cmpl $0x2, 0x18(%r12)
jne 0x1c32e
jmp 0x1c333
cmpl $0x2, 0x18(%r10)
jb 0x1c333
testl %r14d, %r14d
jle 0x1c336
orl $0x2, %eax
leal (%rax,%r15,4), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shrl $0x2, %ecx
movl 0x2b8(%r13), %r8d
sarl %cl, %r8d
testl %r8d, %r8d
je 0x1c0b5
movq 0x10(%rax), %rcx
movl 0x4(%rcx), %ebx
jmp 0x1c0b5
cmpl $0x0, 0x2b4(%r13)
je 0x1c203
movslq -0x3c(%rbp), %rax
shlq $0x4, %rax
addq %r13, %rax
addq $0x304, %rax            # imm = 0x304
movq %rax, -0x38(%rbp)
leaq 0xae1f(%rip), %rdi      # 0x271b4
leaq 0x113c8(%rip), %rsi     # 0x2d764
leaq 0x117a3(%rip), %rdx     # 0x2db46
xorl %r15d, %r15d
xorl %eax, %eax
movq %r10, %rbx
callq 0x4a56
movq -0x38(%rbp), %rax
movq %rbx, %r10
xorl %ebx, %ebx
cmpl $0x1, (%rax,%r15,4)
sbbl $-0x1, %ebx
incq %r15
cmpq $0x4, %r15
jne 0x1c3b9
jmp 0x1c203
cmpl $0x2, 0x2b4(%r13)
jne 0x1c2c5
movq 0x10(%rax), %rcx
movl 0x4(%rcx), %ebx
jmp 0x1c2c5
nopl (%rax)