// File: /workspace/github_cpp_makefile_star2_O3/zeeev[P]DASVC/bamtools/src/toolkit/bamtools_split.cpp
// Function: BamTools::SplitTool::SplitToolPrivate::SplitMapped()
bool SplitTool::SplitToolPrivate::SplitMapped(void) {
    
    // set up splitting data structure
    map<bool, BamWriter*> outputFiles;
    map<bool, BamWriter*>::iterator writerIter;
    
    // iterate through alignments
    BamAlignment al;
    BamWriter* writer;
    bool isCurrentAlignmentMapped;
    while ( m_reader.GetNextAlignment(al) ) {
      
        // see if bool value exists
        isCurrentAlignmentMapped = al.IsMapped();
        writerIter = outputFiles.find(isCurrentAlignmentMapped);
          
        // if no writer associated with this value
        if ( writerIter == outputFiles.end() ) {
        
            // open new BamWriter
            const string outputFilename = m_outputFilenameStub + ( isCurrentAlignmentMapped
                                                                  ? SPLIT_MAPPED_TOKEN
                                                                  : SPLIT_UNMAPPED_TOKEN ) + ".bam";
            writer = new BamWriter;
            if ( !writer->Open(outputFilename, m_header, m_references) ) {
                cerr << "bamtools split ERROR: could not open " << outputFilename
                     << " for writing." << endl;
                return false;
            }
          
            // store in map
            outputFiles.insert( make_pair(isCurrentAlignmentMapped, writer) );
        } 
        
        // 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 $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, %rbx
leaq 0x78(%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 0xa0(%rsp), %rdi
callq 0x27220
leaq 0x28(%rbx), %rax
movq %rax, 0x68(%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0x60(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x58(%rsp)
movq %rbx, 0x48(%rsp)
leaq 0x50(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0xa0(%rsp), %rbp
leaq 0x8(%rsp), %rbx
movq 0x68(%rsp), %rdi
movq %rbp, %rsi
callq 0x27980
movl %eax, %r15d
testb %al, %al
je 0x537b2
movq %rbp, %rdi
callq 0x270d0
movl %eax, %r13d
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x5365c
leaq 0x78(%rsp), %rax
movq %rax, %rcx
movq %rdi, %rdx
movb 0x20(%rdi), %sil
xorl %edi, %edi
cmpb %r13b, %sil
setb %dil
movq %rdx, %rax
cmovbq %rcx, %rax
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x5361d
leaq 0x78(%rsp), %rdi
cmpq %rdi, %rax
je 0x5365c
cmpb %r13b, %sil
cmovbq %rcx, %rdx
cmpb %r13b, 0x20(%rdx)
jbe 0x537a4
testb %r13b, %r13b
leaq 0x3cc62(%rip), %rdx     # 0x902c8
leaq 0x3cc3b(%rip), %rax     # 0x902a8
cmovneq %rax, %rdx
leaq 0x28(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x4aed0
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x2f10a
movq %rbx, %rdi
leaq 0x21465(%rip), %rsi     # 0x74b0e
callq 0x27c00
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x536c2
callq 0x27560
movl $0x8, %edi
callq 0x275c0
movq %rax, %r12
movq %rax, %rdi
callq 0x27360
movq %r12, %rdi
movq %rbx, %rsi
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
callq 0x279a0
movl %eax, %r14d
testb %al, %al
je 0x5370e
movb %r13b, 0x28(%rsp)
movq %r12, 0x30(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x5c9ce
jmp 0x5377b
movl $0x25, %edx
movq 0x3b8c6(%rip), %rdi     # 0x8efe0
leaq 0x2169b(%rip), %rsi     # 0x74dbc
callq 0x276b0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x3b8a9(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %r13
movl $0xd, %edx
movq %rax, %rdi
leaq 0x1e722(%rip), %rsi     # 0x71e70
callq 0x276b0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %r13, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5378f
callq 0x27560
testb %r14b, %r14b
je 0x537c1
movq %r12, %rdi
movq %rbp, %rsi
callq 0x27bd0
jmp 0x535e8
movq 0x28(%rax), %r12
testq %r12, %r12
jne 0x53794
jmp 0x535e8
leaq 0x70(%rsp), %rsi
movq 0x48(%rsp), %rdi
callq 0x54e60
leaq 0xa0(%rsp), %rdi
callq 0x27920
xorb $0x1, %r15b
leaq 0x70(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x5c962
movl %r15d, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x53835
movq %rax, %rbx
jmp 0x5385e
jmp 0x5383a
jmp 0x53835
movq %rax, %rbx
jmp 0x5381c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5381c
callq 0x27560
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
jmp 0x53847
movq %rax, %rbx
movq %r12, %rdi
callq 0x27560
jmp 0x5383d
movq %rax, %rbx
jmp 0x53851
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x53851
callq 0x27560
leaq 0xa0(%rsp), %rdi
callq 0x27920
leaq 0x70(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x5c962
movq %rbx, %rdi
callq 0x27b10
movq %rax, %rdi
callq 0x2e1cd