// File: /workspace/github_cpp_makefile_star2_O1/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 0x276b0
movq (%rbx), %rsi
addq $0x70, %rsi
movq %r14, %rdi
callq 0x46a3e
testb %al, %al
je 0x492c0
leaq 0x8(%rbx), %rsi
leaq 0x18(%rsp), %rdi
callq 0x46a84
testb %al, %al
je 0x49320
leaq 0x90(%rsp), %rdi
callq 0x27130
testb %al, %al
je 0x4915f
leaq 0x18(%rsp), %rdi
callq 0x27120
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x27b60
testl %eax, %eax
je 0x491c8
movq 0x46e6a(%rip), %rdi     # 0x8ffe0
leaq 0x2b95c(%rip), %rsi     # 0x74ad9
movl $0x36, %edx
callq 0x276c0
movq (%rbx), %rax
movq 0x70(%rax), %rsi
movq 0x78(%rax), %rdx
movq 0x46e47(%rip), %rdi     # 0x8ffe0
callq 0x276c0
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 0x277a0
testb %al, %al
je 0x49396
leaq 0x378(%rsp), %rdi
movq %rsp, %rsi
callq 0x277d0
movq %rsp, %rdi
callq 0x27090
movq %rax, %r14
movq (%rbx), %r15
callq 0x646ea
movq 0x38(%r15), %rdx
xorl %ebp, %ebp
cmpq 0x8(%rax), %rdx
jne 0x49235
testq %rdx, %rdx
je 0x4922b
movq (%rax), %rsi
movq 0x30(%r15), %rdi
callq 0x275f0
testl %eax, %eax
jne 0x49235
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 0x493f6
leaq 0x220(%rsp), %rdi
callq 0x27220
movq %rsp, %r14
leaq 0x220(%rsp), %r15
leaq 0x8(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x27990
testb %al, %al
je 0x4946d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x48ef2
movq %r12, %rdi
movq %r15, %rsi
callq 0x27be0
jmp 0x49295
movq 0x46d19(%rip), %rdi     # 0x8ffe0
leaq 0x2b77a(%rip), %rsi     # 0x74a48
movl $0x48, %edx
callq 0x276c0
movq (%rbx), %rax
movq 0x70(%rax), %rsi
movq 0x78(%rax), %rdx
movq 0x46cf6(%rip), %rdi     # 0x8ffe0
callq 0x276c0
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 0x494ab
movq 0x46cb9(%rip), %rdi     # 0x8ffe0
leaq 0x2b763(%rip), %rsi     # 0x74a91
movl $0x47, %edx
callq 0x276c0
movq (%rbx), %rax
movq 0x70(%rax), %rsi
movq 0x78(%rax), %rdx
movq 0x46c96(%rip), %rdi     # 0x8ffe0
callq 0x276c0
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 0x49319
leaq 0x18(%rsp), %rdi
callq 0x27120
jmp 0x49319
movq 0x46c43(%rip), %rdi     # 0x8ffe0
leaq 0x2b518(%rip), %rsi     # 0x748bc
movl $0x37, %edx
callq 0x276c0
movq (%rbx), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
movq 0x46c20(%rip), %rdi     # 0x8ffe0
callq 0x276c0
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 0x494a3
movq 0x46be3(%rip), %rdi     # 0x8ffe0
leaq 0x2b70c(%rip), %rsi     # 0x74b10
movl $0x27, %edx
callq 0x276c0
movq (%rbx), %rax
movq 0x30(%rax), %rsi
movq 0x38(%rax), %rdx
movq 0x46bc0(%rip), %rdi     # 0x8ffe0
callq 0x276c0
movq %rax, %rbx
leaq 0x29a41(%rip), %rsi     # 0x72e70
movl $0xd, %edx
movq %rax, %rdi
callq 0x276c0
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 0x4948c
movq %rsp, %rdi
callq 0x270b0
leaq 0x8(%rsp), %rdi
callq 0x27370
leaq 0x220(%rsp), %rdi
callq 0x27930
leaq 0x8(%rsp), %rdi
callq 0x27430
leaq 0x378(%rsp), %rdi
callq 0x275a0
movq %rsp, %rdi
callq 0x27620
leaq 0x18(%rsp), %rdi
callq 0x4af58
movl %ebp, %eax
addq $0x4d0, %rsp            # imm = 0x4D0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x494e4
jmp 0x494df
jmp 0x494da
jmp 0x494d3
jmp 0x494d3
jmp 0x494df
movq %rax, %rbx
jmp 0x494fe
jmp 0x49515
movq %rax, %rbx
jmp 0x494f4
movq %rax, %rbx
jmp 0x4950b
movq %rax, %rbx
leaq 0x220(%rsp), %rdi
callq 0x27930
leaq 0x8(%rsp), %rdi
callq 0x27430
leaq 0x378(%rsp), %rdi
callq 0x275a0
movq %rsp, %rdi
callq 0x27620
jmp 0x49518
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x4af58
movq %rbx, %rdi
callq 0x27b20
movq %rax, %rdi
callq 0x2e1ed