// File: /workspace/github_cpp_makefile_star2_O3/readmapping[P]alfalfa/src/mapper.cpp
// Function: pairAlignmentToWindow(sparseSA const&, read_t&, read_t&, align_opt const&, paired_opt const&, std::vector<alnScoreInfo_t, std::allocator<alnScoreInfo_t>>&, std::vector<alnScoreInfo_t, std::allocator<alnScoreInfo_t>>&, int&, int)
void pairAlignmentToWindow(const sparseSA& sa, read_t & mate1, read_t & mate2, 
        const align_opt & alnOptions, const paired_opt & pairedOpt, vector<alnScoreInfo_t> & alnMateAlns, 
        vector<alnScoreInfo_t> & windowMateAlns, int & alnCount, int maxAlnCount){
    size_t i = 0;
    int trial = 0;
    while(i < alnMateAlns.size() && alnCount < maxAlnCount && trial < alnOptions.maxTrial){
        alignment_t * aln = alnMateAlns[i].firstMate ? mate1.alignments[alnMateAlns[i].position] : mate2.alignments[alnMateAlns[i].position]; 
        if(!aln->paired()){
            if(alnOptions.print >= 4) cerr << "find window for aligment of mate " << (alnMateAlns[i].firstMate ? "1" : "0") << " on strand " << (aln->flag.test(4) ? "R" : "F") << " and position " << aln->refB << endl;
            trial++;
            //FIND WINDOW
            long refB, refE;
            bool fw;
            read_t & windowMate = alnMateAlns[i].firstMate ? mate2 : mate1;
            int Plength = windowMate.sequence.length();
            dpWindow(aln->refB, aln->refE, alnMateAlns[i].firstMate, !aln->flag.test(4), 
                    Plength, pairedOpt, refB, refE, fw);
            if(alnOptions.print >= 4) cerr << "window is located on " << (fw ? "F" : "R") << " strand and position has interval " << refB << "," << refE << endl;
            //CHECK IF AN ALIGNMENT ALREADY EXISTS IN THIS WINDOW
            int windowMatePos = bestAlignmentInWindow(windowMate, windowMateAlns, alnMateAlns[i].firstMate, refB, refE, fw);
            if(alnOptions.print >= 4) cerr << "an alignment of the mate was found as the " << windowMatePos << " 'th alignment of the mate" << endl;
            if(alnOptions.print >= 2) cerr << "#WINDOWLIST " << (windowMatePos>=0) << endl;
            if(windowMatePos < 0){
                //TRY TO ALIGN IN WINDOW    
                int tLen = refE-refB+1;
                uint8_t * target = (uint8_t *)malloc(tLen);
                for (int j = 0; j < tLen; ++j) // convert to the nt4 encoding
                    target[j] = Utils::ORDVALUE[(size_t)sa.S[refB+j]];
                int xtra = KSW_XSTART | (Plength * alnOptions.match < 250? KSW_XBYTE : 0);
                kswr_t alnResult = ksw_align(Plength, fw ? windowMate.readP : windowMate.rcReadP, tLen, 
                        target, 5, alnOptions.mat, alnOptions.openGap, alnOptions.extendGap, xtra, 0);
                free(target);
                //if succes, set paired, trial back to 0
                int editDist = (int)(alnOptions.errorPercent*Plength)+1;
                int minScore = (int) (Plength*alnOptions.match + (alnOptions.mismatch-alnOptions.match)*editDist);
                if(alnOptions.print >= 4) cerr << "an alignment was produced with score " << alnResult.score << ". Min score is " << minScore << endl;
                if(alnResult.score > minScore){
                    alignment_t * newAln = new alignment_t();
                    newAln->alignmentScore = alnResult.score;
                    newAln->qB = alnResult.qb;
                    newAln->qE = alnResult.qe;
                    newAln->refB = refB + alnResult.tb;
                    newAln->refE = refB + alnResult.te;
                    newAln->refLength = alnResult.te - alnResult.tb + 1;
                    newAln->flag.set(4, !fw);
                    windowMate.alignments.push_back(newAln);
                    windowMatePos = windowMate.alignments.size()-1;
                    windowMateAlns.push_back(alnScoreInfo_t(!alnMateAlns[i].firstMate,windowMatePos,alnResult.score));
                }
                if(alnOptions.print >= 2) cerr << "#WINDOWALIGN " << (windowMatePos >= 0) << endl;
            }
            if(windowMatePos >= 0){
                //PAIR ALIGNMENTS, SUCCES
                if(alnOptions.print >= 4) cerr << "found concordancy between 2 alns." << endl;
                if(alnMateAlns[i].firstMate)
                    setPaired(sa, mate1, mate2, alnMateAlns[i].position,windowMatePos, true);
                else
                    setPaired(sa, mate1, mate2,windowMatePos, alnMateAlns[i].position, true);
                trial = 0;
                alnCount++;
            }
        }
        i++;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r8, 0xa8(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x30(%rsp)
movl 0x100(%rsp), %r11d
movq 0xf8(%rsp), %rax
movq (%r9), %r15
movq %r9, 0x10(%rsp)
movq 0x8(%r9), %r10
cmpq %r15, %r10
setne %sil
movl (%rax), %eax
cmpl %r11d, %eax
setl %dil
movq %rcx, 0x8(%rsp)
movl 0x54(%rcx), %edx
testl %edx, %edx
setg %r8b
andb %sil, %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x268a3
movq 0x8(%rsp), %rcx
addq $0x10, %rcx
movq %rcx, 0x98(%rsp)
xorl %r13d, %r13d
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
xorl %ebp, %ebp
leaq (,%r13,2), %r12
addq %r13, %r12
movb (%r15,%r12,4), %bl
movslq 0x4(%r15,%r12,4), %rsi
testb %bl, %bl
movq 0x20(%rsp), %rdi
cmovneq 0x18(%rsp), %rdi
movq 0xb0(%rdi), %rdi
movq (%rdi,%rsi,8), %r14
movq 0x40(%r14), %r9
testb $0x1, %r9b
jne 0x26870
movl %ebp, 0x50(%rsp)
movq 0x8(%rsp), %rax
movl 0x78(%rax), %ebp
cmpl $0x4, %ebp
jl 0x26240
movl $0x21, %edx
movq 0x2de89(%rip), %rbx     # 0x53fe8
movq %rbx, %rdi
leaq 0x1f191(%rip), %rsi     # 0x452fa
callq 0x7340
movq 0x10(%rsp), %r15
movq (%r15), %rax
leaq (,%r13,4), %rcx
movq %r12, %rbp
leaq (%rcx,%rcx,2), %r12
cmpb $0x0, (%rax,%r12)
leaq 0x1b996(%rip), %rsi     # 0x41b27
leaq 0x19ee8(%rip), %rax     # 0x40080
cmovneq %rax, %rsi
movl $0x1, %edx
movq %rbx, %rdi
callq 0x7340
movl $0xb, %edx
movq %rbx, %rdi
leaq 0x1f164(%rip), %rsi     # 0x4531c
callq 0x7340
testb $0x10, 0x40(%r14)
leaq 0x1f15f(%rip), %rsi     # 0x45328
leaq 0x1f15a(%rip), %rax     # 0x4532a
cmoveq %rax, %rsi
movl $0x1, %edx
movq %rbx, %rdi
callq 0x7340
movl $0xe, %edx
movq %rbx, %rdi
leaq 0x1f13c(%rip), %rsi     # 0x4532c
callq 0x7340
movq (%r14), %rsi
movq %rbx, %rdi
callq 0x72a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movq (%r15), %r15
movb (%r15,%r12), %bl
movq %rbp, %r12
movq 0x40(%r14), %r9
movq 0x8(%rsp), %rax
movl 0x78(%rax), %ebp
testb $0x1, %bl
movq 0x18(%rsp), %rax
cmovneq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0x28(%rax), %r8d
movq (%r14), %rdi
movq 0x8(%r14), %rsi
xorl %ecx, %ecx
testb $0x10, %r9b
sete %cl
subq $0x8, %rsp
movzbl %bl, %edx
andl $0x1, %edx
movl %r8d, 0x54(%rsp)
movq 0xb0(%rsp), %r9
leaq 0xf(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x25e92
addq $0x20, %rsp
cmpl $0x3, %ebp
jle 0x2636f
movl $0x15, %edx
movq 0x2dd37(%rip), %r14     # 0x53fe8
movq %r14, %rdi
leaq 0x1f080(%rip), %rsi     # 0x4533b
callq 0x7340
movb 0x7(%rsp), %bl
testb %bl, %bl
leaq 0x1f05b(%rip), %rsi     # 0x45328
leaq 0x1f056(%rip), %rax     # 0x4532a
cmovneq %rax, %rsi
movl $0x1, %edx
movq %r14, %rdi
callq 0x7340
movl $0x22, %edx
movq %r14, %rdi
leaq 0x1f05d(%rip), %rsi     # 0x45351
callq 0x7340
movq 0x70(%rsp), %rbp
movq %r14, %rdi
movq %rbp, %rsi
callq 0x72a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1eb75(%rip), %rsi     # 0x44e90
callq 0x7340
movq 0x68(%rsp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x72a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movq %rbp, %rcx
movq 0x10(%rsp), %rax
movq (%rax), %r15
movq 0x8(%rsp), %rax
movl 0x78(%rax), %ebp
jmp 0x2637d
movq 0x70(%rsp), %rcx
movq 0x68(%rsp), %r14
movb 0x7(%rsp), %bl
movq 0xf0(%rsp), %rsi
movq %r12, 0x60(%rsp)
movzbl (%r15,%r12,4), %edx
movzbl %bl, %r9d
andl $0x1, %r9d
movq 0x40(%rsp), %rdi
movq %rcx, 0x38(%rsp)
movq %r14, %r8
callq 0x25fe6
movl %eax, %r12d
cmpl $0x4, %ebp
jl 0x2641d
movl $0x2a, %edx
movq 0x2dc2b(%rip), %r15     # 0x53fe8
movq %r15, %rdi
leaq 0x1efad(%rip), %rsi     # 0x45374
callq 0x7340
movq %r15, %rdi
movl %r12d, %esi
callq 0x75d0
movq %rax, %r15
movl $0x1a, %edx
movq %rax, %rdi
leaq 0x1efb6(%rip), %rsi     # 0x4539f
callq 0x7340
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movq 0x8(%rsp), %rax
movl 0x78(%rax), %ebp
cmpl $0x2, %ebp
jl 0x26477
movl $0xc, %edx
movq 0x2dbba(%rip), %r15     # 0x53fe8
movq %r15, %rdi
leaq 0x1ef82(%rip), %rsi     # 0x453ba
callq 0x7340
movl %r12d, %esi
notl %esi
shrl $0x1f, %esi
movq %r15, %rdi
callq 0x75a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
testl %r12d, %r12d
movq 0x38(%rsp), %rax
jns 0x267a1
movb %bl, 0x28(%rsp)
movq %r12, 0xa0(%rsp)
subl %eax, %r14d
leal 0x1(%r14), %ebp
movslq %ebp, %rdi
callq 0x7430
movq %rax, %r15
cmpl $0x7ffffffe, %r14d      # imm = 0x7FFFFFFE
leaq 0x1e74f(%rip), %rdi     # 0x44c00
ja 0x264da
movq 0x30(%rsp), %rax
movq 0x50(%rax), %rax
addq 0x38(%rsp), %rax
movl %ebp, %ecx
xorl %edx, %edx
movsbq (%rax,%rdx), %rsi
movb (%rsi,%rdi), %sil
movb %sil, (%r15,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x264c5
movq 0x8(%rsp), %rbx
movl (%rbx), %eax
movl 0x4c(%rsp), %r12d
imull %r12d, %eax
xorl %r10d, %r10d
cmpl $0xfa, %eax
setl %r10b
orl $0x8, %r10d
shll $0x10, %r10d
movb 0x28(%rsp), %al
notb %al
movzbl %al, %ecx
andl $0x1, %ecx
movq 0x40(%rsp), %rax
movq %rcx, 0x28(%rsp)
movq 0xa0(%rax,%rcx,8), %rdx
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %r11d
subq $0x8, %rsp
leaq 0x84(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %ecx
movq %r15, %r8
movl $0x5, %r9d
pushq $0x0
pushq %r10
pushq %r11
pushq %rax
pushq 0xc0(%rsp)
callq 0x3f651
addq $0x30, %rsp
movq %r15, %rdi
callq 0x7380
cvtsi2sd %r12d, %xmm0
mulsd 0x30(%rbx), %xmm0
cvttsd2si %xmm0, %eax
incl %eax
movl (%rbx), %ecx
movl 0x4(%rbx), %r14d
imull %ecx, %r12d
subl %ecx, %r14d
imull %eax, %r14d
addl %r12d, %r14d
cmpl $0x3, 0x78(%rbx)
jle 0x265f9
movl $0x25, %edx
movq 0x2da56(%rip), %rbx     # 0x53fe8
movq %rbx, %rdi
leaq 0x1ee2b(%rip), %rsi     # 0x453c7
callq 0x7340
movl 0x7c(%rsp), %esi
movq %rbx, %rdi
callq 0x75d0
movq %rax, %rbx
movl $0xf, %edx
movq %rax, %rdi
leaq 0x1ee2e(%rip), %rsi     # 0x453ed
callq 0x7340
movq %rbx, %rdi
movl %r14d, %esi
callq 0x75d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
cmpl %r14d, 0x7c(%rsp)
movl 0x50(%rsp), %ebp
movq 0xa0(%rsp), %r12
jle 0x26738
movl $0x100, %edi            # imm = 0x100
callq 0x72e0
movq %rax, %rbx
movq %rax, %rdi
callq 0x2c490
movq %rbx, 0xb0(%rsp)
movl 0x7c(%rsp), %eax
movl %eax, 0x70(%rbx)
movl 0x94(%rsp), %ecx
movl %ecx, 0x10(%rbx)
movl 0x84(%rsp), %ecx
movl %ecx, 0x14(%rbx)
movslq 0x90(%rsp), %rcx
movq %rcx, %rdx
movq 0x38(%rsp), %rsi
addq %rsi, %rdx
movq %rdx, (%rbx)
movslq 0x80(%rsp), %rdx
addq %rdx, %rsi
movq %rsi, 0x8(%rbx)
subl %ecx, %edx
incl %edx
movl %edx, 0x98(%rbx)
movq 0x40(%rbx), %rcx
andq $-0x11, %rcx
movq 0x28(%rsp), %rdx
shll $0x4, %edx
orq %rcx, %rdx
movq %rdx, 0x40(%rbx)
movq 0x40(%rsp), %r15
leaq 0xb0(%r15), %r14
movq 0xb8(%r15), %rsi
cmpq 0xc0(%r15), %rsi
je 0x266c1
movq %rbx, (%rsi)
movq 0xb8(%r15), %r12
addq $0x8, %r12
movq %r12, 0xb8(%r15)
jmp 0x266dc
movq %r14, %rdi
leaq 0xb0(%rsp), %rdx
callq 0x30830
movq 0xb8(%r15), %r12
movl 0x7c(%rsp), %eax
subq (%r14), %r12
shrq $0x3, %r12
decl %r12d
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movq 0x60(%rsp), %rdx
movb (%rcx,%rdx,4), %cl
xorb $0x1, %cl
movb %cl, 0x54(%rsp)
movl %r12d, 0x58(%rsp)
movl %eax, 0x5c(%rsp)
movq 0xf0(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x2672e
movl 0x5c(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0x54(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x8(%rdi)
jmp 0x26738
leaq 0x54(%rsp), %rdx
callq 0x3185c
movq 0x8(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x26798
movl $0xd, %edx
movq 0x2d899(%rip), %rbx     # 0x53fe8
movq %rbx, %rdi
leaq 0x1eca4(%rip), %rsi     # 0x453fd
callq 0x7340
movl %r12d, %esi
notl %esi
shrl $0x1f, %esi
movq %rbx, %rdi
callq 0x75a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
testl %r12d, %r12d
js 0x26895
movq 0x8(%rsp), %rax
cmpl $0x4, 0x78(%rax)
jl 0x267ee
movl $0x21, %edx
movq 0x2d830(%rip), %r14     # 0x53fe8
movq %r14, %rdi
leaq 0x1ec49(%rip), %rsi     # 0x4540b
callq 0x7340
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x60(%rsp), %rcx
movl 0x4(%rax,%rcx,4), %r8d
cmpb $0x1, (%rax,%rcx,4)
jne 0x2681d
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r8d, %ecx
movl %r12d, %r8d
jmp 0x2682f
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r12d, %ecx
movl $0x1, %r9d
callq 0x25907
movq 0xf8(%rsp), %rcx
movl (%rcx), %eax
incl %eax
movl %eax, (%rcx)
xorl %ebp, %ebp
movl 0x100(%rsp), %r11d
movq 0x10(%rsp), %rcx
movq (%rcx), %r15
movq 0x8(%rcx), %r10
movq 0x8(%rsp), %rcx
movl 0x54(%rcx), %edx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
incq %r13
movq %r10, %rsi
subq %r15, %rsi
sarq $0x2, %rsi
imulq %rcx, %rsi
cmpq %rsi, %r13
jae 0x268a3
cmpl %r11d, %eax
jge 0x268a3
cmpl %edx, %ebp
jl 0x26104
jmp 0x268a3
incl %ebp
movq 0xf8(%rsp), %rax
movl (%rax), %eax
jmp 0x2684a
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x72f0
movq %r14, %rdi
callq 0x7600