// File: 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:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xd8(%rsp), %rdi
xorl %esi, %esi
callq 0x861a0
movq 0xd8(%rsp), %rdi
callq 0x863d0
testb $0x1, %al
jne 0xcba69
jmp 0xcbd81
movq 0xd8(%rsp), %rdi
callq 0x860f0
testb $0x1, %al
jne 0xcba7c
jmp 0xcba8d
movq 0xd8(%rsp), %rdi
callq 0x86880
testb $0x1, %al
jne 0xcba92
jmp 0xcbd81
movq 0xd8(%rsp), %rax
movl 0xa8(%rax), %eax
movq 0xd8(%rsp), %rcx
cmpl 0xd0(%rcx), %eax
je 0xcbab5
jmp 0xcbd81
movq 0x60(%rsp), %rcx
movq 0xd8(%rsp), %rax
movzwl 0xb2(%rax), %eax
movq (%rcx), %rcx
movzwl 0x98(%rcx), %ecx
cmpl %ecx, %eax
jge 0xcbadc
jmp 0xcbd81
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x86da0
movq 0x58(%rsp), %rdx
leaq 0x69179(%rip), %rsi     # 0x134c73
leaq 0xb8(%rsp), %rdi
callq 0x86a00
jmp 0xcbb09
leaq 0xb7(%rsp), %rdi
callq 0x867b0
movq 0xd8(%rsp), %rdi
leaq 0x9a11b(%rip), %rsi     # 0x165c40
leaq 0xb8(%rsp), %rdx
callq 0xbe2f0
jmp 0xcbb34
movq 0x60(%rsp), %rdi
addq $0x8, %rdi
leaq 0xb8(%rsp), %rsi
callq 0xcf770
movq %rax, 0x50(%rsp)
jmp 0xcbb51
movq 0x60(%rsp), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0x98(%rsp)
addq $0x8, %rdi
callq 0xcf480
movq %rax, 0x48(%rsp)
jmp 0xcbb73
movq 0x48(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0xcf7c0
movb %al, 0x47(%rsp)
jmp 0xcbb9b
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0xcbba8
jmp 0xcbc44
movq 0x99431(%rip), %rdi     # 0x164fe0
leaq 0x6561d(%rip), %rsi     # 0x1311d3
callq 0x86700
movq %rax, 0x38(%rsp)
jmp 0xcbbc2
movq 0x38(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x86640
movq %rax, 0x30(%rsp)
jmp 0xcbbdb
movq 0x30(%rsp), %rdi
movq 0x99389(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0xcbbee
movl $0x1, %edi
callq 0x868d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0xb7(%rsp), %rdi
callq 0x867b0
jmp 0xcbd8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x86f68
jmp 0xcbd89
leaq 0x98(%rsp), %rdi
callq 0xcf7e0
movq %rax, 0x28(%rsp)
jmp 0xcbc58
movq 0x28(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0xc7770
movb %al, 0x27(%rsp)
jmp 0xcbc84
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0xcbc9e
jmp 0xcbc8e
movl $0x1, 0x84(%rsp)
jmp 0xcbd74
movq 0x88(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0xc7710
testb $0x1, %al
jne 0xcbcc7
movl $0x1, 0x84(%rsp)
jmp 0xcbd74
leaq 0x78(%rsp), %rdi
callq 0xd0030
jmp 0xcbcd3
movq 0x88(%rsp), %rdi
addq $0x30, %rdi
movq 0xd8(%rsp), %rsi
callq 0xd0050
movq %rax, 0x18(%rsp)
jmp 0xcbcf3
movq 0x18(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x88(%rsp), %rdi
addq $0x30, %rdi
callq 0xd00a0
movq %rax, 0x10(%rsp)
jmp 0xcbd1f
movq 0x10(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0xd0080
movb %al, 0xf(%rsp)
jmp 0xcbd3e
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0xcbd48
jmp 0xcbd55
movl $0x1, 0x84(%rsp)
jmp 0xcbd74
movq 0xd8(%rsp), %rdi
movl $0x1, %esi
callq 0x861a0
jmp 0xcbd69
movl $0x0, 0x84(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x86f68
addq $0xe8, %rsp
retq
jmp 0xcbd8b
movq 0xa8(%rsp), %rdi
callq 0x86d80
movq %rax, %rdi
callq 0x91290