// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
addq $0xc, %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
cmpl $0x0, 0xc(%rbx)
je 0x3ccb
leaq 0x10(%rbx), %rdx
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x5fee
cmpl $0xff, 0x10(%rbx)
jne 0x3ccb
leaq 0x14(%rbx), %rdx
pushq $0x10
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
leaq 0x18(%rbx), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
leaq 0x1c(%rbx), %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
cmpl $0x0, 0x1c(%rbx)
je 0x3cef
leaq 0x20(%rbx), %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
leaq 0x24(%rbx), %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
cmpl $0x0, 0x24(%rbx)
je 0x3d65
leaq 0x28(%rbx), %rdx
pushq $0x3
popq %rsi
movq %r14, %rdi
callq 0x5fee
leaq 0x2c(%rbx), %rdx
pushq $0x1
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
leaq 0x30(%rbx), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
cmpl $0x0, 0x30(%rbx)
je 0x3d65
leaq 0x34(%rbx), %rdx
pushq $0x8
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
leaq 0x38(%rbx), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
leaq 0x3c(%rbx), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
leaq 0x40(%rbx), %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
cmpl $0x0, 0x40(%rbx)
je 0x3d92
leaq 0x44(%rbx), %rsi
movq %r14, %rdi
callq 0x6160
leaq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x6160
leaq 0x4c(%rbx), %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
cmpl $0x0, 0x4c(%rbx)
je 0x3dd5
leaq 0x50(%rbx), %rdx
pushq $0x20
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
leaq 0x54(%rbx), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
leaq 0x58(%rbx), %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
leaq 0x5c(%rbx), %r15
pushq $0x1
popq %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x5fee
cmpl $0x0, 0x5c(%rbx)
je 0x3df9
leaq 0x60(%rbx), %rdx
movq %r14, %rsi
callq 0x3b12
leaq 0x208(%rbx), %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
cmpl $0x0, 0x208(%rbx)
je 0x3e2f
leaq 0x210(%rbx), %rdx
movq %r14, %rsi
callq 0x3b12
cmpl $0x0, 0x208(%rbx)
sete %al
jmp 0x3e31
movb $0x1, %al
cmpl $0x0, (%r15)
jne 0x3e3b
testb %al, %al
jne 0x3e4d
leaq 0x3b8(%rbx), %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
leaq 0x3bc(%rbx), %rdx
pushq $0x1
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
leaq 0x3c0(%rbx), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x5fee
cmpl $0x0, 0x3c0(%rbx)
je 0x3ee7
leaq 0x3c4(%rbx), %rdx
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5fee
leaq 0x3c8(%rbx), %rsi
movq %r14, %rdi
callq 0x6160
leaq 0x3cc(%rbx), %rsi
movq %r14, %rdi
callq 0x6160
leaq 0x3d0(%rbx), %rsi
movq %r14, %rdi
callq 0x6160
leaq 0x3d4(%rbx), %rsi
movq %r14, %rdi
callq 0x6160
leaq 0x3d8(%rbx), %rsi
movq %r14, %rdi
callq 0x6160
leaq 0x3dc(%rbx), %rsi
movq %r14, %rdi
callq 0x6160
movl 0x20(%r14), %eax
testl %eax, %eax
jne 0x3ef3
movb $0x1, 0x8(%rbx)
testl %eax, %eax
sete %al
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop