// File: /workspace/github_cpp_makefile_star2_O2/zeeev[P]DASVC/bamtools/src/toolkit/bamtools_resolve.cpp
// Function: BamTools::ResolveTool::ResolveToolPrivate::ResolvePairs()
bool ResolveTool::ResolveToolPrivate::ResolvePairs(void) {

    // open file containing read names of candidate proper pairs
    ResolveTool::ReadNamesFileReader readNamesReader;
    if ( !readNamesReader.Open(m_settings->ReadNamesFilename) ) {
        cerr << "bamtools resolve ERROR: could not open (temp) inputput read names file: "
             << m_settings->ReadNamesFilename << endl;
        return false;
    }

    // parse read names (matching with corresponding read groups)
    if ( !readNamesReader.Read(m_readGroups) ) {
        cerr << "bamtools resolve ERROR: could not read candidate read names from file: "
             << m_settings->ReadNamesFilename << endl;
        readNamesReader.Close();
        return false;
    }

    // close read name file reader & delete temp file
    readNamesReader.Close();
    if ( remove(m_settings->ReadNamesFilename.c_str()) != 0 ) {
        cerr << "bamtools resolve WARNING: could not delete temp file: "
             << m_settings->ReadNamesFilename << endl;
    }

    // open our BAM reader
    BamReader reader;
    if ( !reader.Open(m_settings->InputBamFilename) ) {
        cerr << "bamtools resolve ERROR: could not open input BAM file: "
             << m_settings->InputBamFilename << endl;
        return false;
    }

    // retrieve header & reference dictionary info
    const SamHeader& header = reader.GetHeader();
    const RefVector& references = reader.GetReferenceData();

    // determine compression mode for BamWriter
    bool writeUncompressed = ( m_settings->OutputBamFilename == Options::StandardOut() &&
                               !m_settings->IsForceCompression );
    BamWriter::CompressionMode compressionMode = BamWriter::Compressed;
    if ( writeUncompressed ) compressionMode = BamWriter::Uncompressed;

    // open BamWriter
    BamWriter writer;
    writer.SetCompressionMode(compressionMode);
    if ( !writer.Open(m_settings->OutputBamFilename, header, references) ) {
        cerr << "bamtools resolve ERROR: could not open "
             << m_settings->OutputBamFilename << " for writing." << endl;
        reader.Close();
        return false;
    }

    // plow through alignments, setting/clearing 'proper pair' flag
    // and writing to new output BAM file
    BamAlignment al;
    while ( reader.GetNextAlignment(al) ) {
        ResolveAlignment(al);
        writer.SaveAlignment(al);
    }

    // clean up & return success
    reader.Close();
    writer.Close();
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x4d0, %rsp            # imm = 0x4D0
movq %rdi, %rbx
leaq 0x2c8(%rsp), %r14
movq %r14, %rdi
callq 0x356a0
movq (%rbx), %rsi
addq $0x70, %rsi
movq %r14, %rdi
callq 0x4ea72
testb %al, %al
je 0x50699
leaq 0x8(%rbx), %rsi
leaq 0x2c8(%rsp), %rdi
callq 0x4eaa8
testb %al, %al
je 0x506c5
leaq 0x2c8(%rsp), %rdi
callq 0x4ea56
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x35b90
testl %eax, %eax
je 0x505b3
movq 0x44a50(%rip), %rdi     # 0x94fe0
leaq 0x234d0(%rip), %rsi     # 0x73a67
callq 0x355b0
movq (%rbx), %rsi
addq $0x70, %rsi
movq %rax, %rdi
callq 0x35510
movq %rax, %rdi
callq 0x35300
movq %rsp, %rdi
callq 0x353f0
movq (%rbx), %rsi
addq $0x10, %rsi
movq %rsp, %rdi
callq 0x357b0
testb %al, %al
je 0x50703
leaq 0x170(%rsp), %rdi
movq %rsp, %rsi
callq 0x357e0
movq %rsp, %rdi
callq 0x35080
movq %rax, %r14
movq (%rbx), %r15
callq 0x65ec6
addq $0x30, %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x3a2a9
xorl %ecx, %ecx
testb %al, %al
je 0x50614
movq (%rbx), %rax
movzbl 0x6(%rax), %ecx
xorl $0x1, %ecx
movl %ecx, 0x14(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x35350
leaq 0x8(%rsp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x35230
movq (%rbx), %rsi
addq $0x30, %rsi
leaq 0x8(%rsp), %rdi
leaq 0x170(%rsp), %rdx
movq %r14, %rcx
callq 0x351e0
movl %eax, %ebp
testb %al, %al
je 0x50731
leaq 0x18(%rsp), %rdi
callq 0x35200
movq %rsp, %r14
leaq 0x18(%rsp), %r15
leaq 0x8(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x359b0
testb %al, %al
je 0x50774
movq %rbx, %rdi
movq %r15, %rsi
callq 0x503b0
movq %r12, %rdi
movq %r15, %rsi
callq 0x35c00
jmp 0x5066e
movq 0x44940(%rip), %rdi     # 0x94fe0
leaq 0x2332f(%rip), %rsi     # 0x739d6
callq 0x355b0
movq (%rbx), %rsi
addq $0x70, %rsi
movq %rax, %rdi
callq 0x35510
movq %rax, %rdi
callq 0x35300
jmp 0x506fc
movq 0x44914(%rip), %rdi     # 0x94fe0
leaq 0x2334c(%rip), %rsi     # 0x73a1f
callq 0x355b0
movq (%rbx), %rsi
addq $0x70, %rsi
movq %rax, %rdi
callq 0x35510
movq %rax, %rdi
callq 0x35300
leaq 0x2c8(%rsp), %rdi
callq 0x4ea56
xorl %ebp, %ebp
jmp 0x507af
movq 0x448d6(%rip), %rdi     # 0x94fe0
leaq 0x23139(%rip), %rsi     # 0x7384a
callq 0x355b0
movq (%rbx), %rsi
addq $0x10, %rsi
movq %rax, %rdi
callq 0x35510
movq %rax, %rdi
callq 0x35300
xorl %ebp, %ebp
jmp 0x507a7
movq 0x448a8(%rip), %rdi     # 0x94fe0
leaq 0x2335f(%rip), %rsi     # 0x73a9e
callq 0x355b0
movq (%rbx), %rsi
addq $0x30, %rsi
movq %rax, %rdi
callq 0x35510
leaq 0x216a3(%rip), %rsi     # 0x71dfd
movq %rax, %rdi
callq 0x355b0
movq %rax, %rdi
callq 0x35300
movq %rsp, %rdi
callq 0x350a0
jmp 0x50790
movq %rsp, %rdi
callq 0x350a0
leaq 0x8(%rsp), %rdi
callq 0x35360
leaq 0x18(%rsp), %rdi
callq 0x35940
leaq 0x8(%rsp), %rdi
callq 0x35420
leaq 0x170(%rsp), %rdi
callq 0x355a0
movq %rsp, %rdi
callq 0x35620
leaq 0x2c8(%rsp), %rdi
callq 0x51d2c
movl %ebp, %eax
addq $0x4d0, %rsp            # imm = 0x4D0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x50803
jmp 0x507e6
jmp 0x507e1
jmp 0x507da
jmp 0x507e6
jmp 0x507da
movq %rax, %rbx
jmp 0x5081a
jmp 0x507eb
movq %rax, %rbx
jmp 0x50810
movq %rax, %rbx
jmp 0x50827
movq %rax, %rbx
leaq 0x2c8(%rsp), %rdi
callq 0x51d2c
movq %rbx, %rdi
callq 0x35b50
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x35940
leaq 0x8(%rsp), %rdi
callq 0x35420
leaq 0x170(%rsp), %rdi
callq 0x355a0
movq %rsp, %rdi
callq 0x35620
jmp 0x507ee
movq %rax, %rdi
callq 0x3a198
nop