// File: readmapping[P]alfalfa/src/mapper.cpp
// Function: calculateCandRegions(sparseSA const&, read_t const&, align_opt const&, std::vector<lis_t, std::allocator<lis_t>>&, double)
void calculateCandRegions(const sparseSA& sa, const read_t & read, const align_opt & alnOptions, vector<lis_t> & lisIntervals, double errorPercent){
    const string & P = read.sequence;
    const string & Prc = read.rcSequence;
    int Plength = P.length();
    int editDist = (int)(errorPercent*Plength)+1;
    int min_len = alnOptions.minMemLength;
    if(!alnOptions.fixedMinLength && Plength >= 1000){
        min_len += (20*((int)(Plength/500)))/((int)100*errorPercent);
    }
    if(alnOptions.fixedMinLength && Plength/editDist > min_len){
        min_len = Plength/editDist;
    }
    ////////////////////////////
    //FIND SEEDS
    ///////////////////////////
    vector<match_t> matches;
    vector<match_t> matchesRC;
    //calc seeds
    if(alnOptions.print >= 4) cerr << "calculate seeds" << endl;
    calculateSeedsBothStrands(sa, P, Prc, min_len, alnOptions, matches, matchesRC);
#ifndef NDEBUG
    if(alnOptions.debugFile != NULL){
        printSimRegion(sa, read, alnOptions, editDist);
        fprintf(alnOptions.debugFile,"#MEM %lu %lu\n", matches.size(), matchesRC.size());
        fprintf(alnOptions.debugFile,"#MEMF\n");
        for(size_t i = 0; i < matches.size(); i++)
            fprintf(alnOptions.debugFile,"%d %ld %d\n", matches[i].query, matches[i].ref, matches[i].len);
        fprintf(alnOptions.debugFile,"#MEMR\n");
        for(size_t i = 0; i < matchesRC.size(); i++)
            fprintf(alnOptions.debugFile,"%d %ld %d\n", matchesRC[i].query, matchesRC[i].ref, matchesRC[i].len);
    }
#endif
    if(matches.size()>0 || matchesRC.size()>0){
        /////////////////////////
        //FIND CANDIDATE REGIONS
        /////////////////////////
        if(alnOptions.print >= 4) cerr << "calculate clusters" << endl;
        identifyAndFilter(matches, true, Plength, editDist, lisIntervals, alnOptions);
        size_t lisForward = lisIntervals.size();
        if(alnOptions.print >= 2) cerr << "#LISF " << lisIntervals.size() << endl;
        identifyAndFilter(matchesRC, false, Plength, editDist, lisIntervals, alnOptions);
        if(alnOptions.print >= 2) cerr << "#LISR " << (lisIntervals.size()-lisForward) << endl;
        //fair calculation of len: coverage
        for(size_t i = 0; i < lisIntervals.size(); i++)
            lisIntervals[i].score = coveredBases(lisIntervals[i]);
        sort(lisIntervals.begin(),lisIntervals.end(), compIntervals);
    }
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movq %rcx, 0xd8(%rsp)
movsd %xmm0, 0xd0(%rsp)
movq 0xe8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0xc8(%rsp)
movq 0xe8(%rsp), %rax
addq $0x60, %rax
movq %rax, 0xc0(%rsp)
movq 0xc8(%rsp), %rdi
callq 0x8630
movl %eax, 0xbc(%rsp)
movsd 0xd0(%rsp), %xmm0
cvtsi2sdl 0xbc(%rsp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
movq 0xe0(%rsp), %rax
movl 0x38(%rax), %eax
movl %eax, 0xb4(%rsp)
movq 0xe0(%rsp), %rax
testb $0x1, 0x3c(%rax)
jne 0x42ac0
cmpl $0x3e8, 0xbc(%rsp) # imm = 0x3E8
jl 0x42ac0
movl 0xbc(%rsp), %eax
movl $0x1f4, %ecx            # imm = 0x1F4
cltd
idivl %ecx
imull $0x14, %eax, %eax
cvtsi2sd %eax, %xmm1
movsd 0x3b0b5(%rip), %xmm0    # 0x7db50
mulsd 0xd0(%rsp), %xmm0
divsd %xmm0, %xmm1
cvtsi2sdl 0xb4(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xb4(%rsp)
movq 0xe0(%rsp), %rax
testb $0x1, 0x3c(%rax)
je 0x42afc
movl 0xbc(%rsp), %eax
cltd
idivl 0xb8(%rsp)
cmpl 0xb4(%rsp), %eax
jle 0x42afc
movl 0xbc(%rsp), %eax
cltd
idivl 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x4c520
leaq 0x80(%rsp), %rdi
callq 0x4c520
movq 0xe0(%rsp), %rax
cmpl $0x4, 0x78(%rax)
jl 0x42b80
movq 0x544c5(%rip), %rdi     # 0x96ff0
leaq 0x3b533(%rip), %rsi     # 0x7e065
callq 0x8360
movq %rax, 0x48(%rsp)
jmp 0x42b3e
movq 0x48(%rsp), %rdi
movq 0x54466(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x42b51
jmp 0x42b80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xdbc0
leaq 0x98(%rsp), %rdi
callq 0xdbc0
jmp 0x42e37
movq 0xf0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movq 0xc0(%rsp), %rdx
movl 0xb4(%rsp), %ecx
movq 0xe0(%rsp), %r8
movq %rsp, %rax
leaq 0x80(%rsp), %r9
movq %r9, (%rax)
leaq 0x98(%rsp), %r9
callq 0x3d3f0
jmp 0x42bc4
leaq 0x98(%rsp), %rdi
callq 0x23440
cmpq $0x0, %rax
ja 0x42bee
leaq 0x80(%rsp), %rdi
callq 0x23440
cmpq $0x0, %rax
jbe 0x42e15
movq 0xe0(%rsp), %rax
cmpl $0x4, 0x78(%rax)
jl 0x42c2b
movq 0x543ed(%rip), %rdi     # 0x96ff0
leaq 0x3b46b(%rip), %rsi     # 0x7e075
callq 0x8360
movq %rax, 0x40(%rsp)
jmp 0x42c16
movq 0x40(%rsp), %rdi
movq 0x5438e(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x42c29
jmp 0x42c2b
movl 0xbc(%rsp), %edx
movl 0xb8(%rsp), %ecx
movq 0xd8(%rsp), %r8
movq 0xe0(%rsp), %r9
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
callq 0x3dc10
jmp 0x42c5d
movq 0xd8(%rsp), %rdi
callq 0x4c4b0
movq %rax, 0x68(%rsp)
movq 0xe0(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x42ccd
movq 0x5436c(%rip), %rdi     # 0x96ff0
leaq 0x3b3fd(%rip), %rsi     # 0x7e088
callq 0x8360
movq %rax, 0x38(%rsp)
jmp 0x42c97
movq 0xd8(%rsp), %rdi
callq 0x4c4b0
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x8100
movq %rax, 0x30(%rsp)
jmp 0x42cb8
movq 0x30(%rsp), %rdi
movq 0x542ec(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x42ccb
jmp 0x42ccd
movl 0xbc(%rsp), %edx
movl 0xb8(%rsp), %ecx
movq 0xd8(%rsp), %r8
movq 0xe0(%rsp), %r9
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x3dc10
jmp 0x42cfc
movq 0xe0(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x42d62
movq 0x542df(%rip), %rdi     # 0x96ff0
leaq 0x3b377(%rip), %rsi     # 0x7e08f
callq 0x8360
movq %rax, 0x28(%rsp)
jmp 0x42d24
movq 0xd8(%rsp), %rdi
callq 0x4c4b0
movq 0x28(%rsp), %rdi
movq %rax, %rsi
movq 0x68(%rsp), %rax
subq %rax, %rsi
callq 0x8100
movq %rax, 0x20(%rsp)
jmp 0x42d4d
movq 0x20(%rsp), %rdi
movq 0x54257(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x42d60
jmp 0x42d62
movq $0x0, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x4c4b0
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x42dd7
movq 0xd8(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x4c850
movq %rax, %rdi
callq 0x3ec20
movl %eax, 0x14(%rsp)
jmp 0x42daf
movq 0xd8(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x4c850
movl 0x14(%rsp), %ecx
movl %ecx, (%rax)
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x42d6b
movq 0xd8(%rsp), %rdi
callq 0x4e290
movq %rax, 0x58(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x4e300
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
leaq -0x13cc(%rip), %rdx     # 0x41a40
callq 0x4e410
jmp 0x42e13
jmp 0x42e15
leaq 0x80(%rsp), %rdi
callq 0xdbc0
leaq 0x98(%rsp), %rdi
callq 0xdbc0
addq $0xf8, %rsp
retq
movq 0x78(%rsp), %rdi
callq 0x8730
nopw %cs:(%rax,%rax)