// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
xorl %esi, %esi
callq 0x27150
movq %rbx, %rdi
callq 0x27330
testb %al, %al
je 0x49089
movq %rbx, %rdi
callq 0x270d0
testb %al, %al
je 0x49089
movq %rbx, %rdi
callq 0x276f0
testb %al, %al
je 0x49089
movl 0xa8(%rbx), %eax
cmpl 0xd0(%rbx), %eax
jne 0x49089
movzwl 0xb2(%rbx), %eax
movq (%r14), %rcx
cmpw 0x98(%rcx), %ax
jb 0x49089
leaq 0x20(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2e8a4(%rip), %rdx     # 0x7781b
leaq 0x10(%rsp), %rdi
movq %rdx, %rsi
callq 0x2f1b2
cmpb $0x0, 0x130(%rbx)
jne 0x4900a
movq 0x90(%rbx), %rax
testq %rax, %rax
je 0x4900a
movq 0x88(%rbx), %rcx
leaq 0x8(%rsp), %rdx
movq %rcx, (%rdx)
leaq 0x34(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x30(%rsp), %r8
movl $0x0, (%r8)
leaq 0x47af6(%rip), %rsi     # 0x90ab8
movq %rbx, %rdi
callq 0x27710
testb %al, %al
je 0x4900a
movq 0x8(%rsp), %rdi
callq 0x272f0
leaq 0x10(%rsp), %rdi
movq $0x0, 0x8(%rdi)
movq (%rdi), %rcx
movb $0x0, (%rcx)
movl %eax, %r15d
movq %r15, %rsi
xorl %edx, %edx
callq 0x271f0
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x274c0
leaq 0x8(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4cda6
movq %rax, %r15
addq $0x10, %r14
cmpq %r14, %rax
je 0x49095
movq %rbx, %rdi
callq 0x46367
movzwl %ax, %eax
incl %eax
cmpw 0x4c(%r15), %ax
je 0x4903f
cmpw 0x4e(%r15), %ax
jne 0x4907a
movl 0xd8(%rbx), %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
cmpl 0x40(%r15), %eax
jl 0x4907a
cmpl 0x48(%r15), %eax
jg 0x4907a
leaq 0x70(%r15), %rdi
movq %rbx, %rsi
callq 0x4d2b0
addq $0x78, %r15
cmpq %r15, %rax
je 0x4907a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x27150
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x49089
callq 0x27560
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x46f44(%rip), %rdi     # 0x8ffe0
leaq 0x2b962(%rip), %rsi     # 0x74a05
movl $0x42, %edx
callq 0x276c0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x46f22(%rip), %rdi     # 0x8ffe0
callq 0x276c0
movq %rax, %rdi
callq 0x27310
movl $0x1, %edi
callq 0x27720
jmp 0x490dd
jmp 0x490dd
jmp 0x490dd
jmp 0x490dd
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x490ef
callq 0x27560
movq %rbx, %rdi
callq 0x27b20
nop