// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rsi, %r12
movq %rdi, %rbx
leaq 0xe0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x39cd1(%rip), %rsi     # 0x96388
leaq 0x98(%rsp), %rdi
callq 0x35810
movq (%rbx), %rsi
cmpb $0x1, 0x3(%rsi)
jne 0x5c6de
addq $0x50, %rsi
leaq 0x98(%rsp), %rdi
callq 0x35340
leaq 0x98(%rsp), %rdi
pushq $0x2e
popq %rsi
xorl %edx, %edx
callq 0x35790
testq %rax, %rax
je 0x5c754
leaq 0x19a22(%rip), %rsi     # 0x7611e
leaq 0x28(%rsp), %rdi
leaq 0x108(%rsp), %rdx
callq 0x35280
leaq 0x150(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0x51d62
leaq 0x98(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x35340
leaq 0x150(%rsp), %rdi
callq 0x35730
leaq 0x28(%rsp), %rdi
callq 0x35730
movl $0x90, %esi
addq (%rbx), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x35810
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x28(%rbx), %rax
movq %rax, 0x90(%rsp)
leaq 0x160(%rsp), %r13
leaq 0x8(%rbx), %rax
movq %rax, 0x88(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x80(%rsp)
leaq 0x50(%rbx), %rax
movq %rax, 0x78(%rsp)
movl $0xb0, %ebp
movq %r12, 0x70(%rsp)
movq 0x90(%rsp), %rdi
movq %r12, %rsi
callq 0x359b0
movb %al, 0x7(%rsp)
testb %al, %al
je 0x5cac4
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movq %r12, %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x60aa4
testb %al, %al
je 0x5c83d
leaq 0x150(%rsp), %rdi
callq 0x35430
movq 0x50(%rsp), %r14
movq 0x58(%rsp), %r15
cmpq %r15, %r14
je 0x5c850
movsbl (%r14), %esi
movq %r13, %rdi
callq 0x356e0
movq (%rbx), %rsi
addq %rbp, %rsi
movq %rax, %rdi
callq 0x35510
incq %r14
jmp 0x5c819
leaq 0x8(%rsp), %rdi
leaq 0x18252(%rip), %rsi     # 0x74a9b
callq 0x35c40
jmp 0x5c8c4
leaq 0x28(%rsp), %r14
movq %r14, %rdi
leaq 0x168(%rsp), %rsi
callq 0x359c0
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x35340
movq %r14, %rdi
callq 0x35730
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0x5c8b7
movq (%rbx), %rax
subq 0xb8(%rax), %rcx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x35600
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x35340
movq %r14, %rdi
callq 0x35730
leaq 0x150(%rsp), %rdi
callq 0x35490
leaq 0xd8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x609b2
leaq 0xe0(%rsp), %rcx
cmpq %rcx, %rax
je 0x5c8f8
movq 0x40(%rax), %r14
testq %r14, %r14
jne 0x5ca9c
movb $0x1, %r15b
jmp 0x5caaf
leaq 0x150(%rsp), %rdi
callq 0x35430
leaq 0x160(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x35510
movq %rax, %rdi
leaq 0x98(%rsp), %rsi
callq 0x35510
movq %rax, %rdi
leaq 0xb8(%rsp), %rsi
callq 0x35510
movq %rax, %rdi
leaq 0x18380(%rip), %rsi     # 0x74cc4
callq 0x355b0
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x35510
movq %rax, %rdi
leaq 0x1817f(%rip), %rsi     # 0x74adf
callq 0x355b0
pushq $0x8
popq %rdi
callq 0x355d0
movq %rax, %r14
movq %rax, %rdi
callq 0x35350
leaq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0x168(%rsp), %rsi
callq 0x359c0
movq %r14, %rdi
movq %r15, %rsi
movq 0x80(%rsp), %rdx
movq 0x78(%rsp), %rcx
callq 0x359d0
movb %al, 0x6(%rsp)
movq %r15, %rdi
callq 0x35730
cmpb $0x0, 0x6(%rsp)
je 0x5ca2c
leaq 0x130(%rsp), %r15
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x35810
leaq 0x108(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x35810
movq %r14, 0x128(%rsp)
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x6071e
leaq 0xd8(%rsp), %rdi
movq %r15, %rsi
callq 0x607aa
movq %r15, %rdi
callq 0x35730
leaq 0x108(%rsp), %rdi
callq 0x35730
leaq 0x130(%rsp), %rdi
callq 0x35730
jmp 0x5ca83
movq 0x385ad(%rip), %rdi     # 0x94fe0
leaq 0x18352(%rip), %rsi     # 0x74d8c
callq 0x355b0
movq %rax, %r15
leaq 0x28(%rsp), %r12
movq %r12, %rdi
leaq 0x168(%rsp), %rsi
callq 0x359c0
movq %r15, %rdi
movq %r12, %rsi
callq 0x35510
movq %rax, %rdi
leaq 0x15391(%rip), %rsi     # 0x71dfd
callq 0x355b0
movq %rax, %rdi
callq 0x35300
leaq 0x28(%rsp), %rdi
callq 0x35730
leaq 0x150(%rsp), %rdi
callq 0x35490
cmpb $0x0, 0x6(%rsp)
movq 0x70(%rsp), %r12
je 0x5caac
movb $0x1, %r15b
movq %r14, %rdi
movq %r12, %rsi
callq 0x35c00
jmp 0x5caaf
xorl %r15d, %r15d
leaq 0x8(%rsp), %rdi
callq 0x35730
testb %r15b, %r15b
jne 0x5c7b8
jmp 0x5cad4
leaq 0xd8(%rsp), %rsi
movq %rbx, %rdi
callq 0x6073e
leaq 0x50(%rsp), %rdi
callq 0x60f26
leaq 0xb8(%rsp), %rdi
callq 0x35730
movb 0x7(%rsp), %bl
leaq 0x98(%rsp), %rdi
callq 0x35730
xorb $0x1, %bl
leaq 0xd8(%rsp), %rdi
callq 0x60a9a
movl %ebx, %eax
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5cb57
jmp 0x5cbf8
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x35730
jmp 0x5cb48
movq %rax, %rbx
jmp 0x5cc38
jmp 0x5cb57
jmp 0x5cb57
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x35730
jmp 0x5cc45
movq %rax, %rbx
jmp 0x5cc45
movq %rax, %rbx
jmp 0x5cc52
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x35730
jmp 0x5cb8b
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x35730
jmp 0x5cc17
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x35730
jmp 0x5cbae
movq %rax, %rbx
movq %r14, %rdi
callq 0x35570
jmp 0x5cc05
jmp 0x5cc02
jmp 0x5cc02
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x35730
jmp 0x5cc05
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x35730
jmp 0x5cc05
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x35730
jmp 0x5cc17
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x35730
jmp 0x5cc05
jmp 0x5cc14
jmp 0x5cbfd
jmp 0x5cc02
jmp 0x5cc14
jmp 0x5cbfd
jmp 0x5cbfd
jmp 0x5cbf8
movq %rax, %rbx
jmp 0x5cc2e
movq %rax, %rbx
jmp 0x5cc24
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x35490
jmp 0x5cc24
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x35490
leaq 0x8(%rsp), %rdi
callq 0x35730
leaq 0x50(%rsp), %rdi
callq 0x60f26
leaq 0xb8(%rsp), %rdi
callq 0x35730
leaq 0x98(%rsp), %rdi
callq 0x35730
leaq 0xd8(%rsp), %rdi
callq 0x60a9a
movq %rbx, %rdi
callq 0x35b50
movq %rax, %rdi
callq 0x3a198
nop