// File: /workspace/github_cpp_makefile_star2_O1/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 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x38ade(%rip), %rsi     # 0x91350
movq 0x38adf(%rip), %rdx     # 0x91358
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x2f122
movq (%r13), %rsi
cmpb $0x1, 0x3(%rsi)
jne 0x5889e
addq $0x50, %rsi
leaq 0x78(%rsp), %rdi
callq 0x27350
leaq 0x78(%rsp), %rdi
movl $0x2e, %esi
xorl %edx, %edx
callq 0x27780
testq %rax, %rax
je 0x5891e
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1e89d(%rip), %rsi     # 0x77161
leaq 0x1e897(%rip), %rdx     # 0x77162
movq %rsp, %rdi
callq 0x2f1b2
leaq 0x140(%rsp), %rdi
movq %rsp, %rsi
leaq 0x78(%rsp), %rdx
callq 0x4af9e
leaq 0x78(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x27350
leaq 0x150(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x58910
callq 0x27560
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x5891e
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 0x2f122
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1eebf(%rip), %rdx     # 0x7781b
movq %rsp, %rdi
movq %rdx, %rsi
callq 0x2f1b2
leaq 0x140(%rsp), %rdi
movq %rsp, %rsi
movl $0x18, %edx
callq 0x279c0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5898f
callq 0x27560
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpb $0x0, 0x130(%r14)
jne 0x58c1a
movq 0x90(%r14), %rax
testq %rax, %rax
je 0x58c1a
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 0x27710
movl %eax, %ebx
testb %al, %al
je 0x58c1a
movq (%rsp), %rdi
callq 0x272f0
leaq 0x30(%rsp), %rdi
movq $0x0, 0x8(%rdi)
movq (%rdi), %rcx
movb $0x0, (%rcx)
movl %eax, %r15d
movq %r15, %rsi
xorl %edx, %edx
callq 0x271f0
movq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq %r15, %rdx
callq 0x274c0
testb %bl, %bl
je 0x58c1a
leaq 0x150(%rsp), %rdi
movq 0x8(%r13), %rsi
movq 0x10(%r13), %rdx
callq 0x276c0
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq %rax, %rdi
callq 0x276c0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276c0
movq %rax, %rbx
leaq 0x1d279(%rip), %rsi     # 0x75d02
movl $0x1, %edx
movq %rax, %rdi
callq 0x276c0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x276c0
leaq 0x1d047(%rip), %rsi     # 0x75af6
movl $0x4, %edx
movq %rax, %rdi
callq 0x276c0
movl $0x8, %edi
callq 0x275c0
movq %rax, %r15
movq %rax, %rdi
callq 0x27360
leaq 0x158(%rsp), %rbx
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x279a0
leaq 0x30(%r13), %rdx
leaq 0x50(%r13), %rcx
movq %rsp, %rsi
movq %r15, %rdi
callq 0x279b0
movl %eax, %ebp
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58b0c
callq 0x27560
testb %bpl, %bpl
je 0x58fab
movq %r15, %rdi
movq %r14, %rsi
callq 0x27be0
movq %r13, %rbp
leaq 0x100(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf0(%rsp), %rdi
callq 0x2f122
leaq 0x60(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0xf0(%rsp), %rsi
movq 0xf8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0x2f122
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 0x2f122
movq 0x70(%rsp), %rax
movq %rsp, %rsi
movq %rax, 0x20(%rsi)
leaq 0x110(%rsp), %rdi
callq 0x5db00
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58bbe
callq 0x27560
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x58bcd
callq 0x27560
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
movq %rbp, %r13
je 0x58be2
callq 0x27560
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1ec27(%rip), %rdx     # 0x7781b
movq %rdx, %rsi
callq 0x2f1b2
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x278b0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58c1a
callq 0x27560
leaq 0x28(%r13), %r12
leaq 0x30(%r13), %rax
movq %rax, 0xe8(%rsp)
movq %r13, 0x98(%rsp)
leaq 0x50(%r13), %rax
movq %rax, 0xe0(%rsp)
movq %rsp, %rbp
leaq 0x50(%rsp), %r13
movq %r12, %rdi
movq %r14, %rsi
callq 0x27990
testb %al, %al
je 0x58f1d
cmpb $0x0, 0x130(%r14)
jne 0x58c46
movq 0x90(%r14), %rax
testq %rax, %rax
je 0x58c46
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 0x27710
movl %eax, %r15d
testb %al, %al
je 0x58c46
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
testb %r15b, %r15b
je 0x58c46
leaq 0x110(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5dca8
leaq 0x118(%rsp), %rcx
cmpq %rcx, %rax
je 0x58d15
movq 0x40(%rax), %r15
jmp 0x58f04
movq 0x98(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
leaq 0x150(%rsp), %rdi
callq 0x276c0
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq %rax, %rdi
callq 0x276c0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276c0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1cf91(%rip), %rsi     # 0x75d02
callq 0x276c0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r15, %rdi
callq 0x276c0
movl $0x4, %edx
movq %rax, %rdi
leaq 0x1cd5f(%rip), %rsi     # 0x75af6
callq 0x276c0
movl $0x8, %edi
callq 0x275c0
movq %rax, %r15
movq %rax, %rdi
callq 0x27360
movq %rbp, %rdi
leaq 0x158(%rsp), %rsi
callq 0x279a0
movq %r15, %rdi
movq %rbp, %rsi
movq 0xe8(%rsp), %rdx
movq 0xe0(%rsp), %rcx
callq 0x279b0
movl %eax, %ebx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58df1
callq 0x27560
testb %bl, %bl
je 0x59023
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0x2f122
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x2f122
movq %r15, 0x70(%rsp)
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x2f122
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x110(%rsp), %rdi
movq %rbp, %rsi
callq 0x5db00
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58e98
callq 0x27560
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x58eac
callq 0x27560
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x58ec6
callq 0x27560
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
leaq 0x1e942(%rip), %rdx     # 0x7781b
movq %rdx, %rsi
callq 0x2f1b2
leaq 0x158(%rsp), %rdi
movq %rbp, %rsi
callq 0x278b0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x58f04
callq 0x27560
testq %r15, %r15
je 0x58c46
movq %r15, %rdi
movq %r14, %rsi
callq 0x27be0
jmp 0x58c46
movb $0x1, %bl
leaq 0x110(%rsp), %rsi
movq 0x98(%rsp), %rdi
callq 0x5da7a
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x58f48
callq 0x27560
leaq 0x140(%rsp), %rdi
callq 0x27490
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x58f6f
callq 0x27560
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x58f86
callq 0x27560
leaq 0x110(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x5dd10
movl %ebx, %eax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3702e(%rip), %rdi     # 0x8ffe0
leaq 0x1ce11(%rip), %rsi     # 0x75dca
movl $0x25, %edx
callq 0x276c0
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x279a0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x37002(%rip), %rdi     # 0x8ffe0
callq 0x276c0
movq %rax, %rbx
leaq 0x19e83(%rip), %rsi     # 0x72e70
movl $0xd, %edx
movq %rax, %rdi
callq 0x276c0
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 0x5909e
movq 0x36fb6(%rip), %rdi     # 0x8ffe0
leaq 0x1cdbf(%rip), %rsi     # 0x75df0
movl $0x24, %edx
callq 0x276c0
movq %rsp, %rdi
leaq 0x158(%rsp), %rsi
callq 0x279a0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x36f85(%rip), %rdi     # 0x8ffe0
callq 0x276c0
movq %rax, %rbx
leaq 0x19e06(%rip), %rsi     # 0x72e70
movl $0xd, %edx
movq %rax, %rdi
callq 0x276c0
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 0x590b1
callq 0x27560
xorl %ebx, %ebx
jmp 0x58f34
jmp 0x5920c
jmp 0x591c5
jmp 0x5920c
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x590e2
callq 0x27560
jmp 0x590e2
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x590f6
callq 0x27560
jmp 0x590f6
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
jne 0x591d6
jmp 0x5920f
jmp 0x5920c
jmp 0x5920c
jmp 0x591c5
jmp 0x5920c
jmp 0x591bb
jmp 0x591c5
jmp 0x591c5
jmp 0x591fe
movq %rax, %rbx
leaq 0x150(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x59152
callq 0x27560
jmp 0x59152
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
jne 0x59245
jmp 0x5924a
jmp 0x591fe
jmp 0x5920c
movq %rax, %rbx
jmp 0x591a7
movq %rax, %rbx
jmp 0x59193
jmp 0x5920c
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x59193
callq 0x27560
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x591a7
callq 0x27560
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
jmp 0x591d1
jmp 0x591c5
movq %rax, %rbx
movq %r15, %rdi
jmp 0x591d6
jmp 0x5920c
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5920f
callq 0x27560
jmp 0x5920f
jmp 0x591f7
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x59230
callq 0x27560
jmp 0x59230
movq %rax, %rbx
jmp 0x59230
jmp 0x591fe
movq %rax, %rbx
jmp 0x5924a
movq %rax, %rbx
jmp 0x59261
jmp 0x5920c
jmp 0x5920c
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x59223
callq 0x27560
leaq 0x140(%rsp), %rdi
callq 0x27490
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x5924a
callq 0x27560
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x59261
callq 0x27560
leaq 0x110(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x5dd10
movq %rbx, %rdi
callq 0x27b20
movq %rax, %rdi
callq 0x2e1ed