// File: /workspace/github_cpp_makefile_star2_O2/lukasz-wiecaszek[P]h264iframedecoder/picture_cabac.cpp
// Function: ymn::h264::picture_cabac::decode_residual()
void picture_cabac::decode_residual()
{
    mb* curr_mb = m_context_variables.curr_mb;
    uint32_t mb_type = curr_mb->type;
    int cbp_chroma = curr_mb->cbp_chroma;

    const uint8_t* const scan4x4 = MB_IS_INTERLACED(mb_type) ?
        field_scan_4x4 : frame_scan_4x4;
    const uint8_t* const scan8x8 = MB_IS_INTERLACED(mb_type) ?
        field_scan_8x8 : frame_scan_8x8;

    for (int i = 0; i < CC_MAX; ++i)
        memset(&m_context_variables.coeffs_ac[i], 0, sizeof(m_context_variables.coeffs_ac[i]));

    decode_residual(scan4x4, scan8x8, colour_component_e::Y);

    if (m_context_variables.chroma_array_type == 0) { /* monochrome */
        /* do nothing */
    }
    else
    if (m_context_variables.chroma_array_type == 1) { /* 4:2:0 */
        if (cbp_chroma & 3) { /* chroma DC residual present */
            memset(&m_context_variables.coeffs_dc[CC_Cb], 0, 4 * sizeof(dctcoeff));
            memset(&m_context_variables.coeffs_dc[CC_Cr], 0, 4 * sizeof(dctcoeff));

            decode_residual_dc(m_context_variables.coeffs_dc[CC_Cb],
                CAT_CHROMA_DC, MB_NZC_DC_BLOCK_IDX(CC_Cb), scan_table_chroma_dc, 4);
            decode_residual_dc(m_context_variables.coeffs_dc[CC_Cr],
                CAT_CHROMA_DC, MB_NZC_DC_BLOCK_IDX(CC_Cr), scan_table_chroma_dc, 4);
        }
        if (cbp_chroma & 2) { /* chroma AC residual present */
            for (int i4x4 = 0; i4x4 < 4; ++i4x4)
                decode_residual_ac(&m_context_variables.coeffs_ac[CC_Cb][16 * i4x4],
                    CAT_CHROMA_AC, MB_NZC_AC_BLOCK_IDX(CC_Cb, i4x4), scan4x4 + 1, 15);
            for (int i4x4 = 0; i4x4 < 4; ++i4x4)
                decode_residual_ac(&m_context_variables.coeffs_ac[CC_Cr][16 * i4x4],
                    CAT_CHROMA_AC, MB_NZC_AC_BLOCK_IDX(CC_Cr, i4x4), scan4x4 + 1, 15);
        }
        else {
            mb_cache_fill_rectangle_4x4(m_context_variables.non_zero_count_cache[CC_Cb], mb_cache_idx[0], 0);
            mb_cache_fill_rectangle_4x4(m_context_variables.non_zero_count_cache[CC_Cr], mb_cache_idx[0], 0);
        }
    }
    else
    if (m_context_variables.chroma_array_type == 2) { /* 4:2:2 */
        if (cbp_chroma & 3) { /* chroma DC residual present */
            memset(&m_context_variables.coeffs_dc[CC_Cb], 0, 8 * sizeof(dctcoeff));
            memset(&m_context_variables.coeffs_dc[CC_Cr], 0, 8 * sizeof(dctcoeff));
        }
        if (cbp_chroma & 2) { /* chroma AC residual present */
        }
        else {
            mb_cache_fill_rectangle_4x4(m_context_variables.non_zero_count_cache[CC_Cb], mb_cache_idx[0], 0);
            mb_cache_fill_rectangle_4x4(m_context_variables.non_zero_count_cache[CC_Cr], mb_cache_idx[0], 0);
        }
    }
    else { /* 4:4:4 */
        decode_residual(scan4x4, scan8x8, colour_component_e::Cb);
        decode_residual(scan4x4, scan8x8, colour_component_e::Cr);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x28(%rdi), %rax
movl 0x10(%rax), %ebp
movl 0x70(%rax), %r13d
addq $0x1b8, %rdi            # imm = 0x1B8
btl $0x8, %ebp
leaq 0x1f8f(%rip), %rax      # 0x14fa0
leaq 0x6518(%rip), %r14      # 0x19530
movq %r14, %r15
cmovaeq %rax, %r15
leaq 0x1f8a(%rip), %rax      # 0x14fb0
leaq 0x6513(%rip), %r12      # 0x19540
cmovaeq %rax, %r12
movl $0xc00, %edx            # imm = 0xC00
xorl %esi, %esi
callq 0x20c0
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x12db4
movl 0x40(%rbx), %eax
testl %eax, %eax
je 0x13180
cmpl $0x2, %eax
je 0x1311d
cmpl $0x1, %eax
jne 0x1318f
testb $0x3, %r13b
je 0x130c8
leaq 0x138(%rbx), %rsi
xorps %xmm0, %xmm0
movups %xmm0, 0x138(%rbx)
leaq 0x178(%rbx), %r15
movups %xmm0, 0x178(%rbx)
leaq 0x64ea(%rip), %r8       # 0x19580
pushq $0x3
popq %r12
pushq $0x31
popq %rcx
pushq $0x4
popq %r9
movq %rbx, %rdi
movl %r12d, %edx
callq 0x12c88
pushq $0x32
popq %rcx
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
leaq 0x64c1(%rip), %r8       # 0x19580
pushq $0x4
popq %r9
callq 0x12c88
testb $0x2, %r13b
je 0x13148
leaq 0x5b8(%rbx), %r15
btl $0x8, %ebp
leaq 0x1ec0(%rip), %rax      # 0x14fa0
cmovaeq %rax, %r14
incq %r14
xorl %r13d, %r13d
pushq $0x4
popq %rbp
pushq $0xf
popq %r12
cmpq $0x4, %r13
je 0x131bf
movl %r13d, %ecx
orl $0x10, %ecx
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r14, %r8
movl %r12d, %r9d
callq 0x12cf8
incq %r13
addq $0x40, %r15
jmp 0x130f1
testb $0x3, %r13b
je 0x13142
xorps %xmm0, %xmm0
movups %xmm0, 0x148(%rbx)
movups %xmm0, 0x138(%rbx)
movups %xmm0, 0x178(%rbx)
movups %xmm0, 0x188(%rbx)
testb $0x2, %r13b
jne 0x13180
andl $0x0, 0xb4(%rbx)
andl $0x0, 0xbc(%rbx)
andl $0x0, 0xc4(%rbx)
andl $0x0, 0xcc(%rbx)
andl $0x0, 0xdc(%rbx)
andl $0x0, 0xe4(%rbx)
andl $0x0, 0xec(%rbx)
andl $0x0, 0xf4(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x12db4
pushq $0x2
popq %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12db4
leaq 0x9b8(%rbx), %r15
xorl %r13d, %r13d
pushq $0x4
popq %rbp
pushq $0xf
popq %r12
cmpq $0x4, %r13
je 0x13180
movl %r13d, %ecx
orl $0x20, %ecx
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r14, %r8
movl %r12d, %r9d
callq 0x12cf8
incq %r13
addq $0x40, %r15
jmp 0x131d0