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

    do {
        bool status;
        uint8_t last;

        h264::sei& sei = m_sei;
        sei.reset();

        sei.payload_type = 0;
        sei.payload_size = 0;

        while ((true == (status = s.read_u8(last))) && 0xff == last)
            sei.payload_type += 255;

        if (status)
            sei.payload_type += last;
        else
            break;

        while ((true == (status = s.read_u8(last))) && 0xff == last)
            sei.payload_size += 255;

        if (status)
            sei.payload_size += last;
        else
            break;

        uint32_t i = 0;
        while ((i < sei.payload_size) && (i < sizeof(sei.payload_data)) && (true == (status = s.read_u8(sei.payload_data[i]))))
            ++i;

        if (!status)
            break;

        sei.set_valid(true);
        retval = h264_parser_status_e::SEI_PARSED;
    } while (0);

    return retval;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x2, 0x24(%rsp)
movq 0x8(%rsp), %rax
addq $0x87938, %rax          # imm = 0x87938
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
callq 0x17530
movq 0x18(%rsp), %rax
movl $0x0, 0xc(%rax)
movq 0x18(%rsp), %rax
movl $0x0, 0x10(%rax)
movq 0x28(%rsp), %rdi
leaq 0x22(%rsp), %rsi
callq 0x17540
movb %al, %cl
andb $0x1, %cl
movb %cl, 0x23(%rsp)
andb $0x1, %al
movzbl %al, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl %edx, %ecx
movb %al, 0x7(%rsp)
jne 0x15341
movzbl 0x22(%rsp), %ecx
movl $0xff, %eax
cmpl %ecx, %eax
sete %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x1534b
jmp 0x1535e
movq 0x18(%rsp), %rax
movl 0xc(%rax), %ecx
addl $0xff, %ecx
movl %ecx, 0xc(%rax)
jmp 0x15302
testb $0x1, 0x23(%rsp)
je 0x15377
movzbl 0x22(%rsp), %ecx
movq 0x18(%rsp), %rax
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
jmp 0x1537c
jmp 0x15493
jmp 0x1537e
movq 0x28(%rsp), %rdi
leaq 0x22(%rsp), %rsi
callq 0x17540
movb %al, %cl
andb $0x1, %cl
movb %cl, 0x23(%rsp)
andb $0x1, %al
movzbl %al, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl %edx, %ecx
movb %al, 0x6(%rsp)
jne 0x153bd
movzbl 0x22(%rsp), %ecx
movl $0xff, %eax
cmpl %ecx, %eax
sete %al
movb %al, 0x6(%rsp)
movb 0x6(%rsp), %al
testb $0x1, %al
jne 0x153c7
jmp 0x153da
movq 0x18(%rsp), %rax
movl 0x10(%rax), %ecx
addl $0xff, %ecx
movl %ecx, 0x10(%rax)
jmp 0x1537e
testb $0x1, 0x23(%rsp)
je 0x153f3
movzbl 0x22(%rsp), %ecx
movq 0x18(%rsp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
jmp 0x153f8
jmp 0x15493
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %ecx
movq 0x18(%rsp), %rdx
xorl %eax, %eax
cmpl 0x10(%rdx), %ecx
movb %al, 0x5(%rsp)
jae 0x1545c
movl 0x14(%rsp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq $0x10, %rcx
movb %al, 0x5(%rsp)
jae 0x1545c
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
addq $0x14, %rsi
movl 0x14(%rsp), %eax
addq %rax, %rsi
callq 0x17540
movb %al, %cl
andb $0x1, %cl
movb %cl, 0x23(%rsp)
andb $0x1, %al
movzbl %al, %ecx
movl $0x1, %eax
cmpl %ecx, %eax
sete %al
movb %al, 0x5(%rsp)
movb 0x5(%rsp), %al
testb $0x1, %al
jne 0x15466
jmp 0x15473
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x15400
testb $0x1, 0x23(%rsp)
jne 0x1547c
jmp 0x15493
movq 0x18(%rsp), %rdi
movl $0x1, %esi
callq 0x17160
movl $0x6, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x38, %rsp
retq
nopl (%rax)