// File: 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:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movl %edx, 0x5c(%rsp)
movl %ecx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movl %r9d, 0x4c(%rsp)
cmpl $0x5, 0x4c(%rsp)
jl 0x45cb9
movq 0x51352(%rip), %rdi     # 0x96ff0
leaq 0x38740(%rip), %rsi     # 0x7e3e5
callq 0x8360
movq %rax, %rdi
movq 0x512fc(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0x68(%rsp), %rax
movb 0x4(%rax), %al
andb $0x1, %al
movb %al, 0x4a(%rsp)
movq 0x60(%rsp), %rax
movb 0x4(%rax), %al
andb $0x1, %al
movb %al, 0x49(%rsp)
movq 0x50(%rsp), %rax
cmpl $0x1, 0x18(%rax)
je 0x45ceb
movq 0x50(%rsp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x45d35
movb 0x4a(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movb 0x49(%rsp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x45d35
cmpl $0x5, 0x4c(%rsp)
jl 0x45d2b
movq 0x512e0(%rip), %rdi     # 0x96ff0
leaq 0x386ec(%rip), %rsi     # 0x7e403
callq 0x8360
movq %rax, %rdi
movq 0x5128a(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x0, 0x77(%rsp)
jmp 0x461f6
movq 0x50(%rsp), %rax
cmpl $0x2, 0x18(%rax)
jne 0x45d8a
movb 0x4a(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movb 0x49(%rsp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x45d8a
cmpl $0x5, 0x4c(%rsp)
jl 0x45d80
movq 0x5128b(%rip), %rdi     # 0x96ff0
leaq 0x38697(%rip), %rsi     # 0x7e403
callq 0x8360
movq %rax, %rdi
movq 0x51235(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x0, 0x77(%rsp)
jmp 0x461f6
jmp 0x45d8c
movq 0x50(%rsp), %rax
cmpl $0x2, 0x18(%rax)
je 0x45da2
movq 0x50(%rsp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x45dae
movb 0x4a(%rsp), %al
andb $0x1, %al
movb %al, 0x4b(%rsp)
jmp 0x45dba
movb 0x4a(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x4b(%rsp)
testb $0x1, 0x4b(%rsp)
je 0x45e08
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x68(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jg 0x45e08
cmpl $0x5, 0x4c(%rsp)
jl 0x45dfe
movq 0x5120d(%rip), %rdi     # 0x96ff0
leaq 0x382fb(%rip), %rsi     # 0x7e0e5
callq 0x8360
movq %rax, %rdi
movq 0x511b7(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x0, 0x77(%rsp)
jmp 0x461f6
testb $0x1, 0x4b(%rsp)
jne 0x45e56
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x60(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jg 0x45e56
cmpl $0x5, 0x4c(%rsp)
jl 0x45e4c
movq 0x511bf(%rip), %rdi     # 0x96ff0
leaq 0x382ad(%rip), %rsi     # 0x7e0e5
callq 0x8360
movq %rax, %rdi
movq 0x51169(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x0, 0x77(%rsp)
jmp 0x461f6
jmp 0x45e58
movq 0x68(%rsp), %rdi
addq $0x8, %rdi
movq 0x60(%rsp), %rsi
addq $0x8, %rsi
callq 0x1efc0
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x68(%rsp), %rdi
addq $0x10, %rdi
movq 0x60(%rsp), %rsi
addq $0x10, %rsi
callq 0x1ec80
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
subq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl 0x58(%rsp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq 0x50(%rsp), %rcx
movslq (%rcx), %rcx
cmpq %rcx, %rax
jl 0x45eea
movq 0x30(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl 0x58(%rsp), %ecx
movslq %ecx, %rcx
subq %rcx, %rax
movq 0x50(%rsp), %rcx
movslq 0x4(%rcx), %rcx
cmpq %rcx, %rax
jle 0x45f37
cmpl $0x2, 0x4c(%rsp)
jl 0x45f2d
movq 0x510f8(%rip), %rdi     # 0x96ff0
leaq 0x381f9(%rip), %rsi     # 0x7e0f8
callq 0x8360
movq %rax, %rdi
movq 0x30(%rsp), %rsi
movl 0x5c(%rsp), %eax
addl 0x58(%rsp), %eax
cltq
addq %rax, %rsi
callq 0x8790
movq %rax, %rdi
movq 0x51088(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x0, 0x77(%rsp)
jmp 0x461f6
movq 0x68(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rax
movslq 0x5c(%rsp), %rcx
subq %rcx, %rax
movq 0x18(%rsp), %rcx
movslq 0x58(%rsp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jl 0x45fb3
movq 0x20(%rsp), %rcx
movslq 0x5c(%rsp), %rax
addq %rax, %rcx
movq 0x10(%rsp), %rdx
movslq 0x58(%rsp), %rax
subq %rax, %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, 0xd(%rsp)
jle 0x46004
movq 0x18(%rsp), %rcx
movslq 0x58(%rsp), %rax
subq %rax, %rcx
movq 0x28(%rsp), %rdx
movslq 0x5c(%rsp), %rax
addq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0xc(%rsp)
jl 0x45ffc
movq 0x10(%rsp), %rax
movslq 0x58(%rsp), %rcx
addq %rcx, %rax
movq 0x20(%rsp), %rcx
movslq 0x5c(%rsp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
setle %al
movb %al, 0xc(%rsp)
movb 0xc(%rsp), %al
movb %al, 0xd(%rsp)
movb 0xd(%rsp), %al
andb $0x1, %al
movb %al, 0xf(%rsp)
testb $0x1, 0xf(%rsp)
je 0x46053
movq 0x50(%rsp), %rax
testb $0x1, 0xb(%rax)
jne 0x46053
cmpl $0x5, 0x4c(%rsp)
jl 0x46049
movq 0x50fc2(%rip), %rdi     # 0x96ff0
leaq 0x3691a(%rip), %rsi     # 0x7c94f
callq 0x8360
movq %rax, %rdi
movq 0x50f6c(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x0, 0x77(%rsp)
jmp 0x461f6
movb $0x1, %al
testb $0x1, 0xf(%rsp)
movb %al, 0xb(%rsp)
jne 0x460b3
movq 0x10(%rsp), %rcx
movslq 0x58(%rsp), %rax
subq %rax, %rcx
movq 0x28(%rsp), %rdx
movslq 0x5c(%rsp), %rax
addq %rax, %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, 0xa(%rsp)
jl 0x460a9
movq 0x18(%rsp), %rax
movslq 0x58(%rsp), %rcx
addq %rcx, %rax
movq 0x20(%rsp), %rcx
movslq 0x5c(%rsp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
setg %al
movb %al, 0xa(%rsp)
movb 0xa(%rsp), %al
xorb $-0x1, %al
movb %al, 0xb(%rsp)
movb 0xb(%rsp), %al
andb $0x1, %al
movb %al, 0xe(%rsp)
movq 0x50(%rsp), %rax
testb $0x1, 0xc(%rax)
jne 0x46102
testb $0x1, 0xe(%rsp)
je 0x46102
cmpl $0x5, 0x4c(%rsp)
jl 0x460f8
movq 0x50f13(%rip), %rdi     # 0x96ff0
leaq 0x368ca(%rip), %rsi     # 0x7c9ae
callq 0x8360
movq %rax, %rdi
movq 0x50ebd(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x0, 0x77(%rsp)
jmp 0x461f6
testb $0x1, 0x4b(%rsp)
je 0x46128
movq 0x18(%rsp), %rax
movslq 0x58(%rsp), %rcx
addq %rcx, %rax
movq 0x28(%rsp), %rcx
movslq 0x5c(%rsp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jl 0x46152
testb $0x1, 0x4b(%rsp)
jne 0x461c8
movq 0x28(%rsp), %rax
movslq 0x5c(%rsp), %rcx
addq %rcx, %rax
movq 0x18(%rsp), %rcx
movslq 0x58(%rsp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jge 0x461c8
testb $0x1, 0xe(%rsp)
jne 0x46189
cmpl $0x5, 0x4c(%rsp)
jl 0x46182
movq 0x50e89(%rip), %rdi     # 0x96ff0
leaq 0x37fd7(%rip), %rsi     # 0x7e145
callq 0x8360
movq %rax, %rdi
movq 0x50e33(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x0, 0x77(%rsp)
jmp 0x461f6
movq 0x50(%rsp), %rax
testb $0x1, 0xa(%rax)
jne 0x461c4
cmpl $0x5, 0x4c(%rsp)
jl 0x461bd
movq 0x50e4e(%rip), %rdi     # 0x96ff0
leaq 0x37f9c(%rip), %rsi     # 0x7e145
callq 0x8360
movq %rax, %rdi
movq 0x50df8(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x0, 0x77(%rsp)
jmp 0x461f6
jmp 0x461c6
jmp 0x461c8
cmpl $0x5, 0x4c(%rsp)
jl 0x461f1
movq 0x50e1a(%rip), %rdi     # 0x96ff0
leaq 0x38236(%rip), %rsi     # 0x7e413
callq 0x8360
movq %rax, %rdi
movq 0x50dc4(%rip), %rsi     # 0x96fb0
callq 0x83b0
movb $0x1, 0x77(%rsp)
movb 0x77(%rsp), %al
andb $0x1, %al
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)