// File: zeeev[P]DASVC/bamtools/src/toolkit/bamtools_split.cpp
// Function: BamTools::SplitTool::SplitToolPrivate::SplitPaired()
bool SplitTool::SplitToolPrivate::SplitPaired(void) {
  
    // set up splitting data structure
    map<bool, BamWriter*> outputFiles;
    map<bool, BamWriter*>::iterator writerIter;
    
    // iterate through alignments
    BamAlignment al;
    BamWriter* writer;
    bool isCurrentAlignmentPaired;
    while ( m_reader.GetNextAlignment(al) ) {
      
        // see if bool value exists
        isCurrentAlignmentPaired = al.IsPaired();
        writerIter = outputFiles.find(isCurrentAlignmentPaired);
          
        // if no writer associated with this value
        if ( writerIter == outputFiles.end() ) {
        
            // open new BamWriter
            const string outputFilename = m_outputFilenameStub + ( isCurrentAlignmentPaired
                                                                  ? SPLIT_PAIRED_TOKEN
                                                                  : SPLIT_SINGLE_TOKEN ) + ".bam";
            writer = new BamWriter;
            if ( !writer->Open(outputFilename, m_header, m_references) ) {
                cerr << "bamtool split ERROR: could not open " << outputFilename
                     << " for writing." << endl;
                return false;
            }
          
            // store in map
            outputFiles.insert( make_pair(isCurrentAlignmentPaired, 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 0xe578b
leaq 0x128(%rsp), %rdi
callq 0x86260
jmp 0xe579a
jmp 0xe579c
movq 0x88(%rsp), %rdi
addq $0x28, %rdi
leaq 0x128(%rsp), %rsi
callq 0x86bb0
movb %al, 0x87(%rsp)
jmp 0xe57be
movb 0x87(%rsp), %al
testb $0x1, %al
jne 0xe57ce
jmp 0xe5b7e
leaq 0x128(%rsp), %rdi
callq 0x863d0
movb %al, 0x86(%rsp)
jmp 0xe57e4
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 0xe5810
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 0xe5841
movq 0x70(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0x290(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0xe81a0
movb %al, 0x6f(%rsp)
jmp 0xe5869
movb 0x6f(%rsp), %al
testb $0x1, %al
jne 0xe5876
jmp 0xe5b30
movq 0x88(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x60(%rsp)
testb $0x1, 0x11f(%rsp)
je 0xe589f
leaq 0x80be0(%rip), %rax     # 0x166478
movq %rax, 0x58(%rsp)
jmp 0xe58ad
leaq 0x80bf2(%rip), %rax     # 0x166498
movq %rax, 0x58(%rsp)
jmp 0xe58ad
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq 0xc8(%rsp), %rdi
callq 0xd0140
jmp 0xe58c6
leaq 0x4ca52(%rip), %rdx     # 0x13231f
leaq 0xe8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x927c0
jmp 0xe58e4
leaq 0xc8(%rsp), %rdi
callq 0x86f68
jmp 0xe58f3
movl $0x8, %edi
callq 0x86720
movq %rax, 0x50(%rsp)
jmp 0xe5904
movq 0x50(%rsp), %rdi
callq 0x863f0
jmp 0xe5910
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 0xe594b
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0xe5a65
jmp 0xe5959
movq 0x7f680(%rip), %rdi     # 0x164fe0
leaq 0x4d5f1(%rip), %rsi     # 0x132f58
callq 0x86700
movq %rax, 0x40(%rsp)
jmp 0xe5973
movq 0x40(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x86640
movq %rax, 0x38(%rsp)
jmp 0xe598c
movq 0x38(%rsp), %rdi
leaq 0x49cad(%rip), %rsi     # 0x12f645
callq 0x86700
movq %rax, 0x30(%rsp)
jmp 0xe59a4
movq 0x30(%rsp), %rdi
movq 0x7f5c0(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0xe59b7
movb $0x0, 0x2d7(%rsp)
movl $0x1, 0xc4(%rsp)
jmp 0xe5afa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0xe5be6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0xe5bd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x86f68
jmp 0xe5a24
jmp 0xe5bd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
jmp 0xe5b1c
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x288(%rsp)
movl %eax, 0x284(%rsp)
callq 0x866a0
jmp 0xe5b1c
movq 0x120(%rsp), %rsi
movzbl 0x11f(%rsp), %edi
andl $0x1, %edi
callq 0xe8240
movq %rdx, 0x20(%rsp)
movb %al, 0x2f(%rsp)
jmp 0xe5a88
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 0xe5ab7
leaq 0x298(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0xe81f0
movb %dl, 0x17(%rsp)
movq %rax, 0x18(%rsp)
jmp 0xe5ad7
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 0xe5b09
movl 0xc4(%rsp), %eax
testl %eax, %eax
jne 0xe5ba8
jmp 0xe5b1a
jmp 0xe5b55
leaq 0xe8(%rsp), %rdi
callq 0x86f68
jmp 0xe5b2b
jmp 0xe5bd5
leaq 0x290(%rsp), %rdi
callq 0xe82b0
movq %rax, 0x8(%rsp)
jmp 0xe5b44
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x120(%rsp)
cmpq $0x0, 0x120(%rsp)
je 0xe5b79
movq 0x120(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x86e80
jmp 0xe5b77
jmp 0xe5b79
jmp 0xe579c
movq 0x88(%rsp), %rdi
leaq 0x298(%rsp), %rsi
callq 0xe82d0
jmp 0xe5b95
movb $0x1, 0x2d7(%rsp)
movl $0x1, 0xc4(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x86b30
jmp 0xe5bb7
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 0xe5be4
jmp 0xe5be6
leaq 0x298(%rsp), %rdi
callq 0xe83b0
jmp 0xe5bf5
jmp 0xe5bf7
movq 0x288(%rsp), %rdi
callq 0x86d80
movq %rax, %rdi
callq 0x91290
nopl (%rax)