// File: /workspace/github_cpp_makefile_star2_O2/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 %r9d, %ebx
movq %r8, %r14
movl %ecx, %r15d
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, %rbp
cmpl $0x5, %r9d
jl 0x1ee83
movq 0x2b179(%rip), %rdi     # 0x49fe8
leaq 0x186cf(%rip), %rsi     # 0x37545
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movb 0x4(%rbp), %al
movb 0x4(%r13), %dl
movl 0x18(%r14), %ecx
cmpl $0x2, %ecx
setae %sil
cmpb %dl, %al
setne %dil
orb %sil, %dil
je 0x1eeda
cmpb %dl, %al
sete %dl
cmpl $0x2, %ecx
setne %sil
orb %dl, %sil
je 0x1eeda
testl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
je 0x1eebb
xorb $0x1, %al
testb %al, %al
je 0x1ef05
movq 0x10(%r13), %rdi
movq 0x8(%rbp), %rcx
cmpq %rcx, %rdi
jle 0x1ef7f
movq 0x8(%r13), %rdx
movq 0x10(%rbp), %rsi
jmp 0x1ef1a
cmpl $0x5, %ebx
jl 0x1f071
movq 0x2b0fe(%rip), %rdi     # 0x49fe8
leaq 0x18672(%rip), %rsi     # 0x37563
callq 0x72b0
xorl %ebp, %ebp
movq %rax, %rdi
callq 0x7160
jmp 0x1f073
movq 0x10(%rbp), %rsi
movq 0x8(%r13), %rdx
cmpq %rdx, %rsi
jle 0x1ef7f
movq 0x8(%rbp), %rcx
movq 0x10(%r13), %rdi
cmpq %rcx, %rdx
movq %rcx, %r8
cmovlq %rdx, %r8
cmpq %rdi, %rsi
cmovgq %rsi, %rdi
subq %r8, %rdi
leal (%r15,%r12), %r8d
movslq %r8d, %r8
leaq (%rdi,%r8), %r13
incq %r13
movslq (%r14), %r9
cmpq %r9, %r13
jl 0x1ef53
incq %rdi
subq %r8, %rdi
movslq 0x4(%r14), %r8
cmpq %r8, %rdi
jle 0x1ef9b
cmpl $0x2, %ebx
jl 0x1f071
movq 0x2b085(%rip), %rdi     # 0x49fe8
leaq 0x182ee(%rip), %rsi     # 0x37258
callq 0x72b0
movq %rax, %rdi
movq %r13, %rsi
callq 0x72a0
jmp 0x1eef6
cmpl $0x5, %ebx
jl 0x1f071
movq 0x2b059(%rip), %rdi     # 0x49fe8
leaq 0x182af(%rip), %rsi     # 0x37245
jmp 0x1eef1
movslq %r12d, %rdi
movq %rcx, %r9
subq %rdi, %r9
movslq %r15d, %r8
leaq (%rdx,%r8), %r10
cmpq %r10, %r9
jl 0x1efbf
leaq (%rsi,%rdi), %r11
movq %rsi, %r15
subq %r8, %r15
cmpq %r15, %r11
jle 0x1effb
movq %rdx, %r15
subq %r8, %r15
leaq (%rcx,%rdi), %r11
cmpq %r11, %r15
jge 0x1efd6
movq %rsi, %r15
subq %rdi, %r15
jmp 0x1efe5
leaq (%rsi,%r8), %r12
movq %rsi, %r15
subq %rdi, %r15
cmpq %r15, %r12
jle 0x1effb
subq %r8, %rsi
cmpq %r11, %rsi
setge %r11b
cmpq %r15, %r10
setle %sil
andb %r11b, %sil
jmp 0x1f005
movb $0x1, %sil
cmpb $0x0, 0xb(%r14)
je 0x1f059
cmpb $0x0, 0xc(%r14)
jne 0x1f029
testb %sil, %sil
je 0x1f029
cmpl $0x5, %ebx
jl 0x1f071
movq 0x2afcb(%rip), %rdi     # 0x49fe8
leaq 0x169ca(%rip), %rsi     # 0x359ee
jmp 0x1eef1
cmpq %r9, %r10
setl %r9b
testb %al, %r9b
je 0x1f084
testb %sil, %sil
je 0x1f041
cmpb $0x0, 0xa(%r14)
jne 0x1f093
cmpl $0x5, %ebx
jl 0x1f071
movq 0x2af9b(%rip), %rdi     # 0x49fe8
leaq 0x18251(%rip), %rsi     # 0x372a5
jmp 0x1eef1
cmpl $0x5, %ebx
jl 0x1f071
movq 0x2af83(%rip), %rdi     # 0x49fe8
leaq 0x16923(%rip), %rsi     # 0x3598f
jmp 0x1eef1
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %al, %al
jne 0x1f093
addq %rdi, %rcx
subq %r8, %rdx
cmpq %rdx, %rcx
jl 0x1f035
movb $0x1, %bpl
cmpl $0x5, %ebx
jl 0x1f073
movq 0x2af46(%rip), %rdi     # 0x49fe8
leaq 0x184ca(%rip), %rsi     # 0x37573
callq 0x72b0
movb $0x1, %bpl
jmp 0x1eef8