// File: /workspace/github_cpp_makefile_star2_O2/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:
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 0x583d5
movq %rbp, %rdi
callq 0x35320
movb %al, 0xf(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0xf(%rsp), %rsi
callq 0x5f348
leaq 0x58(%rsp), %rcx
cmpq %rcx, %rax
je 0x582f3
movq 0x28(%rax), %rbx
testq %rbx, %rbx
jne 0x583c5
jmp 0x582a9
cmpb $0x0, 0xf(%rsp)
leaq 0x3e049(%rip), %rdx     # 0x96348
leaq 0x3e022(%rip), %rax     # 0x96328
cmovneq %rax, %rdx
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x51d62
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x1c7b6(%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 0x58383
movb 0xf(%rsp), %al
movb %al, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5f39a
jmp 0x583b8
movq 0x3cc56(%rip), %rdi     # 0x94fe0
leaq 0x1ca21(%rip), %rsi     # 0x74db2
callq 0x355b0
movq %rax, %rdi
movq %r13, %rsi
callq 0x35510
movq %rax, %rdi
leaq 0x19a52(%rip), %rsi     # 0x71dfd
callq 0x355b0
movq %rax, %rdi
callq 0x35300
movq %r13, %rdi
callq 0x35730
testb %r12b, %r12b
je 0x583e4
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x35c00
jmp 0x582a9
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 0x58451
movq %rax, %r14
jmp 0x58461
jmp 0x5843f
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x35730
jmp 0x58454
movq %rax, %r14
movq %rbx, %rdi
callq 0x35570
jmp 0x58442
jmp 0x58451
jmp 0x58451
jmp 0x58451
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x35730
jmp 0x58454
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