// File: /workspace/github_cpp_makefile_star2_O1/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
movl %ecx, %r12d
movl %edx, %r11d
movq %rsi, %rbp
movq %rdi, %r13
cmpl $0x5, %r9d
jl 0x27489
movq 0x2cbb0(%rip), %r15     # 0x53fe8
leaq 0x1e146(%rip), %rsi     # 0x45585
movl $0x1d, %edx
movq %r15, %rdi
movl %r9d, 0x4(%rsp)
movq %r8, %rbx
movq %r11, %r14
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
movq %r14, %r11
movq %rbx, %r8
movl 0x4(%rsp), %r9d
movb 0x4(%r13), %al
movb 0x4(%rbp), %dl
movl 0x18(%r8), %r10d
cmpl $0x2, %r10d
setae %sil
cmpb %dl, %al
setne %dil
orb %sil, %dil
je 0x274f5
cmpb %dl, %al
sete %dl
cmpl $0x2, %r10d
setne %sil
orb %dl, %sil
je 0x274f5
testl $0xfffffffd, %r10d      # imm = 0xFFFFFFFD
je 0x274c4
xorb $0x1, %al
testb %al, %al
je 0x27550
movq 0x10(%rbp), %rdx
cmpq 0x8(%r13), %rdx
jg 0x2755a
cmpl $0x5, %r9d
jl 0x2753d
movq 0x2cb01(%rip), %rbx     # 0x53fe8
leaq 0x1dd97(%rip), %rsi     # 0x45285
movl $0x12, %edx
jmp 0x2750e
cmpl $0x5, %r9d
jl 0x2753d
movq 0x2cae6(%rip), %rbx     # 0x53fe8
leaq 0x1e09a(%rip), %rsi     # 0x455a3
movl $0xf, %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
movq 0x10(%r13), %rdx
cmpq 0x8(%rbp), %rdx
jle 0x274da
movq 0x8(%rbp), %r10
movq 0x10(%rbp), %rdi
movq 0x8(%r13), %rdx
movq 0x10(%r13), %rsi
cmpq %rdx, %r10
movq %rdx, %rbx
cmovlq %r10, %rbx
cmpq %rdi, %rsi
cmovgq %rsi, %rdi
subq %rbx, %rdi
leal (%r12,%r11), %ebx
movslq %ebx, %rbx
leaq (%rdi,%rbx), %r13
incq %r13
movslq (%r8), %r14
cmpq %r14, %r13
jl 0x275a3
incq %rdi
subq %rbx, %rdi
movslq 0x4(%r8), %rbx
cmpq %rbx, %rdi
jle 0x275da
cmpl $0x2, %r9d
jl 0x2753d
movq 0x2ca38(%rip), %rbx     # 0x53fe8
leaq 0x1dce1(%rip), %rsi     # 0x45298
movl $0xb, %edx
movq %rbx, %rdi
callq 0x7340
movq %rbx, %rdi
movq %r13, %rsi
callq 0x72a0
movq %rax, %rbx
movq (%rax), %rax
jmp 0x27519
movslq %r11d, %rdi
movq %rdx, %rbx
subq %rdi, %rbx
movslq %r12d, %r14
leaq (%r10,%r14), %rcx
cmpq %rcx, %rbx
jl 0x27601
leaq (%rsi,%rdi), %r11
movq %rsi, %r15
subq %r14, %r15
movb $0x1, %bpl
cmpq %r15, %r11
jle 0x27625
movq %r10, %r11
subq %r14, %r11
leaq (%rdx,%rdi), %r15
cmpq %r15, %r11
jge 0x27614
xorl %ebp, %ebp
jmp 0x27625
leaq (%rsi,%r14), %r11
movq %rsi, %r15
subq %rdi, %r15
cmpq %r15, %r11
setle %bpl
testb %bpl, %bpl
je 0x2763d
cmpb $0x0, 0xb(%r8)
je 0x276b8
movb $0x1, %r11b
testb %bpl, %bpl
jne 0x2765b
movq %rsi, %r11
subq %r14, %r11
leaq (%rdx,%rdi), %r15
cmpq %r15, %r11
setge %bpl
subq %rdi, %rsi
cmpq %rsi, %rcx
setle %r11b
andb %bpl, %r11b
cmpb $0x0, 0xc(%r8)
jne 0x27681
testb %r11b, %r11b
je 0x27681
cmpl $0x5, %r9d
jl 0x2753d
movq 0x2c970(%rip), %rbx     # 0x53fe8
leaq 0x1c2ef(%rip), %rsi     # 0x4396e
jmp 0x276d0
cmpq %rbx, %rcx
setl %sil
testb %al, %sil
je 0x276ea
testb %r11b, %r11b
je 0x27699
cmpb $0x0, 0xa(%r8)
jne 0x276f9
cmpl $0x5, %r9d
jl 0x2753d
movq 0x2c93e(%rip), %rbx     # 0x53fe8
leaq 0x1dc34(%rip), %rsi     # 0x452e5
movl $0x8, %edx
jmp 0x276d5
cmpl $0x5, %r9d
jl 0x2753d
movq 0x2c91f(%rip), %rbx     # 0x53fe8
leaq 0x1c23f(%rip), %rsi     # 0x4390f
movl $0x7, %edx
movq %rbx, %rdi
callq 0x7340
movq %rbx, %rdi
callq 0x7150
jmp 0x2753d
testb %al, %al
jne 0x276f9
addq %rdi, %rdx
subq %r14, %r10
cmpq %r10, %rdx
jl 0x2768d
movb $0x1, %bpl
cmpl $0x5, %r9d
jl 0x2753f
movq 0x2c8db(%rip), %rbx     # 0x53fe8
leaq 0x1de9f(%rip), %rsi     # 0x455b3
movl $0x15, %edx
movq %rbx, %rdi
callq 0x7340
movq %rbx, %rdi
callq 0x7150
jmp 0x2753f