// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0xc00, %edx            # imm = 0xC00
xorl %esi, %esi
callq 0x20e0
btl $0x8, %ebp
leaq 0x1e71(%rip), %rax      # 0x19f00
leaq 0x642a(%rip), %r14      # 0x1e4c0
movq %r14, %r15
cmovaeq %rax, %r15
leaq 0x1e6c(%rip), %rax      # 0x19f10
leaq 0x6425(%rip), %r12      # 0x1e4d0
cmovaeq %rax, %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x17e1a
movl 0x40(%rbx), %eax
testl %eax, %eax
je 0x1823d
cmpl $0x2, %eax
je 0x181e0
cmpl $0x1, %eax
jne 0x1824c
testb $0x3, %r13b
je 0x18141
leaq 0x138(%rbx), %rsi
xorps %xmm0, %xmm0
movups %xmm0, 0x138(%rbx)
leaq 0x178(%rbx), %r15
movups %xmm0, 0x178(%rbx)
leaq 0x6408(%rip), %r12      # 0x1e510
movq %rbx, %rdi
movl $0x3, %edx
movl $0x31, %ecx
movq %r12, %r8
movl $0x4, %r9d
callq 0x17cdc
movq %rbx, %rdi
movq %r15, %rsi
movl $0x3, %edx
movl $0x32, %ecx
movq %r12, %r8
movl $0x4, %r9d
callq 0x17cdc
testb $0x2, %r13b
je 0x1820b
leaq 0x5b8(%rbx), %r15
btl $0x8, %ebp
movq %r14, %r12
leaq 0x1da0(%rip), %rax      # 0x19f00
cmovaeq %rax, %r12
incq %r12
xorl %r13d, %r13d
movl %r13d, %ecx
orl $0x10, %ecx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x4, %edx
movq %r12, %r8
movl $0xf, %r9d
callq 0x17d4c
incq %r13
addq $0x40, %r15
cmpq $0x4, %r13
jne 0x1816a
leaq 0x9b8(%rbx), %r15
btl $0x8, %ebp
leaq 0x1d58(%rip), %rax      # 0x19f00
cmovaeq %rax, %r14
incq %r14
xorl %r12d, %r12d
movl %r12d, %ecx
orl $0x20, %ecx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x4, %edx
movq %r14, %r8
movl $0xf, %r9d
callq 0x17d4c
incq %r12
addq $0x40, %r15
cmpq $0x4, %r12
jne 0x181b2
jmp 0x1823d
testb $0x3, %r13b
je 0x18205
xorps %xmm0, %xmm0
movups %xmm0, 0x148(%rbx)
movups %xmm0, 0x138(%rbx)
movups %xmm0, 0x178(%rbx)
movups %xmm0, 0x188(%rbx)
testb $0x2, %r13b
jne 0x1823d
xorl %eax, %eax
movl %eax, 0xb4(%rbx)
movl %eax, 0xbc(%rbx)
movl %eax, 0xc4(%rbx)
movl %eax, 0xcc(%rbx)
movl %eax, 0xdc(%rbx)
movl %eax, 0xe4(%rbx)
movl %eax, 0xec(%rbx)
movl %eax, 0xf4(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl $0x1, %ecx
callq 0x17e1a
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl $0x2, %ecx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17e1a