// File: 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:
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdi, 0x2c8(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x298(%rsp), %rdi
callq 0xe8140
leaq 0x290(%rsp), %rdi
callq 0xe8150
jmp 0xe52cb
leaq 0x128(%rsp), %rdi
callq 0x86260
jmp 0xe52da
jmp 0xe52dc
movq 0x88(%rsp), %rdi
addq $0x28, %rdi
leaq 0x128(%rsp), %rsi
callq 0x86bb0
movb %al, 0x87(%rsp)
jmp 0xe52fe
movb 0x87(%rsp), %al
testb $0x1, %al
jne 0xe530e
jmp 0xe56be
leaq 0x128(%rsp), %rdi
callq 0x860f0
movb %al, 0x86(%rsp)
jmp 0xe5324
movb 0x86(%rsp), %al
andb $0x1, %al
movb %al, 0x11f(%rsp)
leaq 0x298(%rsp), %rdi
leaq 0x11f(%rsp), %rsi
callq 0xe8170
movq %rax, 0x78(%rsp)
jmp 0xe5350
movq 0x78(%rsp), %rax
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x290(%rsp)
leaq 0x298(%rsp), %rdi
callq 0xe81c0
movq %rax, 0x70(%rsp)
jmp 0xe5381
movq 0x70(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0x290(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0xe81a0
movb %al, 0x6f(%rsp)
jmp 0xe53a9
movb 0x6f(%rsp), %al
testb $0x1, %al
jne 0xe53b6
jmp 0xe5670
movq 0x88(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x60(%rsp)
testb $0x1, 0x11f(%rsp)
je 0xe53df
leaq 0x81060(%rip), %rax     # 0x166438
movq %rax, 0x58(%rsp)
jmp 0xe53ed
leaq 0x81072(%rip), %rax     # 0x166458
movq %rax, 0x58(%rsp)
jmp 0xe53ed
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq 0xc8(%rsp), %rdi
callq 0xd0140
jmp 0xe5406
leaq 0x4cf12(%rip), %rdx     # 0x13231f
leaq 0xe8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x927c0
jmp 0xe5424
leaq 0xc8(%rsp), %rdi
callq 0x86f68
jmp 0xe5433
movl $0x8, %edi
callq 0x86720
movq %rax, 0x50(%rsp)
jmp 0xe5444
movq 0x50(%rsp), %rdi
callq 0x863f0
jmp 0xe5450
movq 0x88(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x120(%rsp), %rdi
movq %rcx, %rdx
addq $0x30, %rdx
addq $0x50, %rcx
leaq 0xe8(%rsp), %rsi
callq 0x86bd0
movb %al, 0x4f(%rsp)
jmp 0xe548b
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0xe55a5
jmp 0xe5499
movq 0x7fb40(%rip), %rdi     # 0x164fe0
leaq 0x4da8b(%rip), %rsi     # 0x132f32
callq 0x86700
movq %rax, 0x40(%rsp)
jmp 0xe54b3
movq 0x40(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x86640
movq %rax, 0x38(%rsp)
jmp 0xe54cc
movq 0x38(%rsp), %rdi
leaq 0x4a16d(%rip), %rsi     # 0x12f645
callq 0x86700
movq %rax, 0x30(%rsp)
jmp 0xe54e4
movq 0x30(%rsp), %rdi
movq 0x7fa80(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0xe54f7
movb $0x0, 0x2d7(%rsp)
movl $0x1, 0xc4(%rsp)
jmp 0xe563a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0xe5726
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0xe5715
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x86f68
jmp 0xe5564
jmp 0xe5715
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0xe565c
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
callq 0x866a0
jmp 0xe565c
movq 0x120(%rsp), %rsi
movzbl 0x11f(%rsp), %edi
andl $0x1, %edi
callq 0xe8240
movq %rdx, 0x20(%rsp)
movb %al, 0x2f(%rsp)
jmp 0xe55c8
movq 0x20(%rsp), %rax
movb 0x2f(%rsp), %cl
movb %cl, 0xa0(%rsp)
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xe8280
jmp 0xe55f7
leaq 0x298(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0xe81f0
movb %dl, 0x17(%rsp)
movq %rax, 0x18(%rsp)
jmp 0xe5617
movb 0x17(%rsp), %al
movq 0x18(%rsp), %rcx
movq %rcx, 0x90(%rsp)
movb %al, 0x98(%rsp)
movl $0x0, 0xc4(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x86f68
jmp 0xe5649
movl 0xc4(%rsp), %eax
testl %eax, %eax
jne 0xe56e8
jmp 0xe565a
jmp 0xe5695
leaq 0xe8(%rsp), %rdi
callq 0x86f68
jmp 0xe566b
jmp 0xe5715
leaq 0x290(%rsp), %rdi
callq 0xe82b0
movq %rax, 0x8(%rsp)
jmp 0xe5684
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x120(%rsp)
cmpq $0x0, 0x120(%rsp)
je 0xe56b9
movq 0x120(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x86e80
jmp 0xe56b7
jmp 0xe56b9
jmp 0xe52dc
movq 0x88(%rsp), %rdi
leaq 0x298(%rsp), %rsi
callq 0xe82d0
jmp 0xe56d5
movb $0x1, 0x2d7(%rsp)
movl $0x1, 0xc4(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x86b30
jmp 0xe56f7
leaq 0x298(%rsp), %rdi
callq 0xe83b0
movb 0x2d7(%rsp), %al
andb $0x1, %al
addq $0x2d8, %rsp            # imm = 0x2D8
retq
leaq 0x128(%rsp), %rdi
callq 0x86b30
jmp 0xe5724
jmp 0xe5726
leaq 0x298(%rsp), %rdi
callq 0xe83b0
jmp 0xe5735
jmp 0xe5737
movq 0x288(%rsp), %rdi
callq 0x86d80
movq %rax, %rdi
callq 0x91290
nopl (%rax)