// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/mapper.cpp
// Function: identifyAndFilter(std::vector<match_t, std::allocator<match_t>>&, bool, int, int, std::vector<lis_t, std::allocator<lis_t>>&, align_opt const&)
void identifyAndFilter(vector<match_t>& matches, bool fw, int qLength, int editDist, vector<lis_t>& lisIntervals, const align_opt & alnOptions){
    if(!matches.empty()){
        size_t emptySize = lisIntervals.size();
        //FIND SMEMS AND REGIONS
        size_t maxSmemOcc = alnOptions.maxSeedCandidates;
        long minMemLength = alnOptions.minMemRegLength;
        size_t maxPossOccIncrease = alnOptions.maxRegionMems;
        //sort according to query offset and len
        sort(matches.begin(),matches.end(), compMatchesSMEM);
        ///////////////////////////////////////////////////
        //TRIAGE: smems and mems to fill candidate regions
        ///////////////////////////////////////////////////
        vector<match_t> smems;
        vector<match_t> reserves;
        smems.reserve(matches.size());
        reserves.reserve(matches.size());
        long previousStart = matches[0].query;
        long previousEnd = matches[0].query + matches[0].len;
        long previousREnd = -1L;
        size_t rangeStart = 0;
        size_t currentSmemRange = 0;
        size_t index = 0;
        ///////////////////////////
        //IDENTIFY SMEMS
        //////////////////////////
        if(alnOptions.print >= 5) cerr << "number of MEMs before calculating regions: " << matches.size() << endl;
        while(index < matches.size()){
            rangeStart = index;
            previousStart = matches[index].query;
            previousEnd = matches[index].query + matches[index].len;
            index++;
            //same mem/smem
            while(index < matches.size() && matches[index].query == previousStart && matches[index].query+matches[index].len == previousEnd)
                index++;
            //region of same query position seeds: insert this region in triage
            assert(index>=rangeStart);
            if(previousEnd > previousREnd)
                currentSmemRange = index-rangeStart;
            else
                currentSmemRange += index-rangeStart;
            if ((previousEnd > previousREnd && currentSmemRange <= maxSmemOcc) || 
                    (currentSmemRange <= maxPossOccIncrease 
                    && previousEnd-previousStart >= minMemLength)){
                        for(size_t j = rangeStart; j < index; j++)
                            smems.push_back(matches[j]);
            }
            else {
                for(size_t j = rangeStart; j < index; j++)
                    reserves.push_back(matches[j]);
            }
            //new values of fields
            previousREnd = previousEnd;
        }
        if(alnOptions.print >= 5){ 
            cerr << "number of SMEMs: " << smems.size() << endl;
            cerr << "number of reserves: " << reserves.size() << endl;
        }
        ///////////////////////////
        //CREATE CANDIDATE REGIONS
        //////////////////////////
        sort(smems.begin(),smems.end(), compMatches);
        int begin, end, longest;
        begin = end = longest = 0;
        long refEnd, refBegin;
        while(begin < (int) smems.size()){
            //left most --> define right most boundary
            refEnd = smems[begin].ref - smems[begin].query + qLength + editDist;
            longest = begin;
            end = begin+1;
            //find right most boundary
            while(end < (int) smems.size() && smems[end].ref + smems[end].len <= refEnd){
                if(smems[longest].len < smems[end].len){
                    longest = end;
                    refEnd = smems[longest].ref - smems[longest].query + qLength + editDist;
                }
                end++;
            }
            //first to left
            refBegin = smems[longest].ref - smems[longest].query - editDist;
            //begin = longest-1;
            begin--;
            int beginFix = begin;//bugfix: merge region contains some seeds twice
            while(begin >= 0 && smems[begin].ref >= refBegin)
                begin--;
            //add interval to list and calculate coverage
            if(emptySize==lisIntervals.size() || lisIntervals.back().refEnd < refBegin){
                //no overlap, calc coverage and push
                lisIntervals.push_back(lis_t(fw));
                lisIntervals.back().addSeeds(smems,begin+1,end-1);
                lisIntervals.back().refBegin = refBegin;
                lisIntervals.back().refEnd = refEnd;
                if(alnOptions.print >= 5) cerr << "region found with " << (end-begin-1) << " seeds" << endl;
            }
            else{//overlap with previous: merge two regions
                lisIntervals.back().addSeeds(smems,beginFix+1,end-1);
                lisIntervals.back().refBegin = min(lisIntervals.back().refBegin,refBegin);
                lisIntervals.back().refEnd = min(lisIntervals.back().refEnd,refEnd);
                if(alnOptions.print >= 5) cerr << "previous region extended with " << (end-beginFix-1) << " seeds" << endl;
            }
            //start new interval
            begin = end;
        }
        if(alnOptions.print >= 5) cerr << (lisIntervals.size() - emptySize) << " regions found" << endl;
        ///////////////////////////
        //FILL CANDIDATE REGIONS
        //////////////////////////
        //region fill: merge reserves in regions fill both matches and lisIntervals
        int reservesAdded = 0;
        if(emptySize < lisIntervals.size()){
            sort(reserves.begin(),reserves.end(), compMatches);
            size_t curReserve = 0;
            size_t curInterval = emptySize;
            while(curReserve < reserves.size() && curInterval < lisIntervals.size()){
                if(reserves[curReserve].ref < lisIntervals[curInterval].refBegin)
                    curReserve++;
                else if(lisIntervals[curInterval].refEnd < reserves[curReserve].ref)
                    curInterval++;
                else{
                    lisIntervals[curInterval].addSeed(reserves[curReserve]);
                    reservesAdded++;
                    curReserve++;
                }
            }
        }
        if(alnOptions.print >= 5) cerr << reservesAdded << " extra seeds added to region" << endl;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %esi, 0x7c(%rsp)
movq %rdi, %rbp
movq (%rdi), %rdi
movq 0x8(%rbp), %rsi
cmpq %rsi, %rdi
je 0x1b312
movq %r9, %rbx
movl %ecx, %r14d
movl %edx, %r15d
movq 0x8(%r8), %rax
movq %r8, 0x10(%rsp)
subq (%r8), %rax
pushq $0x38
popq %rcx
movq %rax, 0x80(%rsp)
cqto
idivq %rcx
movq %rax, 0x18(%rsp)
movslq 0x40(%r9), %rax
movq %rax, 0x28(%rsp)
movslq 0x48(%r9), %rax
movq %rax, 0x88(%rsp)
movslq 0x4c(%r9), %rax
movq %rax, 0x68(%rsp)
leaq -0x92(%rip), %rdx       # 0x1acdd
callq 0x24f4c
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x4, %rsi
callq 0x21fd8
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x4, %rsi
leaq 0x30(%rsp), %rdi
callq 0x21fd8
movl %r15d, 0x74(%rsp)
movl %r14d, 0x78(%rsp)
movq %rbx, 0x20(%rsp)
cmpl $0x4, 0x78(%rbx)
jle 0x1adfa
movq 0x2f216(%rip), %rdi     # 0x49fe8
leaq 0x1c085(%rip), %rsi     # 0x36e5e
callq 0x72b0
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x4, %rsi
movq %rax, %rdi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
pushq $-0x1
popq %rax
leaq 0x50(%rsp), %rbx
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
movq (%rbp), %rcx
movq 0x8(%rbp), %rdx
subq %rcx, %rdx
sarq $0x4, %rdx
cmpq %rdx, %r12
jae 0x1aefc
movq %r12, %r15
shlq $0x4, %r15
leaq (%rcx,%r15), %rsi
addq $0x1c, %rsi
movslq -0x14(%rsi), %rcx
movslq -0x10(%rsi), %rdi
movq %rdi, %r14
addq %rcx, %r14
leaq 0x1(%r12), %r8
movq %r12, %r13
cmpq %rdx, %r8
jae 0x1ae68
cmpl %ecx, -0x4(%rsi)
jne 0x1ae6d
incq %r8
leaq 0x10(%rsi), %r9
incq %r13
cmpl %edi, (%rsi)
movq %r9, %rsi
je 0x1ae4b
jmp 0x1ae70
movq %rdx, %r13
jmp 0x1ae70
movq %r8, %r13
movq %r13, %rdx
subq %r12, %rdx
cmpq %r14, %rax
movl $0x0, %esi
movq 0x8(%rsp), %rdi
cmovlq %rsi, %rdi
addq %rdx, %rdi
cmpq %r14, %rax
movq %rdi, %rax
movq %rdi, 0x8(%rsp)
jge 0x1ae9e
cmpq 0x28(%rsp), %rax
jbe 0x1aecd
cmpq 0x68(%rsp), %rax
ja 0x1aeec
movq %r14, %rax
subq %rcx, %rax
cmpq 0x88(%rsp), %rax
jge 0x1aecd
jmp 0x1aeec
movq (%rbp), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0x2205e
incq %r12
addq $0x10, %r15
cmpq %r13, %r12
jb 0x1aeb7
jmp 0x1aef1
movq (%rbp), %rsi
addq %r15, %rsi
leaq 0x30(%rsp), %rdi
callq 0x2205e
incq %r12
addq $0x10, %r15
cmpq %r13, %r12
jb 0x1aed4
movq %r13, %r12
movq %r14, %rax
jmp 0x1ae0e
movq 0x20(%rsp), %rax
cmpl $0x5, 0x78(%rax)
jl 0x1af69
movq 0x2f0da(%rip), %rdi     # 0x49fe8
leaq 0x1bf75(%rip), %rsi     # 0x36e8a
callq 0x72b0
movq 0x58(%rsp), %rsi
subq 0x50(%rsp), %rsi
sarq $0x4, %rsi
movq %rax, %rdi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
movq 0x2f0a9(%rip), %rdi     # 0x49fe8
leaq 0x1bf56(%rip), %rsi     # 0x36e9c
callq 0x72b0
movq 0x38(%rsp), %rsi
subq 0x30(%rsp), %rsi
sarq $0x4, %rsi
movq %rax, %rdi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
leaq -0x2b9(%rip), %rdx      # 0x1acc1
callq 0x24f4c
movslq 0x74(%rsp), %rax
movslq 0x78(%rsp), %rcx
movq %rcx, 0x68(%rsp)
addq %rcx, %rax
movq %rax, 0x28(%rsp)
xorl %r13d, %r13d
movl %r13d, %r12d
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r13
subq %rcx, %r13
shrq $0x4, %r13
cmpl %r13d, %r12d
jge 0x1b1de
movslq %r12d, %rdx
movq %rdx, %rax
shlq $0x4, %rax
movslq 0x8(%rcx,%rax), %rsi
movq (%rcx,%rax), %r15
addq 0x28(%rsp), %r15
subq %rsi, %r15
movslq %r13d, %rsi
leal -0x1(%r13), %eax
movl %eax, 0x8(%rsp)
leaq 0x1c(%rcx), %rdi
movq %rdx, %r9
movl %r12d, %r8d
movslq %r8d, %r8
shlq $0x4, %r8
leaq (%rcx,%r8), %r11
addq $0xc, %r11
movq %r9, %r10
shlq $0x4, %r10
addq %rdi, %r10
movq %r9, %r14
leaq 0x1(%r14), %r9
cmpq %rsi, %r9
jge 0x1b03b
movq -0xc(%r10), %rbx
movslq (%r10), %rbp
leaq (%rbx,%rbp), %rax
cmpq %r15, %rax
jg 0x1b042
addq $0x10, %r10
movq %r9, %r14
cmpl %ebp, (%r11)
jge 0x1b002
movslq -0x14(%r10), %rax
addq 0x28(%rsp), %rbx
subq %rax, %rbx
movq %rbx, %r15
movl %r9d, %r8d
jmp 0x1afe6
movl 0x8(%rsp), %r9d
jmp 0x1b049
leal 0x1(%r14), %r13d
movl %r14d, %r9d
movq (%rcx,%r8), %r14
movslq 0x8(%rcx,%r8), %rax
addq 0x68(%rsp), %rax
subq %rax, %r14
movl %r12d, %eax
movl %r12d, %edi
sarl $0x1f, %edi
andl %r12d, %edi
shlq $0x4, %rax
leaq (%rcx,%rax), %rsi
addq $-0x10, %rsi
movl %r12d, %ecx
testl %ecx, %ecx
jle 0x1b08f
decl %ecx
leaq -0x10(%rsi), %rax
cmpq %r14, (%rsi)
movq %rax, %rsi
jge 0x1b075
incl %ecx
movl %ecx, 0x8(%rsp)
jmp 0x1b093
movl %edi, 0x8(%rsp)
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rdi
movq %rdi, %rax
subq (%rcx), %rax
movslq %r9d, %rbp
cmpq %rax, 0x80(%rsp)
leaq 0x90(%rsp), %rbx
je 0x1b0c1
cmpq %r14, -0x28(%rdi)
jge 0x1b15a
andl $0x0, 0x90(%rsp)
movl 0x7c(%rsp), %eax
movb %al, 0x94(%rsp)
leaq 0x98(%rsp), %rax
andq $0x0, 0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, (%rax)
movb $0x0, 0x10(%rax)
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x25c16
movq %rbx, %rdi
callq 0x22086
movq 0x8(%r12), %rdi
addq $-0x38, %rdi
movl 0x8(%rsp), %r12d
movslq %r12d, %rdx
leaq 0x50(%rsp), %rsi
movq %rbp, %rcx
callq 0x220a4
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq %r14, -0x30(%rax)
movq %r15, -0x28(%rax)
movq 0x20(%rsp), %rax
cmpl $0x5, 0x78(%rax)
jl 0x1af99
movq 0x2ee9c(%rip), %rdi     # 0x49fe8
leaq 0x1bd5e(%rip), %rsi     # 0x36eb1
callq 0x72b0
jmp 0x1b1b4
addq $-0x38, %rdi
leaq 0x50(%rsp), %rsi
movq %rbp, %rcx
callq 0x220a4
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rax), %rcx
cmpq %rcx, %r14
cmovlq %r14, %rcx
movq -0x28(%rax), %rdx
cmpq %rdx, %r15
cmovlq %r15, %rdx
movq %rcx, -0x30(%rax)
movq %rdx, -0x28(%rax)
movq 0x20(%rsp), %rax
cmpl $0x5, 0x78(%rax)
jl 0x1af99
movq 0x2ee40(%rip), %rdi     # 0x49fe8
leaq 0x1bd15(%rip), %rsi     # 0x36ec4
callq 0x72b0
movl %r13d, %esi
subl %r12d, %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
leaq 0x1c002(%rip), %rsi     # 0x371ce
callq 0x72b0
movq %rax, %rdi
callq 0x7160
jmp 0x1af99
movq 0x20(%rsp), %r15
cmpl $0x5, 0x78(%r15)
movq 0x10(%rsp), %r12
movq 0x8(%r12), %rax
jl 0x1b230
subq (%r12), %rax
cqto
pushq $0x38
popq %rcx
idivq %rcx
subq 0x18(%rsp), %rax
movq 0x2eddc(%rip), %rdi     # 0x49fe8
movq %rax, %rsi
callq 0x71d0
leaq 0x1bcc8(%rip), %rsi     # 0x36ee3
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq 0x8(%r12), %rax
subq (%r12), %rax
xorl %ebx, %ebx
cmpq %rax, 0x80(%rsp)
jae 0x1b2d2
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq -0x594(%rip), %rdx      # 0x1acc1
callq 0x24f4c
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
subq %rcx, %r8
sarq $0x4, %r8
movq (%r12), %r9
movq 0x8(%r12), %rax
subq %r9, %rax
cqto
pushq $0x38
popq %rsi
idivq %rsi
addq $0x20, %r9
movq %r14, %rsi
shlq $0x4, %rsi
addq %rcx, %rsi
imulq $0x38, 0x18(%rsp), %rdi
addq %r9, %rdi
cmpq %r8, %r14
jae 0x1b2d2
cmpq %rax, 0x18(%rsp)
jae 0x1b2d2
movq (%rsi), %rdx
cmpq -0x18(%rdi), %rdx
jl 0x1b2c1
cmpq %rdx, -0x10(%rdi)
jge 0x1b2c6
incq 0x18(%rsp)
addq $0x38, %rdi
jmp 0x1b29b
incq %r14
jmp 0x1b288
callq 0x2205e
incl %ebx
incq %r14
jmp 0x1b25f
cmpl $0x5, 0x78(%r15)
jl 0x1b2fe
movq 0x2ed08(%rip), %rdi     # 0x49fe8
movl %ebx, %esi
callq 0x75c0
leaq 0x1bc04(%rip), %rsi     # 0x36ef2
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
leaq 0x30(%rsp), %rdi
callq 0x9fce
leaq 0x50(%rsp), %rdi
callq 0x9fce
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1b344
jmp 0x1b344
jmp 0x1b344
jmp 0x1b344
jmp 0x1b344
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x22086
jmp 0x1b347
jmp 0x1b344
jmp 0x1b344
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x9fce
leaq 0x50(%rsp), %rdi
callq 0x9fce
movq %rbx, %rdi
callq 0x75e0