// File: zeeev[P]DASVC/bamtools/src/toolkit/bamtools_split.cpp
// Function: bool BamTools::SplitTool::SplitToolPrivate::SplitListTagImpl<signed char>(BamTools::BamAlignment&)
bool SplitTool::SplitToolPrivate::SplitListTagImpl(BamAlignment& al) {

    typedef T         TagElementType;
    typedef vector<T> TagValueType;
    typedef map<string, BamWriter*> WriterMap;
    typedef typename WriterMap::iterator WriterMapIterator;

    // set up splitting data structure
    WriterMap outputFiles;
    WriterMapIterator writerIter;

    // determine tag prefix
    string tagPrefix = SPLIT_TAG_TOKEN;
    if ( m_settings->HasCustomTagPrefix )
        tagPrefix = m_settings->CustomTagPrefix;

    // make sure prefix starts with '.'
    const size_t dotFound = tagPrefix.find('.');
    if ( dotFound != 0 )
        tagPrefix = string(".") + tagPrefix;

    const string tag = m_settings->TagToSplit;
    BamWriter* writer;
    TagValueType currentValue;
    while (m_reader.GetNextAlignment(al)) {

        string listTagLabel;
        if (!al.GetTag(tag, currentValue))
            listTagLabel = "none";
        else {
            // make list label from tag data
            stringstream listTagLabelStream;
            typename TagValueType::const_iterator tagValueIter = currentValue.begin();
            typename TagValueType::const_iterator tagValueEnd  = currentValue.end();
            for (; tagValueIter != tagValueEnd; ++tagValueIter)
                listTagLabelStream << (*tagValueIter) << m_settings->ListTagDelimiter;
            listTagLabel = listTagLabelStream.str();
            if (!listTagLabel.empty())
                listTagLabel = listTagLabel.substr(0, listTagLabel.size() - m_settings->ListTagDelimiter.size()); // pop last delimiter
        }

        // lookup writer for label
        writerIter = outputFiles.find(listTagLabel);

        // if not found, create one
        if (writerIter == outputFiles.end()) {

            // open new BamWriter, save first alignment
            stringstream outputFilenameStream;
            outputFilenameStream << m_outputFilenameStub << tagPrefix << tag << "_" << listTagLabel << ".bam";
            writer = new BamWriter;
            if ( !writer->Open(outputFilenameStream.str(), m_header, m_references) ) {
                cerr << "bamtools split ERROR: could not open " << outputFilenameStream.str()
                     << " for writing." << endl;
                return false;
            }

            // store in map
            outputFiles.insert( make_pair(listTagLabel, writer) );
        }

        // else grab existing writer
        else writer = (*writerIter).second;

        // store alignment in proper BAM output file
        if ( writer )
            writer->SaveAlignment(al);
    }

    // clean up & return success
    CloseWriters(outputFiles);
    return true;
}

// Assembly:
subq $0x658, %rsp            # imm = 0x658
movq %rdi, 0x648(%rsp)
movq %rsi, 0x640(%rsp)
movq 0x648(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0x610(%rsp), %rdi
callq 0xfccc0
leaq 0x608(%rsp), %rdi
callq 0xfccd0
jmp 0xeef83
leaq 0x7754e(%rip), %rsi     # 0x1664d8
leaq 0x5d8(%rsp), %rdi
callq 0x86350
jmp 0xeef99
movq 0xd8(%rsp), %rax
movq (%rax), %rax
testb $0x1, 0x3(%rax)
je 0xeeffc
movq 0xd8(%rsp), %rax
movq (%rax), %rsi
addq $0x50, %rsi
leaq 0x5d8(%rsp), %rdi
callq 0x86070
jmp 0xeefc8
jmp 0xeeffc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xefa6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xefa5b
xorl %eax, %eax
movl %eax, %edx
leaq 0x5d8(%rsp), %rdi
movl $0x2e, %esi
callq 0x86960
movq %rax, 0xd0(%rsp)
jmp 0xef01c
movq 0xd0(%rsp), %rax
movq %rax, 0x5d0(%rsp)
cmpq $0x0, 0x5d0(%rsp)
je 0xef145
leaq 0x58f(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x86da0
movq 0xc8(%rsp), %rdx
leaq 0x45282(%rip), %rsi     # 0x1342e1
leaq 0x590(%rsp), %rdi
callq 0x86a00
jmp 0xef06e
leaq 0x5b0(%rsp), %rdi
leaq 0x590(%rsp), %rsi
leaq 0x5d8(%rsp), %rdx
callq 0xd0140
jmp 0xef08d
leaq 0x5d8(%rsp), %rdi
leaq 0x5b0(%rsp), %rsi
callq 0x86070
jmp 0xef0a4
leaq 0x5b0(%rsp), %rdi
callq 0x86f68
jmp 0xef0b3
leaq 0x590(%rsp), %rdi
callq 0x86f68
jmp 0xef0c2
leaq 0x58f(%rsp), %rdi
callq 0x867b0
jmp 0xef145
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xef133
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xef122
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
leaq 0x5b0(%rsp), %rdi
callq 0x86f68
jmp 0xef120
jmp 0xef122
leaq 0x590(%rsp), %rdi
callq 0x86f68
jmp 0xef131
jmp 0xef133
leaq 0x58f(%rsp), %rdi
callq 0x867b0
jmp 0xefa5b
movq 0xd8(%rsp), %rax
movq (%rax), %rsi
addq $0x90, %rsi
leaq 0x568(%rsp), %rdi
callq 0x86350
jmp 0xef166
leaq 0x548(%rsp), %rdi
callq 0xfdcf0
jmp 0xef175
jmp 0xef177
movq 0xd8(%rsp), %rdi
addq $0x28, %rdi
movq 0x640(%rsp), %rsi
callq 0x86bb0
movb %al, 0xc7(%rsp)
jmp 0xef199
movb 0xc7(%rsp), %al
testb $0x1, %al
jne 0xef1a9
jmp 0xef9c4
leaq 0x528(%rsp), %rdi
callq 0x86a30
jmp 0xef1b8
movq 0x640(%rsp), %rdi
leaq 0x568(%rsp), %rsi
leaq 0x548(%rsp), %rdx
callq 0xfdd00
movb %al, 0xc6(%rsp)
jmp 0xef1de
movb 0xc6(%rsp), %al
testb $0x1, %al
jne 0xef251
jmp 0xef1eb
leaq 0x430e9(%rip), %rsi     # 0x1322db
leaq 0x528(%rsp), %rdi
callq 0x869f0
jmp 0xef201
jmp 0xef500
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xefa2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xefa0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xef9b3
leaq 0x3a0(%rsp), %rdi
callq 0x86520
jmp 0xef260
leaq 0x548(%rsp), %rdi
callq 0xfe360
movq %rax, 0xb8(%rsp)
jmp 0xef277
movq 0xb8(%rsp), %rax
movq %rax, 0x390(%rsp)
leaq 0x398(%rsp), %rdi
leaq 0x390(%rsp), %rsi
callq 0xfe390
jmp 0xef29e
leaq 0x548(%rsp), %rdi
callq 0xfe3d0
movq %rax, 0xb0(%rsp)
jmp 0xef2b5
movq 0xb0(%rsp), %rax
movq %rax, 0x380(%rsp)
leaq 0x388(%rsp), %rdi
leaq 0x380(%rsp), %rsi
callq 0xfe390
jmp 0xef2dc
jmp 0xef2de
leaq 0x398(%rsp), %rdi
leaq 0x388(%rsp), %rsi
callq 0xfe400
movb %al, 0xaf(%rsp)
jmp 0xef2fc
movb 0xaf(%rsp), %al
testb $0x1, %al
jne 0xef30c
jmp 0xef3a5
leaq 0x3b0(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x398(%rsp), %rdi
callq 0xfe440
movq %rax, 0xa0(%rsp)
jmp 0xef333
movq 0x98(%rsp), %rdi
movq 0xa0(%rsp), %rax
movsbl (%rax), %esi
callq 0x869e0
movq %rax, 0x90(%rsp)
jmp 0xef355
movq 0x90(%rsp), %rdi
movq 0xd8(%rsp), %rax
movq (%rax), %rsi
addq $0xb0, %rsi
callq 0x86640
jmp 0xef376
jmp 0xef378
leaq 0x398(%rsp), %rdi
callq 0xfe450
jmp 0xef387
jmp 0xef2de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xef4ec
leaq 0x360(%rsp), %rdi
leaq 0x3a0(%rsp), %rsi
callq 0x866f0
jmp 0xef3bc
leaq 0x528(%rsp), %rdi
leaq 0x360(%rsp), %rsi
callq 0x86070
jmp 0xef3d3
leaq 0x360(%rsp), %rdi
callq 0x86f68
jmp 0xef3e2
leaq 0x528(%rsp), %rdi
callq 0x86c90
movb %al, 0x8f(%rsp)
jmp 0xef3f8
movb 0x8f(%rsp), %al
testb $0x1, %al
jne 0xef4db
jmp 0xef409
leaq 0x528(%rsp), %rdi
callq 0x86500
movq %rax, 0x80(%rsp)
jmp 0xef420
movq 0xd8(%rsp), %rax
movq (%rax), %rdi
addq $0xb0, %rdi
callq 0x86500
movq %rax, 0x78(%rsp)
jmp 0xef43e
movq 0x78(%rsp), %rax
movq 0x80(%rsp), %rcx
subq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq 0x340(%rsp), %rdi
leaq 0x528(%rsp), %rsi
callq 0x86750
jmp 0xef469
leaq 0x528(%rsp), %rdi
leaq 0x340(%rsp), %rsi
callq 0x86070
jmp 0xef480
leaq 0x340(%rsp), %rdi
callq 0x86f68
jmp 0xef48f
jmp 0xef4db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
leaq 0x360(%rsp), %rdi
callq 0x86f68
jmp 0xef4b4
jmp 0xef4ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
leaq 0x340(%rsp), %rdi
callq 0x86f68
jmp 0xef4d9
jmp 0xef4ec
leaq 0x3a0(%rsp), %rdi
callq 0x86580
jmp 0xef4ea
jmp 0xef500
leaq 0x3a0(%rsp), %rdi
callq 0x86580
jmp 0xef4fb
jmp 0xef9b3
leaq 0x610(%rsp), %rdi
leaq 0x528(%rsp), %rsi
callq 0xfcdd0
movq %rax, 0x70(%rsp)
jmp 0xef51c
movq 0x70(%rsp), %rax
movq %rax, 0x338(%rsp)
movq 0x338(%rsp), %rax
movq %rax, 0x608(%rsp)
leaq 0x610(%rsp), %rdi
callq 0xfce20
movq %rax, 0x68(%rsp)
jmp 0xef54d
movq 0x68(%rsp), %rax
movq %rax, 0x330(%rsp)
leaq 0x608(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0xfce00
testb $0x1, %al
jne 0xef578
jmp 0xef94a
leaq 0x1a8(%rsp), %rdi
callq 0x86520
jmp 0xef587
movq 0xd8(%rsp), %rsi
leaq 0x1b8(%rsp), %rdi
addq $0x8, %rsi
callq 0x86640
movq %rax, 0x60(%rsp)
jmp 0xef5a7
movq 0x60(%rsp), %rdi
leaq 0x5d8(%rsp), %rsi
callq 0x86640
movq %rax, 0x58(%rsp)
jmp 0xef5c0
movq 0x58(%rsp), %rdi
leaq 0x568(%rsp), %rsi
callq 0x86640
movq %rax, 0x50(%rsp)
jmp 0xef5d9
movq 0x50(%rsp), %rdi
leaq 0x43885(%rip), %rsi     # 0x132e6a
callq 0x86700
movq %rax, 0x48(%rsp)
jmp 0xef5f1
movq 0x48(%rsp), %rdi
leaq 0x528(%rsp), %rsi
callq 0x86640
movq %rax, 0x40(%rsp)
jmp 0xef60a
movq 0x40(%rsp), %rdi
leaq 0x42d09(%rip), %rsi     # 0x13231f
callq 0x86700
jmp 0xef61d
movl $0x8, %edi
callq 0x86720
movq %rax, 0x38(%rsp)
jmp 0xef62e
movq 0x38(%rsp), %rdi
callq 0x863f0
jmp 0xef63a
movq 0x38(%rsp), %rax
movq %rax, 0x560(%rsp)
movq 0x560(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x188(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x866f0
jmp 0xef66b
movq 0x30(%rsp), %rdi
movq 0xd8(%rsp), %rcx
movq %rcx, %rdx
addq $0x30, %rdx
addq $0x50, %rcx
leaq 0x188(%rsp), %rsi
callq 0x86bd0
movb %al, 0x2f(%rsp)
jmp 0xef696
movb 0x2f(%rsp), %al
xorb $0x1, %al
movb %al, 0x2e(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x86f68
jmp 0xef6af
movb 0x2e(%rsp), %al
testb $0x1, %al
jne 0xef6bc
jmp 0xef7e4
movq 0x7591d(%rip), %rdi     # 0x164fe0
leaq 0x43868(%rip), %rsi     # 0x132f32
callq 0x86700
movq %rax, 0x20(%rsp)
jmp 0xef6d6
leaq 0x168(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x866f0
jmp 0xef6ed
movq 0x20(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x86640
movq %rax, 0x18(%rsp)
jmp 0xef706
movq 0x18(%rsp), %rdi
leaq 0x3ff33(%rip), %rsi     # 0x12f645
callq 0x86700
movq %rax, 0x10(%rsp)
jmp 0xef71e
movq 0x10(%rsp), %rdi
movq 0x75846(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0xef731
leaq 0x168(%rsp), %rdi
callq 0x86f68
jmp 0xef740
movb $0x0, 0x657(%rsp)
movl $0x1, 0x164(%rsp)
jmp 0xef8a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xef939
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
callq 0x866a0
jmp 0xef939
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x86f68
jmp 0xef7b7
jmp 0xef939
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x86f68
jmp 0xef7df
jmp 0xef939
leaq 0xf0(%rsp), %rdi
leaq 0x528(%rsp), %rsi
callq 0x86350
jmp 0xef7fb
movq 0x560(%rsp), %rdx
leaq 0x110(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0xfcd40
jmp 0xef81a
leaq 0x138(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0xfcd70
jmp 0xef831
leaq 0x610(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0xfccf0
movb %dl, 0x7(%rsp)
movq %rax, 0x8(%rsp)
jmp 0xef851
movb 0x7(%rsp), %al
movq 0x8(%rsp), %rcx
movq %rcx, 0xe0(%rsp)
movb %al, 0xe8(%rsp)
leaq 0x138(%rsp), %rdi
callq 0xfcdb0
jmp 0xef878
leaq 0x110(%rsp), %rdi
callq 0xfcdc0
jmp 0xef887
leaq 0xf0(%rsp), %rdi
callq 0x86f68
jmp 0xef896
movl $0x0, 0x164(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x86580
jmp 0xef8b0
movl 0x164(%rsp), %eax
testl %eax, %eax
jne 0xef992
jmp 0xef8c1
jmp 0xef963
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xef928
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
jmp 0xef917
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x600(%rsp)
movl %eax, 0x5fc(%rsp)
leaq 0x138(%rsp), %rdi
callq 0xfcdb0
jmp 0xef915
jmp 0xef917
leaq 0x110(%rsp), %rdi
callq 0xfcdc0
jmp 0xef926
jmp 0xef928
leaq 0xf0(%rsp), %rdi
callq 0x86f68
jmp 0xef937
jmp 0xef939
leaq 0x1a8(%rsp), %rdi
callq 0x86580
jmp 0xef948
jmp 0xef9b3
leaq 0x608(%rsp), %rdi
callq 0xfce50
movq 0x20(%rax), %rax
movq %rax, 0x560(%rsp)
cmpq $0x0, 0x560(%rsp)
je 0xef987
movq 0x560(%rsp), %rdi
movq 0x640(%rsp), %rsi
callq 0x86e80
jmp 0xef985
jmp 0xef987
movl $0x0, 0x164(%rsp)
leaq 0x528(%rsp), %rdi
callq 0x86f68
jmp 0xef9a1
movl 0x164(%rsp), %eax
testl %eax, %eax
jne 0xef9ee
jmp 0xef9ae
jmp 0xef177
leaq 0x528(%rsp), %rdi
callq 0x86f68
jmp 0xef9c2
jmp 0xefa0c
movq 0xd8(%rsp), %rdi
leaq 0x610(%rsp), %rsi
callq 0xfce70
jmp 0xef9db
movb $0x1, 0x657(%rsp)
movl $0x1, 0x164(%rsp)
leaq 0x548(%rsp), %rdi
callq 0xfe470
jmp 0xef9fd
leaq 0x568(%rsp), %rdi
callq 0x86f68
jmp 0xefa1d
leaq 0x548(%rsp), %rdi
callq 0xfe470
jmp 0xefa1b
jmp 0xefa2c
leaq 0x5d8(%rsp), %rdi
callq 0x86f68
jmp 0xefa3d
leaq 0x568(%rsp), %rdi
callq 0x86f68
jmp 0xefa3b
jmp 0xefa5b
leaq 0x610(%rsp), %rdi
callq 0xfcf50
movb 0x657(%rsp), %al
andb $0x1, %al
addq $0x658, %rsp            # imm = 0x658
retq
leaq 0x5d8(%rsp), %rdi
callq 0x86f68
jmp 0xefa6a
jmp 0xefa6c
leaq 0x610(%rsp), %rdi
callq 0xfcf50
jmp 0xefa7b
jmp 0xefa7d
movq 0x600(%rsp), %rdi
callq 0x86d80
movq %rax, %rdi
callq 0x91290
nopw %cs:(%rax,%rax)
nopl (%rax)