// File: /workspace/github_cpp_makefile_star2_O1/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), %r14
movl $0x0, (%r14)
xorl %eax, %eax
movq %rax, 0x8(%r14)
movq %r14, 0x10(%r14)
movq %r14, 0x18(%r14)
movq %rax, 0x20(%r14)
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 0x8(%rsp), %rbp
movq 0x68(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x27990
movl %eax, %r15d
testb %al, %al
je 0x538fd
leaq 0xa0(%rsp), %rdi
callq 0x270d0
movl %eax, %r13d
movq 0x80(%rsp), %rcx
movq %r14, %rax
testq %rcx, %rcx
je 0x53788
movq %r14, %rax
xorl %edx, %edx
cmpb %r13b, 0x20(%rcx)
setb %dl
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x53771
movq %r14, %rcx
cmpq %r14, %rax
je 0x5379b
cmpb %r13b, 0x20(%rax)
cmovaq %r14, %rax
movq %rax, %rcx
cmpq %r14, %rcx
je 0x537a9
movq 0x28(%rcx), %r12
jmp 0x538df
testb %r13b, %r13b
leaq 0x3db1d(%rip), %rdx     # 0x912d0
leaq 0x3daf6(%rip), %rax     # 0x912b0
cmovneq %rax, %rdx
leaq 0x28(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x4af9e
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x2f122
movq %rbp, %rdi
leaq 0x22300(%rip), %rsi     # 0x75af6
callq 0x27c10
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x5380f
callq 0x27560
movl $0x8, %edi
callq 0x275c0
movq %rax, %r12
movq %rax, %rdi
callq 0x27360
movq %r12, %rdi
movq %rbp, %rsi
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
callq 0x279b0
movl %eax, %ebx
testb %al, %al
je 0x5385a
movb %r13b, 0x28(%rsp)
movq %r12, 0x30(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x5cafe
jmp 0x538c7
movl $0x25, %edx
movq 0x3c77a(%rip), %rdi     # 0x8ffe0
leaq 0x2255d(%rip), %rsi     # 0x75dca
callq 0x276c0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x3c75d(%rip), %rdi     # 0x8ffe0
callq 0x276c0
movq %rax, %r13
movl $0xd, %edx
movq %rax, %rdi
leaq 0x1f5d6(%rip), %rsi     # 0x72e70
callq 0x276c0
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 0x538db
callq 0x27560
testb %bl, %bl
je 0x5390c
testq %r12, %r12
je 0x53731
movq %r12, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x27be0
jmp 0x53731
leaq 0x70(%rsp), %rsi
movq 0x48(%rsp), %rdi
callq 0x54fd6
leaq 0xa0(%rsp), %rdi
callq 0x27930
xorb $0x1, %r15b
leaq 0x70(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x5ca92
movl %r15d, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x53999
movq %rax, %rbx
jmp 0x539a9
jmp 0x53980
jmp 0x53999
movq %rax, %rbx
jmp 0x53967
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x53967
callq 0x27560
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
jmp 0x5398d
movq %rax, %rbx
movq %r12, %rdi
callq 0x27560
jmp 0x53983
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5399c
callq 0x27560
jmp 0x5399c
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x27930
leaq 0x70(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x5ca92
movq %rbx, %rdi
callq 0x27b20
movq %rax, %rdi
callq 0x2e1ed
nop