// File: /workspace/github_cpp_makefile_star2_O3/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:
movq 0x8(%rdi), %r9
movq 0x88358(%r9), %r8
movq 0x88360(%r9), %r10
cmpl $0x0, 0x6fc(%r8)
je 0x15fcf
movl $0x0, 0x10(%rdi)
movb $0x0, 0x18(%rdi)
cmpl $0x0, 0x28(%rsi)
setne %cl
xorl %r11d, %r11d
jmp 0x15ff1
cmpl $0x0, 0x28(%rsi)
je 0x160c1
cmpl $0x1, 0x2c(%rsi)
movl $0x2, %r11d
sbbl $0x0, %r11d
movl %r11d, 0x10(%rdi)
movb $0x0, 0x18(%rdi)
movb $0x1, %cl
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
testl %r11d, %r11d
setne 0x19(%rdi)
movl 0x14(%rsi), %eax
movl 0x88340(%r9), %ebx
xorl %edx, %edx
divl %ebx
movl %eax, %ebp
shll %cl, %ebp
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpl $0x2, %r11d
sete %r15b
addl %ebp, %r15d
cmpl $0x2, %r11d
movl %edx, 0x1c(%rdi)
cmovel %r15d, %eax
testb %cl, %cl
cmovnel %r15d, %eax
movl %eax, 0x20(%rdi)
imull %ebx, %r15d
addl %edx, %r15d
movl %r15d, 0x24(%rdi)
movslq %r15d, %rax
imulq $0xb0, %rax, %rcx
addq 0xdb8(%rdi), %rcx
cmpl 0x88348(%r9), %eax
cmovlq %rcx, %r14
movq %r14, 0x28(%rdi)
movl $0x0, 0x30(%rdi)
movslq 0x438(%r10), %rax
movslq 0x95c(%rsi), %rcx
leaq (%rax,%rcx), %rdx
leaq 0x1a(%rax,%rcx), %rax
movl %eax, 0x34(%rdi)
movzbl 0xa63ea(%r9,%rdx), %eax
movl %eax, 0x38(%rdi)
movzbl 0xa642a(%r9,%rdx), %eax
movl %eax, 0x3c(%rdi)
movl 0x10(%r8), %eax
movl %eax, 0x40(%rdi)
cmpl $0x3, %eax
jne 0x160b3
cmpl $0x0, 0x14(%r8)
je 0x160b3
movl $0x0, 0x40(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rdi)
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x10(%rdi)
cmpl $0x0, 0x700(%r8)
setne %cl
setne 0x18(%rdi)
jmp 0x15fca