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

    do {
        if (!CHK_EXPR(s.read_exp_golomb_u(hrd.cpb_cnt_minus1), std::cout) ||
            !CHK_STRUCT_RANGE(hrd, cpb_cnt_minus1, 0U, 31U, std::cout)) {
            s.mark_corrupted();
            break;
        }

        s.read_bits(4, hrd.bit_rate_scale);
        s.read_bits(4, hrd.cpb_size_scale);

        for (uint32_t schedSelIdx = 0;
            (schedSelIdx <= hrd.cpb_cnt_minus1) && (s.status() == ISTREAM_STATUS_OK);
           ++schedSelIdx) {
            s.read_exp_golomb_u(hrd.bit_rate_value_minus1[schedSelIdx]);
            s.read_exp_golomb_u(hrd.cpb_size_value_minus1[schedSelIdx]);
            s.read_bits(1, hrd.cbr_flag[schedSelIdx]);
        }

        s.read_bits(5, hrd.initial_cpb_removal_delay_length_minus1);
        s.read_bits(5, hrd.cpb_removal_delay_length_minus1);
        s.read_bits(5, hrd.dpb_output_delay_length_minus1);
        s.read_bits(5, hrd.time_offset_length);

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

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

    return retval;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movb $0x0, 0xf(%rsp)
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
addq $0xc, %rsi
callq 0x17200
movzbl %al, %esi
andl $0x1, %esi
leaq 0x12460(%rip), %rdi     # 0x25268
movq 0x1b1b1(%rip), %rdx     # 0x2dfc0
callq 0x17180
testb $0x1, %al
jne 0x12e1a
jmp 0x12e40
movq 0x10(%rsp), %rax
movl 0xc(%rax), %esi
leaq 0x12467(%rip), %rdi     # 0x25290
xorl %edx, %edx
movl $0x1f, %ecx
movq 0x1b189(%rip), %r8      # 0x2dfc0
callq 0x17330
testb $0x1, %al
jne 0x12e4f
movq 0x18(%rsp), %rdi
callq 0x17130
jmp 0x12fbf
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
addq $0x10, %rdx
movl $0x4, %esi
callq 0x16f30
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
addq $0x14, %rdx
movl $0x4, %esi
callq 0x16f30
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %ecx
movq 0x10(%rsp), %rdx
xorl %eax, %eax
cmpl 0xc(%rdx), %ecx
movb %al, 0x7(%rsp)
ja 0x12eaf
movq 0x18(%rsp), %rdi
callq 0x17150
cmpl $0x0, %eax
sete %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x12eb9
jmp 0x12f2e
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
addq $0x18, %rsi
movl 0x8(%rsp), %eax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x17200
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
addq $0x98, %rsi
movl 0x8(%rsp), %eax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x17200
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
addq $0x118, %rdx            # imm = 0x118
movl 0x8(%rsp), %eax
shlq $0x2, %rax
addq %rax, %rdx
movl $0x1, %esi
callq 0x16f30
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x12e87
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
addq $0x198, %rdx            # imm = 0x198
movl $0x5, %esi
callq 0x16f30
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
addq $0x19c, %rdx            # imm = 0x19C
movl $0x5, %esi
callq 0x16f30
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
addq $0x1a0, %rdx            # imm = 0x1A0
movl $0x5, %esi
callq 0x16f30
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
addq $0x1a4, %rdx            # imm = 0x1A4
movl $0x5, %esi
callq 0x16f30
movq 0x18(%rsp), %rdi
callq 0x17150
cmpl $0x0, %eax
je 0x12fab
jmp 0x12fbf
movq 0x10(%rsp), %rdi
movl $0x1, %esi
callq 0x17160
movb $0x1, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
addq $0x28, %rsp
retq
nopw (%rax,%rax)