// File: /workspace/github_cpp_makefile_star2_O3/lukasz-wiecaszek[P]h264iframedecoder/h264_parser.cpp
// Function: ymn::h264_parser::parse_vui_parameters(ymn::istream<0>&, ymn::h264::vui_parameters&)
bool h264_parser::parse_vui_parameters(istream_be& s, h264::vui_parameters& vui)
{
    bool retval = false;

    do {
        s.read_bits(1, vui.aspect_ratio_info_present_flag);
        if (vui.aspect_ratio_info_present_flag) {
            s.read_bits(8, vui.aspect_ratio_idc);
            if (vui.aspect_ratio_idc == static_cast<uint32_t>(h264::aspect_ratio_idc_e::SAR_EXTENDED)) {
                s.read_bits(16, vui.sar_width);
                s.read_bits(16, vui.sar_height);
            }
        }

        s.read_bits(1, vui.overscan_info_present_flag);
        if (vui.overscan_info_present_flag)
            s.read_bits(1, vui.overscan_appropriate_flag);

        s.read_bits(1, vui.video_signal_type_present_flag);
        if (vui.video_signal_type_present_flag) {
            s.read_bits(3, vui.video_format);
            s.read_bits(1, vui.video_full_range_flag);
            s.read_bits(1, vui.colour_description_present_flag);
            if (vui.colour_description_present_flag) {
                s.read_bits(8, vui.colour_primaries);
                s.read_bits(8, vui.transfer_characteristics);
                s.read_bits(8, vui.matrix_coefficients);
            }
        }

        s.read_bits(1, vui.chroma_loc_info_present_flag);
        if (vui.chroma_loc_info_present_flag) {
            s.read_exp_golomb_u(vui.chroma_sample_loc_type_top_field);
            s.read_exp_golomb_u(vui.chroma_sample_loc_type_bottom_field);
        }

        s.read_bits(1, vui.timing_info_present_flag);
        if (vui.timing_info_present_flag) {
            s.read_bits(32, vui.num_units_in_tick);
            s.read_bits(32, vui.time_scale);
            s.read_bits(1, vui.fixed_frame_rate_flag);
        }

        s.read_bits(1, vui.nal_hrd_parameters_present_flag);
        if (vui.nal_hrd_parameters_present_flag)
            parse_hrd_parameters(s, vui.nal_hrd);

        s.read_bits(1, vui.vcl_hrd_parameters_present_flag);
        if (vui.vcl_hrd_parameters_present_flag)
            parse_hrd_parameters(s, vui.vcl_hrd);

        if (vui.nal_hrd_parameters_present_flag || vui.vcl_hrd_parameters_present_flag) {
            s.read_bits(1, vui.low_delay_hrd_flag);
        }

        s.read_bits(1, vui.pic_struct_present_flag);
        s.read_bits(1, vui.bitstream_restriction_flag);
        if (vui.bitstream_restriction_flag) {
            s.read_bits(1, vui.motion_vectors_over_pic_boundaries_flag);
            s.read_exp_golomb_u(vui.max_bytes_per_pic_denom);
            s.read_exp_golomb_u(vui.max_bits_per_mb_denom);
            s.read_exp_golomb_u(vui.log2_max_mv_length_horizontal);
            s.read_exp_golomb_u(vui.log2_max_mv_length_vertical);
            s.read_exp_golomb_u(vui.max_num_reorder_frames);
            s.read_exp_golomb_u(vui.max_dec_frame_buffering);
        }

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

        vui.set_valid(true);
        retval = true;
    } while (0);

    return retval;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
addq $0xc, %rdx
movq %rsi, %rdi
movl $0x1, %esi
callq 0x6ee2
cmpl $0x0, 0xc(%rbx)
je 0x41e4
leaq 0x10(%rbx), %rdx
movq %r14, %rdi
movl $0x8, %esi
callq 0x6ee2
cmpl $0xff, 0x10(%rbx)
jne 0x41e4
leaq 0x14(%rbx), %rdx
movq %r14, %rdi
movl $0x10, %esi
callq 0x6ee2
leaq 0x18(%rbx), %rdx
movq %r14, %rdi
movl $0x10, %esi
callq 0x6ee2
leaq 0x1c(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
cmpl $0x0, 0x1c(%rbx)
je 0x420c
leaq 0x20(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
leaq 0x24(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
cmpl $0x0, 0x24(%rbx)
je 0x428f
leaq 0x28(%rbx), %rdx
movq %r14, %rdi
movl $0x3, %esi
callq 0x6ee2
leaq 0x2c(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
leaq 0x30(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
cmpl $0x0, 0x30(%rbx)
je 0x428f
leaq 0x34(%rbx), %rdx
movq %r14, %rdi
movl $0x8, %esi
callq 0x6ee2
leaq 0x38(%rbx), %rdx
movq %r14, %rdi
movl $0x8, %esi
callq 0x6ee2
leaq 0x3c(%rbx), %rdx
movq %r14, %rdi
movl $0x8, %esi
callq 0x6ee2
leaq 0x40(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
cmpl $0x0, 0x40(%rbx)
je 0x42be
leaq 0x44(%rbx), %rsi
movq %r14, %rdi
callq 0x70b4
leaq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x70b4
leaq 0x4c(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
cmpl $0x0, 0x4c(%rbx)
je 0x4308
leaq 0x50(%rbx), %rdx
movq %r14, %rdi
movl $0x20, %esi
callq 0x6ee2
leaq 0x54(%rbx), %rdx
movq %r14, %rdi
movl $0x20, %esi
callq 0x6ee2
leaq 0x58(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
leaq 0x5c(%rbx), %r15
movq %r14, %rdi
movl $0x1, %esi
movq %r15, %rdx
callq 0x6ee2
cmpl $0x0, 0x5c(%rbx)
je 0x432e
leaq 0x60(%rbx), %rdx
movq %r14, %rsi
callq 0x3fa2
leaq 0x208(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
cmpl $0x0, 0x208(%rbx)
je 0x4366
leaq 0x210(%rbx), %rdx
movq %r14, %rsi
callq 0x3fa2
cmpl $0x0, 0x208(%rbx)
sete %al
jmp 0x4368
movb $0x1, %al
cmpl $0x0, (%r15)
jne 0x4372
testb %al, %al
jne 0x4386
leaq 0x3b8(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
leaq 0x3bc(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
leaq 0x3c0(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
cmpl $0x0, 0x3c0(%rbx)
je 0x4425
leaq 0x3c4(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ee2
leaq 0x3c8(%rbx), %rsi
movq %r14, %rdi
callq 0x70b4
leaq 0x3cc(%rbx), %rsi
movq %r14, %rdi
callq 0x70b4
leaq 0x3d0(%rbx), %rsi
movq %r14, %rdi
callq 0x70b4
leaq 0x3d4(%rbx), %rsi
movq %r14, %rdi
callq 0x70b4
leaq 0x3d8(%rbx), %rsi
movq %r14, %rdi
callq 0x70b4
leaq 0x3dc(%rbx), %rsi
movq %r14, %rdi
callq 0x70b4
movl 0x20(%r14), %eax
testl %eax, %eax
jne 0x4431
movb $0x1, 0x8(%rbx)
testl %eax, %eax
sete %al
popq %rbx
popq %r14
popq %r15
retq