// File: /workspace/github_cpp_makefile_star2_O2/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), %r15
leal -0x1(%r15), %eax
cmpl %eax, %ebx
jge 0x229d1
movq %r9, %r12
movq %r8, %r13
movq %rdx, %rbp
movq (%rcx), %r14
cmpq %r8, %r14
jge 0x226d9
movq %rdi, (%rsp)
movq %rsi, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %r12, %rax
movl 0x90(%rsp), %r12d
movq %rax, 0x38(%rsp)
cmpl $0x7, 0x78(%rax)
jl 0x22669
movq 0x279a7(%rip), %rdi     # 0x49fe8
leaq 0x15136(%rip), %rsi     # 0x3777e
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq 0x10(%rsp), %rax
movq (%rax), %r14
movq 0x18(%rsp), %rax
movq 0x8(%rax), %r15
movl (%rbp), %ebx
movq %rbp, 0x30(%rsp)
movl %ebx, %eax
notl %eax
movl %eax, 0x20(%rsp)
cltq
movslq %r12d, %rbp
addq %r14, %rbp
addq %r15, %rbp
addq %rax, %rbp
cmpq %r13, %rbp
cmovgeq %r13, %rbp
subq %r14, %rbp
movslq %ebp, %r12
movq %r12, %rdi
callq 0x7430
movq %rax, %r13
movq (%rsp), %rax
movq (%rax), %rax
addq %r14, %rax
incq %rax
xorl %ecx, %ecx
testl %r12d, %r12d
movl $0x0, %edx
cmovgl %ebp, %edx
leaq 0x14533(%rip), %r14     # 0x36bf0
cmpq %rcx, %rdx
je 0x2275d
movsbq (%rax,%rcx), %rsi
movb (%rsi,%r14), %sil
movb %sil, (%r13,%rcx)
incq %rcx
jmp 0x226bd
jne 0x229d1
cmpb $0x1, 0x2a(%r12)
jne 0x229d1
cmpl $0x7, 0x78(%r12)
jl 0x2273a
movq 0x278ee(%rip), %rdi     # 0x49fe8
movq %rsi, %rbx
leaq 0x150aa(%rip), %rsi     # 0x377ae
callq 0x72b0
movslq (%rbp), %rsi
notq %rsi
addq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x71d0
leaq 0x15053(%rip), %rsi     # 0x37776
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movl 0x8(%rbx), %r15d
movl (%rbp), %ebx
notl %ebx
addl %r15d, %ebx
imull 0xc(%r12), %ebx
movq 0x80(%rsp), %rcx
movl (%rcx), %eax
addl 0x8(%r12), %eax
addl %ebx, %eax
movl %eax, (%rcx)
jmp 0x229d1
movq %rbp, (%rsp)
addl 0x20(%rsp), %r15d
movslq %r15d, %r12
movq %r12, %rdi
callq 0x7430
movq %rax, %rbp
movq 0x18(%rsp), %rax
movq (%rax), %rdx
xorl %eax, %eax
testl %r12d, %r12d
movl $0x0, %ecx
cmovgl %r15d, %ecx
movslq %ebx, %rsi
addq %rsi, %rdx
incq %rdx
movq 0x38(%rsp), %rbx
cmpq %rax, %rcx
je 0x227b0
movsbq (%rdx,%rax), %rsi
movb (%rsi,%r14), %sil
movb %sil, (%rbp,%rax)
incq %rax
jmp 0x22798
movl 0x78(%rbx), %eax
cmpl $0x6, %eax
movl 0x88(%rsp), %r14d
jle 0x22825
movq 0x27821(%rip), %rdi     # 0x49fe8
leaq 0x1454a(%rip), %rsi     # 0x36d18
callq 0x72b0
movq %rax, %rdi
movl %r15d, %esi
callq 0x75c0
leaq 0x106d6(%rip), %rsi     # 0x32ebb
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x75c0
leaq 0x14532(%rip), %rsi     # 0x36d32
movq %rax, %rdi
callq 0x72b0
cmpl %r14d, %r15d
movl %r14d, %esi
cmovll %r15d, %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
movl 0x78(%rbx), %eax
cmpl $0x1, %eax
jle 0x22861
movq 0x277b7(%rip), %rdi     # 0x49fe8
leaq 0x147cf(%rip), %rsi     # 0x37007
callq 0x72b0
cmpl %r14d, %r15d
cmovll %r15d, %r14d
movl %r14d, %esi
movq (%rsp), %r12
imull %r12d, %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
jmp 0x2286c
cmpl %r14d, %r15d
cmovll %r15d, %r14d
movq (%rsp), %r12
leaq 0x10(%rbx), %r9
xorl %eax, %eax
subl 0x8(%rbx), %eax
xorl %r10d, %r10d
subl 0xc(%rbx), %r10d
movq 0x80(%rsp), %rcx
movl (%rcx), %r11d
leaq 0x44(%rsp), %rbx
pushq $0x5
popq %r8
movl %r15d, %edi
movq %rcx, %r15
movq %rbp, %rsi
movl %r12d, %edx
movq %r13, %rcx
pushq %rbx
leaq 0x14(%rsp), %rbx
pushq %rbx
leaq 0x34(%rsp), %rbx
pushq %rbx
movq 0x50(%rsp), %rbx
leaq 0x40(%rsp), %r12
pushq %r12
leaq 0x4c(%rsp), %r12
pushq %r12
pushq %r11
pushq $0x64
pushq %r14
pushq %r10
pushq %rax
callq 0x30dc9
addq $0x50, %rsp
movl %eax, (%r15)
cmpl $0x7, 0x78(%rbx)
jl 0x22900
movq 0x27707(%rip), %rdi     # 0x49fe8
leaq 0x14724(%rip), %rsi     # 0x3700c
callq 0x72b0
movl (%r15), %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
movl 0xc(%rsp), %eax
cmpb $0x0, 0x2a(%rbx)
jne 0x22954
movl 0x4(%rbx), %ecx
subl (%rbx), %ecx
leal (%rcx,%rcx,2), %ecx
addl (%r15), %ecx
cmpl %ecx, %eax
jge 0x22954
movl 0x2c(%rsp), %eax
movq 0x30(%rsp), %r14
addl %eax, (%r14)
movslq 0x28(%rsp), %rax
movq 0x10(%rsp), %rcx
addq %rax, (%rcx)
cmpl $0x7, 0x78(%rbx)
jl 0x229c1
movq 0x276a5(%rip), %rdi     # 0x49fe8
leaq 0x14e52(%rip), %rsi     # 0x3779c
callq 0x72b0
movl (%r14), %esi
jmp 0x22992
movl %eax, (%r15)
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
decl %eax
movq 0x30(%rsp), %rcx
movl %eax, (%rcx)
movslq 0x24(%rsp), %rax
movq 0x10(%rsp), %rcx
addq %rax, (%rcx)
cmpl $0x7, 0x78(%rbx)
jl 0x229c1
movq 0x27666(%rip), %rdi     # 0x49fe8
leaq 0x14d96(%rip), %rsi     # 0x3771f
callq 0x72b0
movl 0xc(%rsp), %esi
movq %rax, %rdi
callq 0x75c0
leaq 0x14ded(%rip), %rsi     # 0x3778e
movq %rax, %rdi
callq 0x72b0
movq 0x10(%rsp), %rcx
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x72a0
movq %rax, %rdi
callq 0x7160
movq %rbp, %rdi
callq 0x7360
movq %r13, %rdi
callq 0x7360
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq