// File: /workspace/github_cpp_makefile_star2_O2/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 0x58(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0xa0(%rsp), %rdi
callq 0x35200
leaq 0x28(%rbx), %r14
leaq 0x8(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %rbx, 0x10(%rsp)
leaq 0x50(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0xa0(%rsp), %rbp
leaq 0x80(%rsp), %r13
movq %r14, %rdi
movq %rbp, %rsi
callq 0x359b0
movl %eax, %r15d
testb %al, %al
je 0x58193
movq %rbp, %rdi
callq 0x350c0
movb %al, 0xf(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0xf(%rsp), %rsi
callq 0x5f348
leaq 0x58(%rsp), %rcx
cmpq %rcx, %rax
je 0x580b1
movq 0x28(%rax), %rbx
testq %rbx, %rbx
jne 0x58183
jmp 0x58067
cmpb $0x0, 0xf(%rsp)
leaq 0x3e24b(%rip), %rdx     # 0x96308
leaq 0x3e224(%rip), %rax     # 0x962e8
cmovneq %rax, %rdx
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x51d62
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x1c9f8(%rip), %rdx     # 0x74adf
callq 0x3ab7a
movq %rbx, %rdi
callq 0x35730
pushq $0x8
popq %rdi
callq 0x355d0
movq %rax, %rbx
movq %rax, %rdi
callq 0x35350
movq %rbx, %rdi
movq %r13, %rsi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x359d0
movl %eax, %r12d
testb %al, %al
je 0x58141
movb 0xf(%rsp), %al
movb %al, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5f39a
jmp 0x58176
movq 0x3ce98(%rip), %rdi     # 0x94fe0
leaq 0x1cc3d(%rip), %rsi     # 0x74d8c
callq 0x355b0
movq %rax, %rdi
movq %r13, %rsi
callq 0x35510
movq %rax, %rdi
leaq 0x19c94(%rip), %rsi     # 0x71dfd
callq 0x355b0
movq %rax, %rdi
callq 0x35300
movq %r13, %rdi
callq 0x35730
testb %r12b, %r12b
je 0x581a2
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x35c00
jmp 0x58067
leaq 0x50(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x59512
leaq 0xa0(%rsp), %rdi
callq 0x35940
xorb $0x1, %r15b
leaq 0x50(%rsp), %rdi
callq 0x5f2cc
movl %r15d, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5820f
movq %rax, %r14
jmp 0x5821f
jmp 0x581fd
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x35730
jmp 0x58212
movq %rax, %r14
movq %rbx, %rdi
callq 0x35570
jmp 0x58200
jmp 0x5820f
jmp 0x5820f
jmp 0x5820f
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x35730
jmp 0x58212
movq %rax, %r14
leaq 0xa0(%rsp), %rdi
callq 0x35940
leaq 0x50(%rsp), %rdi
callq 0x5f2cc
movq %r14, %rdi
callq 0x35b50
movq %rax, %rdi
callq 0x3a198
nop