// File: /workspace/github_cpp_makefile_star2_O3/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 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x276a0
movq (%rbx), %rsi
addq $0x70, %rsi
movq %r14, %rdi
callq 0x46938
testb %al, %al
je 0x491be
leaq 0x8(%rbx), %rsi
leaq 0x18(%rsp), %rdi
callq 0x4697e
testb %al, %al
je 0x4921e
leaq 0x90(%rsp), %rdi
callq 0x27130
testb %al, %al
je 0x4905d
leaq 0x18(%rsp), %rdi
callq 0x27120
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x27b50
testl %eax, %eax
je 0x490c6
movq 0x45f6c(%rip), %rdi     # 0x8efe0
leaq 0x2aa76(%rip), %rsi     # 0x73af1
movl $0x36, %edx
callq 0x276b0
movq (%rbx), %rax
movq 0x70(%rax), %rsi
movq 0x78(%rax), %rdx
movq 0x45f49(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %r14, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
movq %rsp, %rdi
callq 0x273f0
movq (%rbx), %rsi
addq $0x10, %rsi
movq %rsp, %rdi
callq 0x27790
testb %al, %al
je 0x49294
leaq 0x378(%rsp), %rdi
movq %rsp, %rsi
callq 0x277c0
movq %rsp, %rdi
callq 0x27090
movq %rax, %r14
movq (%rbx), %r15
callq 0x641aa
movq 0x38(%r15), %rdx
xorl %ebp, %ebp
cmpq 0x8(%rax), %rdx
jne 0x49133
testq %rdx, %rdx
je 0x49129
movq (%rax), %rsi
movq 0x30(%r15), %rdi
callq 0x275f0
testl %eax, %eax
jne 0x49133
movq (%rbx), %rax
movzbl 0x6(%rax), %ebp
xorl $0x1, %ebp
movl %ebp, 0x14(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x27360
leaq 0x8(%rsp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x27250
movq (%rbx), %rsi
addq $0x30, %rsi
leaq 0x8(%rsp), %rdi
leaq 0x378(%rsp), %rdx
movq %r14, %rcx
callq 0x271e0
movl %eax, %ebp
testb %al, %al
je 0x492f4
leaq 0x220(%rsp), %rdi
callq 0x27220
movq %rsp, %r14
leaq 0x220(%rsp), %r15
leaq 0x8(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x27980
testb %al, %al
je 0x4936b
movq %rbx, %rdi
movq %r15, %rsi
callq 0x48df0
movq %r12, %rdi
movq %r15, %rsi
callq 0x27bd0
jmp 0x49193
movq 0x45e1b(%rip), %rdi     # 0x8efe0
leaq 0x2a894(%rip), %rsi     # 0x73a60
movl $0x48, %edx
callq 0x276b0
movq (%rbx), %rax
movq 0x70(%rax), %rsi
movq 0x78(%rax), %rdx
movq 0x45df8(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
xorl %ebp, %ebp
jmp 0x493a9
movq 0x45dbb(%rip), %rdi     # 0x8efe0
leaq 0x2a87d(%rip), %rsi     # 0x73aa9
movl $0x47, %edx
callq 0x276b0
movq (%rbx), %rax
movq 0x70(%rax), %rsi
movq 0x78(%rax), %rdx
movq 0x45d98(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
leaq 0x90(%rsp), %rdi
callq 0x27130
testb %al, %al
je 0x49217
leaq 0x18(%rsp), %rdi
callq 0x27120
jmp 0x49217
movq 0x45d45(%rip), %rdi     # 0x8efe0
leaq 0x2a632(%rip), %rsi     # 0x738d4
movl $0x37, %edx
callq 0x276b0
movq (%rbx), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
movq 0x45d22(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
xorl %ebp, %ebp
jmp 0x493a1
movq 0x45ce5(%rip), %rdi     # 0x8efe0
leaq 0x2a826(%rip), %rsi     # 0x73b28
movl $0x27, %edx
callq 0x276b0
movq (%rbx), %rax
movq 0x30(%rax), %rsi
movq 0x38(%rax), %rdx
movq 0x45cc2(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rbx
leaq 0x28b43(%rip), %rsi     # 0x71e70
movl $0xd, %edx
movq %rax, %rdi
callq 0x276b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
movq %rsp, %rdi
callq 0x270b0
jmp 0x4938a
movq %rsp, %rdi
callq 0x270b0
leaq 0x8(%rsp), %rdi
callq 0x27370
leaq 0x220(%rsp), %rdi
callq 0x27920
leaq 0x8(%rsp), %rdi
callq 0x27430
leaq 0x378(%rsp), %rdi
callq 0x275a0
movq %rsp, %rdi
callq 0x27620
leaq 0x18(%rsp), %rdi
callq 0x4ae8a
movl %ebp, %eax
addq $0x4d0, %rsp            # imm = 0x4D0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x493e2
jmp 0x493dd
jmp 0x493d8
jmp 0x493d1
jmp 0x493d1
jmp 0x493dd
movq %rax, %rbx
jmp 0x493fc
jmp 0x49413
movq %rax, %rbx
jmp 0x493f2
movq %rax, %rbx
jmp 0x49409
movq %rax, %rbx
leaq 0x220(%rsp), %rdi
callq 0x27920
leaq 0x8(%rsp), %rdi
callq 0x27430
leaq 0x378(%rsp), %rdi
callq 0x275a0
movq %rsp, %rdi
callq 0x27620
jmp 0x49416
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x4ae8a
movq %rbx, %rdi
callq 0x27b10
movq %rax, %rdi
callq 0x2e1cd