// File: readmapping[P]alfalfa/src/mapper.cpp
// Function: rightExtension(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int&, long&, long, align_opt const&, int&, int, int)
inline void rightExtension(const string& S, const string& P, int & tmpQE, long & tmpRE, 
        long chrEnd, const align_opt & alnOptions, int & curScore, int bandSize, int editDist){
    if(tmpQE < (int)(P.length()-1) && tmpRE < chrEnd){
        int zdrop = 100;
        if(alnOptions.print >= 7) cerr << "end DP required" << endl;
        int qle, tle, gtle, gscore, max_off;
        uint8_t *target;
        long alignmentBoundRight = min((long)(tmpRE+(P.length()-1-tmpQE)+editDist),chrEnd);
        int tLen = alignmentBoundRight-tmpRE;
        target = (uint8_t *)malloc(tLen);
        for (int j = 0; j < tLen; ++j) // convert to the nt4 encoding
            target[j] = Utils::ORDVALUE[(size_t)S[tmpRE+1+j]];
        uint8_t *query;
        int qLen = P.length()-1-tmpQE;
        query = (uint8_t *)malloc(qLen);
        for (int j = 0; j < qLen; ++j)
            query[j] = Utils::ORDVALUE[(size_t)P[tmpQE+1+j]];
        if(alnOptions.print >= 7) cerr << "dp called with dimension " << (qLen) << "x" << (tLen) << " and band " << min(bandSize,qLen) << endl;
        if(alnOptions.print >= 2) cerr << "#DP " << (min(bandSize,qLen)*tLen) << endl;
        curScore = ksw_extend(qLen, query, tLen, target, 5, alnOptions.mat, 
                -1*alnOptions.openGap, -1*alnOptions.extendGap, 
                min(bandSize,qLen), zdrop, curScore, &qle, &tle, &gtle, &gscore, &max_off);
        if(alnOptions.print >= 7) cerr << "curScore is " << curScore << endl;
        if(alnOptions.global || gscore >= curScore + (alnOptions.mismatch-alnOptions.match)*3){
            curScore = gscore;
            tmpQE = P.length()-1;
            tmpRE = tmpRE+gtle;
            if(alnOptions.print >= 7) cerr << "global score is " << gscore << " with refEnd " << tmpRE << endl;
        }
        else{
            tmpQE = tmpQE+qle;
            tmpRE = tmpRE+tle;
            if(alnOptions.print >= 7) cerr << "local end pos is " << tmpQE << " with refEnd " << tmpRE << endl;
        }
        free(query);
        free(target);
    }
    else if(tmpQE < (int)(P.length()-1) && tmpRE == chrEnd && alnOptions.global){
        if(alnOptions.print >= 7) cerr << "end of refseq: " << P.length()-1-tmpQE << " insert" << endl;
        curScore += alnOptions.openGap + alnOptions.extendGap*((int)(P.length()-1-tmpQE));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl 0x180(%rsp), %eax
movl 0x178(%rsp), %eax
movq 0x170(%rsp), %rax
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
movq %rdx, 0x120(%rsp)
movq %rcx, 0x118(%rsp)
movq %r8, 0x110(%rsp)
movq %r9, 0x108(%rsp)
movq 0x120(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xbc(%rsp)
movq 0x128(%rsp), %rdi
callq 0x8630
movq %rax, %rcx
movl 0xbc(%rsp), %eax
subq $0x1, %rcx
cmpl %ecx, %eax
jge 0x4dc57
movq 0x118(%rsp), %rax
movq (%rax), %rax
cmpq 0x110(%rsp), %rax
jge 0x4dc57
movl $0x64, 0x104(%rsp)
movq 0x108(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4d65f
movq 0x499ac(%rip), %rdi     # 0x96ff0
leaq 0x30fd3(%rip), %rsi     # 0x7e61e
callq 0x8360
movq %rax, %rdi
movq 0x49956(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0x118(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xb0(%rsp)
movq 0x128(%rsp), %rdi
callq 0x8630
movq %rax, %rcx
movq 0xb0(%rsp), %rax
subq $0x1, %rcx
movq 0x120(%rsp), %rdx
movslq (%rdx), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movslq 0x180(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0xd8(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x1efc0
movq (%rax), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rax
movq 0x118(%rsp), %rcx
subq (%rcx), %rax
movl %eax, 0xd4(%rsp)
movslq 0xd4(%rsp), %rdi
callq 0x8560
movq %rax, 0xe8(%rsp)
movl $0x0, 0xd0(%rsp)
movl 0xd0(%rsp), %eax
cmpl 0xd4(%rsp), %eax
jge 0x4d777
movq 0x130(%rsp), %rdi
movq 0x118(%rsp), %rax
movq (%rax), %rsi
addq $0x1, %rsi
movslq 0xd0(%rsp), %rax
addq %rax, %rsi
callq 0x8410
movsbq (%rax), %rcx
leaq 0x31052(%rip), %rax     # 0x7e7a0
movb (%rax,%rcx), %dl
movq 0xe8(%rsp), %rax
movslq 0xd0(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x4d70c
movq 0x128(%rsp), %rdi
callq 0x8630
subq $0x1, %rax
movq 0x120(%rsp), %rcx
movslq (%rcx), %rcx
subq %rcx, %rax
movl %eax, 0xc4(%rsp)
movslq 0xc4(%rsp), %rdi
callq 0x8560
movq %rax, 0xc8(%rsp)
movl $0x0, 0xc0(%rsp)
movl 0xc0(%rsp), %eax
cmpl 0xc4(%rsp), %eax
jge 0x4d825
movq 0x128(%rsp), %rdi
movq 0x120(%rsp), %rax
movl (%rax), %eax
addl $0x1, %eax
addl 0xc0(%rsp), %eax
movslq %eax, %rsi
callq 0x8410
movsbq (%rax), %rcx
leaq 0x30fa4(%rip), %rax     # 0x7e7a0
movb (%rax,%rcx), %dl
movq 0xc8(%rsp), %rax
movslq 0xc0(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0xc0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc0(%rsp)
jmp 0x4d7bd
movq 0x108(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4d8c1
movq 0x497b2(%rip), %rdi     # 0x96ff0
leaq 0x30373(%rip), %rsi     # 0x7dbb8
callq 0x8360
movq %rax, %rdi
movl 0xc4(%rsp), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x2c618(%rip), %rsi     # 0x79e7b
callq 0x8360
movq %rax, %rdi
movl 0xd4(%rsp), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x30351(%rip), %rsi     # 0x7dbd2
callq 0x8360
movq %rax, 0xa8(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0xc4(%rsp), %rsi
callq 0xc080
movq 0xa8(%rsp), %rdi
movl (%rax), %esi
callq 0x8710
movq %rax, %rdi
movq 0x496f4(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0x108(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x4d925
movq 0x4971a(%rip), %rdi     # 0x96ff0
leaq 0x305ca(%rip), %rsi     # 0x7dea7
callq 0x8360
movq %rax, 0xa0(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0xc4(%rsp), %rsi
callq 0xc080
movq 0xa0(%rsp), %rdi
movl (%rax), %esi
imull 0xd4(%rsp), %esi
callq 0x8710
movq %rax, %rdi
movq 0x49690(%rip), %rsi     # 0x96fb0
callq 0x83b0
movl 0xc4(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x70(%rsp)
movl 0xd4(%rsp), %eax
movl %eax, 0x7c(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x108(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x88(%rsp)
movq 0x108(%rsp), %rax
imull $0xffffffff, 0x8(%rax), %eax # imm = 0xFFFFFFFF
movl %eax, 0x94(%rsp)
movq 0x108(%rsp), %rax
imull $0xffffffff, 0xc(%rax), %r13d # imm = 0xFFFFFFFF
leaq 0x178(%rsp), %rdi
leaq 0xc4(%rsp), %rsi
callq 0xc080
movl 0x6c(%rsp), %edi
movq 0x70(%rsp), %rsi
movl 0x7c(%rsp), %edx
movq 0x80(%rsp), %rcx
movq 0x88(%rsp), %r9
movl (%rax), %r12d
movl 0x104(%rsp), %r15d
movq 0x170(%rsp), %rax
movl (%rax), %ebp
movl $0x5, %r8d
leaq 0x100(%rsp), %r14
leaq 0xfc(%rsp), %rbx
leaq 0xf8(%rsp), %r11
leaq 0xf4(%rsp), %r10
leaq 0xf0(%rsp), %rax
movq %rax, 0x98(%rsp)
movl 0x94(%rsp), %eax
movl %eax, (%rsp)
movq 0x98(%rsp), %rax
movl %r13d, 0x8(%rsp)
movl %r12d, 0x10(%rsp)
movl %r15d, 0x18(%rsp)
movl %ebp, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x76640
movl %eax, %ecx
movq 0x170(%rsp), %rax
movl %ecx, (%rax)
movq 0x108(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4daa0
movq 0x4957d(%rip), %rdi     # 0x96ff0
leaq 0x30432(%rip), %rsi     # 0x7deac
callq 0x8360
movq %rax, %rdi
movq 0x170(%rsp), %rax
movl (%rax), %esi
callq 0x8710
movq %rax, %rdi
movq 0x49515(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0x108(%rsp), %rax
testb $0x1, 0x2a(%rax)
jne 0x4dae1
movl 0xf4(%rsp), %eax
movq 0x170(%rsp), %rcx
movl (%rcx), %ecx
movq 0x108(%rsp), %rdx
movl 0x4(%rdx), %edx
movq 0x108(%rsp), %rsi
subl (%rsi), %edx
imull $0x3, %edx, %edx
addl %edx, %ecx
cmpl %ecx, %eax
jl 0x4db96
movl 0xf4(%rsp), %ecx
movq 0x170(%rsp), %rax
movl %ecx, (%rax)
movq 0x128(%rsp), %rdi
callq 0x8630
subq $0x1, %rax
movl %eax, %ecx
movq 0x120(%rsp), %rax
movl %ecx, (%rax)
movq 0x118(%rsp), %rax
movq (%rax), %rcx
movslq 0xf8(%rsp), %rax
addq %rax, %rcx
movq 0x118(%rsp), %rax
movq %rcx, (%rax)
movq 0x108(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4db91
movq 0x494ab(%rip), %rdi     # 0x96ff0
leaq 0x30a73(%rip), %rsi     # 0x7e5bf
callq 0x8360
movq %rax, %rdi
movl 0xf4(%rsp), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x30ac4(%rip), %rsi     # 0x7e62e
callq 0x8360
movq %rax, %rdi
movq 0x118(%rsp), %rax
movq (%rax), %rsi
callq 0x8790
movq %rax, %rdi
movq 0x49424(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4dc38
movq 0x120(%rsp), %rax
movl (%rax), %ecx
addl 0x100(%rsp), %ecx
movq 0x120(%rsp), %rax
movl %ecx, (%rax)
movq 0x118(%rsp), %rax
movq (%rax), %rcx
movslq 0xfc(%rsp), %rax
addq %rax, %rcx
movq 0x118(%rsp), %rax
movq %rcx, (%rax)
movq 0x108(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4dc36
movq 0x49409(%rip), %rdi     # 0x96ff0
leaq 0x30a4e(%rip), %rsi     # 0x7e63c
callq 0x8360
movq %rax, %rdi
movq 0x120(%rsp), %rax
movl (%rax), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x30a1f(%rip), %rsi     # 0x7e62e
callq 0x8360
movq %rax, %rdi
movq 0x118(%rsp), %rax
movq (%rax), %rsi
callq 0x8790
movq %rax, %rdi
movq 0x4937f(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4dc38
movq 0xc8(%rsp), %rdi
callq 0x8470
movq 0xe8(%rsp), %rdi
callq 0x8470
jmp 0x4dd7b
movq 0x120(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x68(%rsp)
movq 0x128(%rsp), %rdi
callq 0x8630
movq %rax, %rcx
movl 0x68(%rsp), %eax
subq $0x1, %rcx
cmpl %ecx, %eax
jge 0x4dd79
movq 0x118(%rsp), %rax
movq (%rax), %rax
cmpq 0x110(%rsp), %rax
jne 0x4dd79
movq 0x108(%rsp), %rax
testb $0x1, 0x2a(%rax)
je 0x4dd79
movq 0x108(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4dd20
movq 0x4932b(%rip), %rdi     # 0x96ff0
leaq 0x30982(%rip), %rsi     # 0x7e64e
callq 0x8360
movq %rax, 0x60(%rsp)
movq 0x128(%rsp), %rdi
callq 0x8630
movq 0x60(%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
movq 0x120(%rsp), %rax
movslq (%rax), %rax
subq %rax, %rsi
callq 0x8100
movq %rax, %rdi
leaq 0x3090a(%rip), %rsi     # 0x7e616
callq 0x8360
movq %rax, %rdi
movq 0x49295(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0x108(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x58(%rsp)
movq 0x108(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x5c(%rsp)
movq 0x128(%rsp), %rdi
callq 0x8630
movl 0x58(%rsp), %ecx
movq %rax, %rdx
movl 0x5c(%rsp), %eax
subq $0x1, %rdx
movq 0x120(%rsp), %rsi
movslq (%rsi), %rsi
subq %rsi, %rdx
imull %edx, %eax
addl %eax, %ecx
movq 0x170(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x4dd7b
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)