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

    // clear proper-pair flag
    al.SetIsProperPair(false);

    // quit check if alignment is not from paired-end read
    if ( !al.IsPaired() ) return;

    // quit check if either alignment or its mate are unmapped
    if ( !al.IsMapped() || !al.IsMateMapped() ) return;

    // quit check if alignment & its mate are on differenct references
    if ( al.RefID != al.MateRefID ) return;

    // quit check if map quality less than cutoff
    if ( al.MapQuality < m_settings->MinimumMapQuality ) return;

    // get read group from alignment
    // empty string if not found, this is OK - we handle empty read group case
    string readGroupName("");
    al.GetTag(READ_GROUP_TAG, readGroupName);

    // look up read group's 'resolver'
    map<string, ReadGroupResolver>::iterator rgIter = m_readGroups.find(readGroupName);
    if ( rgIter == m_readGroups.end() ) {
        cerr << "bamtools resolve ERROR - read group found that was not in header: "
             << readGroupName << endl;
        exit(1);
    }
    const ReadGroupResolver& resolver = (*rgIter).second;

    // quit check if pairs are not in proper orientation (can differ for each RG)
    if ( !resolver.IsValidOrientation(al) ) return;

    // quit check if pairs are not within "reasonable" distance (can differ for each RG)
    if ( !resolver.IsValidInsertSize(al) ) return;

    // quit check if alignment is not a "candidate proper pair"
    map<string, bool>::const_iterator readNameIter;
    readNameIter = resolver.ReadNames.find(al.Name);
    if ( readNameIter == resolver.ReadNames.end() )
        return;

    // if we get here, alignment is OK - set 'proper pair' flag
    al.SetIsProperPair(true);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
xorl %esi, %esi
callq 0x35150
movq %rbx, %rdi
callq 0x35320
testb %al, %al
je 0x504ba
movq %rbx, %rdi
callq 0x350c0
testb %al, %al
je 0x504ba
movq %rbx, %rdi
callq 0x356d0
testb %al, %al
je 0x504ba
movl 0xa8(%rbx), %eax
cmpl 0xd0(%rbx), %eax
jne 0x504ba
movzwl 0xb2(%rbx), %eax
movq (%r14), %rcx
cmpw 0x98(%rcx), %ax
jb 0x504ba
leaq 0x263ce(%rip), %rsi     # 0x767f7
leaq 0x10(%rsp), %r15
leaq 0xf(%rsp), %rdx
movq %r15, %rdi
callq 0x35280
leaq 0x456ae(%rip), %rsi     # 0x95af0
movq %rbx, %rdi
movq %r15, %rdx
callq 0x4ac46
leaq 0x8(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x539f2
movq %rax, %r15
addq $0x10, %r14
cmpq %r14, %rax
je 0x504c4
leaq 0x40(%r15), %rdi
movq %rbx, %rsi
callq 0x4e6bc
testb %al, %al
je 0x504b0
movl 0xd8(%rbx), %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
cmpl 0x40(%r15), %eax
jl 0x504b0
cmpl 0x48(%r15), %eax
jg 0x504b0
leaq 0x70(%r15), %rdi
movq %rbx, %rsi
callq 0x53f32
addq $0x78, %r15
cmpq %r15, %rax
je 0x504b0
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x35150
leaq 0x10(%rsp), %rdi
callq 0x35730
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq 0x44b15(%rip), %rdi     # 0x94fe0
leaq 0x234c1(%rip), %rsi     # 0x73993
callq 0x355b0
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x35510
movq %rax, %rdi
callq 0x35300
pushq $0x1
popq %rdi
callq 0x35720
jmp 0x504fc
jmp 0x504fc
jmp 0x504fc
jmp 0x504fc
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x35730
movq %rbx, %rdi
callq 0x35b50
movq %rax, %rdi
callq 0x3a198
nop