// File: lukasz-wiecaszek[P]h264iframedecoder/picture_cabac.cpp
// Function: ymn::h264::picture_cabac::non_zero_count_save()
void picture_cabac::non_zero_count_save()
{
    mb* curr_mb = m_context_variables.curr_mb;
    uint8_t* nzc = curr_mb->non_zero_count;

    const mb_cache& nzc_cache_y  = m_context_variables.non_zero_count_cache[CC_Y];
    const mb_cache& nzc_cache_cb = m_context_variables.non_zero_count_cache[CC_Cb];
    const mb_cache& nzc_cache_cr = m_context_variables.non_zero_count_cache[CC_Cr];

    nzc[MB_NZC_DC_BLOCK_IDX(CC_Y)] = nzc_cache_y[0];

    std::memcpy(&nzc[0 * 4], &nzc_cache_y[1 * 8 + 4], 4);
    std::memcpy(&nzc[1 * 4], &nzc_cache_y[2 * 8 + 4], 4);
    std::memcpy(&nzc[2 * 4], &nzc_cache_y[3 * 8 + 4], 4);
    std::memcpy(&nzc[3 * 4], &nzc_cache_y[4 * 8 + 4], 4);

    if (m_context_variables.chroma_array_type == 0)
        return;

    nzc[MB_NZC_DC_BLOCK_IDX(CC_Cb)] = nzc_cache_cb[0];
    nzc[MB_NZC_DC_BLOCK_IDX(CC_Cr)] = nzc_cache_cr[0];

    std::memcpy(&nzc[4 * 4], &nzc_cache_cb[1 * 8 + 4], 4);
    std::memcpy(&nzc[5 * 4], &nzc_cache_cb[2 * 8 + 4], 4);
    std::memcpy(&nzc[8 * 4], &nzc_cache_cr[1 * 8 + 4], 4);
    std::memcpy(&nzc[9 * 4], &nzc_cache_cr[2 * 8 + 4], 4);

    if (m_context_variables.chroma_array_type < 3)
        return;

    std::memcpy(&nzc[ 6 * 4], &nzc_cache_cb[3 * 8 + 4], 4);
    std::memcpy(&nzc[ 7 * 4], &nzc_cache_cb[4 * 8 + 4], 4);
    std::memcpy(&nzc[10 * 4], &nzc_cache_cr[3 * 8 + 4], 4);
    std::memcpy(&nzc[11 * 4], &nzc_cache_cr[4 * 8 + 4], 4);
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x28(%rax), %rcx
movq %rcx, 0x88(%rsp)
movq 0x88(%rsp), %rcx
addq $0x78, %rcx
movq %rcx, 0x80(%rsp)
movq %rax, %rcx
addq $0x18, %rcx
addq $0x68, %rcx
movq %rcx, 0x78(%rsp)
movq %rax, %rcx
addq $0x18, %rcx
addq $0x68, %rcx
addq $0x28, %rcx
movq %rcx, 0x70(%rsp)
addq $0x18, %rax
addq $0x68, %rax
addq $0x50, %rax
movq %rax, 0x68(%rsp)
movq 0x78(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x223f0
movb (%rax), %cl
movq 0x80(%rsp), %rax
movb %cl, 0x30(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x78(%rsp), %rdi
movl $0xc, %esi
callq 0x223f0
movq %rax, %rcx
movq 0x40(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, (%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x78(%rsp), %rdi
movl $0x14, %esi
callq 0x223f0
movq %rax, %rcx
movq 0x48(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x4(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x78(%rsp), %rdi
movl $0x1c, %esi
callq 0x223f0
movq %rax, %rcx
movq 0x50(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x8(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x78(%rsp), %rdi
movl $0x24, %esi
callq 0x223f0
movq 0x58(%rsp), %rcx
movq %rax, %rdx
movq 0x60(%rsp), %rax
movl (%rdx), %edx
movl %edx, 0xc(%rcx)
cmpl $0x0, 0x40(%rax)
jne 0x2077f
jmp 0x2090b
movq 0x70(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x223f0
movb (%rax), %cl
movq 0x80(%rsp), %rax
movb %cl, 0x31(%rax)
movq 0x68(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x223f0
movb (%rax), %cl
movq 0x80(%rsp), %rax
movb %cl, 0x32(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rdi
movl $0xc, %esi
callq 0x223f0
movq %rax, %rcx
movq 0x20(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x10(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x70(%rsp), %rdi
movl $0x14, %esi
callq 0x223f0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x14(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x68(%rsp), %rdi
movl $0xc, %esi
callq 0x223f0
movq %rax, %rcx
movq 0x30(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x20(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x68(%rsp), %rdi
movl $0x14, %esi
callq 0x223f0
movq 0x38(%rsp), %rcx
movq %rax, %rdx
movq 0x60(%rsp), %rax
movl (%rdx), %edx
movl %edx, 0x24(%rcx)
cmpl $0x3, 0x40(%rax)
jge 0x20869
jmp 0x2090b
movq 0x80(%rsp), %rax
movq %rax, (%rsp)
movq 0x70(%rsp), %rdi
movl $0x1c, %esi
callq 0x223f0
movq %rax, %rcx
movq (%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x18(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x70(%rsp), %rdi
movl $0x24, %esi
callq 0x223f0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x1c(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %rdi
movl $0x1c, %esi
callq 0x223f0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x28(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rdi
movl $0x24, %esi
callq 0x223f0
movq %rax, %rcx
movq 0x18(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x2c(%rax)
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)