// File: /workspace/github_cpp_makefile_star2_O3/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 0x25484
movq 0x2eba0(%rip), %r12     # 0x53fe8
leaq 0x1fdf8(%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 0x254a4
testq %rdx, %rdx
je 0x254f8
movq 0x48(%r14), %rsi
movq 0x48(%r15), %rdi
callq 0x7300
testl %eax, %eax
je 0x254f8
cmpl $0x4, %ebp
jl 0x254eb
movq 0x2eb38(%rip), %rbx     # 0x53fe8
leaq 0x1fda2(%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), %ecx
movq 0x40(%r15), %rax
movl %eax, %esi
andl $0x10, %esi
shrl $0x4, %esi
movb 0x40(%r14), %dl
andb $0x10, %dl
shrb $0x4, %dl
xorb %sil, %dl
testl %ecx, %ecx
je 0x25526
cmpl $0x2, %ecx
jne 0x2554d
testb %dl, %dl
je 0x2552e
jmp 0x25606
testb %dl, %dl
je 0x25606
testb $0x10, %al
je 0x25559
movq 0x8(%r15), %rsi
movq (%r14), %rdi
cmpq %rdi, %rsi
jle 0x25622
movq (%r15), %rdx
movq 0x8(%r14), %rcx
xorl %eax, %eax
jmp 0x25572
testb %dl, %dl
je 0x25606
testb $0x10, %al
je 0x25532
movq 0x8(%r14), %rcx
movq (%r15), %rdx
cmpq %rdx, %rcx
jle 0x25622
movq (%r14), %rdi
movq 0x8(%r15), %rsi
movb $0x1, %al
cmpq %rdx, %rdi
cmovlq %rdi, %rdx
cmpq %rcx, %rsi
cmovgq %rsi, %rcx
subq %rdx, %rcx
leaq 0x1(%rcx), %r12
movslq (%rbx), %rdx
cmpq %rdx, %r12
jl 0x25643
movslq 0x4(%rbx), %rdx
cmpq %rdx, %rcx
jge 0x25643
movq 0x18(%r15), %rcx
movslq 0x98(%r15), %rdi
addq %rcx, %rdi
movq 0x18(%r14), %rdx
movslq 0x98(%r14), %r8
addq %rdx, %r8
cmpq %rdx, %rcx
jl 0x255c6
cmpq %r8, %rdi
jle 0x255d8
cmpq %rcx, %rdx
jl 0x25719
cmpq %rdi, %r8
jg 0x25719
movb $0x1, %sil
cmpb $0x0, 0xb(%rbx)
jne 0x25740
cmpl $0x4, %ebp
jl 0x254eb
movq 0x2e9f3(%rip), %rbx     # 0x53fe8
leaq 0x1fcca(%rip), %rsi     # 0x452c6
movl $0xc, %edx
jmp 0x257df
cmpl $0x4, %ebp
jl 0x254eb
movq 0x2e9d2(%rip), %rbx     # 0x53fe8
leaq 0x1fc52(%rip), %rsi     # 0x4526f
jmp 0x254b7
cmpl $0x4, %ebp
jl 0x254eb
movq 0x2e9b6(%rip), %rbx     # 0x53fe8
leaq 0x1fc4c(%rip), %rsi     # 0x45285
movl $0x12, %edx
jmp 0x254bc
cmpl $0x2, %ebp
jl 0x254eb
movq 0x2e995(%rip), %r14     # 0x53fe8
leaq 0x1fc3e(%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 0x254eb
movq 0x2e93c(%rip), %r14     # 0x53fe8
leaq 0x1fbf1(%rip), %rsi     # 0x452a4
movl $0xc, %edx
movq %r14, %rdi
callq 0x7340
movq %r14, %rdi
movq %r12, %rsi
callq 0x72a0
movq %rax, %r14
leaq 0x1fbdc(%rip), %rsi     # 0x452b1
movl $0x14, %edx
movq %rax, %rdi
callq 0x7340
movl (%rbx), %esi
movq %r14, %rdi
callq 0x75d0
movq %rax, %r14
leaq 0x1f217(%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 0x254c7
cmpq %rcx, %rdx
setge %r9b
cmpq %rdi, %rdx
setl %r10b
movb $0x1, %sil
testb %r10b, %r9b
jne 0x25740
cmpq %rdi, %r8
setle %dil
cmpq %rcx, %r8
setg %sil
andb %dil, %sil
cmpb $0x0, 0xc(%rbx)
jne 0x25769
testb %sil, %sil
je 0x25769
cmpl $0x4, %ebp
jl 0x254eb
movq 0x2e88d(%rip), %rbx     # 0x53fe8
leaq 0x1fb71(%rip), %rsi     # 0x452d3
movl $0xe, %edx
jmp 0x257df
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rdx, %rcx
setl %dil
setg %r8b
testb %al, %al
cmovnel %r8d, %edi
cmpb $0x1, %dil
jne 0x25790
testb %sil, %sil
je 0x257c3
cmpb $0x0, 0xa(%rbx)
je 0x257c3
movb $0x1, %bl
cmpl $0x2, %ebp
jl 0x254ed
movq 0x2e846(%rip), %r14     # 0x53fe8
leaq 0x1fb45(%rip), %rsi     # 0x452ee
movl $0xb, %edx
movq %r14, %rdi
callq 0x7340
movq %r14, %rdi
callq 0x7150
jmp 0x254ed
cmpl $0x4, %ebp
jl 0x254eb
movq 0x2e815(%rip), %rbx     # 0x53fe8
leaq 0x1fb08(%rip), %rsi     # 0x452e2
movl $0xb, %edx
movq %rbx, %rdi
callq 0x7340
movq %rbx, %rdi
callq 0x7150
jmp 0x254eb