// File: mmoanis[P]mpegts_demux/MpegTsDemux.cpp
// Function: MpegTsDemuxer::RegisterStream(unsigned short, Program const&, bool)
bool MpegTsDemuxer::RegisterStream(PID id, const Program& prog, bool video)
{
    Streams::iterator s = m_streams.find(id);
    if (s == m_streams.end()) {
        string filename = GetFileName(video, id, prog.id);
        Stream *S = new Stream(filename.c_str(), id, prog.id);
        m_streams.insert( make_pair(id, S) );
        if (m_info)
            cout << "[INFO]: PKT#" << m_pnum << " STREAM=" << id << " PROGRAM=" << prog.id << " TYPE=" << (video? "VIDEO" : "AUDIO") << endl;
        else
            cout << "[INFO]: PKT#" << m_pnum << " STREAM=" << id << " TYPE=" << (video? "VIDEO" : "AUDIO") << endl;
        // expect packet for stream
        m_filters.insert( make_pair(id, DEMUXER_EVENT_PES) );
    }  else {
        if ((*s).second->GetPId() != prog.id && prog.id != MPEGTS_PID_NULL) {
            // Support updating stream information.
            cout << "[WARNING]: PKT#" << m_pnum << " STREAM=" << id << " PROGRAM=" << (*s).second->GetPId() << " appeared in PROGRAM=" << prog.id << endl;
            (*s).second->SetPId(prog.id);
        }
    }
    return true;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movb %cl, %al
movw %si, %cx
movq %rdi, 0x180(%rsp)
movw %cx, 0x17e(%rsp)
movq %rdx, 0x170(%rsp)
andb $0x1, %al
movb %al, 0x16f(%rsp)
movq 0x180(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
addq $0x30, %rdi
leaq 0x17e(%rsp), %rsi
callq 0x5910
movq 0xd8(%rsp), %rdi
movq %rax, 0x160(%rsp)
addq $0x30, %rdi
callq 0x56a0
movq %rax, 0x158(%rsp)
leaq 0x160(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x5940
testb $0x1, %al
jne 0x4f3d
jmp 0x534c
movzwl 0x17e(%rsp), %edx
movq 0x170(%rsp), %rax
movzwl (%rax), %ecx
movzbl 0x16f(%rsp), %esi
andl $0x1, %esi
leaq 0x138(%rsp), %rdi
callq 0x5480
movl $0x10, %edi
callq 0x2160
movq %rax, 0xd0(%rsp)
jmp 0x4f7c
leaq 0x138(%rsp), %rdi
callq 0x2090
movq 0xd0(%rsp), %rdi
movq %rax, %rsi
movzwl 0x17e(%rsp), %edx
movq 0x170(%rsp), %rax
movzwl (%rax), %ecx
callq 0x2a30
jmp 0x4fae
movq 0xd8(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq %rcx, 0x130(%rsp)
addq $0x30, %rax
movq %rax, 0xb8(%rsp)
leaq 0x17e(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x5b30
movq %rdx, 0xc0(%rsp)
movw %ax, 0xce(%rsp)
jmp 0x4ff9
movq 0xb8(%rsp), %rdi
movq 0xc0(%rsp), %rax
movw 0xce(%rsp), %cx
movw %cx, 0x110(%rsp)
movq %rax, 0x118(%rsp)
leaq 0x110(%rsp), %rsi
callq 0x5ae0
movb %dl, 0xaf(%rsp)
movq %rax, 0xb0(%rsp)
jmp 0x503f
movq 0xd8(%rsp), %rax
movb 0xaf(%rsp), %cl
movq 0xb0(%rsp), %rdx
movq %rdx, 0x100(%rsp)
movb %cl, 0x108(%rsp)
testb $0x1, 0x98(%rax)
je 0x51da
movq 0x7f57(%rip), %rdi      # 0xcfd0
leaq 0x4566(%rip), %rsi      # 0x95e6
callq 0x2140
movq %rax, 0xa0(%rsp)
jmp 0x508f
movq 0xa0(%rsp), %rdi
movq 0xd8(%rsp), %rax
movq 0x90(%rax), %rsi
callq 0x2040
movq %rax, 0x98(%rsp)
jmp 0x50b5
movq 0x98(%rsp), %rdi
leaq 0x415a(%rip), %rsi      # 0x921e
callq 0x2140
movq %rax, 0x90(%rsp)
jmp 0x50d3
movq 0x90(%rsp), %rdi
movzwl 0x17e(%rsp), %esi
callq 0x2200
movq %rax, 0x88(%rsp)
jmp 0x50f2
movq 0x88(%rsp), %rdi
leaq 0x43ad(%rip), %rsi      # 0x94ae
callq 0x2140
movq %rax, 0x80(%rsp)
jmp 0x5110
movq 0x80(%rsp), %rdi
movq 0x170(%rsp), %rax
movzwl (%rax), %esi
callq 0x2200
movq %rax, 0x78(%rsp)
jmp 0x512f
movq 0x78(%rsp), %rdi
leaq 0x4516(%rip), %rsi      # 0x9651
callq 0x2140
movq %rax, 0x70(%rsp)
jmp 0x5147
testb $0x1, 0x16f(%rsp)
je 0x515f
leaq 0x4500(%rip), %rax      # 0x9658
movq %rax, 0x68(%rsp)
jmp 0x516d
leaq 0x44f8(%rip), %rax      # 0x965e
movq %rax, 0x68(%rsp)
jmp 0x516d
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x2140
movq %rax, 0x60(%rsp)
jmp 0x5183
movq 0x60(%rsp), %rdi
movq 0x7e31(%rip), %rsi      # 0xcfc0
callq 0x2180
jmp 0x5196
jmp 0x52ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x533a
movq 0xd0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
callq 0x2120
jmp 0x533a
movq 0x7def(%rip), %rdi      # 0xcfd0
leaq 0x43fe(%rip), %rsi      # 0x95e6
callq 0x2140
movq %rax, 0x58(%rsp)
jmp 0x51f4
movq 0x58(%rsp), %rdi
movq 0xd8(%rsp), %rax
movq 0x90(%rax), %rsi
callq 0x2040
movq %rax, 0x50(%rsp)
jmp 0x5214
movq 0x50(%rsp), %rdi
leaq 0x3ffe(%rip), %rsi      # 0x921e
callq 0x2140
movq %rax, 0x48(%rsp)
jmp 0x522c
movq 0x48(%rsp), %rdi
movzwl 0x17e(%rsp), %esi
callq 0x2200
movq %rax, 0x40(%rsp)
jmp 0x5245
movq 0x40(%rsp), %rdi
leaq 0x4400(%rip), %rsi      # 0x9651
callq 0x2140
movq %rax, 0x38(%rsp)
jmp 0x525d
testb $0x1, 0x16f(%rsp)
je 0x5275
leaq 0x43ea(%rip), %rax      # 0x9658
movq %rax, 0x30(%rsp)
jmp 0x5283
leaq 0x43e2(%rip), %rax      # 0x965e
movq %rax, 0x30(%rsp)
jmp 0x5283
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x2140
movq %rax, 0x28(%rsp)
jmp 0x5299
movq 0x28(%rsp), %rdi
movq 0x7d1b(%rip), %rsi      # 0xcfc0
callq 0x2180
jmp 0x52ac
jmp 0x52ae
movq 0xd8(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x18(%rsp)
movl $0x2, 0xf4(%rsp)
leaq 0x17e(%rsp), %rdi
leaq 0xf4(%rsp), %rsi
callq 0x5a90
movq %rax, 0x20(%rsp)
jmp 0x52e6
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rax
movq %rax, 0xf8(%rsp)
leaq 0xf8(%rsp), %rsi
callq 0x5a40
movb %dl, 0xf(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x5310
movb 0xf(%rsp), %al
movq 0x10(%rsp), %rcx
movq %rcx, 0xe0(%rsp)
movb %al, 0xe8(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x20b0
jmp 0x5460
leaq 0x138(%rsp), %rdi
callq 0x20b0
jmp 0x546c
leaq 0x160(%rsp), %rdi
callq 0x56f0
movq 0x8(%rax), %rdi
callq 0x5b70
movzwl %ax, %eax
movq 0x170(%rsp), %rcx
movzwl (%rcx), %ecx
cmpl %ecx, %eax
je 0x545e
movq 0x170(%rsp), %rax
movzwl (%rax), %eax
cmpl $0x1fff, %eax           # imm = 0x1FFF
je 0x545e
movq 0x7c3b(%rip), %rdi      # 0xcfd0
leaq 0x4038(%rip), %rsi      # 0x93d4
callq 0x2140
movq %rax, %rdi
movq 0xd8(%rsp), %rax
movq 0x90(%rax), %rsi
callq 0x2040
movq %rax, %rdi
leaq 0x3e5c(%rip), %rsi      # 0x921e
callq 0x2140
movq %rax, %rdi
movzwl 0x17e(%rsp), %esi
callq 0x2200
movq %rax, %rdi
leaq 0x40cd(%rip), %rsi      # 0x94ae
callq 0x2140
movq %rax, (%rsp)
leaq 0x160(%rsp), %rdi
callq 0x56f0
movq 0x8(%rax), %rdi
callq 0x5b70
movq (%rsp), %rdi
movzwl %ax, %esi
callq 0x2200
movq %rax, %rdi
leaq 0x424e(%rip), %rsi      # 0x9664
callq 0x2140
movq %rax, %rdi
movq 0x170(%rsp), %rax
movzwl (%rax), %esi
callq 0x2200
movq %rax, %rdi
movq 0x7b88(%rip), %rsi      # 0xcfc0
callq 0x2180
leaq 0x160(%rsp), %rdi
callq 0x56f0
movq 0x8(%rax), %rdi
movq 0x170(%rsp), %rax
movzwl (%rax), %esi
callq 0x5b80
jmp 0x5460
movb $0x1, %al
andb $0x1, %al
addq $0x188, %rsp            # imm = 0x188
retq
movq 0x128(%rsp), %rdi
callq 0x2220
nopl (%rax)