// File: zeeev[P]DASVC/bamtools/src/api/internal/bam/BamMultiReader_p.cpp
// Function: BamTools::Internal::BamMultiReaderPrivate::SetExplicitMergeOrder(BamTools::BamMultiReader::MergeOrder)
bool BamMultiReaderPrivate::SetExplicitMergeOrder(BamMultiReader::MergeOrder order) {

    // set new merge flags
    m_hasUserMergeOrder = true;
    m_mergeOrder = order;

    // remove any existing merger (storing any existing data sitting in the cache)
    vector<MergeItem> currentCacheData;
    if ( m_alignmentCache ) {        
        while ( !m_alignmentCache->IsEmpty() )
            currentCacheData.push_back( m_alignmentCache->TakeFirst() );
        delete m_alignmentCache;
        m_alignmentCache = 0;
    }

    // create new cache using the new merge flags
    m_alignmentCache = CreateAlignmentCache();
    if ( m_alignmentCache == 0 ) {
        SetErrorString("BamMultiReader::SetExplicitMergeOrder", "requested order is unrecognized");
        return false;
    }

    // push current data onto new cache
    vector<MergeItem>::const_iterator readerIter = currentCacheData.begin();
    vector<MergeItem>::const_iterator readerEnd  = currentCacheData.end();
    for ( ; readerIter != readerEnd; ++readerIter ) {
        const MergeItem& item = (*readerIter);
        m_alignmentCache->Add(item);
    }

    // return success
    return true;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x128(%rsp)
movl %esi, 0x124(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x58(%rsp)
movb $0x1, 0x20(%rax)
movl 0x124(%rsp), %ecx
movl %ecx, 0x24(%rax)
leaq 0x108(%rsp), %rdi
callq 0x728d0
movq 0x58(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0xa27cf
jmp 0xa26f0
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rdi
movq (%rdi), %rax
movq 0x28(%rax), %rax
callq *%rax
movb %al, 0x57(%rsp)
jmp 0xa2708
movb 0x57(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xa2717
jmp 0xa279c
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rsi
movq (%rsi), %rax
movq 0x40(%rax), %rax
leaq 0xe8(%rsp), %rdi
callq *%rax
jmp 0xa2733
leaq 0x108(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x758d0
jmp 0xa274a
leaq 0xe8(%rsp), %rdi
callq 0x7bb70
jmp 0xa2759
jmp 0xa26f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xa2a9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x7bb70
jmp 0xa2797
jmp 0xa2a9b
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, %rax
je 0xa27c2
movq 0x48(%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0xa27c0
jmp 0xa27c2
movq 0x58(%rsp), %rax
movq $0x0, 0x18(%rax)
movq 0x58(%rsp), %rdi
callq 0x74be0
movq %rax, 0x40(%rsp)
jmp 0xa27e0
movq 0x58(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0x18(%rax)
cmpq $0x0, 0x18(%rax)
jne 0xa2940
leaq 0xc7(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x7b5f0
movq 0x38(%rsp), %rdx
leaq 0x48084(%rip), %rsi     # 0xea89b
leaq 0xc8(%rsp), %rdi
callq 0x78e70
jmp 0xa2826
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x7b5f0
movq 0x30(%rsp), %rdx
leaq 0x4807d(%rip), %rsi     # 0xea8c1
leaq 0xa0(%rsp), %rdi
callq 0x78e70
jmp 0xa2853
movq 0x58(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x77c30
jmp 0xa286f
leaq 0xa0(%rsp), %rdi
callq 0x7cce8
jmp 0xa287e
leaq 0x9f(%rsp), %rdi
callq 0x76f80
leaq 0xc8(%rsp), %rdi
callq 0x7cce8
jmp 0xa289a
leaq 0xc7(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x137(%rsp)
movl $0x1, 0x98(%rsp)
jmp 0xa2a7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xa292e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xa2910
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x7cce8
jmp 0xa290e
jmp 0xa2910
leaq 0x9f(%rsp), %rdi
callq 0x76f80
leaq 0xc8(%rsp), %rdi
callq 0x7cce8
jmp 0xa292c
jmp 0xa292e
leaq 0xc7(%rsp), %rdi
callq 0x76f80
jmp 0xa2a9b
leaq 0x108(%rsp), %rdi
callq 0x73770
movq %rax, 0x28(%rsp)
jmp 0xa2954
movq 0x28(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x7b230
jmp 0xa2978
leaq 0x108(%rsp), %rdi
callq 0x74890
movq %rax, 0x20(%rsp)
jmp 0xa298c
movq 0x20(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x7b230
jmp 0xa29aa
jmp 0xa29ac
leaq 0x90(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x732a0
movb %al, 0x1f(%rsp)
jmp 0xa29c7
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0xa29d4
jmp 0xa2a6a
leaq 0x90(%rsp), %rdi
callq 0x7aa50
movq %rax, 0x10(%rsp)
jmp 0xa29e8
movq 0x58(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x70(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x70(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x79cc0
jmp 0xa2a11
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq 0x60(%rsp), %rsi
callq *%rax
jmp 0xa2a26
leaq 0x60(%rsp), %rdi
callq 0x7bb70
jmp 0xa2a32
jmp 0xa2a34
leaq 0x90(%rsp), %rdi
callq 0x717c0
jmp 0xa2a43
jmp 0xa29ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x7bb70
jmp 0xa2a68
jmp 0xa2a9b
movb $0x1, 0x137(%rsp)
movl $0x1, 0x98(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x79ee0
movb 0x137(%rsp), %al
andb $0x1, %al
addq $0x138, %rsp            # imm = 0x138
retq
leaq 0x108(%rsp), %rdi
callq 0x79ee0
jmp 0xa2aaa
jmp 0xa2aac
movq 0x100(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)