// File: /workspace/github_cpp_makefile_star2_O1/readmapping[P]alfalfa/src/mapper.cpp
// Function: isConcordant(alignment_t const*, alignment_t const*, paired_opt const&, int)
bool isConcordant(const alignment_t* mate1, const alignment_t* mate2, const paired_opt& options, int print){
    assert(mate1->rname.compare("*") != 0);
    assert(mate2->rname.compare("*") != 0);
    if(print >= 4) cerr << "check concordancy" << endl;
    bool firstLeft = true;
    //Check same chromosome
    if(mate1->rname != mate2->rname){
        if(print >= 4) cerr << "different chromosomes" << endl;
        return false;
    }
    //Check strand
    if(options.orientation == PAIR_FF){
        if(mate1->flag.test(4)!=mate2->flag.test(4)){
            if(print >= 4) cerr << "different orientation" << endl;
            return false;
        }
        else
            firstLeft = !mate1->flag.test(4);//if rc must be right
    }
    else if(options.orientation == PAIR_FR){
        if(mate1->flag.test(4)==mate2->flag.test(4)){
            if(print >= 4) cerr << "different orientation" << endl;
            return false;
        }
        else
            firstLeft = !mate1->flag.test(4);//if rc must be right
    }
    else{
        if(mate1->flag.test(4)==mate2->flag.test(4)){
            if(print >= 4) cerr << "different orientation" << endl;
            return false;
        }
        else
            firstLeft = mate1->flag.test(4);//if rc must be left
    }
    if(firstLeft && mate2->refE <= mate1->refB){
        if(print >= 4) cerr << "bad order of reads" << endl;
        return false;
    }
    else if(!firstLeft && mate1->refE <= mate2->refB){
        if(print >= 4) cerr << "bad order of reads" << endl;
        return false;
    }
    //check fragment insert size
    long begin = min(mate1->refB,mate2->refB);
    long end = max(mate1->refE,mate2->refE);
    long size = end - begin +1L;
    if(size < options.minInsert || size > options.maxInsert){
        if(print >= 2) cerr << "#INSERTERR " << size << endl;
        if(print >= 4) cerr << "bad insert: " << size << " is not in interval " << options.minInsert << ", " << options.maxInsert << endl;
        return false;
    }
    long begin1 = mate1->pos;
    long end1 = begin1 + (long)mate1->refLength-1L;
    long begin2 = mate2->pos;
    long end2 = begin2 + (long)mate2->refLength-1L;
    //check contain
    bool contain = (begin1 >= begin2 && end1 <= end2) || (begin2 >= begin1 && end2 <= end1);
    if(contain && !options.contain){
        if(print >= 4) cerr << "is contained" << endl;
        return false;
    }
    //check overlap
    bool overlap = contain || (begin2 >= begin1 && begin2 <= end1) || (end2 >= begin1 && end2 <= end1);
    if(!options.overlap && overlap){
        if(print >= 4) cerr << "is overlapping" << endl;
        return false;
    }
    //check dovetail
    if((firstLeft && (begin2 < begin1)) || (!firstLeft && (begin1 < begin2)) ){
        if(!overlap){
            if(print >= 4) cerr << "is dovetail" << endl;
            return false;
        }
        else if(!options.dovetail){
            if(print >= 4) cerr << "is dovetail" << endl;
            return false;
        }
    }
    if(print >= 2) cerr << "#CONCORDANT" << endl;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
cmpl $0x4, %ecx
jl 0x25579
movq 0x2eaab(%rip), %r12     # 0x53fe8
leaq 0x1fd03(%rip), %rsi     # 0x45247
movl $0x11, %edx
movq %r12, %rdi
callq 0x7340
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movq 0x50(%r15), %rdx
cmpq 0x50(%r14), %rdx
jne 0x25599
testq %rdx, %rdx
je 0x255ed
movq 0x48(%r14), %rsi
movq 0x48(%r15), %rdi
callq 0x7300
testl %eax, %eax
je 0x255ed
cmpl $0x4, %ebp
jl 0x255e0
movq 0x2ea43(%rip), %rbx     # 0x53fe8
leaq 0x1fcad(%rip), %rsi     # 0x45259
movl $0x15, %edx
movq %rbx, %rdi
callq 0x7340
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x18(%rbx), %edx
movq 0x40(%r15), %rcx
movl %ecx, %eax
andl $0x10, %eax
shrl $0x4, %eax
movb 0x40(%r14), %sil
andb $0x10, %sil
shrb $0x4, %sil
xorb %al, %sil
testl %edx, %edx
je 0x2561e
cmpl $0x2, %edx
jne 0x2562f
testb %sil, %sil
je 0x25627
jmp 0x25742
testb %sil, %sil
je 0x25742
testb $0x10, %cl
sete %al
jmp 0x25638
testb %sil, %sil
je 0x25742
testb %al, %al
je 0x2564d
movq 0x8(%r14), %rcx
cmpq (%r15), %rcx
jle 0x2575e
testb %al, %al
jne 0x2565a
movq 0x8(%r15), %rcx
cmpq (%r14), %rcx
jle 0x2575e
movq (%r15), %rdx
movq 0x8(%r15), %rsi
movq (%r14), %rcx
cmpq %rdx, %rcx
cmovlq %rcx, %rdx
movq 0x8(%r14), %rcx
cmpq %rcx, %rsi
cmovgq %rsi, %rcx
subq %rdx, %rcx
leaq 0x1(%rcx), %r12
movslq (%rbx), %rdx
cmpq %rdx, %r12
jl 0x2577f
movslq 0x4(%rbx), %rdx
cmpq %rdx, %rcx
jge 0x2577f
movq 0x18(%r15), %rcx
movslq 0x98(%r15), %rsi
addq %rcx, %rsi
movq 0x18(%r14), %rdx
movslq 0x98(%r14), %rdi
addq %rdx, %rdi
cmpq %rdx, %rcx
jl 0x256bf
movb $0x1, %r9b
cmpq %rdi, %rsi
jle 0x256d0
cmpq %rcx, %rdx
setge %r8b
cmpq %rsi, %rdi
setle %r9b
andb %r8b, %r9b
testb %r9b, %r9b
je 0x256e7
cmpb $0x0, 0xb(%rbx)
je 0x258a9
movb $0x1, %r8b
testb %r9b, %r9b
jne 0x2570e
cmpq %rcx, %rdx
setge %r9b
cmpq %rsi, %rdx
setl %r10b
movb $0x1, %r8b
testb %r10b, %r9b
jne 0x2570e
cmpq %rcx, %rdi
setg %r9b
cmpq %rsi, %rdi
setle %r8b
andb %r9b, %r8b
cmpb $0x0, 0xc(%rbx)
jne 0x25851
testb %r8b, %r8b
je 0x25851
cmpl $0x4, %ebp
jl 0x255e0
movq 0x2e8b7(%rip), %rbx     # 0x53fe8
leaq 0x1fb9b(%rip), %rsi     # 0x452d3
movl $0xe, %edx
jmp 0x258e3
cmpl $0x4, %ebp
jl 0x255e0
movq 0x2e896(%rip), %rbx     # 0x53fe8
leaq 0x1fb16(%rip), %rsi     # 0x4526f
jmp 0x255ac
cmpl $0x4, %ebp
jl 0x255e0
movq 0x2e87a(%rip), %rbx     # 0x53fe8
leaq 0x1fb10(%rip), %rsi     # 0x45285
movl $0x12, %edx
jmp 0x255b1
cmpl $0x2, %ebp
jl 0x257d4
movq 0x2e85d(%rip), %r14     # 0x53fe8
leaq 0x1fb06(%rip), %rsi     # 0x45298
movl $0xb, %edx
movq %r14, %rdi
callq 0x7340
movq %r14, %rdi
movq %r12, %rsi
callq 0x72a0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
cmpl $0x4, %ebp
jl 0x255e0
movq 0x2e804(%rip), %r14     # 0x53fe8
leaq 0x1fab9(%rip), %rsi     # 0x452a4
movl $0xc, %edx
movq %r14, %rdi
callq 0x7340
movq %r14, %rdi
movq %r12, %rsi
callq 0x72a0
movq %rax, %r14
leaq 0x1faa4(%rip), %rsi     # 0x452b1
movl $0x14, %edx
movq %rax, %rdi
callq 0x7340
movl (%rbx), %esi
movq %r14, %rdi
callq 0x75d0
movq %rax, %r14
leaq 0x1f0df(%rip), %rsi     # 0x4490d
movl $0x2, %edx
movq %rax, %rdi
callq 0x7340
movl 0x4(%rbx), %esi
movq %r14, %rdi
callq 0x75d0
movq %rax, %rbx
movq (%rax), %rax
jmp 0x255bc
xorl %esi, %esi
xorl %edi, %edi
cmpq %rdx, %rcx
setl %sil
setg %dil
testb %al, %al
cmovnel %edi, %esi
cmpb $0x1, %sil
jne 0x25876
testb %r8b, %r8b
je 0x258c7
cmpb $0x0, 0xa(%rbx)
je 0x258c7
movb $0x1, %bl
cmpl $0x2, %ebp
jl 0x255e2
movq 0x2e760(%rip), %r14     # 0x53fe8
leaq 0x1fa5f(%rip), %rsi     # 0x452ee
movl $0xb, %edx
movq %r14, %rdi
callq 0x7340
movq %r14, %rdi
callq 0x7150
jmp 0x255e2
cmpl $0x4, %ebp
jl 0x255e0
movq 0x2e72f(%rip), %rbx     # 0x53fe8
leaq 0x1fa06(%rip), %rsi     # 0x452c6
movl $0xc, %edx
jmp 0x258e3
cmpl $0x4, %ebp
jl 0x255e0
movq 0x2e711(%rip), %rbx     # 0x53fe8
leaq 0x1fa04(%rip), %rsi     # 0x452e2
movl $0xb, %edx
movq %rbx, %rdi
callq 0x7340
movq %rbx, %rdi
callq 0x7150
jmp 0x255e0