// File: /workspace/github_cpp_makefile_star2_O3/mmoanis[P]mpegts_demux/MpegTsDemux.cpp
// Function: MpegTsDemuxer::DecodePacket(Packet const&)
bool MpegTsDemuxer::DecodePacket(const Packet& packet)
{
    ++m_pnum;

    Packet::const_iterator p = packet.begin(), e = packet.end();
    PacketHeader header;
    if (!ReadHeader(p, e, header))
        return false;

    PID &id = header.id;
    //cout << "DecodePacket: PID=" << id << endl;

    // Lookup this ID in our filters
    Filters::iterator f = m_filters.find(id);
    if (f != m_filters.end()) {
        DemuxerEvents E = (*f).second;
        switch (E) {
        case DEMUXER_EVENT_NIL:
            // NULL PACKET
            //cout << "[INFO]: PKT#" << m_pnum << " Null packet." << endl;
            return true;
        case DEMUXER_EVENT_PAT:
            if (!ReadPAT(p, e))
                return false;
            break;
        case DEMUXER_EVENT_PMT:
            if (!ReadPMT(p, e))
                return false;
            break;
        case DEMUXER_EVENT_PES:
            if (!ReadPES(p, e, header, id))
                return false;
            break;
        default:
            cout << "[WARNING]: PID=" << id << " filtered but not handled." << endl;
            break;
        }
    } else {
        // Check if orphaned PES with no program.
        if (CheckPES(p, e, header)) {
            if (!ReadPES(p, e, header, id))
                return false;
        }
    }
    return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rdi, %r14
incq 0x90(%rdi)
movq %rsi, %rbx
leaq 0x8(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0x16(%rsp), %rcx
callq 0x2d02
testb %al, %al
je 0x2c8e
addq $0xbc, %rbx
movq 0x70(%r14), %rcx
testq %rcx, %rcx
je 0x2bf0
leaq 0x68(%r14), %rdx
movzwl 0x1a(%rsp), %r15d
movq %rdx, %rax
xorl %esi, %esi
cmpw %r15w, 0x20(%rcx)
setb %sil
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x2bcb
cmpq %rdx, %rax
je 0x2bf0
cmpw 0x20(%rax), %r15w
jae 0x2c34
cmpb $0x1, 0x17(%rsp)
jne 0x2cf6
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x2cf6
cmpb $0x0, 0x1(%rax)
jne 0x2cf6
cmpb $0x1, 0x2(%rax)
jne 0x2cf6
leaq 0x16(%rsp), %rcx
movzwl 0x4(%rcx), %r8d
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
jmp 0x2c73
movl 0x24(%rax), %eax
decl %eax
cmpl $0x3, %eax
ja 0x2c92
leaq 0x2583(%rip), %rcx      # 0x51c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x3170
jmp 0x2c8a
leaq 0x8(%rsp), %rsi
leaq 0x16(%rsp), %rcx
movq %r14, %rdi
movq %rbx, %rdx
movl %r15d, %r8d
callq 0x36de
jmp 0x2c8a
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x2e22
testb %al, %al
jne 0x2cf6
xorl %eax, %eax
jmp 0x2cf8
movq 0x5337(%rip), %rbx      # 0x7fd0
leaq 0x25a7(%rip), %rsi      # 0x5247
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2160
movq %rbx, %rdi
movq %r15, %rsi
callq 0x20b0
movq %rax, %rbx
leaq 0x2595(%rip), %rsi      # 0x5257
movl $0x1a, %edx
movq %rax, %rdi
callq 0x2160
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq