// File: /workspace/github_c_makefile_star2_O0/akumrao[P]videoAnalyzer/encoder/macroblock.c
// Function: block_residual_write_cavlc(x264_t*, bs_s*, x264_macroblock_t*, int, int*, int)
static void block_residual_write_cavlc(x264_t *h, bs_t *s, x264_macroblock_t *mb, int i_idx, int *l, int i_count) {LOG_CALL;
    int level[16], run[16];
    int i_total, i_trailing;
    int i_total_zero;
    int i_last;
    unsigned int i_sign;

    int i;
    int i_zero_left;
    int i_suffix_length;

    /* first find i_last */
    i_last = i_count - 1;
    while (i_last >= 0 && l[i_last] == 0)
    {
        i_last--;
    }

    i_sign = 0;
    i_total = 0;
    i_trailing = 0;
    i_total_zero = 0;

    if (i_last >= 0)
    {
        int b_trailing = 1;
        int idx = 0;

        /* level and run and total */
        while (i_last >= 0)
        {
            level[idx] = l[i_last--];

            run[idx] = 0;
            while (i_last >= 0 && l[i_last] == 0)
            {
                run[idx]++;
                i_last--;
            }

            i_total++;
            i_total_zero += run[idx];

            if (b_trailing && abs(level[idx]) == 1 && i_trailing < 3)
            {
                i_sign <<= 1;
                if (level[idx] < 0)
                {
                    i_sign |= 0x01;
                }

                i_trailing++;
            } else
            {
                b_trailing = 0;
            }

            idx++;
        }
    }

    /* total/trailing */
    if (i_idx == BLOCK_INDEX_CHROMA_DC)
    {
        bs_write_vlc(s, x264_coeff_token[4][i_total * 4 + i_trailing], "vlc BLOCK_INDEX_CHROMA_DC x264_coeff_token");
    } else
    {
        /* x264_mb_predict_non_zero_code return 0 <-> (16+16+1)>>1 = 16 */
        static const int ct_index[17] = {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};
        int nC;

        if (i_idx == BLOCK_INDEX_LUMA_DC)
        {
            nC = x264_mb_predict_non_zero_code(h, mb, 0);
        } else
        {
            nC = x264_mb_predict_non_zero_code(h, mb, i_idx);
        }

        bs_write_vlc(s, x264_coeff_token[ct_index[nC]][i_total * 4 + i_trailing],"vlc x264_coeff_token");
    }

    if (i_total <= 0)
    {
        return;
    }

    i_suffix_length = i_total > 10 && i_trailing < 3 ? 1 : 0;
    if (i_trailing > 0)
    {
        bs_write(s, i_trailing, i_sign,"i_trailing");
    }
    for (i = i_trailing; i < i_total; i++)
    {
        int i_level_code;

        /* calculate level code */
        if (level[i] < 0)
        {
            i_level_code = -2 * level[i] - 1;
        } else /* if( level[i] > 0 ) */
        {
            i_level_code = 2 * level[i] - 2;
        }
        if (i == i_trailing && i_trailing < 3)
        {
            i_level_code -= 2; /* as level[i] can't be 1 for the first one if i_trailing < 3 */
        }

        if ((i_level_code >> i_suffix_length) < 14)
        {
            bs_write_vlc(s, x264_level_prefix[i_level_code >> i_suffix_length],"vlc x264_level_prefix");
            if (i_suffix_length > 0)
            {
                bs_write(s, i_suffix_length, i_level_code,"i_suffix_length");
            }
        } else if (i_suffix_length == 0 && i_level_code < 30)
        {
            bs_write_vlc(s, x264_level_prefix[14],"vlc x264_level_prefix");
            bs_write(s, 4, i_level_code - 14,"i_level_code");
        } else if (i_suffix_length > 0 && (i_level_code >> i_suffix_length) == 14)
        {
            bs_write_vlc(s, x264_level_prefix[14],"vlc x264_level_prefix");
            bs_write(s, i_suffix_length, i_level_code,"i_suffix_length");
        } else
        {
            bs_write_vlc(s, x264_level_prefix[15],"vlc x264_level_prefix");
            i_level_code -= 15 << i_suffix_length;
            if (i_suffix_length == 0)
            {
                i_level_code -= 15;
            }

            if (i_level_code >= (1 << 12) || i_level_code < 0)
            {
                fprintf(stderr, "OVERFLOW levelcode=%d\n", i_level_code);
            }

            bs_write(s, 12, i_level_code,"i_level_code"); /* check overflow ?? */
        }

        if (i_suffix_length == 0)
        {
            i_suffix_length++;
        }
        if (abs(level[i]) > (3 << (i_suffix_length - 1)) && i_suffix_length < 6)
        {
            i_suffix_length++;
        }
    }

    if (i_total < i_count)
    {
        if (i_idx == BLOCK_INDEX_CHROMA_DC)
        {
            bs_write_vlc(s, x264_total_zeros_dc[i_total - 1][i_total_zero],"vlc x264_total_zeros_dc");
        } else
        {
            bs_write_vlc(s, x264_total_zeros[i_total - 1][i_total_zero],"vlc x264_total_zeros");
        }
    }

    for (i = 0, i_zero_left = i_total_zero; i < i_total - 1; i++)
    {
        int i_zl;

        if (i_zero_left <= 0)
        {
            break;
        }

        i_zl = X264_MIN(i_zero_left - 1, 6);

        bs_write_vlc(s, x264_run_before[i_zl][run[i]],"vlc x264_run_before");

        i_zero_left -= run[i];
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
leaq 0xb367(%rip), %rdi      # 0x28eb0
leaq 0x11f84(%rip), %rsi     # 0x2fad4
leaq 0x123a2(%rip), %rdx     # 0x2fef9
movb $0x0, %al
callq 0x4d20
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xc0(%rbp)
xorl %eax, %eax
cmpl $0x0, -0xc0(%rbp)
movb %al, -0x12d(%rbp)
jl 0x1db93
movq -0x28(%rbp), %rax
movslq -0xc0(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
sete %al
movb %al, -0x12d(%rbp)
movb -0x12d(%rbp), %al
testb $0x1, %al
jne 0x1db9f
jmp 0x1dbb0
movl -0xc0(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x1db6a
movl $0x0, -0xc4(%rbp)
movl $0x0, -0xb4(%rbp)
movl $0x0, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
cmpl $0x0, -0xc0(%rbp)
jl 0x1dd4a
movl $0x1, -0xd4(%rbp)
movl $0x0, -0xd8(%rbp)
cmpl $0x0, -0xc0(%rbp)
jl 0x1dd48
movq -0x28(%rbp), %rax
movl -0xc0(%rbp), %ecx
movl %ecx, %edx
addl $-0x1, %edx
movl %edx, -0xc0(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movslq -0xd8(%rbp), %rax
movl %ecx, -0x70(%rbp,%rax,4)
movslq -0xd8(%rbp), %rax
movl $0x0, -0xb0(%rbp,%rax,4)
xorl %eax, %eax
cmpl $0x0, -0xc0(%rbp)
movb %al, -0x12e(%rbp)
jl 0x1dc67
movq -0x28(%rbp), %rax
movslq -0xc0(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
sete %al
movb %al, -0x12e(%rbp)
movb -0x12e(%rbp), %al
testb $0x1, %al
jne 0x1dc73
jmp 0x1dc9c
movslq -0xd8(%rbp), %rax
movl -0xb0(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0xb0(%rbp,%rax,4)
movl -0xc0(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x1dc3e
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
movslq -0xd8(%rbp), %rax
movl -0xb0(%rbp,%rax,4), %eax
addl -0xbc(%rbp), %eax
movl %eax, -0xbc(%rbp)
cmpl $0x0, -0xd4(%rbp)
je 0x1dd2a
movslq -0xd8(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jne 0x1dd2a
cmpl $0x3, -0xb8(%rbp)
jge 0x1dd2a
movl -0xc4(%rbp), %eax
shll %eax
movl %eax, -0xc4(%rbp)
movslq -0xd8(%rbp), %rax
cmpl $0x0, -0x70(%rbp,%rax,4)
jge 0x1dd19
movl -0xc4(%rbp), %eax
orl $0x1, %eax
movl %eax, -0xc4(%rbp)
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x1dd34
movl $0x0, -0xd4(%rbp)
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd8(%rbp)
jmp 0x1dbf9
jmp 0x1dd4a
cmpl $-0x1, -0x1c(%rbp)
jne 0x1dd94
movq -0x10(%rbp), %rdi
movl -0xb4(%rbp), %eax
shll $0x2, %eax
addl -0xb8(%rbp), %eax
movslq %eax, %rcx
leaq 0x10793(%rip), %rax     # 0x2e500
movq 0x880(%rax,%rcx,8), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rsi
leaq 0x1218a(%rip), %rdx     # 0x2ff14
callq 0x20950
jmp 0x1de1e
cmpl $-0x2, -0x1c(%rbp)
jne 0x1ddb1
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
callq 0x7520
movl %eax, -0xe4(%rbp)
jmp 0x1ddc7
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x7520
movl %eax, -0xe4(%rbp)
movq -0x10(%rbp), %rdi
movslq -0xe4(%rbp), %rcx
leaq 0x105f7(%rip), %rax     # 0x2e3d0
movslq (%rax,%rcx,4), %rcx
leaq 0x1071c(%rip), %rax     # 0x2e500
imulq $0x220, %rcx, %rcx      # imm = 0x220
addq %rcx, %rax
movl -0xb4(%rbp), %ecx
shll $0x2, %ecx
addl -0xb8(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xec(%rbp)
movq -0xec(%rbp), %rsi
leaq 0x12126(%rip), %rdx     # 0x2ff3f
callq 0x20950
cmpl $0x0, -0xb4(%rbp)
jg 0x1de2c
jmp 0x1e2e2
xorl %eax, %eax
cmpl $0xa, -0xb4(%rbp)
movb %al, -0x12f(%rbp)
jle 0x1de4d
cmpl $0x3, -0xb8(%rbp)
setl %al
movb %al, -0x12f(%rbp)
movb -0x12f(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0xd0(%rbp)
cmpl $0x0, -0xb8(%rbp)
jle 0x1de8b
movq -0x10(%rbp), %rdi
movl -0xb8(%rbp), %esi
movl -0xc4(%rbp), %edx
leaq 0x120ce(%rip), %rcx     # 0x2ff54
callq 0x1d890
movl -0xb8(%rbp), %eax
movl %eax, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
cmpl -0xb4(%rbp), %eax
jge 0x1e15a
movslq -0xc8(%rbp), %rax
cmpl $0x0, -0x70(%rbp,%rax,4)
jge 0x1ded1
movslq -0xc8(%rbp), %rax
imull $0xfffffffe, -0x70(%rbp,%rax,4), %eax # imm = 0xFFFFFFFE
subl $0x1, %eax
movl %eax, -0xf0(%rbp)
jmp 0x1dee7
movslq -0xc8(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
shll %eax
subl $0x2, %eax
movl %eax, -0xf0(%rbp)
movl -0xc8(%rbp), %eax
cmpl -0xb8(%rbp), %eax
jne 0x1df0d
cmpl $0x3, -0xb8(%rbp)
jge 0x1df0d
movl -0xf0(%rbp), %eax
subl $0x2, %eax
movl %eax, -0xf0(%rbp)
movl -0xf0(%rbp), %eax
movl -0xd0(%rbp), %ecx
sarl %cl, %eax
cmpl $0xe, %eax
jge 0x1df84
movq -0x10(%rbp), %rdi
movl -0xf0(%rbp), %eax
movl -0xd0(%rbp), %ecx
sarl %cl, %eax
movslq %eax, %rcx
leaq 0x104e4(%rip), %rax     # 0x2e420
movq (%rax,%rcx,8), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rsi
leaq 0x1200a(%rip), %rdx     # 0x2ff5f
callq 0x20950
cmpl $0x0, -0xd0(%rbp)
jle 0x1df7f
movq -0x10(%rbp), %rdi
movl -0xd0(%rbp), %esi
movl -0xf0(%rbp), %edx
leaq 0xde34(%rip), %rcx      # 0x2bdae
callq 0x1d890
jmp 0x1e0ec
cmpl $0x0, -0xd0(%rbp)
jne 0x1dfde
cmpl $0x1e, -0xf0(%rbp)
jge 0x1dfde
movq -0x10(%rbp), %rdi
movq 0x104ef(%rip), %rax     # 0x2e490
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rsi
leaq 0x11fa9(%rip), %rdx     # 0x2ff5f
callq 0x20950
movq -0x10(%rbp), %rdi
movl -0xf0(%rbp), %edx
subl $0xe, %edx
movl $0x4, %esi
leaq 0xddea(%rip), %rcx      # 0x2bdbe
callq 0x1d890
jmp 0x1e0ea
cmpl $0x0, -0xd0(%rbp)
jle 0x1e040
movl -0xf0(%rbp), %eax
movl -0xd0(%rbp), %ecx
sarl %cl, %eax
cmpl $0xe, %eax
jne 0x1e040
movq -0x10(%rbp), %rdi
movq 0x1048b(%rip), %rax     # 0x2e490
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rsi
leaq 0x11f45(%rip), %rdx     # 0x2ff5f
callq 0x20950
movq -0x10(%rbp), %rdi
movl -0xd0(%rbp), %esi
movl -0xf0(%rbp), %edx
leaq 0xdd78(%rip), %rcx      # 0x2bdae
callq 0x1d890
jmp 0x1e0e8
movq -0x10(%rbp), %rdi
movq 0x1044d(%rip), %rax     # 0x2e498
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rsi
leaq 0x11eff(%rip), %rdx     # 0x2ff5f
callq 0x20950
movl -0xd0(%rbp), %ecx
movl $0xf, %eax
shll %cl, %eax
movl %eax, %ecx
movl -0xf0(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xf0(%rbp)
cmpl $0x0, -0xd0(%rbp)
jne 0x1e09a
movl -0xf0(%rbp), %eax
subl $0xf, %eax
movl %eax, -0xf0(%rbp)
cmpl $0x1000, -0xf0(%rbp)    # imm = 0x1000
jge 0x1e0af
cmpl $0x0, -0xf0(%rbp)
jge 0x1e0cd
movq 0x17f1a(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
movl -0xf0(%rbp), %edx
leaq 0x11eaf(%rip), %rsi     # 0x2ff75
movb $0x0, %al
callq 0x2160
movq -0x10(%rbp), %rdi
movl -0xf0(%rbp), %edx
movl $0xc, %esi
leaq 0xdcdb(%rip), %rcx      # 0x2bdbe
callq 0x1d890
jmp 0x1e0ea
jmp 0x1e0ec
cmpl $0x0, -0xd0(%rbp)
jne 0x1e104
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
movslq -0xc8(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl -0xd0(%rbp), %ecx
subl $0x1, %ecx
movl $0x3, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jle 0x1e144
cmpl $0x6, -0xd0(%rbp)
jge 0x1e144
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x1e146
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x1de97
movl -0xb4(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x1e1f9
cmpl $-0x1, -0x1c(%rbp)
jne 0x1e1b4
movq -0x10(%rbp), %rdi
movl -0xb4(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x1031a(%rip), %rax     # 0x2e4a0
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0xbc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rsi
leaq 0x11ddf(%rip), %rdx     # 0x2ff8c
callq 0x20950
jmp 0x1e1f7
movq -0x10(%rbp), %rdi
movl -0xb4(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x10dd5(%rip), %rax     # 0x2efa0
shlq $0x7, %rcx
addq %rcx, %rax
movslq -0xbc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rsi
leaq 0x11db2(%rip), %rdx     # 0x2ffa4
callq 0x20950
jmp 0x1e1f9
movl $0x0, -0xc8(%rbp)
movl -0xbc(%rbp), %eax
movl %eax, -0xcc(%rbp)
movl -0xc8(%rbp), %eax
movl -0xb4(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1e2e2
cmpl $0x0, -0xcc(%rbp)
jg 0x1e234
jmp 0x1e2e2
movl -0xcc(%rbp), %eax
subl $0x1, %eax
cmpl $0x6, %eax
jge 0x1e253
movl -0xcc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x134(%rbp)
jmp 0x1e260
movl $0x6, %eax
movl %eax, -0x134(%rbp)
jmp 0x1e260
movl -0x134(%rbp), %eax
movl %eax, -0x124(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x124(%rbp), %rcx
leaq 0x114a2(%rip), %rax     # 0x2f720
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0xc8(%rbp), %rcx
movslq -0xb0(%rbp,%rcx,4), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x12c(%rbp)
movq -0x12c(%rbp), %rsi
leaq 0x11d0c(%rip), %rdx     # 0x2ffb9
callq 0x20950
movslq -0xc8(%rbp), %rax
movl -0xb0(%rbp,%rax,4), %ecx
movl -0xcc(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xcc(%rbp)
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x1e20f
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopl (%rax,%rax)