// File: /workspace/github_cpp_makefile_star2_O3/lukasz-wiecaszek[P]h264iframedecoder/h264_parser.cpp
// Function: ymn::h264_parser::parse_nal_unit(ymn::istream<0>&)
h264_parser_status_e h264_parser::parse_nal_unit(istream_be& s)
{
    uint8_t nal_header;
    uint32_t nal_ref_idc;
    uint32_t nal_unit_type;
    bool status;

    status = s.read_u8(nal_header);
    if (!status)
        return h264_parser_status_e::NAL_UNIT_CORRUPTED;

    nal_ref_idc = (nal_header & 0x60) >> 5;
    nal_unit_type = nal_header & 0x1f;

    std::cout << std::endl;
    std::cout << "nal_unit_type: " << nal_unit_type;
    std::cout << " '" << ymn::to_string(static_cast<nal_unit_type_e>(nal_unit_type)) << "'";
    std::cout << " size: " << s.size();
    std::cout << std::endl;

    switch (static_cast<nal_unit_type_e>(nal_unit_type)) {
        case nal_unit_type_e::AUD:
            return parse_aud(s);

        case nal_unit_type_e::SPS:
            return parse_sps(s);

        case nal_unit_type_e::PPS:
            return parse_pps(s);

        case nal_unit_type_e::SEI:
            return parse_sei(s);

        case nal_unit_type_e::CODED_SLICE_NON_IDR_PICTURE:
        case nal_unit_type_e::CODED_SLICE_IDR_PICTURE:
            return parse_slice_header(s, nal_ref_idc, nal_unit_type);

        default:
            break;
    }

    return h264_parser_status_e::NAL_UNIT_SKIPPED;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x7(%rsp), %rsi
movq %rbx, %rdi
callq 0x7946
movl %eax, %ecx
movl $0x2, %eax
testb %cl, %cl
je 0x6da2
movzbl 0x7(%rsp), %r15d
movl %r15d, %r12d
andl $0x1f, %r12d
movq 0x1a365(%rip), %r13     # 0x20fc0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
leaq 0x11f1b(%rip), %rsi     # 0x18ba5
movl $0xf, %edx
movq %r13, %rdi
callq 0x21d0
movq %r13, %rdi
movq %r12, %rsi
callq 0x2100
leaq 0x159de(%rip), %rsi     # 0x1c687
movl $0x2, %edx
movq %r13, %rdi
callq 0x21d0
movl %r12d, %eax
leaq 0x19da0(%rip), %rcx     # 0x20a60
movq (%rcx,%rax,8), %rbp
movq %rbp, %rdi
callq 0x20b0
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x21d0
leaq 0x159a7(%rip), %rsi     # 0x1c688
movl $0x1, %edx
movq %r13, %rdi
callq 0x21d0
leaq 0x11ec0(%rip), %rsi     # 0x18bb5
movl $0x7, %edx
movq %r13, %rdi
callq 0x21d0
movq 0x8(%rbx), %rsi
movq %r13, %rdi
callq 0x2100
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movl $0x1, %eax
leal -0x1(%r12), %ecx
cmpl $0x8, %ecx
ja 0x6da2
leaq 0x11860(%rip), %rdx     # 0x185ac
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x5, %r15d
andl $0x3, %r15d
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x614e
jmp 0x6da2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x602e
jmp 0x6da2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x484a
jmp 0x6da2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4946
jmp 0x6da2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x51ea
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop