// File: /workspace/github_cpp_makefile_star2_O2/lukasz-wiecaszek[P]h264iframedecoder/picture.cpp
// Function: ymn::h264::picture::init_coxtext_variables(ymn::h264::slice_header const&)
void picture::init_coxtext_variables(const h264::slice_header& sh)
{
    const sps* sps = m_decoder.m_active_sps;
    const pps* pps = m_decoder.m_active_pps;

    if (sps->frame_mbs_only_flag) {
        m_picture_structure = picture_structure_e::frame;
        m_context_variables.mb_aff_frame = false;
    }
    else {
        if (sh.field_pic_flag) {
            if (sh.bottom_field_flag)
                m_picture_structure = picture_structure_e::field_bottom;
            else
                m_picture_structure = picture_structure_e::field_top;
            m_context_variables.mb_aff_frame = false;
        }
        else {
            m_picture_structure = picture_structure_e::frame;
            m_context_variables.mb_aff_frame = sps->mb_adaptive_frame_field_flag;
        }
    }

    m_context_variables.mb_field_decoding_flag = m_picture_structure != picture_structure_e::frame;

    m_context_variables.mb_x = sh.first_mb_in_slice % m_decoder.m_dimensions.mb_width;
    m_context_variables.mb_y = sh.first_mb_in_slice / m_decoder.m_dimensions.mb_width;

    if (sh.field_pic_flag || m_context_variables.mb_aff_frame)
        m_context_variables.mb_y *= 2;

    if (m_picture_structure == picture_structure_e::field_bottom)
        m_context_variables.mb_y +=1;

    update_mb_pos();

    m_context_variables.lastQPdelta = 0;
    m_context_variables.QPy = pps->pic_init_qp_minus26 + 26 + sh.slice_qp_delta;
    m_context_variables.QPc[0] = m_decoder.m_chroma_qp_table[0][m_context_variables.QPy];
    m_context_variables.QPc[1] = m_decoder.m_chroma_qp_table[1][m_context_variables.QPy];

    m_context_variables.chroma_array_type = sps->chroma_format_idc;
    if (sps->chroma_format_idc == 3 && sps->separate_colour_plane_flag)
        m_context_variables.chroma_array_type = 0;

    m_context_variables.left_blocks = nullptr; // it will be evaluated in calculate_neighbours_part2()
    m_context_variables.left_blocks_nzc = nullptr; // it will be evaluated in calculate_neighbours_part2()

    //m_context_variables.intraNxN_pred_mode_cache - it will be initialized during processing of macroblock
    //m_context_variables.non_zero_count           - it will be initialized during processing of macroblock
    //m_context_variables.coeffs_ac                - it will be initialized during processing of macroblock
    //m_context_variables.coeffs_dc                - it will be initialized during processing of macroblock
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %rsi
movq 0x88358(%rsi), %r15
movq 0x88360(%rsi), %r12
cmpl $0x0, 0x6fc(%r15)
je 0x115fc
andl $0x0, 0x10(%rbx)
movb $0x0, 0x18(%rbx)
cmpl $0x0, 0x28(%r14)
setne %cl
xorl %edi, %edi
jmp 0x1161b
cmpl $0x0, 0x28(%r14)
je 0x116bd
cmpl $0x1, 0x2c(%r14)
pushq $0x2
popq %rdi
sbbl $0x0, %edi
movl %edi, 0x10(%rbx)
movb $0x0, 0x18(%rbx)
movb $0x1, %cl
testl %edi, %edi
setne 0x19(%rbx)
movl 0x14(%r14), %eax
xorl %edx, %edx
divl 0x88340(%rsi)
xorl %esi, %esi
cmpl $0x2, %edi
sete %sil
movl %eax, %r8d
shll %cl, %r8d
addl %r8d, %esi
cmpl $0x2, %edi
movl %edx, 0x1c(%rbx)
cmovel %esi, %eax
testb %cl, %cl
cmovnel %esi, %eax
movl %eax, 0x20(%rbx)
movq %rbx, %rdi
callq 0x116f4
andl $0x0, 0x30(%rbx)
movslq 0x438(%r12), %rax
movslq 0x95c(%r14), %rcx
leaq (%rax,%rcx), %rdx
addq %rcx, %rax
addq $0x1a, %rax
movl %eax, 0x34(%rbx)
movq 0x8(%rbx), %rax
movzbl 0xa63ea(%rax,%rdx), %ecx
movl %ecx, 0x38(%rbx)
movzbl 0xa642a(%rax,%rdx), %eax
movl %eax, 0x3c(%rbx)
movl 0x10(%r15), %eax
movl %eax, 0x40(%rbx)
cmpl $0x3, %eax
jne 0x116aa
cmpl $0x0, 0x14(%r15)
je 0x116aa
andl $0x0, 0x40(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
andl $0x0, 0x10(%rbx)
cmpl $0x0, 0x700(%r15)
setne %cl
setne 0x18(%rbx)
jmp 0x115f8
nop