// File: /workspace/github_cpp_makefile_star2_O2/zeeev[P]DASVC/bamtools/src/toolkit/bamtools_split.cpp
// Function: bool BamTools::SplitTool::SplitToolPrivate::SplitTagImpl<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>(BamTools::BamAlignment&)
bool SplitTool::SplitToolPrivate::SplitTagImpl(BamAlignment& al) {
  
    typedef T TagValueType;
    typedef map<TagValueType, 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;

    // local variables
    const string tag = m_settings->TagToSplit;
    BamWriter* writer;
    stringstream outputFilenameStream("");
    TagValueType currentValue;
    
    // retrieve first alignment tag value
    if ( al.GetTag(tag, currentValue) ) {
      
        // open new BamWriter, save first alignment
        outputFilenameStream << m_outputFilenameStub << tagPrefix << tag << "_" << currentValue << ".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;
        }
        writer->SaveAlignment(al);
        
        // store in map
        outputFiles.insert( make_pair(currentValue, writer) );
        
        // reset stream
        outputFilenameStream.str("");
    }
    
    // iterate through remaining alignments
    while ( m_reader.GetNextAlignment(al) ) {
      
        // skip if this alignment doesn't have TAG 
        if ( !al.GetTag(tag, currentValue) ) continue;
        
        // look up tag value in map
        writerIter = outputFiles.find(currentValue);
          
        // if no writer associated with this value
        if ( writerIter == outputFiles.end() ) {
        
            // open new BamWriter
            outputFilenameStream << m_outputFilenameStub << tagPrefix << tag << "_" << currentValue << ".bam";
            writer = new BamWriter;
            if ( !writer->Open(outputFilenameStream.str(), m_header, m_references) ) {
                cerr << "bamtool split ERROR: could not open " << outputFilenameStream.str()
                     << " for writing." << endl;
                return false;
            }

            // store in map
            outputFiles.insert( make_pair(currentValue, writer) );
            
            // reset stream
            outputFilenameStream.str("");
        } 
        
        // else grab corresponding writer
        else writer = (*writerIter).second;
        
        // store alignment in proper BAM output file 
        if ( writer ) 
            writer->SaveAlignment(al);
    }
    
    // clean up BamWriters  
    CloseWriters(outputFiles);
    
    // return success
    return true;  
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xd8(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x3a3d3(%rip), %rsi     # 0x96388
leaq 0x78(%rsp), %rdi
callq 0x35810
movq %rbx, 0x28(%rsp)
movq (%rbx), %rsi
cmpb $0x1, 0x3(%rsi)
jne 0x5bfdb
addq $0x50, %rsi
leaq 0x78(%rsp), %rdi
callq 0x35340
leaq 0x78(%rsp), %rdi
pushq $0x2e
popq %rsi
xorl %edx, %edx
callq 0x35790
testq %rax, %rax
je 0x5c03f
leaq 0x1a128(%rip), %rsi     # 0x7611e
movq %rsp, %rdi
leaq 0x50(%rsp), %rdx
callq 0x35280
leaq 0x140(%rsp), %rdi
movq %rsp, %rsi
leaq 0x78(%rsp), %rdx
callq 0x51d62
leaq 0x78(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x35340
leaq 0x140(%rsp), %rdi
callq 0x35730
movq %rsp, %rdi
callq 0x35730
movl $0x90, %esi
movq 0x28(%rsp), %rax
addq (%rax), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x35810
leaq 0x1a797(%rip), %rsi     # 0x767f7
movq %rsp, %rdi
leaq 0x50(%rsp), %rdx
callq 0x35280
leaq 0x140(%rsp), %rdi
movq %rsp, %rsi
pushq $0x18
popq %rdx
callq 0x359e0
movq %rsp, %rdi
callq 0x35730
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xb0(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
callq 0x4ac46
testb %al, %al
je 0x5c1fb
leaq 0x150(%rsp), %rdi
movq 0x28(%rsp), %rax
leaq 0x8(%rax), %rsi
callq 0x35510
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x35510
leaq 0xb0(%rsp), %rsi
movq %rax, %rdi
callq 0x35510
leaq 0x18bd4(%rip), %rsi     # 0x74cc4
movq %rax, %rdi
callq 0x355b0
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x35510
leaq 0x189d3(%rip), %rsi     # 0x74adf
movq %rax, %rdi
callq 0x355b0
pushq $0x8
popq %rdi
callq 0x355d0
movq %rax, %r15
movq %rax, %rdi
callq 0x35350
leaq 0x158(%rsp), %rbx
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x359c0
movq 0x28(%rsp), %rax
leaq 0x30(%rax), %rdx
leaq 0x50(%rax), %rcx
movq %rsp, %rsi
movq %r15, %rdi
callq 0x359d0
movl %eax, %ebp
movq %rsp, %rdi
callq 0x35730
testb %bpl, %bpl
je 0x5c3f4
movq %r15, %rdi
movq %r14, %rsi
callq 0x35c00
leaq 0x100(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x35810
leaq 0x50(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x35810
leaq 0x50(%rsp), %rsi
movq %r15, 0x20(%rsi)
movq %rsp, %rdi
callq 0x6071e
leaq 0xd0(%rsp), %rdi
movq %rsp, %rsi
callq 0x607aa
movq %rsp, %rdi
callq 0x35730
leaq 0x50(%rsp), %rdi
callq 0x35730
leaq 0x100(%rsp), %rdi
callq 0x35730
leaq 0x1a61c(%rip), %rsi     # 0x767f7
movq %rsp, %rdi
leaq 0x50(%rsp), %rdx
callq 0x35280
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x358d0
movq %rsp, %rdi
callq 0x35730
movq 0x28(%rsp), %rax
leaq 0x28(%rax), %r12
leaq 0x8(%rax), %rcx
movq %rcx, 0xa8(%rsp)
leaq 0x30(%rax), %rcx
movq %rcx, 0xa0(%rsp)
addq $0x50, %rax
movq %rax, 0x98(%rsp)
leaq 0x120(%rsp), %r15
movq %r12, %rdi
movq %r14, %rsi
callq 0x359b0
testb %al, %al
je 0x5c3db
movq %r14, %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x4ac46
testb %al, %al
je 0x5c230
leaq 0xd0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x609b2
leaq 0xd8(%rsp), %rcx
cmpq %rcx, %rax
je 0x5c28a
movq 0x40(%rax), %r13
testq %r13, %r13
jne 0x5c3cb
jmp 0x5c230
leaq 0x150(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0x35510
movq %rax, %rdi
leaq 0x78(%rsp), %rsi
callq 0x35510
movq %rax, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x35510
movq %rax, %rdi
leaq 0x189fe(%rip), %rsi     # 0x74cc4
callq 0x355b0
movq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0x35510
movq %rax, %rdi
leaq 0x187fd(%rip), %rsi     # 0x74adf
callq 0x355b0
pushq $0x8
popq %rdi
callq 0x355d0
movq %rax, %r13
movq %r15, %rbx
movq %rax, %rdi
callq 0x35350
movq %rsp, %rbp
movq %rbp, %rdi
leaq 0x158(%rsp), %rsi
callq 0x359c0
movq %r13, %rdi
movq %rbp, %rsi
movq 0xa0(%rsp), %rdx
movq 0x98(%rsp), %rcx
callq 0x359d0
movl %eax, %r15d
movq %rbp, %rdi
callq 0x35730
testb %r15b, %r15b
je 0x5c441
movq %rbx, %r15
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
callq 0x35810
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x35810
movq %r13, 0x70(%rsp)
movq %rsp, %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x6071e
leaq 0xd0(%rsp), %rdi
movq %rbx, %rsi
callq 0x607aa
movq %rbx, %rdi
callq 0x35730
leaq 0x50(%rsp), %rdi
callq 0x35730
movq %r15, %rdi
callq 0x35730
movq %rsp, %rbx
movq %rbx, %rdi
leaq 0x1a44e(%rip), %rsi     # 0x767f7
leaq 0x50(%rsp), %rdx
callq 0x35280
leaq 0x158(%rsp), %rdi
movq %rbx, %rsi
callq 0x358d0
movq %rbx, %rdi
callq 0x35730
movq %r13, %rdi
movq %r14, %rsi
callq 0x35c00
jmp 0x5c230
movb $0x1, %bl
leaq 0xd0(%rsp), %rsi
movq 0x28(%rsp), %rdi
callq 0x6073e
jmp 0x5c493
movq 0x38be5(%rip), %rdi     # 0x94fe0
leaq 0x1898a(%rip), %rsi     # 0x74d8c
callq 0x355b0
movq %rax, %r14
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x359c0
movq %rsp, %rsi
movq %r14, %rdi
callq 0x35510
leaq 0x159d6(%rip), %rsi     # 0x71dfd
movq %rax, %rdi
callq 0x355b0
movq %rax, %rdi
callq 0x35300
movq %rsp, %rdi
callq 0x35730
jmp 0x5c491
movq 0x38b98(%rip), %rdi     # 0x94fe0
leaq 0x18963(%rip), %rsi     # 0x74db2
callq 0x355b0
movq %rax, %rbx
movq %rsp, %rdi
leaq 0x158(%rsp), %rsi
callq 0x359c0
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x35510
leaq 0x15984(%rip), %rsi     # 0x71dfd
movq %rax, %rdi
callq 0x355b0
movq %rax, %rdi
callq 0x35300
movq %rsp, %rdi
callq 0x35730
xorl %ebx, %ebx
leaq 0x30(%rsp), %rdi
callq 0x35730
leaq 0x140(%rsp), %rdi
callq 0x35490
leaq 0xb0(%rsp), %rdi
callq 0x35730
leaq 0x78(%rsp), %rdi
callq 0x35730
leaq 0xd0(%rsp), %rdi
callq 0x60a9a
movl %ebx, %eax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5c62d
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c630
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c526
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c630
jmp 0x5c62d
jmp 0x5c62d
movq %rax, %rbx
jmp 0x5c530
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x35730
leaq 0x100(%rsp), %rdi
callq 0x35730
jmp 0x5c630
jmp 0x5c62d
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c630
movq %rax, %rbx
movq %r15, %rdi
jmp 0x5c5ee
jmp 0x5c5b9
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x35730
jmp 0x5c5ac
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c630
jmp 0x5c5c9
movq %rax, %rbx
jmp 0x5c63a
jmp 0x5c62d
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c647
jmp 0x5c5b9
jmp 0x5c5b9
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c654
movq %rax, %rbx
jmp 0x5c654
movq %rax, %rbx
jmp 0x5c65e
movq %rax, %rbx
jmp 0x5c647
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c630
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c610
movq %rax, %rbx
movq %r13, %rdi
callq 0x35570
jmp 0x5c630
movq %rax, %rbx
movq %rsp, %rdi
callq 0x35730
jmp 0x5c630
jmp 0x5c62d
jmp 0x5c62d
jmp 0x5c62d
movq %rax, %rbx
jmp 0x5c61a
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x35730
leaq 0x120(%rsp), %rdi
callq 0x35730
jmp 0x5c630
jmp 0x5c62d
jmp 0x5c62d
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x35730
leaq 0x140(%rsp), %rdi
callq 0x35490
leaq 0xb0(%rsp), %rdi
callq 0x35730
leaq 0x78(%rsp), %rdi
callq 0x35730
leaq 0xd0(%rsp), %rdi
callq 0x60a9a
movq %rbx, %rdi
callq 0x35b50
movq %rax, %rdi
callq 0x3a198
nop