// File: /workspace/github_cpp_makefile_star2_O3/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, %r13
leaq 0x118(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x37bf8(%rip), %rsi     # 0x90348
movq 0x37bf9(%rip), %rdx     # 0x90350
addq %rsi, %rdx
leaq 0x80(%rsp), %rdi
callq 0x2f10a
movq (%r13), %rsi
cmpb $0x1, 0x3(%rsi)
jne 0x58782
addq $0x50, %rsi
leaq 0x80(%rsp), %rdi
callq 0x27350
leaq 0x80(%rsp), %rdi
movl $0x2e, %esi
xorl %edx, %edx
callq 0x27770
testq %rax, %rax
je 0x5880b
leaq 0x10(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x1d9b6(%rip), %rsi     # 0x76161
leaq 0x1d9b0(%rip), %rdx     # 0x76162
movq %rsp, %rdi
callq 0x2f1a0
leaq 0x140(%rsp), %rdi
movq %rsp, %rsi
leaq 0x80(%rsp), %rdx
callq 0x4aed0
leaq 0x80(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x27350
leaq 0x150(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x587fd
callq 0x27560
movq (%rsp), %rdi
cmpq %rbx, %rdi
je 0x5880b
callq 0x27560
movq (%r13), %rax
leaq 0xb0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq 0x90(%rax), %rsi
movq 0x98(%rax), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %rdi
callq 0x2f10a
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1dfce(%rip), %rdx     # 0x76817
movq %rsp, %rdi
movq %rdx, %rsi
callq 0x2f1a0
leaq 0x140(%rsp), %rdi
movq %rsp, %rsi
movl $0x18, %edx
callq 0x279b0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5887c
callq 0x27560
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpb $0x0, 0x130(%r14)
movq %r13, 0x78(%rsp)
jne 0x58b03
movq 0x90(%r14), %rax
testq %rax, %rax
je 0x58b03
movq 0x88(%r14), %rcx
movq %rsp, %rdx
movq %rcx, (%rdx)
leaq 0x50(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x2c(%rsp), %r8
movl $0x0, (%r8)
leaq 0xa0(%rsp), %rsi
movq %r14, %rdi
callq 0x27700
testb %al, %al
je 0x58b03
movq (%rsp), %rdi
callq 0x272f0
leaq 0x30(%rsp), %rdi
movq $0x0, 0x8(%rdi)
movq (%rdi), %rcx
movb $0x0, (%rcx)
movl %eax, %ebx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x271f0
movq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
callq 0x274c0
leaq 0x150(%rsp), %rdi
movq 0x8(%r13), %rsi
movq 0x10(%r13), %rdx
callq 0x276b0
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movq %rax, %rbx
leaq 0x1c381(%rip), %rsi     # 0x74cf4
movl $0x1, %edx
movq %rax, %rdi
callq 0x276b0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x276b0
leaq 0x1c175(%rip), %rsi     # 0x74b0e
movl $0x4, %edx
movq %rax, %rdi
callq 0x276b0
movl $0x8, %edi
callq 0x275c0
movq %rax, %r15
movq %rax, %rdi
callq 0x27360
leaq 0x158(%rsp), %rbx
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x27990
leaq 0x30(%r13), %rdx
leaq 0x50(%r13), %rcx
movq %rsp, %rsi
movq %r15, %rdi
callq 0x279a0
movl %eax, %ebp
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x589f6
callq 0x27560
testb %bpl, %bpl
je 0x58e82
movq %r15, %rdi
movq %r14, %rsi
callq 0x27bd0
leaq 0x100(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf0(%rsp), %rdi
callq 0x2f10a
leaq 0x60(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0xf0(%rsp), %rsi
movq 0xf8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0x2f10a
movq %r15, 0x70(%rsp)
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
callq 0x2f10a
movq 0x70(%rsp), %rax
movq %rsp, %rsi
movq %rax, 0x20(%rsi)
leaq 0x110(%rsp), %rdi
callq 0x5d752
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58aa5
callq 0x27560
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x58ab4
callq 0x27560
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
movq 0x78(%rsp), %r13
je 0x58acb
callq 0x27560
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1dd3a(%rip), %rdx     # 0x76817
movq %rdx, %rsi
callq 0x2f1a0
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x278a0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58b03
callq 0x27560
leaq 0x28(%r13), %r12
leaq 0x30(%r13), %rax
movq %rax, 0xe8(%rsp)
leaq 0x50(%r13), %rax
movq %rax, 0xe0(%rsp)
movq %rsp, %rbp
leaq 0x50(%rsp), %r13
movq %r12, %rdi
movq %r14, %rsi
callq 0x27980
testb %al, %al
je 0x58df4
cmpb $0x0, 0x130(%r14)
jne 0x58b27
movq 0x90(%r14), %rax
testq %rax, %rax
je 0x58b27
movq 0x88(%r14), %rcx
movq %rcx, (%rsp)
movl %eax, 0x50(%rsp)
movl $0x0, 0x2c(%rsp)
movq %r14, %rdi
leaq 0xa0(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
leaq 0x2c(%rsp), %r8
callq 0x27700
testb %al, %al
je 0x58b27
movq (%rsp), %rdi
callq 0x272f0
movq $0x0, 0x38(%rsp)
movq 0x30(%rsp), %rcx
movb $0x0, (%rcx)
movl %eax, %ebx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x271f0
movq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
callq 0x274c0
leaq 0x110(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5d8f6
leaq 0x118(%rsp), %rcx
cmpq %rcx, %rax
je 0x58bf3
movq 0x40(%rax), %rbx
testq %rbx, %rbx
jne 0x58de4
jmp 0x58b27
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
leaq 0x150(%rsp), %rdi
callq 0x276b0
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1c0a5(%rip), %rsi     # 0x74cf4
callq 0x276b0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x276b0
movl $0x4, %edx
movq %rax, %rdi
leaq 0x1be99(%rip), %rsi     # 0x74b0e
callq 0x276b0
movl $0x8, %edi
callq 0x275c0
movq %rax, %rbx
movq %rax, %rdi
callq 0x27360
movq %rbp, %rdi
leaq 0x158(%rsp), %rsi
callq 0x27990
movq %rbx, %rdi
movq %rbp, %rsi
movq 0xe8(%rsp), %rdx
movq 0xe0(%rsp), %rcx
callq 0x279a0
movl %eax, %r15d
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58cd0
callq 0x27560
testb %r15b, %r15b
je 0x58efa
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0x2f10a
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x2f10a
movq %rbx, 0x70(%rsp)
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x2f10a
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x110(%rsp), %rdi
movq %rbp, %rsi
callq 0x5d752
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58d78
callq 0x27560
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x58d8c
callq 0x27560
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x58da6
callq 0x27560
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
leaq 0x1da5e(%rip), %rdx     # 0x76817
movq %rdx, %rsi
callq 0x2f1a0
leaq 0x158(%rsp), %rdi
movq %rbp, %rsi
callq 0x278a0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58de4
callq 0x27560
movq %rbx, %rdi
movq %r14, %rsi
callq 0x27bd0
jmp 0x58b27
movb $0x1, %bl
leaq 0x110(%rsp), %rsi
movq 0x78(%rsp), %rdi
callq 0x5d6cc
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x58e1c
callq 0x27560
leaq 0x140(%rsp), %rdi
callq 0x27490
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x58e43
callq 0x27560
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x58e5d
callq 0x27560
leaq 0x110(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x5d95a
movl %ebx, %eax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x36157(%rip), %rdi     # 0x8efe0
leaq 0x1bf2c(%rip), %rsi     # 0x74dbc
movl $0x25, %edx
callq 0x276b0
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x27990
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x3612b(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rbx
leaq 0x18fac(%rip), %rsi     # 0x71e70
movl $0xd, %edx
movq %rax, %rdi
callq 0x276b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
jmp 0x58f75
movq 0x360df(%rip), %rdi     # 0x8efe0
leaq 0x1beda(%rip), %rsi     # 0x74de2
movl $0x24, %edx
callq 0x276b0
movq %rsp, %rdi
leaq 0x158(%rsp), %rsi
callq 0x27990
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x360ae(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rbx
leaq 0x18f2f(%rip), %rsi     # 0x71e70
movl $0xd, %edx
movq %rax, %rdi
callq 0x276b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58f88
callq 0x27560
xorl %ebx, %ebx
jmp 0x58e08
jmp 0x590ed
jmp 0x590d1
jmp 0x590ed
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58fb9
callq 0x27560
jmp 0x58fb9
movq %rax, %r14
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x58fcd
callq 0x27560
jmp 0x58fcd
movq %rax, %r14
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
jne 0x590e2
jmp 0x590f0
jmp 0x590ed
jmp 0x590ed
jmp 0x590d1
jmp 0x590ed
movq %rax, %r14
movq %r15, %rdi
jmp 0x590e2
jmp 0x590d1
jmp 0x590d1
jmp 0x5906b
movq %rax, %r14
leaq 0x150(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5902c
callq 0x27560
jmp 0x5902c
movq %rax, %r14
movq (%rsp), %rdi
cmpq %rbx, %rdi
jne 0x59126
jmp 0x5912b
jmp 0x5906b
jmp 0x59061
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x59111
callq 0x27560
jmp 0x59111
movq %rax, %r14
jmp 0x59111
jmp 0x5906b
movq %rax, %r14
jmp 0x5912b
movq %rax, %r14
jmp 0x59145
movq %rax, %r14
jmp 0x590b1
jmp 0x590ed
movq %rax, %r14
jmp 0x5909d
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5909d
callq 0x27560
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x590b1
callq 0x27560
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
jmp 0x590dd
jmp 0x590d1
jmp 0x590ed
movq %rax, %r14
movq %rbx, %rdi
jmp 0x590e2
jmp 0x590ed
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x590f0
callq 0x27560
jmp 0x590f0
jmp 0x590ed
jmp 0x590ed
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x59104
callq 0x27560
leaq 0x140(%rsp), %rdi
callq 0x27490
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x5912b
callq 0x27560
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x59145
callq 0x27560
leaq 0x110(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x5d95a
movq %r14, %rdi
callq 0x27b10
movq %rax, %rdi
callq 0x2e1cd