// File: /workspace/github_cpp_makefile_star2_O1/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 0x7b70
movl %eax, %ecx
movl $0x2, %eax
testb %cl, %cl
je 0x6f0e
movzbl 0x7(%rsp), %r15d
movl %r15d, %r12d
andl $0x1f, %r12d
movq 0x1b1f9(%rip), %r13     # 0x21fc0
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 0x12daf(%rip), %rsi     # 0x19ba5
movl $0xf, %edx
movq %r13, %rdi
callq 0x21d0
movq %r13, %rdi
movq %r12, %rsi
callq 0x2100
leaq 0x16882(%rip), %rsi     # 0x1d697
movl $0x2, %edx
movq %r13, %rdi
callq 0x21d0
movl %r12d, %eax
leaq 0x1ac1c(%rip), %rcx     # 0x21a48
movq (%rcx,%rax,8), %rbp
movq %rbp, %rdi
callq 0x20b0
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x21d0
leaq 0x1684b(%rip), %rsi     # 0x1d698
movl $0x1, %edx
movq %r13, %rdi
callq 0x21d0
leaq 0x12d54(%rip), %rsi     # 0x19bb5
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 0x6f0e
leaq 0x126f4(%rip), %rdx     # 0x195ac
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 0x62b4
jmp 0x6f0e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6190
jmp 0x6f0e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4996
jmp 0x6f0e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4a9a
jmp 0x6f0e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5330
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop