// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
leaq 0x8347(%rip), %rdi      # 0x28eb0
leaq 0xef64(%rip), %rsi      # 0x2fad4
leaq 0xf5a4(%rip), %rdx      # 0x3011b
movb $0x0, %al
callq 0x4d20
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x34(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x20c23
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x20bf5
movq -0x20(%rbp), %rax
cmpl $0x1, 0x18(%rax)
jne 0x20bf5
movq -0x20(%rbp), %rdi
addq $0x2c4, %rdi            # imm = 0x2C4
movl $0x10, %esi
callq 0x1c5f0
movl %eax, -0x2c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x20c1e
movq -0x28(%rbp), %rax
cmpl $0x1, 0x18(%rax)
jne 0x20c1e
movq -0x28(%rbp), %rdi
addq $0x2c4, %rdi            # imm = 0x2C4
movl $0x10, %esi
callq 0x1c5f0
movl %eax, -0x30(%rbp)
jmp 0x20f70
cmpl $0x1, -0xc(%rbp)
je 0x20c33
cmpl $0x2, -0xc(%rbp)
jne 0x20d9f
movq -0x18(%rbp), %rax
addq $0x4e8, %rax            # imm = 0x4E8
movslq -0x10(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x4e8, %rax            # imm = 0x4E8
movslq -0x10(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movslq -0x10(%rbp), %rcx
leaq 0xc9e9(%rip), %rax      # 0x2d660
movzbl (%rax,%rcx), %eax
movl %eax, -0x40(%rbp)
movslq -0x10(%rbp), %rcx
leaq 0xc9e7(%rip), %rax      # 0x2d670
movzbl (%rax,%rcx), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
subl $0x1, %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0xedcd(%rip), %rax      # 0x2fa70
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x44(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, -0x38(%rbp)
movslq -0x40(%rbp), %rcx
leaq 0xeda8(%rip), %rax      # 0x2fa70
shlq $0x2, %rcx
addq %rcx, %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
andl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x20d42
movq -0x20(%rbp), %rax
cmpl $0x5, 0x18(%rax)
je 0x20d42
movq -0x20(%rbp), %rax
cmpl $0x11, 0x18(%rax)
je 0x20d42
movq -0x20(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x20d42
movq -0x20(%rbp), %rax
movl 0x2b8(%rax), %eax
movl -0x38(%rbp), %ecx
sarl %cl, %eax
cmpl $0x0, %eax
je 0x20d42
movq -0x18(%rbp), %rax
addq $0x4e8, %rax            # imm = 0x4E8
movslq -0x10(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x20d9a
movq -0x28(%rbp), %rax
cmpl $0x5, 0x18(%rax)
je 0x20d9a
movq -0x28(%rbp), %rax
cmpl $0x11, 0x18(%rax)
je 0x20d9a
movq -0x28(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x20d9a
movq -0x28(%rbp), %rax
movl 0x2b8(%rax), %eax
movl -0x3c(%rbp), %ecx
sarl %cl, %eax
cmpl $0x0, %eax
je 0x20d9a
movq -0x18(%rbp), %rax
addq $0x4e8, %rax            # imm = 0x4E8
movslq -0x10(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x20f6e
cmpl $0x3, -0xc(%rbp)
jne 0x20e6f
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x20e15
movq -0x20(%rbp), %rax
cmpl $0x5, 0x18(%rax)
je 0x20e15
movq -0x20(%rbp), %rax
cmpl $0x11, 0x18(%rax)
je 0x20e15
movq -0x20(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x20e15
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2b4(%rax)
je 0x20e15
movq -0x20(%rbp), %rdi
addq $0x304, %rdi            # imm = 0x304
movslq -0x10(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movl $0x4, %esi
callq 0x1c5f0
movl %eax, -0x2c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x20e6a
movq -0x28(%rbp), %rax
cmpl $0x5, 0x18(%rax)
je 0x20e6a
movq -0x28(%rbp), %rax
cmpl $0x11, 0x18(%rax)
je 0x20e6a
movq -0x28(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x20e6a
movq -0x28(%rbp), %rax
cmpl $0x0, 0x2b4(%rax)
je 0x20e6a
movq -0x28(%rbp), %rdi
addq $0x304, %rdi            # imm = 0x304
movslq -0x10(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movl $0x4, %esi
callq 0x1c5f0
movl %eax, -0x30(%rbp)
jmp 0x20f6c
cmpl $0x4, -0xc(%rbp)
jne 0x20f6a
movq -0x18(%rbp), %rax
addq $0x4e8, %rax            # imm = 0x4E8
movl -0x10(%rbp), %ecx
addl $0x10, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x4e8, %rax            # imm = 0x4E8
movl -0x10(%rbp), %ecx
addl $0x10, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x20f12
movq -0x20(%rbp), %rax
cmpl $0x5, 0x18(%rax)
je 0x20f12
movq -0x20(%rbp), %rax
cmpl $0x11, 0x18(%rax)
je 0x20f12
movq -0x20(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x20f12
movq -0x20(%rbp), %rax
cmpl $0x2, 0x2b4(%rax)
jne 0x20f12
movq -0x18(%rbp), %rax
addq $0x4e8, %rax            # imm = 0x4E8
movl -0x10(%rbp), %ecx
addl $0x10, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x20f68
movq -0x28(%rbp), %rax
cmpl $0x5, 0x18(%rax)
je 0x20f68
movq -0x28(%rbp), %rax
cmpl $0x11, 0x18(%rax)
je 0x20f68
movq -0x28(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x20f68
movq -0x28(%rbp), %rax
cmpl $0x2, 0x2b4(%rax)
jne 0x20f68
movq -0x18(%rbp), %rax
addq $0x4e8, %rax            # imm = 0x4E8
movl -0x10(%rbp), %ecx
addl $0x10, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x20f6a
jmp 0x20f6c
jmp 0x20f6e
jmp 0x20f70
cmpq $0x0, -0x20(%rbp)
jne 0x20f8b
movq -0x8(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x20fa2
movq -0x8(%rbp), %rax
cmpl $0x1, 0x18(%rax)
je 0x20fa2
cmpq $0x0, -0x20(%rbp)
je 0x20f9c
movq -0x20(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x20fa2
cmpl $0x0, -0x2c(%rbp)
jle 0x20fab
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x20fc6
movq -0x8(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x20fdd
movq -0x8(%rbp), %rax
cmpl $0x1, 0x18(%rax)
je 0x20fdd
cmpq $0x0, -0x28(%rbp)
je 0x20fd7
movq -0x28(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x20fdd
cmpl $0x0, -0x30(%rbp)
jle 0x20fe6
movl -0x34(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0xc(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)