// File: /workspace/github_cpp_makefile_star2_O2/lukasz-wiecaszek[P]h264iframedecoder/h264_parser.cpp
// Function: ymn::h264_parser::parse_sps(ymn::istream<0>&)
h264_parser_status_e h264_parser::parse_sps(istream_be& s)
{
    h264_parser_status_e retval = h264_parser_status_e::NAL_UNIT_CORRUPTED;

    do {
        bool status;
        uint8_t  profile_idc;
        uint8_t  constraint_flags;
        uint8_t  level_idc;
        uint32_t seq_parameter_set_id;

        s.read_u8(profile_idc);
        s.read_u8(constraint_flags);
        s.read_u8(level_idc);

        if (!CHK_EXPR(s.read_exp_golomb_u(seq_parameter_set_id), std::cout) ||
            !CHK_RANGE(seq_parameter_set_id, 0U, static_cast<unsigned>(H264_PARSER_MAX_NUMBER_OF_SPS - 1), std::cout)) {
            s.mark_corrupted();
            break;
        }

        h264::sps& sps = m_sps_table[seq_parameter_set_id];

        sps.profile_idc = profile_idc;
        sps.constraint_flags = constraint_flags;
        sps.level_idc = level_idc;
        sps.seq_parameter_set_id = seq_parameter_set_id;

        if (sps.profile_idc == 100 || sps.profile_idc == 110 ||
            sps.profile_idc == 122 || sps.profile_idc == 244 ||
            sps.profile_idc ==  44 || sps.profile_idc ==  83 ||
            sps.profile_idc ==  86 || sps.profile_idc == 118 ||
            sps.profile_idc == 128 || sps.profile_idc == 144) {

            s.read_exp_golomb_u(sps.chroma_format_idc);
            if (!CHK_STRUCT_RANGE(sps, chroma_format_idc, 0U, 3U, std::cout)) {
                s.mark_corrupted();
                break;
            }

            if (sps.chroma_format_idc == 3)
                s.read_bits(1, sps.separate_colour_plane_flag);
            else
                sps.separate_colour_plane_flag = 0;

            s.read_exp_golomb_u(sps.bit_depth_luma_minus8);
            if (!CHK_STRUCT_RANGE(sps, bit_depth_luma_minus8, 0U, 6U, std::cout)) {
                s.mark_corrupted();
                break;
            }

            s.read_exp_golomb_u(sps.bit_depth_chroma_minus8);
            if (!CHK_STRUCT_RANGE(sps, bit_depth_chroma_minus8, 0U, 6U, std::cout)) {
                s.mark_corrupted();
                break;
            }

            s.read_bits(1, sps.qpprime_y_zero_transform_bypass_flag);

            s.read_bits(1, sps.seq_scaling_matrix_present_flag);
            if (sps.seq_scaling_matrix_present_flag) {
                status = parse_scaling_matrices(s, sps.sm, true, sps.chroma_format_idc);
                if (!status)
                    break;
                /* for each list which is not transmited, use the fall-back scaling list
                   as defined in Table 7-2 � Assignment of mnemonic names to scaling list
                   indices and specification of fall-back rule */
                if (!sps.sm.scaling_matrices_4x4[SL_4x4_INTRA_Y].scaling_list_present_flag)
                    sps.sm.scaling_matrices_4x4[SL_4x4_INTRA_Y].copy(h264::scaling_list_default_4x4[0]);
                if (!sps.sm.scaling_matrices_4x4[SL_4x4_INTRA_Cb].scaling_list_present_flag)
                    sps.sm.scaling_matrices_4x4[SL_4x4_INTRA_Cb].copy(sps.sm.scaling_matrices_4x4[SL_4x4_INTRA_Y].scaling_list);
                if (!sps.sm.scaling_matrices_4x4[SL_4x4_INTRA_Cr].scaling_list_present_flag)
                    sps.sm.scaling_matrices_4x4[SL_4x4_INTRA_Cr].copy(sps.sm.scaling_matrices_4x4[SL_4x4_INTRA_Cb].scaling_list);
                if (!sps.sm.scaling_matrices_4x4[SL_4x4_INTER_Y].scaling_list_present_flag)
                    sps.sm.scaling_matrices_4x4[SL_4x4_INTER_Y].copy(h264::scaling_list_default_4x4[1]);
                if (!sps.sm.scaling_matrices_4x4[SL_4x4_INTER_Cb].scaling_list_present_flag)
                    sps.sm.scaling_matrices_4x4[SL_4x4_INTER_Cb].copy(sps.sm.scaling_matrices_4x4[SL_4x4_INTER_Y].scaling_list);
                if (!sps.sm.scaling_matrices_4x4[SL_4x4_INTER_Cr].scaling_list_present_flag)
                    sps.sm.scaling_matrices_4x4[SL_4x4_INTER_Cr].copy(sps.sm.scaling_matrices_4x4[SL_4x4_INTER_Cb].scaling_list);

                if (!sps.sm.scaling_matrices_8x8[SL_8x8_INTRA_Y].scaling_list_present_flag)
                    sps.sm.scaling_matrices_8x8[SL_8x8_INTRA_Y].copy(h264::scaling_list_default_8x8[0]);
                if (!sps.sm.scaling_matrices_8x8[SL_8x8_INTER_Y].scaling_list_present_flag)
                    sps.sm.scaling_matrices_8x8[SL_8x8_INTER_Y].copy(h264::scaling_list_default_8x8[1]);

                if (sps.chroma_format_idc == 3) {
                    if (!sps.sm.scaling_matrices_8x8[SL_8x8_INTRA_Cb].scaling_list_present_flag)
                        sps.sm.scaling_matrices_8x8[SL_8x8_INTRA_Cb].copy(sps.sm.scaling_matrices_8x8[SL_8x8_INTRA_Y].scaling_list);
                    if (!sps.sm.scaling_matrices_8x8[SL_8x8_INTER_Cb].scaling_list_present_flag)
                        sps.sm.scaling_matrices_8x8[SL_8x8_INTER_Cb].copy(sps.sm.scaling_matrices_8x8[SL_8x8_INTER_Y].scaling_list);
                    if (!sps.sm.scaling_matrices_8x8[SL_8x8_INTRA_Cr].scaling_list_present_flag)
                        sps.sm.scaling_matrices_8x8[SL_8x8_INTRA_Cr].copy(sps.sm.scaling_matrices_8x8[SL_8x8_INTRA_Cb].scaling_list);
                    if (!sps.sm.scaling_matrices_8x8[SL_8x8_INTER_Cr].scaling_list_present_flag)
                        sps.sm.scaling_matrices_8x8[SL_8x8_INTER_Cr].copy(sps.sm.scaling_matrices_8x8[SL_8x8_INTER_Cb].scaling_list);
                }
            }
            else
                sps.sm.set_defaults();
        }
        else {
            sps.chroma_format_idc = 1;
            sps.separate_colour_plane_flag = 0;
            sps.bit_depth_luma_minus8 = 0;
            sps.bit_depth_chroma_minus8 = 0;
            sps.qpprime_y_zero_transform_bypass_flag = 0;
            sps.seq_scaling_matrix_present_flag = 0;
            sps.sm.set_defaults();
        }

        s.read_exp_golomb_u(sps.log2_max_frame_num_minus4);
        if (!CHK_STRUCT_RANGE(sps, log2_max_frame_num_minus4, 0U, 12U, std::cout)) {
            s.mark_corrupted();
            break;
        }

        s.read_exp_golomb_u(sps.pic_order_cnt_type);
        if (!CHK_STRUCT_RANGE(sps, pic_order_cnt_type, 0U, 2U, std::cout)) {
            s.mark_corrupted();
            break;
        }

        if (0 == sps.pic_order_cnt_type)
            s.read_exp_golomb_u(sps.t0.log2_max_pic_order_cnt_lsb_minus4);
        else
        if (1 == sps.pic_order_cnt_type) {
            s.read_bits(1, sps.t1.delta_pic_order_always_zero_flag);
            s.read_exp_golomb_s(sps.t1.offset_for_non_ref_pic);
            s.read_exp_golomb_s(sps.t1.offset_for_top_to_bottom_field);
            s.read_exp_golomb_u(sps.t1.num_ref_frames_in_pic_order_cnt_cycle);
            if (!CHK_STRUCT_RANGE(sps, t1.num_ref_frames_in_pic_order_cnt_cycle, 0U, 255U, std::cout)) {
                s.mark_corrupted();
                break;
            }
            for (uint32_t i = 0; i < sps.t1.num_ref_frames_in_pic_order_cnt_cycle; ++i)
                if (!s.read_exp_golomb_s(sps.t1.offset_for_ref_frame[i]))
                    break;
        }
        else {
            /* do nothing */
        }

        if (s.status() != ISTREAM_STATUS_OK)
            break;

        s.read_exp_golomb_u(sps.max_num_ref_frames);
        s.read_bits(1, sps.gaps_in_frame_num_value_allowed_flag);
        s.read_exp_golomb_u(sps.pic_width_in_mbs_minus1);
        s.read_exp_golomb_u(sps.pic_height_in_map_units_minus1);

        s.read_bits(1, sps.frame_mbs_only_flag);
        if (!sps.frame_mbs_only_flag)
            s.read_bits(1, sps.mb_adaptive_frame_field_flag);
        else
            sps.mb_adaptive_frame_field_flag = 0;

        s.read_bits(1, sps.direct_8x8_inference_flag);

        s.read_bits(1, sps.frame_cropping_flag);
        if (sps.frame_cropping_flag) {
            s.read_exp_golomb_u(sps.frame_crop_left_offset);
            s.read_exp_golomb_u(sps.frame_crop_right_offset);
            s.read_exp_golomb_u(sps.frame_crop_top_offset);
            s.read_exp_golomb_u(sps.frame_crop_bottom_offset);
        }
        else {
            sps.frame_crop_left_offset = 0;
            sps.frame_crop_right_offset = 0;
            sps.frame_crop_top_offset = 0;
            sps.frame_crop_bottom_offset = 0;
        }

        s.read_bits(1, sps.vui_parameters_present_flag);
        if (sps.vui_parameters_present_flag)
            parse_vui_parameters(s, sps.vui);

        if (s.status() != ISTREAM_STATUS_OK)
            break;

        m_recent_sps = seq_parameter_set_id;

        sps.set_valid(true);
        retval = h264_parser_status_e::SPS_PARSED;
    } while (0);

    return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xb(%rsp), %rsi
movq %rbx, %rdi
callq 0x692a
leaq 0xa(%rsp), %rsi
movq %rbx, %rdi
callq 0x692a
leaq 0x9(%rsp), %rsi
movq %rbx, %rdi
callq 0x692a
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0x6160
movzbl %al, %esi
leaq 0x10322(%rip), %rdi     # 0x1470a
movq 0x19bd1(%rip), %rdx     # 0x1dfc0
callq 0x6109
pushq $0x2
popq %rbp
testb %al, %al
je 0x49e2
movl 0xc(%rsp), %esi
leaq 0x10256(%rip), %rdi     # 0x14660
movq 0x19baf(%rip), %r8      # 0x1dfc0
pushq $0x1f
popq %rcx
xorl %edx, %edx
callq 0x61f6
testb %al, %al
je 0x49e2
movl 0xc(%rsp), %ecx
imulq $0xb00, %rcx, %rax      # imm = 0xB00
leaq (%r14,%rax), %r13
addq $0x128, %r13            # imm = 0x128
movzbl 0xb(%rsp), %eax
movb %al, 0x9(%r13)
movb 0xa(%rsp), %dl
movb %dl, 0xa(%r13)
movb 0x9(%rsp), %dl
movb %dl, 0xb(%r13)
movl %ecx, 0xc(%r13)
leal -0x53(%rax), %ecx
cmpl $0x3d, %ecx
ja 0x44b9
movabsq $0x2000208808020009, %rdx # imm = 0x2000208808020009
btq %rcx, %rdx
jae 0x44b9
leaq 0x10(%r13), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6160
movl 0x10(%r13), %esi
leaq 0x102ac(%rip), %rdi     # 0x14734
movq 0x19b31(%rip), %r8      # 0x1dfc0
pushq $0x3
popq %rcx
xorl %edx, %edx
callq 0x61f6
testb %al, %al
je 0x49e2
leaq 0x14(%r13), %rdx
cmpl $0x3, 0x10(%r13)
jne 0x44e3
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x5fee
jmp 0x44e6
cmpl $0xf4, %eax
je 0x446e
cmpl $0x2c, %eax
je 0x446e
movl $0x1, 0x10(%r13)
leaq 0x28(%r13), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x14(%r13)
andl $0x0, 0x24(%r13)
jmp 0x4832
andl $0x0, (%rdx)
leaq 0x18(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
movl 0x18(%r13), %esi
leaq 0x1024d(%rip), %rdi     # 0x1474a
movq 0x19abc(%rip), %r8      # 0x1dfc0
pushq $0x6
popq %rcx
xorl %edx, %edx
callq 0x61f6
testb %al, %al
je 0x49e2
leaq 0x1c(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
movl 0x1c(%r13), %esi
leaq 0x10237(%rip), %rdi     # 0x14764
movq 0x19a8c(%rip), %r8      # 0x1dfc0
pushq $0x6
popq %rcx
xorl %edx, %edx
callq 0x61f6
testb %al, %al
je 0x49e2
leaq 0x20(%r13), %rdx
pushq $0x1
popq %r12
movq %rbx, %rdi
movl %r12d, %esi
callq 0x5fee
leaq 0x24(%r13), %rdx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x5fee
leaq 0x28(%r13), %rdx
cmpl $0x0, 0x24(%r13)
je 0x482f
movl (%r15), %r8d
pushq $0x1
popq %rcx
movq %rbx, %rsi
callq 0x3ac4
testb %al, %al
je 0x49e6
cmpl $0x0, 0x44(%r13)
jne 0x45a5
movaps 0x10965(%rip), %xmm0    # 0x14f00
movaps %xmm0, 0x48(%r13)
movb $0x1, 0x40(%r13)
cmpl $0x0, 0x64(%r13)
jne 0x45bb
movaps 0x48(%r13), %xmm0
movaps %xmm0, 0x68(%r13)
movb $0x1, 0x60(%r13)
cmpl $0x0, 0x84(%r13)
jne 0x45da
movaps 0x68(%r13), %xmm0
movaps %xmm0, 0x88(%r13)
movb $0x1, 0x80(%r13)
cmpl $0x0, 0xa4(%r13)
jne 0x45fb
movaps 0x10925(%rip), %xmm0    # 0x14f10
movaps %xmm0, 0xa8(%r13)
movb $0x1, 0xa0(%r13)
cmpl $0x0, 0xc4(%r13)
jne 0x461d
movaps 0xa8(%r13), %xmm0
movaps %xmm0, 0xc8(%r13)
movb $0x1, 0xc0(%r13)
cmpl $0x0, 0xe4(%r13)
jne 0x463f
movaps 0xc8(%r13), %xmm0
movaps %xmm0, 0xe8(%r13)
movb $0x1, 0xe0(%r13)
cmpl $0x0, 0x104(%r13)
jne 0x468d
movaps 0x10900(%rip), %xmm0    # 0x14f50
movaps %xmm0, 0x138(%r13)
movaps 0x108e1(%rip), %xmm0    # 0x14f40
movaps %xmm0, 0x128(%r13)
movaps 0x108c2(%rip), %xmm0    # 0x14f30
movaps %xmm0, 0x118(%r13)
movaps 0x108a3(%rip), %xmm0    # 0x14f20
movaps %xmm0, 0x108(%r13)
movb $0x1, 0x100(%r13)
cmpl $0x0, 0x154(%r13)
jne 0x46db
movaps 0x108f2(%rip), %xmm0    # 0x14f90
movaps %xmm0, 0x188(%r13)
movaps 0x108d3(%rip), %xmm0    # 0x14f80
movaps %xmm0, 0x178(%r13)
movaps 0x108b4(%rip), %xmm0    # 0x14f70
movaps %xmm0, 0x168(%r13)
movaps 0x10895(%rip), %xmm0    # 0x14f60
movaps %xmm0, 0x158(%r13)
movb $0x1, 0x150(%r13)
cmpl $0x3, (%r15)
jne 0x4837
cmpl $0x0, 0x1a4(%r13)
jne 0x4737
movaps 0x108(%r13), %xmm0
movaps 0x118(%r13), %xmm1
movaps 0x128(%r13), %xmm2
movaps 0x138(%r13), %xmm3
movaps %xmm3, 0x1d8(%r13)
movaps %xmm2, 0x1c8(%r13)
movaps %xmm1, 0x1b8(%r13)
movaps %xmm0, 0x1a8(%r13)
movb $0x1, 0x1a0(%r13)
cmpl $0x0, 0x1f4(%r13)
jne 0x4789
movaps 0x158(%r13), %xmm0
movaps 0x168(%r13), %xmm1
movaps 0x178(%r13), %xmm2
movaps 0x188(%r13), %xmm3
movaps %xmm3, 0x228(%r13)
movaps %xmm2, 0x218(%r13)
movaps %xmm1, 0x208(%r13)
movaps %xmm0, 0x1f8(%r13)
movb $0x1, 0x1f0(%r13)
cmpl $0x0, 0x244(%r13)
jne 0x47db
movaps 0x1a8(%r13), %xmm0
movaps 0x1b8(%r13), %xmm1
movaps 0x1c8(%r13), %xmm2
movaps 0x1d8(%r13), %xmm3
movaps %xmm3, 0x278(%r13)
movaps %xmm2, 0x268(%r13)
movaps %xmm1, 0x258(%r13)
movaps %xmm0, 0x248(%r13)
movb $0x1, 0x240(%r13)
cmpl $0x0, 0x294(%r13)
jne 0x4837
movaps 0x1f8(%r13), %xmm0
movaps 0x208(%r13), %xmm1
movaps 0x218(%r13), %xmm2
movaps 0x228(%r13), %xmm3
movaps %xmm3, 0x2c8(%r13)
movaps %xmm2, 0x2b8(%r13)
movaps %xmm1, 0x2a8(%r13)
movaps %xmm0, 0x298(%r13)
movb $0x1, 0x290(%r13)
jmp 0x4837
movq %rdx, %rdi
callq 0x63f4
leaq 0x2d8(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
movl 0x2d8(%r13), %esi
leaq 0xff2c(%rip), %rdi      # 0x14780
movq 0x19765(%rip), %r8      # 0x1dfc0
pushq $0xc
popq %rcx
xorl %edx, %edx
callq 0x61f6
testb %al, %al
je 0x49e2
leaq 0x2dc(%r13), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6160
movl 0x2dc(%r13), %esi
leaq 0xff11(%rip), %rdi      # 0x1479e
movq 0x1972c(%rip), %r8      # 0x1dfc0
pushq $0x2
popq %rbp
xorl %edx, %edx
movl %ebp, %ecx
callq 0x61f6
testb %al, %al
je 0x49e2
movl (%r15), %eax
cmpl $0x1, %eax
je 0x4943
testl %eax, %eax
jne 0x48c7
leaq 0x2e0(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
cmpl $0x0, 0x20(%rbx)
jne 0x49e6
leaq 0x6ec(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
leaq 0x6f0(%r13), %rdx
pushq $0x1
popq %r15
movq %rbx, %rdi
movl %r15d, %esi
callq 0x5fee
leaq 0x6f4(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
leaq 0x6f8(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
leaq 0x6fc(%r13), %rdx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x5fee
leaq 0x700(%r13), %rdx
cmpl $0x0, 0x6fc(%r13)
je 0x49f7
andl $0x0, (%rdx)
jmp 0x4a02
leaq 0x2e0(%r13), %rdx
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x5fee
leaq 0x2e4(%r13), %rsi
movq %rbx, %rdi
callq 0x644a
leaq 0x2e8(%r13), %rsi
movq %rbx, %rdi
callq 0x644a
leaq 0x2ec(%r13), %rsi
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
callq 0x6160
movl 0x2ec(%r13), %esi
leaq 0xfe20(%rip), %rdi      # 0x147b5
movq 0x19624(%rip), %r8      # 0x1dfc0
xorl %edx, %edx
movl $0xff, %ecx
callq 0x61f6
testb %al, %al
je 0x49e2
leaq 0x2f0(%r13), %rsi
pushq $-0x1
popq %r12
movq 0x10(%rsp), %rax
movl (%rax), %eax
incq %r12
cmpq %rax, %r12
jae 0x48c7
leaq 0x4(%rsi), %r15
movq %rbx, %rdi
callq 0x644a
movq %r15, %rsi
testb %al, %al
jne 0x49b7
jmp 0x48c7
orb $0x4, 0x20(%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x5fee
leaq 0x704(%r13), %rdx
pushq $0x1
popq %r15
movq %rbx, %rdi
movl %r15d, %esi
callq 0x5fee
leaq 0x708(%r13), %rdx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x5fee
leaq 0x70c(%r13), %rsi
cmpl $0x0, 0x708(%r13)
je 0x4a72
movq %rbx, %rdi
callq 0x6160
leaq 0x710(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
leaq 0x714(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
leaq 0x718(%r13), %rsi
movq %rbx, %rdi
callq 0x6160
jmp 0x4a78
xorps %xmm0, %xmm0
movups %xmm0, (%rsi)
leaq 0x71c(%r13), %rdx
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x5fee
cmpl $0x0, 0x71c(%r13)
je 0x4aa3
leaq 0x720(%r13), %rdx
movq %rbx, %rsi
callq 0x3c72
cmpl $0x0, 0x20(%rbx)
jne 0x49e6
movl 0xc(%rsp), %eax
movl %eax, 0x16128(%r14)
movb $0x1, 0x8(%r13)
pushq $0x4
popq %rbp
jmp 0x49e6
nop