// File: mmoanis[P]mpegts_demux/MpegTsDemux.cpp
// Function: MpegTsDemuxer::RegisterProgram(unsigned short, unsigned short)
void MpegTsDemuxer::RegisterProgram(PID id, PID pid)
{
    assert(id != MPEGTS_PID_NULL);

    Programs::iterator p = m_programs.find(id);
    if (p == m_programs.end()) {
        cout << "[INFO]: PKT#" << m_pnum << " PROGRAM=" << id << " PMT=" << pid << endl;

        Program P;
        P.id = id;
        P.pid = pid;
        m_programs.insert(make_pair(id, P));

        // expect packet for PMT
        m_filters.insert( make_pair(pid, DEMUXER_EVENT_PMT) );
    } else {
        if (p->second.pid != pid) {
            // Support updating program information
            cout << "[WARNING]: PKT#" << m_pnum << " PROGRAM=" << id << " PMT=" << p->second.pid << " appeared with PMT=" << pid <<  endl;
            p->second.pid = pid;

            // expect packet for PMT
            m_filters.insert( make_pair(pid, DEMUXER_EVENT_PMT) );
        }
    }
}

// Assembly:
subq $0xb8, %rsp
movw %dx, %ax
movw %si, %cx
movq %rdi, 0xb0(%rsp)
movw %cx, 0xae(%rsp)
movw %ax, 0xac(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x30(%rsp)
movzwl 0xae(%rsp), %eax
cmpl $0x1fff, %eax           # imm = 0x1FFF
je 0x4853
jmp 0x4872
leaq 0x4d48(%rip), %rdi      # 0x95a2
leaq 0x497b(%rip), %rsi      # 0x91dc
movl $0x1d1, %edx            # imm = 0x1D1
leaq 0x4d4b(%rip), %rcx      # 0x95b8
callq 0x20c0
movq 0x30(%rsp), %rdi
leaq 0xae(%rsp), %rsi
callq 0x5810
movq 0x30(%rsp), %rdi
movq %rax, 0xa0(%rsp)
callq 0x5880
movq %rax, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x5980
testb $0x1, %al
jne 0x48bc
jmp 0x49fe
movq 0x870d(%rip), %rdi      # 0xcfd0
leaq 0x4d1c(%rip), %rsi      # 0x95e6
callq 0x2140
movq %rax, %rdi
movq 0x30(%rsp), %rax
movq 0x90(%rax), %rsi
callq 0x2040
movq %rax, %rdi
leaq 0x4bc1(%rip), %rsi      # 0x94ae
callq 0x2140
movq %rax, %rdi
movzwl 0xae(%rsp), %esi
callq 0x2200
movq %rax, %rdi
leaq 0x4cf5(%rip), %rsi      # 0x9601
callq 0x2140
movq %rax, %rdi
movzwl 0xac(%rsp), %esi
callq 0x2200
movq %rax, %rdi
movq 0x8695(%rip), %rsi      # 0xcfc0
callq 0x2180
leaq 0x94(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x5960
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rax
movw 0xae(%rsp), %cx
movw %cx, 0x94(%rsp)
movw 0xac(%rsp), %cx
movw %cx, 0x96(%rsp)
movq %rax, 0x20(%rsp)
leaq 0xae(%rsp), %rdi
callq 0x59f0
movq 0x20(%rsp), %rdi
movl %eax, %ecx
movl %ecx, 0x8e(%rsp)
shrq $0x20, %rax
movw %ax, 0x92(%rsp)
leaq 0x8e(%rsp), %rsi
callq 0x59a0
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x78(%rsp)
movb %dl, 0x80(%rsp)
addq $0x60, %rax
movq %rax, 0x28(%rsp)
movl $0x1, 0x6c(%rsp)
leaq 0xac(%rsp), %rdi
leaq 0x6c(%rsp), %rsi
callq 0x5a90
movq 0x28(%rsp), %rdi
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %rsi
callq 0x5a40
movq %rax, 0x58(%rsp)
movb %dl, 0x60(%rsp)
jmp 0x4b2d
leaq 0xa0(%rsp), %rdi
callq 0x5ac0
movzwl 0x4(%rax), %eax
movzwl 0xac(%rsp), %ecx
cmpl %ecx, %eax
je 0x4b2b
movq 0x85aa(%rip), %rdi      # 0xcfd0
leaq 0x49a7(%rip), %rsi      # 0x93d4
callq 0x2140
movq %rax, %rdi
movq 0x30(%rsp), %rax
movq 0x90(%rax), %rsi
callq 0x2040
movq %rax, %rdi
leaq 0x4a5e(%rip), %rsi      # 0x94ae
callq 0x2140
movq %rax, %rdi
movzwl 0xae(%rsp), %esi
callq 0x2200
movq %rax, %rdi
leaq 0x4b92(%rip), %rsi      # 0x9601
callq 0x2140
movq %rax, (%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x5ac0
movq (%rsp), %rdi
movzwl 0x4(%rax), %esi
callq 0x2200
movq %rax, %rdi
leaq 0x4b57(%rip), %rsi      # 0x95f3
callq 0x2140
movq %rax, %rdi
movzwl 0xac(%rsp), %esi
callq 0x2200
movq %rax, %rdi
movq 0x8505(%rip), %rsi      # 0xcfc0
callq 0x2180
movw 0xac(%rsp), %ax
movw %ax, 0xe(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x5ac0
movw 0xe(%rsp), %dx
movq %rax, %rcx
movq 0x30(%rsp), %rax
movw %dx, 0x4(%rcx)
addq $0x60, %rax
movq %rax, 0x10(%rsp)
movl $0x1, 0x4c(%rsp)
leaq 0xac(%rsp), %rdi
leaq 0x4c(%rsp), %rsi
callq 0x5a90
movq 0x10(%rsp), %rdi
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rsi
callq 0x5a40
movq %rax, 0x38(%rsp)
movb %dl, 0x40(%rsp)
jmp 0x4b2d
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)