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

    do {
        s.read_bits(1, drpm.adaptive_ref_pic_marking_mode_flag);
        if (drpm.adaptive_ref_pic_marking_mode_flag) {
            size_t i = 0;
            uint32_t memory_management_control_operation;
            uint32_t difference_of_pic_nums_minus1;
            uint32_t long_term_pic_num;
            uint32_t long_term_frame_idx;
            uint32_t max_long_term_frame_idx_plus1;

            do {
                s.read_exp_golomb_u(memory_management_control_operation);

                difference_of_pic_nums_minus1 = 0;
                long_term_pic_num = 0;
                long_term_frame_idx = 0;
                max_long_term_frame_idx_plus1 = 0;

                if (memory_management_control_operation) {
                    if (memory_management_control_operation == 1 ||
                        memory_management_control_operation == 3)
                        s.read_exp_golomb_u(difference_of_pic_nums_minus1);

                    if (memory_management_control_operation == 2)
                        s.read_exp_golomb_u(long_term_pic_num);

                    if (memory_management_control_operation == 3 ||
                        memory_management_control_operation == 6)
                        s.read_exp_golomb_u(long_term_frame_idx);

                    if (memory_management_control_operation == 4)
                        s.read_exp_golomb_u(max_long_term_frame_idx_plus1);
                }

                if (i < TABLE_ELEMENTS(drpm.mmco)) {
                    drpm.mmco[i].memory_management_control_operation = memory_management_control_operation;
                    drpm.mmco[i].difference_of_pic_nums_minus1 = difference_of_pic_nums_minus1;
                    drpm.mmco[i].long_term_pic_num = long_term_pic_num;
                    drpm.mmco[i].long_term_frame_idx = long_term_frame_idx;
                    drpm.mmco[i].max_long_term_frame_idx_plus1 = max_long_term_frame_idx_plus1;
                }

                i++;
            } while ((s.status() == ISTREAM_STATUS_OK) && (memory_management_control_operation != 0));
        }

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

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

    return retval;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movb $0x0, 0x2f(%rsp)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rdx
addq $0xc, %rdx
movl $0x1, %esi
callq 0x16f30
movq 0x30(%rsp), %rax
cmpl $0x0, 0xc(%rax)
je 0x13a19
movq $0x0, 0x20(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x17200
movl $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x0, 0x1c(%rsp)
je 0x13956
cmpl $0x1, 0x1c(%rsp)
je 0x138fc
cmpl $0x3, 0x1c(%rsp)
jne 0x1390b
movq 0x38(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x17200
cmpl $0x2, 0x1c(%rsp)
jne 0x13921
movq 0x38(%rsp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x17200
cmpl $0x3, 0x1c(%rsp)
je 0x1392f
cmpl $0x6, 0x1c(%rsp)
jne 0x1393e
movq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x17200
cmpl $0x4, 0x1c(%rsp)
jne 0x13954
movq 0x38(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x17200
jmp 0x13956
cmpq $0x4, 0x20(%rsp)
jae 0x139da
movl 0x1c(%rsp), %ecx
movq 0x30(%rsp), %rax
addq $0x10, %rax
imulq $0x14, 0x20(%rsp), %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl 0x18(%rsp), %ecx
movq 0x30(%rsp), %rax
addq $0x10, %rax
imulq $0x14, 0x20(%rsp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl 0x14(%rsp), %ecx
movq 0x30(%rsp), %rax
addq $0x10, %rax
imulq $0x14, 0x20(%rsp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl 0x10(%rsp), %ecx
movq 0x30(%rsp), %rax
addq $0x10, %rax
imulq $0x14, 0x20(%rsp), %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl 0xc(%rsp), %ecx
movq 0x30(%rsp), %rax
addq $0x10, %rax
imulq $0x14, 0x20(%rsp), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rdi
callq 0x17150
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0xb(%rsp)
jne 0x13a0b
cmpl $0x0, 0x1c(%rsp)
setne %al
movb %al, 0xb(%rsp)
movb 0xb(%rsp), %al
testb $0x1, %al
jne 0x138b8
jmp 0x13a19
movq 0x38(%rsp), %rdi
callq 0x17150
cmpl $0x0, %eax
je 0x13a2a
jmp 0x13a3e
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0x17160
movb $0x1, 0x2f(%rsp)
movb 0x2f(%rsp), %al
andb $0x1, %al
addq $0x48, %rsp
retq
nopl (%rax)