// File: /workspace/github_cpp_makefile_star2_O3/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 0x48f87
movq %rbx, %rdi
callq 0x270d0
testb %al, %al
je 0x48f87
movq %rbx, %rdi
callq 0x276e0
testb %al, %al
je 0x48f87
movl 0xa8(%rbx), %eax
cmpl 0xd0(%rbx), %eax
jne 0x48f87
movzwl 0xb2(%rbx), %eax
movq (%r14), %rcx
cmpw 0x98(%rcx), %ax
jb 0x48f87
leaq 0x20(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2d9a2(%rip), %rdx     # 0x76817
leaq 0x10(%rsp), %rdi
movq %rdx, %rsi
callq 0x2f1a0
cmpb $0x0, 0x130(%rbx)
jne 0x48f08
movq 0x90(%rbx), %rax
testq %rax, %rax
je 0x48f08
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 0x46bf0(%rip), %rsi     # 0x8fab0
movq %rbx, %rdi
callq 0x27700
testb %al, %al
je 0x48f08
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 0x4cc54
movq %rax, %r15
addq $0x10, %r14
cmpq %r14, %rax
je 0x48f93
movq %rbx, %rdi
callq 0x4624f
movzwl %ax, %eax
incl %eax
cmpw 0x4c(%r15), %ax
je 0x48f3d
cmpw 0x4e(%r15), %ax
jne 0x48f78
movl 0xd8(%rbx), %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
cmpl 0x40(%r15), %eax
jl 0x48f78
cmpl 0x48(%r15), %eax
jg 0x48f78
leaq 0x70(%r15), %rdi
movq %rbx, %rsi
callq 0x4d14e
addq $0x78, %r15
cmpq %r15, %rax
je 0x48f78
movq %rbx, %rdi
movl $0x1, %esi
callq 0x27150
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x48f87
callq 0x27560
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x46046(%rip), %rdi     # 0x8efe0
leaq 0x2aa7c(%rip), %rsi     # 0x73a1d
movl $0x42, %edx
callq 0x276b0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x46024(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rdi
callq 0x27310
movl $0x1, %edi
callq 0x27710
jmp 0x48fdb
jmp 0x48fdb
jmp 0x48fdb
jmp 0x48fdb
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x48fed
callq 0x27560
movq %rbx, %rdi
callq 0x27b10
nop