// File: /workspace/github_cpp_makefile_star2_O3/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), %r13d
movl 0x70(%rax), %ebp
addq $0x1b8, %rdi            # imm = 0x1B8
movl $0xc00, %edx            # imm = 0xC00
xorl %esi, %esi
callq 0x20e0
btl $0x8, %r13d
leaq 0x1278(%rip), %rax      # 0x18f00
leaq 0x5821(%rip), %r14      # 0x1d4b0
movq %r14, %r15
cmovaeq %rax, %r15
leaq 0x1273(%rip), %rax      # 0x18f10
leaq 0x581c(%rip), %r12      # 0x1d4c0
cmovaeq %rax, %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x17a22
movl 0x40(%rbx), %eax
testl %eax, %eax
je 0x17e22
cmpl $0x2, %eax
je 0x17dc5
cmpl $0x1, %eax
jne 0x17e31
testb $0x3, %bpl
je 0x17d3a
leaq 0x138(%rbx), %rsi
xorps %xmm0, %xmm0
movups %xmm0, 0x138(%rbx)
leaq 0x178(%rbx), %r15
movups %xmm0, 0x178(%rbx)
leaq 0x57ff(%rip), %r12      # 0x1d500
movq %rbx, %rdi
movl $0x3, %edx
movl $0x31, %ecx
movq %r12, %r8
movl $0x4, %r9d
callq 0x178e4
movq %rbx, %rdi
movq %r15, %rsi
movl $0x3, %edx
movl $0x32, %ecx
movq %r12, %r8
movl $0x4, %r9d
callq 0x178e4
testb $0x2, %bpl
je 0x17df0
leaq 0x5b8(%rbx), %r15
btl $0x8, %r13d
leaq 0x11a9(%rip), %rax      # 0x18f00
cmovaeq %rax, %r14
incq %r14
xorl %r12d, %r12d
movl %r12d, %ecx
orl $0x10, %ecx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x4, %edx
movq %r14, %r8
movl $0xf, %r9d
callq 0x17954
incq %r12
addq $0x40, %r15
cmpq $0x4, %r12
jne 0x17d61
leaq 0x9b8(%rbx), %r15
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 0x17954
incq %r12
addq $0x40, %r15
cmpq $0x4, %r12
jne 0x17d97
jmp 0x17e22
testb $0x3, %bpl
je 0x17dea
xorps %xmm0, %xmm0
movups %xmm0, 0x148(%rbx)
movups %xmm0, 0x138(%rbx)
movups %xmm0, 0x178(%rbx)
movups %xmm0, 0x188(%rbx)
testb $0x2, %bpl
jne 0x17e22
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 0x17a22
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 0x17a22