// File: /workspace/github_c_makefile_star2_O0/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
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
leaq 0x168e7(%rip), %rdi     # 0x28eb0
leaq 0x19600(%rip), %rsi     # 0x2bbd0
leaq 0x197b7(%rip), %rdx     # 0x2bd8e
movb $0x0, %al
callq 0x4d20
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x12607
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x125e5
cmpl $-0x1, -0x24(%rbp)
jne 0x12665
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10f3e8(%rax), %rsi
callq 0x13d90
movl %eax, -0xd8(%rbp)
cmpl $0x0, %eax
jge 0x12638
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x12c1b
movl -0xd8(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, -0xc8(%rbp)
movl -0xd8(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, -0xcc(%rbp)
jmp 0x126fe
cmpl $-0x2, -0x24(%rbp)
jne 0x12682
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x7520
movl %eax, -0xdc(%rbp)
jmp 0x12698
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x7520
movl %eax, -0xdc(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0xdc(%rbp), %rdx
leaq 0x19412(%rip), %rcx     # 0x2bac0
movslq (%rcx,%rdx,4), %rcx
movq 0x10f3c8(%rax,%rcx,8), %rsi
callq 0x13d90
movl %eax, -0xe0(%rbp)
cmpl $0x0, %eax
jge 0x126d6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x12c1b
movl -0xe0(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, -0xc8(%rbp)
movl -0xe0(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, -0xcc(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x12725
movl -0xc8(%rbp), %ecx
movq -0x20(%rbp), %rax
addq $0x324, %rax            # imm = 0x324
movslq -0x24(%rbp), %rdx
imulq $0x84, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
cmpl $0x0, -0xc8(%rbp)
jg 0x1273a
movl $0x0, -0x4(%rbp)
jmp 0x12c1b
xorl %eax, %eax
cmpl $0xa, -0xc8(%rbp)
movb %al, -0xe9(%rbp)
jle 0x1275b
cmpl $0x3, -0xcc(%rbp)
setl %al
movb %al, -0xe9(%rbp)
movb -0xe9(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0xd0(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0xcc(%rbp), %eax
jge 0x127b2
movq -0x18(%rbp), %rdi
leaq 0x19617(%rip), %rsi     # 0x2bda8
callq 0x122a0
shll %eax
movl $0x1, %ecx
subl %eax, %ecx
movslq -0x38(%rbp), %rax
movl %ecx, -0x80(%rbp,%rax,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1277b
jmp 0x127b4
movl -0x38(%rbp), %eax
cmpl -0xc8(%rbp), %eax
jge 0x12a03
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10f3f0(%rax), %rsi
callq 0x13d90
movl %eax, -0xe4(%rbp)
cmpl $-0x1, -0xe4(%rbp)
jne 0x127f2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x12c1b
cmpl $0xe, -0xe4(%rbp)
jge 0x12851
cmpl $0x0, -0xd0(%rbp)
jle 0x12840
movl -0xe4(%rbp), %eax
movl -0xd0(%rbp), %ecx
shll %cl, %eax
movl %eax, -0xf0(%rbp)
movq -0x18(%rbp), %rdi
movl -0xd0(%rbp), %esi
leaq 0x19585(%rip), %rdx     # 0x2bdae
callq 0x12350
movl %eax, %ecx
movl -0xf0(%rbp), %eax
addl %ecx, %eax
movl %eax, -0xe8(%rbp)
jmp 0x1284c
movl -0xe4(%rbp), %eax
movl %eax, -0xe8(%rbp)
jmp 0x12927
cmpl $0xe, -0xe4(%rbp)
jne 0x128d2
cmpl $0x0, -0xd0(%rbp)
jle 0x1289f
movl -0xe4(%rbp), %eax
movl -0xd0(%rbp), %ecx
shll %cl, %eax
movl %eax, -0xf4(%rbp)
movq -0x18(%rbp), %rdi
movl -0xd0(%rbp), %esi
leaq 0x19526(%rip), %rdx     # 0x2bdae
callq 0x12350
movl %eax, %ecx
movl -0xf4(%rbp), %eax
addl %ecx, %eax
movl %eax, -0xe8(%rbp)
jmp 0x128d0
movl -0xe4(%rbp), %eax
movl %eax, -0xf8(%rbp)
movq -0x18(%rbp), %rdi
movl $0x4, %esi
leaq 0x19503(%rip), %rdx     # 0x2bdbe
callq 0x12350
movl %eax, %ecx
movl -0xf8(%rbp), %eax
addl %ecx, %eax
movl %eax, -0xe8(%rbp)
jmp 0x12925
movl -0xe4(%rbp), %eax
movl -0xd0(%rbp), %ecx
shll %cl, %eax
movl %eax, -0xfc(%rbp)
movq -0x18(%rbp), %rdi
movl $0xc, %esi
leaq 0x194c8(%rip), %rdx     # 0x2bdbe
callq 0x12350
movl %eax, %ecx
movl -0xfc(%rbp), %eax
addl %ecx, %eax
movl %eax, -0xe8(%rbp)
cmpl $0x0, -0xd0(%rbp)
jne 0x12923
movl -0xe8(%rbp), %eax
addl $0xf, %eax
movl %eax, -0xe8(%rbp)
jmp 0x12925
jmp 0x12927
jmp 0x12929
movl -0x38(%rbp), %eax
cmpl -0xcc(%rbp), %eax
jne 0x1294c
cmpl $0x3, -0xcc(%rbp)
jge 0x1294c
movl -0xe8(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xe8(%rbp)
movl -0xe8(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x12979
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x100(%rbp)
jmp 0x12990
movl -0xe8(%rbp), %eax
addl $0x2, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x100(%rbp)
movl -0x100(%rbp), %ecx
movslq -0x38(%rbp), %rax
movl %ecx, -0x80(%rbp,%rax,4)
cmpl $0x0, -0xd0(%rbp)
jne 0x129b6
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
movslq -0x38(%rbp), %rax
movl -0x80(%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 0x129f3
cmpl $0x6, -0xd0(%rbp)
jge 0x129f3
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x129f5
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x127b4
movl -0xc8(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x12a7b
cmpl $-0x1, -0x24(%rbp)
jne 0x12a3d
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl -0xc8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq 0x10f470(%rax,%rcx,8), %rsi
callq 0x13d90
movl %eax, -0xd4(%rbp)
jmp 0x12a64
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl -0xc8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq 0x10f3f8(%rax,%rcx,8), %rsi
callq 0x13d90
movl %eax, -0xd4(%rbp)
cmpl $0x0, -0xd4(%rbp)
jge 0x12a79
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x12c1b
jmp 0x12a85
movl $0x0, -0xd4(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl -0xc8(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x12b64
cmpl $0x0, -0xd4(%rbp)
jg 0x12aae
jmp 0x12b64
movq -0x18(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x10(%rbp), %rax
addq $0x10f488, %rax         # imm = 0x10F488
movq %rax, -0x108(%rbp)
movl -0xd4(%rbp), %eax
subl $0x1, %eax
cmpl $0x6, %eax
jge 0x12ae9
movl -0xd4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x12af6
movl $0x6, %eax
movl %eax, -0x114(%rbp)
jmp 0x12af6
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rax
movl -0x114(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
callq 0x13d90
movl %eax, %ecx
movslq -0x38(%rbp), %rax
movl %ecx, -0xc0(%rbp,%rax,4)
movslq -0x38(%rbp), %rax
cmpl $0x0, -0xc0(%rbp,%rax,4)
jge 0x12b3d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x12c1b
movslq -0x38(%rbp), %rax
movl -0xc0(%rbp,%rax,4), %ecx
movl -0xd4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xd4(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x12a8c
cmpl $0x0, -0xd4(%rbp)
jge 0x12b79
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x12c1b
jmp 0x12b7b
movl -0x38(%rbp), %eax
movl -0xc8(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x12ba5
movslq -0x38(%rbp), %rax
movl $0x0, -0xc0(%rbp,%rax,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x12b7b
movl -0xd4(%rbp), %ecx
movl -0xc8(%rbp), %eax
subl $0x1, %eax
cltq
movl %ecx, -0xc0(%rbp,%rax,4)
movl $0xffffffff, -0xc4(%rbp) # imm = 0xFFFFFFFF
movl -0xc8(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jl 0x12c14
movslq -0x38(%rbp), %rax
movl -0xc0(%rbp,%rax,4), %eax
addl $0x1, %eax
addl -0xc4(%rbp), %eax
movl %eax, -0xc4(%rbp)
movslq -0x38(%rbp), %rax
movl -0x80(%rbp,%rax,4), %edx
movq -0x30(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x12bd3
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw (%rax,%rax)