// File: /workspace/github_c_makefile_star2_O3/akumrao[P]videoAnalyzer/decoder/macroblock.c
// Function: block_residual_read_cavlc(x264_t*, bs_s*, x264_macroblock_t*, int, int*, int)
static int block_residual_read_cavlc(x264_t *h, bs_t *s, x264_macroblock_t *mb,
        int i_idx, int *l, int i_count) {LOG_CALL;
    int i;
    int level[16], run[16];
    int i_coeff;

    int i_total, i_trailing;
    int i_suffix_length;
    int i_zero_left;

    for (i = 0; i < i_count; i++)
    {
        l[i] = 0;
    }

    /* total/trailing */
    if (i_idx == BLOCK_INDEX_CHROMA_DC)
    {
        int i_tt;

        if ((i_tt = bs_read_vlc(s, h->x264_coeff_token_lookup[4])) < 0)// chroma_dc_coeff_token_vlc
        {
            return -1;
        }

        i_total = i_tt / 4;
        i_trailing = i_tt % 4;
    } 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;
        int i_tt;

        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);
        }

        if ((i_tt = bs_read_vlc(s, h->x264_coeff_token_lookup[ct_index[nC]])) < 0)
        {
            return -1;
        }

        i_total = i_tt / 4;
        i_trailing = i_tt % 4;
    }

    if (i_idx >= 0)
    {
        mb->block[i_idx].i_non_zero_count = i_total;
    }

    if (i_total <= 0)
    {
        return 0;
    }

    i_suffix_length = i_total > 10 && i_trailing < 3 ? 1 : 0;

    for (i = 0; i < i_trailing; i++)
    {
        level[i] = 1 - 2 * bs_read1(s,"level");
    }

    for (; i < i_total; i++)
    {
        int i_prefix;
        int i_level_code;

        i_prefix = bs_read_vlc(s, h->x264_level_prefix_lookup);

        if (i_prefix == -1)
        {
            return -1;
        } else if (i_prefix < 14)
        {
            if (i_suffix_length > 0)
            {
                i_level_code = (i_prefix << i_suffix_length) + bs_read(s, i_suffix_length,"i_suffix_length");
            } else
            {
                i_level_code = i_prefix;
            }
        } else if (i_prefix == 14)
        {
            if (i_suffix_length > 0)
            {
                i_level_code = (i_prefix << i_suffix_length) + bs_read(s, i_suffix_length,"i_suffix_length");
            } else
            {
                i_level_code = i_prefix + bs_read(s, 4,"i_level_code");
            }
        } else /* if( i_prefix == 15 ) */
        {
            i_level_code = (i_prefix << i_suffix_length) + bs_read(s, 12,"i_level_code");
            if (i_suffix_length == 0)
            {
                i_level_code += 15;
            }
        }
        if (i == i_trailing && i_trailing < 3)
        {
            i_level_code += 2;
        }
        /* Optimise */
        level[i] = i_level_code & 0x01 ? -((i_level_code + 1) / 2) : (i_level_code + 2) / 2;

        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)
        {
            i_zero_left = bs_read_vlc(s, h->x264_total_zeros_dc_lookup[i_total - 1]);
        } else
        {
            i_zero_left = bs_read_vlc(s, h->x264_total_zeros_lookup[i_total - 1]);
        }
        if (i_zero_left < 0)
        {
            return -1;
        }
    } else
    {
        i_zero_left = 0;
    }

    for (i = 0; i < i_total - 1; i++)
    {
        if (i_zero_left <= 0)
        {
            break;
        }
        run[i] = bs_read_vlc(s, h->x264_run_before_lookup[X264_MIN(i_zero_left - 1, 6)]);

        if (run[i] < 0)
        {
            return -1;
        }
        i_zero_left -= run[i];
    }
    if (i_zero_left < 0)
    {
        return -1;
    }

    for (; i < i_total - 1; i++)
    {
        run[i] = 0;
    }
    run[i_total - 1] = i_zero_left;

    i_coeff = -1;
    for (i = i_total - 1; i >= 0; i--)
    {
        i_coeff += run[i] + 1;
        l[i_coeff] = level[i];
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r9d, %r12d
movq %r8, %r15
movl %ecx, %r13d
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, -0x48(%rbp)
leaq 0x17f3a(%rip), %rdi     # 0x271b4
leaq 0x1adcf(%rip), %rsi     # 0x2a050
leaq 0x1af80(%rip), %rdx     # 0x2a208
xorl %eax, %eax
callq 0x4a56
testl %r12d, %r12d
jle 0xf2a5
movl %r12d, %edx
shlq $0x2, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2070
cmpl $-0x1, %r13d
movl %r12d, -0x60(%rbp)
je 0xf30e
xorl %edx, %edx
cmpl $-0x2, %r13d
cmovnel %r13d, %edx
movq -0x48(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x660f
cltq
leaq 0x1ac3f(%rip), %rcx     # 0x29f10
movslq (%rcx,%rax,4), %rax
movq 0x10f3c8(%r12,%rax,8), %rsi
movq %r14, %rdi
callq 0x102be
testl %eax, %eax
js 0xf824
movl %eax, %edx
shrl $0x2, %edx
testl %r13d, %r13d
js 0xf32e
movl %r13d, %esi
movq %rsi, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rsi,4), %rcx
movl %edx, 0x328(%rbx,%rcx)
jmp 0xf32e
movq -0x48(%rbp), %rax
movq 0x10f3e8(%rax), %rsi
movq %r14, %rdi
callq 0x102be
testl %eax, %eax
js 0xf824
movl %eax, %edx
shrl $0x2, %edx
testl %edx, %edx
je 0xf88c
movl %r13d, -0x5c(%rbp)
movq %r15, -0x68(%rbp)
andl $0x3, %eax
movq %rdx, -0x40(%rbp)
cmpl $0xb, %edx
setae -0x38(%rbp)
cmpl $0x3, %eax
setne -0x58(%rbp)
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0xf3d7
leaq 0x1a671(%rip), %rbx     # 0x299d8
leaq 0x1aeb4(%rip), %r15     # 0x2a222
xorl %r13d, %r13d
movq 0x8(%r14), %rax
movl $0x0, %r12d
cmpq 0x10(%r14), %rax
jae 0xf3ab
movl 0x18(%r14), %ecx
decl %ecx
movl %ecx, 0x18(%r14)
movzbl (%rax), %edx
xorl %r12d, %r12d
btl %ecx, %edx
setb %r12b
testl %ecx, %ecx
jne 0xf3ab
incq %rax
movq %rax, 0x8(%r14)
movl $0x8, 0x18(%r14)
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
xorl %eax, %eax
callq 0x4a56
addl %r12d, %r12d
movl $0x1, %eax
subl %r12d, %eax
movl %eax, -0xf0(%rbp,%r13,4)
incq %r13
cmpq %r13, -0x50(%rbp)
jne 0xf371
movl -0x2c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0xf772
movb -0x38(%rbp), %al
andb -0x58(%rbp), %al
movzbl %al, %r12d
movl -0x40(%rbp), %eax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq %rdi, -0x38(%rbp)
movq -0x48(%rbp), %rax
movq 0x10f3f0(%rax), %rsi
movq %r14, %rdi
callq 0x102be
cmpl $-0x1, %eax
je 0xf824
movl %eax, %ebx
cmpl $0xd, %eax
jg 0xf498
testl %r12d, %r12d
leaq 0x1aa57(%rip), %r8      # 0x29e80
jle 0xf586
movl %r12d, %ecx
shll %cl, %ebx
movq 0x8(%r14), %rax
movq 0x10(%r14), %rdx
xorl %r13d, %r13d
movl %r12d, %esi
cmpq %rdx, %rax
jae 0xf478
movslq 0x18(%r14), %rdi
movl %edi, %ecx
subl %esi, %ecx
movzbl (%rax), %r15d
jns 0xf58e
andl (%r8,%rdi,4), %r15d
negb %cl
shll %cl, %r15d
orl %r15d, %r13d
incq %rax
movq %rax, 0x8(%r14)
movl $0x8, 0x18(%r14)
subl %edi, %esi
jg 0xf442
leaq 0x1a545(%rip), %rdi     # 0x299c4
movl %r13d, %edx
leaq 0x1ad9f(%rip), %rcx     # 0x2a228
xorl %eax, %eax
callq 0x4a56
movl %r13d, %r15d
jmp 0xf5c9
cmpl $0xe, %ebx
leaq 0x1a9de(%rip), %r8      # 0x29e80
jne 0xf51b
testl %r12d, %r12d
jle 0xf5d1
movl $0xe, %r13d
movl %r12d, %ecx
shll %cl, %r13d
movq 0x8(%r14), %rax
movq 0x10(%r14), %rdx
xorl %ebx, %ebx
movl %r12d, %esi
cmpq %rdx, %rax
jae 0xf4fc
movslq 0x18(%r14), %rdi
movl %edi, %ecx
subl %esi, %ecx
movzbl (%rax), %r15d
jns 0xf682
andl (%r8,%rdi,4), %r15d
negb %cl
shll %cl, %r15d
orl %r15d, %ebx
incq %rax
movq %rax, 0x8(%r14)
movl $0x8, 0x18(%r14)
subl %edi, %esi
jg 0xf4c6
leaq 0x1a4c1(%rip), %rdi     # 0x299c4
movl %ebx, %edx
leaq 0x1ad1c(%rip), %rcx     # 0x2a228
xorl %eax, %eax
callq 0x4a56
movl %ebx, %r15d
jmp 0xf6bd
movl %r12d, %ecx
shll %cl, %ebx
movq 0x8(%r14), %rax
movq 0x10(%r14), %rdx
movl $0xc, %esi
xorl %r15d, %r15d
cmpq %rdx, %rax
jae 0xf566
movslq 0x18(%r14), %rdi
movl %edi, %ecx
subl %esi, %ecx
movzbl (%rax), %r13d
jns 0xf635
andl (%r8,%rdi,4), %r13d
negb %cl
shll %cl, %r13d
orl %r13d, %r15d
incq %rax
movq %rax, 0x8(%r14)
movl $0x8, 0x18(%r14)
subl %edi, %esi
jg 0xf530
leaq 0x1a457(%rip), %rdi     # 0x299c4
movl %r15d, %edx
leaq 0x1acc1(%rip), %rcx     # 0x2a238
xorl %eax, %eax
callq 0x4a56
movl %r15d, %r13d
jmp 0xf670
movl %ebx, %r15d
jmp 0xf701
shrl %cl, %r15d
movl %esi, %edx
andl (%r8,%rdx,4), %r15d
movl %ecx, 0x18(%r14)
cmpl %esi, %edi
jne 0xf5ae
incq %rax
movq %rax, 0x8(%r14)
movl $0x8, 0x18(%r14)
orl %r13d, %r15d
leaq 0x1a3f7(%rip), %rdi     # 0x299af
movl %r15d, %edx
leaq 0x1ac66(%rip), %rcx     # 0x2a228
xorl %eax, %eax
callq 0x4a56
addl %ebx, %r15d
jmp 0xf701
movq 0x8(%r14), %rax
movq 0x10(%r14), %rdx
movl $0x4, %esi
xorl %ebx, %ebx
cmpq %rdx, %rax
jae 0xf616
movslq 0x18(%r14), %rdi
movl %edi, %ecx
subl %esi, %ecx
movzbl (%rax), %r15d
jns 0xf6c2
andl (%r8,%rdi,4), %r15d
negb %cl
shll %cl, %r15d
orl %r15d, %ebx
incq %rax
movq %rax, 0x8(%r14)
movl $0x8, 0x18(%r14)
subl %edi, %esi
jg 0xf5e0
leaq 0x1a3a7(%rip), %rdi     # 0x299c4
movl %ebx, %edx
leaq 0x1ac12(%rip), %rcx     # 0x2a238
xorl %eax, %eax
callq 0x4a56
movl %ebx, %r15d
jmp 0xf6fd
shrl %cl, %r13d
movl %esi, %edx
andl (%r8,%rdx,4), %r13d
movl %ecx, 0x18(%r14)
cmpl %esi, %edi
jne 0xf655
incq %rax
movq %rax, 0x8(%r14)
movl $0x8, 0x18(%r14)
orl %r15d, %r13d
leaq 0x1a350(%rip), %rdi     # 0x299af
movl %r13d, %edx
leaq 0x1abcf(%rip), %rcx     # 0x2a238
xorl %eax, %eax
callq 0x4a56
leal (%rbx,%r13), %eax
testl %r12d, %r12d
leal 0xf(%r13,%rbx), %r15d
cmovnel %eax, %r15d
jmp 0xf701
shrl %cl, %r15d
movl %esi, %edx
andl (%r8,%rdx,4), %r15d
movl %ecx, 0x18(%r14)
cmpl %esi, %edi
jne 0xf6a2
incq %rax
movq %rax, 0x8(%r14)
movl $0x8, 0x18(%r14)
orl %ebx, %r15d
leaq 0x1a303(%rip), %rdi     # 0x299af
movl %r15d, %edx
leaq 0x1ab72(%rip), %rcx     # 0x2a228
xorl %eax, %eax
callq 0x4a56
addl %r13d, %r15d
jmp 0xf701
shrl %cl, %r15d
movl %esi, %edx
andl (%r8,%rdx,4), %r15d
movl %ecx, 0x18(%r14)
cmpl %esi, %edi
jne 0xf6e2
incq %rax
movq %rax, 0x8(%r14)
movl $0x8, 0x18(%r14)
orl %ebx, %r15d
leaq 0x1a2c3(%rip), %rdi     # 0x299af
movl %r15d, %edx
leaq 0x1ab42(%rip), %rcx     # 0x2a238
xorl %eax, %eax
callq 0x4a56
addl $0xe, %r15d
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %rdi
leal 0x2(%r15), %eax
cmpq -0x50(%rbp), %rdi
cmovnel %r15d, %eax
cmpl $0x3, %ecx
cmovel %r15d, %eax
testb $0x1, %al
jne 0xf726
addl $0x2, %eax
sarl %eax
jmp 0xf72c
incl %eax
sarl %eax
negl %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
cmpl $0x1, %r12d
adcl $0x0, %r12d
leal -0x1(%r12), %ecx
movl $0x3, %esi
shll %cl, %esi
movl %eax, -0xf0(%rbp,%rdi,4)
cmpl %esi, %edx
setg %al
cmpl $0x6, %r12d
setl %cl
andb %al, %cl
movzbl %cl, %eax
addl %r12d, %eax
incq %rdi
movl %eax, %r12d
cmpq -0x58(%rbp), %rdi
jne 0xf3f8
movq -0x40(%rbp), %rcx
leal -0x1(%rcx), %r12d
xorl %r13d, %r13d
cmpl -0x60(%rbp), %ecx
jge 0xf82c
movq -0x48(%rbp), %rcx
leaq 0x10f3f8(%rcx), %rax
addq $0x10f470, %rcx         # imm = 0x10F470
cmpl $-0x1, -0x5c(%rbp)
movl %r12d, %edx
cmoveq %rcx, %rax
movq (%rax,%rdx,8), %rsi
movq %r14, %rdi
callq 0x102be
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %eax, %eax
js 0xf88f
movl %eax, %ebx
movq -0x40(%rbp), %rcx
leal -0x1(%rcx), %r12d
cmpl $0x1, %ecx
je 0xf82e
testl %ebx, %ebx
je 0xf82e
movslq %r12d, %rax
movq %rax, -0x50(%rbp)
xorl %r13d, %r13d
cmpl $0x7, %ebx
movl $0x7, %eax
cmovbl %ebx, %eax
decl %eax
movq -0x48(%rbp), %rcx
movq 0x10f488(%rcx,%rax,8), %rsi
movq %r14, %rdi
callq 0x102be
movl %eax, -0xb0(%rbp,%r13,4)
testl %eax, %eax
js 0xf88f
subl %eax, %ebx
incq %r13
cmpq -0x50(%rbp), %r13
jge 0xf81a
testl %ebx, %ebx
jg 0xf7da
testl %ebx, %ebx
js 0xf88f
movq -0x40(%rbp), %rcx
jmp 0xf82e
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0xf88f
xorl %ebx, %ebx
cmpl %r12d, %r13d
jge 0xf856
movl %r13d, %eax
leaq -0xb0(,%rax,4), %rdi
addq %rbp, %rdi
subl %r13d, %ecx
addl $-0x2, %ecx
leaq 0x4(,%rcx,4), %rdx
xorl %esi, %esi
callq 0x2070
movl %r12d, %eax
movl %ebx, -0xb0(%rbp,%rax,4)
incl %r12d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq -0x68(%rbp), %rdi
movl -0xb0(%rbp,%rax,4), %edx
addl %edx, %ecx
incl %ecx
movl -0xf0(%rbp,%rax,4), %edx
movslq %ecx, %rsi
movl %edx, (%rdi,%rsi,4)
decq %rax
decl %r12d
jg 0xf86c
xorl %r15d, %r15d
movl %r15d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq