// File: readmapping[P]alfalfa/src/mapper.cpp
// Function: dpWindow(long, long, bool, bool, int, paired_opt const&, long&, long&, bool&)
bool dpWindow(long mateRefB, long mateRefE, bool mateIsFirst, bool mateIsFw, 
        int Plength, const paired_opt& options, long & refB, long & refE, 
        bool& otherFW){
    //FIND VALUE OF OTHER ALNS BEGIN, ORIENTATION and IF ALN IS BEFORE OR AFTER THIS ONE
    long refBmate = mateIsFw ? mateRefB : mateRefE;
    bool rightWindow;
    if(options.orientation == PAIR_FF){
        rightWindow = mateIsFirst ? mateIsFw : !mateIsFw;
        otherFW = mateIsFw;
    }
    else if(options.orientation == PAIR_FR){
        rightWindow = mateIsFw;
        otherFW = !mateIsFw;
    }
    else{
        rightWindow = !mateIsFw;
        otherFW = !mateIsFw;
    }
    //FIND BASIC WINDOW VALUES
    if(rightWindow){
        refB = refBmate + options.minInsert;
        refE = refBmate + options.maxInsert;
    }
    else{
        refB = refBmate - options.maxInsert;
        refE = refBmate - options.minInsert;
    }
    if(otherFW)
        refE += Plength;
    else
        refB -= Plength;
    //ADJUST TO OVERLAP AND DOVETAIL
    if(!options.overlap){
        if(rightWindow)
            refB = max(refB, mateRefE);
        else
            refE = min(refE, mateRefB);
    }
    if(!options.dovetail){
        if(rightWindow)
            refB = max(refB, mateRefB);
        else
            refE = min(refE, mateRefE);
    }
    //RETURN IF WINDOW IS LARGE ENOUGH
    return refE > refB;
}

// Assembly:
subq $0x48, %rsp
movb %cl, %al
movb %dl, %cl
movq 0x60(%rsp), %rdx
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rdx
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
andb $0x1, %cl
movb %cl, 0x37(%rsp)
andb $0x1, %al
movb %al, 0x36(%rsp)
movl %r8d, 0x30(%rsp)
movq %r9, 0x28(%rsp)
testb $0x1, 0x36(%rsp)
je 0x43feb
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x43ff5
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
cmpl $0x2, 0x18(%rax)
jne 0x4403f
testb $0x1, 0x37(%rsp)
je 0x4401b
movb 0x36(%rsp), %al
movb %al, 0xf(%rsp)
jmp 0x44025
movb 0x36(%rsp), %al
xorb $-0x1, %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0x1f(%rsp)
movb 0x36(%rsp), %cl
movq 0x60(%rsp), %rax
andb $0x1, %cl
movb %cl, (%rax)
jmp 0x44086
movq 0x28(%rsp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x44067
movb 0x36(%rsp), %al
andb $0x1, %al
movb %al, 0x1f(%rsp)
movb 0x36(%rsp), %cl
xorb $-0x1, %cl
movq 0x60(%rsp), %rax
andb $0x1, %cl
movb %cl, (%rax)
jmp 0x44084
movb 0x36(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x1f(%rsp)
movb 0x36(%rsp), %cl
xorb $-0x1, %cl
movq 0x60(%rsp), %rax
andb $0x1, %cl
movb %cl, (%rax)
jmp 0x44086
testb $0x1, 0x1f(%rsp)
je 0x440c0
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movslq (%rax), %rax
addq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movslq 0x4(%rax), %rax
addq %rax, %rcx
movq 0x58(%rsp), %rax
movq %rcx, (%rax)
jmp 0x440f1
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movslq 0x4(%rax), %rax
subq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movslq (%rax), %rax
subq %rax, %rcx
movq 0x58(%rsp), %rax
movq %rcx, (%rax)
movq 0x60(%rsp), %rax
testb $0x1, (%rax)
je 0x4410d
movslq 0x30(%rsp), %rcx
movq 0x58(%rsp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x44120
movslq 0x30(%rsp), %rdx
movq 0x50(%rsp), %rax
movq (%rax), %rcx
subq %rdx, %rcx
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
testb $0x1, 0xc(%rax)
jne 0x4416a
testb $0x1, 0x1f(%rsp)
je 0x4414e
movq 0x50(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x1ec80
movq (%rax), %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
jmp 0x44168
movq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1efc0
movq (%rax), %rcx
movq 0x58(%rsp), %rax
movq %rcx, (%rax)
jmp 0x4416a
movq 0x28(%rsp), %rax
testb $0x1, 0xa(%rax)
jne 0x441b4
testb $0x1, 0x1f(%rsp)
je 0x44198
movq 0x50(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1ec80
movq (%rax), %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
jmp 0x441b2
movq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x1efc0
movq (%rax), %rcx
movq 0x58(%rsp), %rax
movq %rcx, (%rax)
jmp 0x441b4
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq 0x50(%rsp), %rcx
cmpq (%rcx), %rax
setg %al
andb $0x1, %al
addq $0x48, %rsp
retq
nop