// File: /workspace/github_c_makefile_star2_O0/akumrao[P]videoAnalyzer/encoder/macroblock.c
// Function: block_residual_write_cabac(x264_t*, x264_macroblock_t*, int, int, int*, int)
static void block_residual_write_cabac(x264_t *h, x264_macroblock_t *mb, int i_ctxBlockCat, int i_idx, int *l, int i_count) {LOG_CALL;
    static const int significant_coeff_flag_offset[5] = {0, 15, 29, 44, 47};
    static const int last_significant_coeff_flag_offset[5] = {0, 15, 29, 44, 47};
    static const int coeff_abs_level_m1_offset[5] = {0, 10, 20, 30, 39};

    int i_coeff_abs_m1[16];
    int i_coeff_sign[16];
    int i_coeff = 0;
    int i_last = 0;

    int i_abslevel1 = 0;
    int i_abslevelgt1 = 0;

    int i;

    /* i_ctxBlockCat: 0-> DC 16x16  i_idx = 0
     *                1-> AC 16x16  i_idx = luma4x4idx
     *                2-> Luma4x4   i_idx = luma4x4idx
     *                3-> DC Chroma i_idx = iCbCr
     *                4-> AC Chroma i_idx = 4 * iCbCr + chroma4x4idx
     */

    //fprintf( stderr, "l[] = " );
    for (i = 0; i < i_count; i++)
    {
        //fprintf( stderr, "%d ", l[i] );
        if (l[i] != 0)
        {
            i_coeff_abs_m1[i_coeff] = abs(l[i]) - 1;
            i_coeff_sign[i_coeff] = (l[i] < 0 ? 1 : 0);
            i_coeff++;

            i_last = i;
        }
    }
    //fprintf( stderr, "\n" );

    if (i_coeff == 0)
    {
        /* codec block flag */
        x264_cabac_encode_decision(&h->cabac, 85 + x264_cabac_mb_cbf_ctxidxinc(mb, i_ctxBlockCat, i_idx), 0);
        return;
    }

    /* block coded */
    x264_cabac_encode_decision(&h->cabac, 85 + x264_cabac_mb_cbf_ctxidxinc(mb, i_ctxBlockCat, i_idx), 1);
    for (i = 0; i < i_count - 1; i++)
    {
        int i_ctxIdxInc;

        i_ctxIdxInc = X264_MIN(i, i_count - 2);

        if (l[i] != 0)
        {
            x264_cabac_encode_decision(&h->cabac, 105 + significant_coeff_flag_offset[i_ctxBlockCat] + i_ctxIdxInc, 1);
            x264_cabac_encode_decision(&h->cabac, 166 + last_significant_coeff_flag_offset[i_ctxBlockCat] + i_ctxIdxInc, i == i_last ? 1 : 0);
        } else
        {
            x264_cabac_encode_decision(&h->cabac, 105 + significant_coeff_flag_offset[i_ctxBlockCat] + i_ctxIdxInc, 0);
        }
        if (i == i_last)
        {
            break;
        }
    }

    for (i = i_coeff - 1; i >= 0; i--)
    {
        int i_prefix;
        int i_ctxIdxInc;

        /* write coeff_abs - 1 */

        /* prefix */
        i_prefix = X264_MIN(i_coeff_abs_m1[i], 14);

        i_ctxIdxInc = (i_abslevelgt1 != 0 ? 0 : X264_MIN(4, i_abslevel1 + 1)) + coeff_abs_level_m1_offset[i_ctxBlockCat];
        if (i_prefix == 0)
        {
            x264_cabac_encode_decision(&h->cabac, 227 + i_ctxIdxInc, 0);
        } else
        {
            int j;
            x264_cabac_encode_decision(&h->cabac, 227 + i_ctxIdxInc, 1);
            i_ctxIdxInc = 5 + X264_MIN(4, i_abslevelgt1) + coeff_abs_level_m1_offset[i_ctxBlockCat];
            for (j = 0; j < i_prefix - 1; j++)
            {
                x264_cabac_encode_decision(&h->cabac, 227 + i_ctxIdxInc, 1);
            }
            if (i_prefix < 14)
            {
                x264_cabac_encode_decision(&h->cabac, 227 + i_ctxIdxInc, 0);
            }
        }
        /* suffix */
        if (i_coeff_abs_m1[i] >= 14)
        {
            int k = 0;
            int i_suffix = i_coeff_abs_m1[i] - 14;

            while (i_suffix >= (1 << k))
            {
                x264_cabac_encode_bypass(&h->cabac, 1);
                i_suffix -= 1 << k;
                k++;
            }
            x264_cabac_encode_bypass(&h->cabac, 0);
            while (k--)
            {
                x264_cabac_encode_bypass(&h->cabac, (i_suffix >> k)&0x01);
            }
        }

        /* write sign */
        x264_cabac_encode_bypass(&h->cabac, i_coeff_sign[i]);


        if (i_coeff_abs_m1[i] == 0)
        {
            i_abslevel1++;
        } else
        {
            i_abslevelgt1++;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
leaq 0x9058(%rip), %rdi      # 0x28eb0
leaq 0xfc75(%rip), %rsi      # 0x2fad4
leaq 0x1029a(%rip), %rdx     # 0x30100
movb $0x0, %al
callq 0x4d20
movl $0x0, -0xb4(%rbp)
movl $0x0, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
movl $0x0, -0xc0(%rbp)
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1ff3c
movq -0x20(%rbp), %rax
movslq -0xc4(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x1ff26
movq -0x20(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movl %ecx, %eax
negl %eax
cmovnsl %eax, %ecx
subl $0x1, %ecx
movslq -0xb4(%rbp), %rax
movl %ecx, -0x70(%rbp,%rax,4)
movq -0x20(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movl (%rax,%rcx,4), %edx
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovll %eax, %ecx
movslq -0xb4(%rbp), %rax
movl %ecx, -0xb0(%rbp,%rax,4)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0xb8(%rbp)
jmp 0x1ff28
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x1fe9f
cmpl $0x0, -0xb4(%rbp)
jne 0x1ff7d
movq -0x8(%rbp), %rax
addq $0x10db60, %rax         # imm = 0x10DB60
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x20b50
movq -0xe8(%rbp), %rdi
movl %eax, %esi
addl $0x55, %esi
xorl %edx, %edx
callq 0x3970
jmp 0x203d9
movq -0x8(%rbp), %rax
addq $0x10db60, %rax         # imm = 0x10DB60
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x20b50
movq -0xf0(%rbp), %rdi
movl %eax, %esi
addl $0x55, %esi
movl $0x1, %edx
callq 0x3970
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x200d9
movl -0xc4(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x1ffef
movl -0xc4(%rbp), %eax
movl %eax, -0xf4(%rbp)
jmp 0x1fffb
movl -0x24(%rbp), %eax
subl $0x2, %eax
movl %eax, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
movl %eax, -0xc8(%rbp)
movq -0x20(%rbp), %rax
movslq -0xc4(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x2008a
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movslq -0x14(%rbp), %rcx
leaq 0xfa52(%rip), %rax      # 0x2fa80
movl (%rax,%rcx,4), %esi
addl $0x69, %esi
addl -0xc8(%rbp), %esi
movl $0x1, %edx
callq 0x3970
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movslq -0x14(%rbp), %rcx
leaq 0xfa46(%rip), %rax      # 0x2faa0
movl (%rax,%rcx,4), %esi
addl $0xa6, %esi
addl -0xc8(%rbp), %esi
movl -0xc4(%rbp), %ecx
movl -0xb8(%rbp), %r8d
xorl %edx, %edx
movl $0x1, %eax
cmpl %r8d, %ecx
cmovel %eax, %edx
callq 0x3970
jmp 0x200b3
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movslq -0x14(%rbp), %rcx
leaq 0xf9e0(%rip), %rax      # 0x2fa80
movl (%rax,%rcx,4), %esi
addl $0x69, %esi
addl -0xc8(%rbp), %esi
xorl %edx, %edx
callq 0x3970
movl -0xc4(%rbp), %eax
cmpl -0xb8(%rbp), %eax
jne 0x200c3
jmp 0x200d9
jmp 0x200c5
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x1ffbd
movl -0xb4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xc4(%rbp)
cmpl $0x0, -0xc4(%rbp)
jl 0x203d9
movslq -0xc4(%rbp), %rax
cmpl $0xe, -0x70(%rbp,%rax,4)
jge 0x20116
movslq -0xc4(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
movl %eax, -0xf8(%rbp)
jmp 0x20123
movl $0xe, %eax
movl %eax, -0xf8(%rbp)
jmp 0x20123
movl -0xf8(%rbp), %eax
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xc0(%rbp)
je 0x20142
xorl %eax, %eax
movl %eax, -0xfc(%rbp)
jmp 0x2017c
movl -0xbc(%rbp), %ecx
addl $0x1, %ecx
movl $0x4, %eax
cmpl %ecx, %eax
jge 0x20161
movl $0x4, %eax
movl %eax, -0x100(%rbp)
jmp 0x20170
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x100(%rbp)
movl -0x100(%rbp), %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
movslq -0x14(%rbp), %rdx
leaq 0xf933(%rip), %rcx      # 0x2fac0
addl (%rcx,%rdx,4), %eax
movl %eax, -0xd0(%rbp)
cmpl $0x0, -0xcc(%rbp)
jne 0x201c2
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movl -0xd0(%rbp), %esi
addl $0xe3, %esi
xorl %edx, %edx
callq 0x3970
jmp 0x2029e
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movl -0xd0(%rbp), %esi
addl $0xe3, %esi
movl $0x1, %edx
callq 0x3970
movl $0x4, %eax
cmpl -0xc0(%rbp), %eax
jge 0x201fd
movl $0x4, %eax
movl %eax, -0x104(%rbp)
jmp 0x20209
movl -0xc0(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0x104(%rbp), %eax
addl $0x5, %eax
movslq -0x14(%rbp), %rdx
leaq 0xf8a3(%rip), %rcx      # 0x2fac0
addl (%rcx,%rdx,4), %eax
movl %eax, -0xd0(%rbp)
movl $0x0, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl -0xcc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x20275
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movl -0xd0(%rbp), %esi
addl $0xe3, %esi
movl $0x1, %edx
callq 0x3970
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x20230
cmpl $0xe, -0xcc(%rbp)
jge 0x2029c
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movl -0xd0(%rbp), %esi
addl $0xe3, %esi
xorl %edx, %edx
callq 0x3970
jmp 0x2029e
movslq -0xc4(%rbp), %rax
cmpl $0xe, -0x70(%rbp,%rax,4)
jl 0x20377
movl $0x0, -0xd8(%rbp)
movslq -0xc4(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
subl $0xe, %eax
movl %eax, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
movl -0xd8(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jl 0x2032a
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movl $0x1, %esi
callq 0x3ba0
movl -0xd8(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movl -0xdc(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xdc(%rbp)
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd8(%rbp)
jmp 0x202ce
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
xorl %esi, %esi
callq 0x3ba0
movl -0xd8(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0xd8(%rbp)
cmpl $0x0, %eax
je 0x20375
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movl -0xdc(%rbp), %esi
movl -0xd8(%rbp), %ecx
sarl %cl, %esi
andl $0x1, %esi
callq 0x3ba0
jmp 0x2033c
jmp 0x20377
movq -0x8(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
movslq -0xc4(%rbp), %rax
movl -0xb0(%rbp,%rax,4), %esi
callq 0x3ba0
movslq -0xc4(%rbp), %rax
cmpl $0x0, -0x70(%rbp,%rax,4)
jne 0x203b4
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x203c3
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x203c5
movl -0xc4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x200e8
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)