// File: /workspace/github_cpp_makefile_star2_O3/readmapping[P]alfalfa/src/mapper.cpp
// Function: isConcordantLIS(lis_t const&, lis_t const&, int, int, paired_opt const&, int)
bool isConcordantLIS(const lis_t& mate1, const lis_t& mate2, int editDist1, int editDist2, const paired_opt& options, int print){
    if(print >= 5) cerr << "check concordancy between LIS" << endl;
    //Check strand
    bool firstLeft;
    bool mate1FW = mate1.fw;
    bool mate2FW = mate2.fw;
    if((options.orientation == PAIR_RF || options.orientation == PAIR_FR) && mate1FW == mate2FW){
        if(print >= 5) cerr << "bad orientation" << endl;
        return false;
    }
    else if(options.orientation == PAIR_FF && mate1FW != mate2FW ){
        if(print >= 5) cerr << "bad orientation" << endl;
        return false;
    }
    //check left-right
    if(options.orientation == PAIR_FF || options.orientation == PAIR_FR)
        firstLeft = mate1FW;//if rc must be right
    else
        firstLeft = !mate1FW;//if rc must be left
    if(firstLeft && mate2.refEnd <= mate1.refBegin){
        if(print >= 5) cerr << "bad order of reads" << endl;
        return false;
    }
    else if(!firstLeft && mate1.refEnd <= mate2.refBegin){
        if(print >= 5) cerr << "bad order of reads" << endl;
        return false;
    }
    //check coordinates versus insert size
    long begin = min(mate1.refBegin,mate2.refBegin);
    long end = max(mate1.refEnd,mate2.refEnd);
    long size = end - begin +1L;
    if(size+(editDist1+editDist2) < options.minInsert || size-(editDist1+editDist2) > options.maxInsert){
        if(print >= 2) cerr << "#INSERTERR " << size+(editDist1+editDist2) << endl;
        return false;
    }
    //check contain, dovetail and overlap
    long begin1 = mate1.refBegin;
    long end1 = mate1.refEnd;
    long begin2 = mate2.refBegin;
    long end2 = mate1.refEnd;
    //check contain
    bool contain = (begin1-editDist1 >= begin2+editDist2 && end1+editDist1 <= end2-editDist2) 
    || (begin2-editDist2 >= begin1+editDist1 && end2+editDist2 <= end1-editDist1);
    if(contain && !options.contain){
        if(print >= 5) cerr << "contain" << endl;
        return false;
    }
    //check overlap
    bool overlap = contain || !(end2-editDist2 < begin1+editDist1 || begin2+editDist2 > end1-editDist1);
    if(!options.overlap && overlap){
        if(print >= 5) cerr << "overlap" << endl;
        return false;
    }
    //check dovetail
    if((firstLeft && (begin2+editDist2 < begin1-editDist1)) || (!firstLeft && (begin1+editDist1 < begin2-editDist2)) ){
        if(!overlap){
            if(print >= 5) cerr << "dovetail" << endl;
            return false;
        }
        else if(!options.dovetail){
            if(print >= 5) cerr << "dovetail" << endl;
            return false;
        }
    }
    if(print >= 5) cerr << "concordant pair found" << endl;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r14
movq %rsi, %r13
movq %rdi, %rbp
cmpl $0x5, %r9d
jl 0x274da
movl %r9d, 0x4(%rsp)
movq %rdx, %rbx
movq %rcx, %r12
movq 0x2cbb7(%rip), %r15     # 0x53fe8
leaq 0x1e14d(%rip), %rsi     # 0x45585
movl $0x1d, %edx
movq %r15, %rdi
callq 0x7340
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movb 0x4(%rbp), %al
movb 0x4(%r13), %dl
movl 0x18(%r14), %r10d
cmpl $0x2, %r10d
setb %sil
cmpb %dl, %al
sete %dil
testb %sil, %dil
jne 0x274a7
cmpb %dl, %al
sete %dl
cmpl $0x2, %r10d
setne %sil
orb %dl, %sil
movq %r12, %rcx
movq %rbx, %rdx
movl 0x4(%rsp), %r9d
jne 0x27501
leaq 0x1e0f5(%rip), %rsi     # 0x455a3
movl $0xf, %edx
movq %r15, %rdi
callq 0x7340
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
jmp 0x275ec
movb 0x4(%rbp), %al
movl 0x18(%r14), %r10d
xorl %edi, %edi
xorl %esi, %esi
cmpl $0x2, %r10d
setae %dil
setne %sil
cmpb 0x4(%r13), %al
cmovel %edi, %esi
testb %sil, %sil
je 0x275f9
testl $0xfffffffd, %r10d      # imm = 0xFFFFFFFD
je 0x2750c
xorb $0x1, %al
testb %al, %al
je 0x2752b
movq 0x10(%r13), %rdi
movq 0x8(%rbp), %r10
cmpq %r10, %rdi
jle 0x275b1
movq 0x8(%r13), %r12
movq 0x10(%rbp), %rsi
jmp 0x27540
movq 0x10(%rbp), %rsi
movq 0x8(%r13), %r12
cmpq %r12, %rsi
jle 0x275b1
movq 0x8(%rbp), %r10
movq 0x10(%r13), %rdi
cmpq %r10, %r12
movq %r10, %r11
cmovlq %r12, %r11
cmpq %rdi, %rsi
cmovgq %rsi, %rdi
subq %r11, %rdi
leal (%rcx,%rdx), %r11d
movslq %r11d, %rbx
leaq (%rdi,%rbx), %r15
incq %r15
movslq (%r14), %r11
cmpq %r11, %r15
jl 0x2757d
incq %rdi
subq %rbx, %rdi
movslq 0x4(%r14), %r8
cmpq %r8, %rdi
jle 0x2760c
cmpl $0x2, %r9d
jl 0x275f9
movq 0x2ca5e(%rip), %rbx     # 0x53fe8
leaq 0x1dd07(%rip), %rsi     # 0x45298
movl $0xb, %edx
movq %rbx, %rdi
callq 0x7340
movq %rbx, %rdi
movq %r15, %rsi
callq 0x72a0
movq %rax, %rbx
movq (%rax), %rax
jmp 0x275d5
cmpl $0x5, %r9d
jl 0x275f9
movq 0x2ca2a(%rip), %rbx     # 0x53fe8
leaq 0x1dcc0(%rip), %rsi     # 0x45285
movl $0x12, %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 %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %edx, %rdi
movq %r10, %rbx
subq %rdi, %rbx
movslq %ecx, %r8
leaq (%r12,%r8), %rcx
cmpq %rcx, %rbx
jl 0x27630
leaq (%rsi,%rdi), %r11
movq %rsi, %r15
subq %r8, %r15
cmpq %r15, %r11
jle 0x2766c
movq %r12, %r15
subq %r8, %r15
leaq (%r10,%rdi), %r11
cmpq %r11, %r15
jge 0x27647
movq %rsi, %r15
subq %rdi, %r15
jmp 0x27656
leaq (%rsi,%r8), %rdx
movq %rsi, %r15
subq %rdi, %r15
cmpq %r15, %rdx
jle 0x2766c
subq %r8, %rsi
cmpq %r11, %rsi
setge %r11b
cmpq %r15, %rcx
setle %sil
andb %r11b, %sil
jmp 0x27676
movb $0x1, %sil
cmpb $0x0, 0xb(%r14)
je 0x276d0
cmpb $0x0, 0xc(%r14)
jne 0x2769c
testb %sil, %sil
je 0x2769c
cmpl $0x5, %r9d
jl 0x275f9
movq 0x2c955(%rip), %rbx     # 0x53fe8
leaq 0x1c2d4(%rip), %rsi     # 0x4396e
jmp 0x276e8
cmpq %rbx, %rcx
jge 0x27702
testb %al, %al
je 0x27702
testb %sil, %sil
je 0x276b1
cmpb $0x0, 0xa(%r14)
jne 0x27711
cmpl $0x5, %r9d
jl 0x275f9
movq 0x2c926(%rip), %rbx     # 0x53fe8
leaq 0x1dc1c(%rip), %rsi     # 0x452e5
movl $0x8, %edx
jmp 0x276ed
cmpl $0x5, %r9d
jl 0x275f9
movq 0x2c907(%rip), %rbx     # 0x53fe8
leaq 0x1c227(%rip), %rsi     # 0x4390f
movl $0x7, %edx
movq %rbx, %rdi
callq 0x7340
movq %rbx, %rdi
callq 0x7150
jmp 0x275f9
testb %al, %al
jne 0x27711
addq %rdi, %r10
subq %r8, %r12
cmpq %r12, %r10
jl 0x276a5
movb $0x1, %bpl
cmpl $0x5, %r9d
jl 0x275fb
movq 0x2c8c3(%rip), %rbx     # 0x53fe8
leaq 0x1de87(%rip), %rsi     # 0x455b3
movl $0x15, %edx
movq %rbx, %rdi
callq 0x7340
movq %rbx, %rdi
callq 0x7150
jmp 0x275fb