// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movl (%rdx), %ebx
movq 0x8(%rsi), %r12
leal -0x1(%r12), %eax
cmpl %eax, %ebx
jge 0x2c480
movq %r8, %r13
movq %rdx, %rbp
movq 0x80(%rsp), %r15
movq (%rcx), %r14
cmpq %r8, %r14
movq %r9, (%rsp)
jge 0x2c1ea
movq %rdi, 0x38(%rsp)
movq %rcx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movl 0x90(%rsp), %r15d
cmpl $0x7, 0x78(%r9)
jl 0x2c00a
movq 0x2802d(%rip), %r14     # 0x53fe8
leaq 0x197fc(%rip), %rsi     # 0x457be
movl $0xf, %edx
movq %r14, %rdi
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 0x8(%rsp), %rax
movq (%rax), %r14
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r12
movl (%rbp), %ebx
movq %rbp, 0x28(%rsp)
movl %ebx, %ebp
notl %ebp
movslq %ebp, %rax
movslq %r15d, %rdx
addq %r14, %rdx
addq %r12, %rdx
addq %rax, %rdx
cmpq %r13, %rdx
cmovgeq %r13, %rdx
subq %r14, %rdx
movq %rdx, 0x30(%rsp)
movslq %edx, %r15
movq %r15, %rdi
callq 0x7430
movq %rax, %r13
testl %r15d, %r15d
jle 0x2c07c
movq 0x38(%rsp), %rax
movq (%rax), %rax
addq %r14, %rax
incq %rax
movq 0x30(%rsp), %rcx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
leaq 0x18b9a(%rip), %rsi     # 0x44c00
movsbq (%rax,%rdx), %rdi
movb (%rdi,%rsi), %dil
movb %dil, (%r13,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x2c066
addl %ebp, %r12d
movslq %r12d, %r15
movq %r15, %rdi
callq 0x7430
movq %rax, %rbp
testl %r15d, %r15d
jle 0x2c0c5
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movl %r12d, %eax
movslq %ebx, %rdx
addq %rdx, %rcx
incq %rcx
xorl %edx, %edx
leaq 0x18b51(%rip), %rsi     # 0x44c00
movsbq (%rcx,%rdx), %rdi
movb (%rdi,%rsi), %dil
movb %dil, (%rbp,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x2c0af
movl 0x88(%rsp), %ebx
movq (%rsp), %rax
movl 0x78(%rax), %eax
cmpl $0x6, %eax
movq 0x30(%rsp), %r14
jle 0x2c182
movq 0x27f00(%rip), %r15     # 0x53fe8
leaq 0x18c69(%rip), %rsi     # 0x44d58
movl $0x19, %edx
movq %r15, %rdi
callq 0x7340
movq %r15, %rdi
movl %r12d, %esi
callq 0x75d0
movq %rax, %r15
leaq 0x14d2a(%rip), %rsi     # 0x40e3b
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
movq %r15, %rdi
movl %r14d, %esi
callq 0x75d0
movq %rax, %r15
leaq 0x18c3f(%rip), %rsi     # 0x44d72
movl $0xa, %edx
movq %rax, %rdi
callq 0x7340
cmpl %ebx, %r12d
movl %ebx, %esi
cmovll %r12d, %esi
movq %r15, %rdi
callq 0x75d0
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 (%rsp), %rax
movl 0x78(%rax), %eax
cmpl $0x1, %eax
jle 0x2c297
movq 0x27e56(%rip), %r15     # 0x53fe8
leaq 0x18eae(%rip), %rsi     # 0x45047
movl $0x4, %edx
movq %r15, %rdi
callq 0x7340
cmpl %ebx, %r12d
cmovll %r12d, %ebx
movl %ebx, %esi
imull %r14d, %esi
movq %r15, %rdi
callq 0x75d0
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
jmp 0x2c29e
jne 0x2c480
cmpb $0x1, 0x2a(%r9)
jne 0x2c480
cmpl $0x7, 0x78(%r9)
jl 0x2c27c
movq 0x27ddf(%rip), %r14     # 0x53fe8
movq %rsi, %rbx
leaq 0x195db(%rip), %rsi     # 0x457ee
movl $0xf, %edx
movq %r14, %rdi
callq 0x7340
movslq (%rbp), %rsi
notq %rsi
addq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x71c0
movq %rax, %r14
leaq 0x19579(%rip), %rsi     # 0x457b6
movl $0x7, %edx
movq %rax, %rdi
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 (%rsp), %r9
movl 0x8(%rbx), %r12d
movl (%rbp), %ebx
notl %ebx
addl %r12d, %ebx
imull 0xc(%r9), %ebx
movl (%r15), %eax
addl 0x8(%r9), %eax
addl %ebx, %eax
movl %eax, (%r15)
jmp 0x2c480
cmpl %ebx, %r12d
cmovll %r12d, %ebx
movq 0x80(%rsp), %rsi
movq %r14, %rdx
movq (%rsp), %rax
leaq 0x10(%rax), %r9
xorl %eax, %eax
movq (%rsp), %rcx
subl 0x8(%rcx), %eax
xorl %r10d, %r10d
movq (%rsp), %rcx
subl 0xc(%rcx), %r10d
movl (%rsi), %r11d
leaq 0x44(%rsp), %r14
leaq 0x18(%rsp), %rcx
leaq 0x1c(%rsp), %r15
movl %r12d, %edi
movq %rcx, %r12
movq %rbp, %rsi
movq %r13, %rcx
movl $0x5, %r8d
pushq %r14
pushq %r12
pushq %r15
movq 0x98(%rsp), %r15
leaq 0x38(%rsp), %r14
pushq %r14
leaq 0x44(%rsp), %r14
pushq %r14
pushq %r11
pushq $0x64
pushq %rbx
pushq %r10
pushq %rax
callq 0x7b59
movq 0x50(%rsp), %rdx
addq $0x50, %rsp
movl %eax, (%r15)
cmpl $0x7, 0x78(%rdx)
jl 0x2c378
movq 0x27cbd(%rip), %r14     # 0x53fe8
leaq 0x18d1a(%rip), %rsi     # 0x4504c
movl $0xc, %edx
movq %r14, %rdi
callq 0x7340
movl (%r15), %esi
movq %r14, %rdi
callq 0x75d0
movq %rax, %r14
movq (%rax), %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 (%rsp), %rdx
movl 0x18(%rsp), %eax
cmpb $0x0, 0x2a(%rdx)
jne 0x2c3d0
movl 0x4(%rdx), %ecx
subl (%rdx), %ecx
leal (%rcx,%rcx,2), %ecx
addl (%r15), %ecx
cmpl %ecx, %eax
jge 0x2c3d0
movl 0x24(%rsp), %eax
movq 0x28(%rsp), %rbx
addl %eax, (%rbx)
movslq 0x20(%rsp), %rax
movq 0x8(%rsp), %rcx
addq %rax, (%rcx)
cmpl $0x7, 0x78(%rdx)
jl 0x2c470
movq 0x27c2e(%rip), %rdi     # 0x53fe8
leaq 0x1941b(%rip), %rsi     # 0x457dc
movl $0x11, %edx
callq 0x7340
movq %rbx, %r12
jmp 0x2c40f
movl %eax, (%r15)
movq 0x10(%rsp), %rax
movl 0x8(%rax), %eax
decl %eax
movq 0x28(%rsp), %rcx
movl %eax, (%rcx)
movslq 0x1c(%rsp), %rax
movq 0x8(%rsp), %rcx
addq %rax, (%rcx)
cmpl $0x7, 0x78(%rdx)
jl 0x2c470
movq 0x27bea(%rip), %rdi     # 0x53fe8
leaq 0x1935a(%rip), %rsi     # 0x4575f
movl $0x10, %edx
callq 0x7340
movl (%r12), %esi
movq 0x27bce(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rbx
leaq 0x193a5(%rip), %rsi     # 0x457ce
movl $0xd, %edx
movq %rax, %rdi
callq 0x7340
movq 0x8(%rsp), %rax
movq (%rax), %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 %rbp, %rdi
callq 0x7380
movq %r13, %rdi
callq 0x7380
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop