// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %r9, %rbx
movq %r8, %r13
movq %rcx, %r14
movq %rdx, %r12
movl (%rdx), %eax
movl 0x8(%rsi), %ecx
decl %ecx
cmpl %ecx, %eax
jge 0x2c441
cmpq %r13, (%r14)
jge 0x2c441
movq %rdi, 0x40(%rsp)
movl 0xa0(%rsp), %r15d
movq %rbx, 0x10(%rsp)
cmpl $0x7, 0x78(%rbx)
jl 0x2c11f
movq %r14, %rbp
movq 0x27f0d(%rip), %r14     # 0x53fe8
movq %rsi, %rbx
leaq 0x196d9(%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
movq %rbp, %r14
callq 0x7040
movq %rax, %rdi
callq 0x71d0
movq %rbx, %rsi
movq %r14, 0x28(%rsp)
movq (%r14), %rbp
movq %rsi, 0x30(%rsp)
movq 0x8(%rsi), %r14
movq %r12, 0x48(%rsp)
movslq (%r12), %rbx
movq %rbx, 0x38(%rsp)
notq %rbx
movslq %r15d, %r15
addq %rbp, %r15
addq %r14, %r15
addq %rbx, %r15
cmpq %r13, %r15
cmovgeq %r13, %r15
subq %rbp, %r15
movslq %r15d, %r12
movq %r12, %rdi
callq 0x7430
movq %rax, %r13
testl %r12d, %r12d
jle 0x2c1a0
movq 0x40(%rsp), %rax
movq (%rax), %rax
addq %rbp, %rax
incq %rax
movl %r15d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
leaq 0x18a76(%rip), %rsi     # 0x44c00
movsbq (%rax,%rdx), %rdi
movb (%rdi,%rsi), %dil
movb %dil, (%r13,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x2c18a
addl %ebx, %r14d
movslq %r14d, %r12
movq %r12, %rdi
callq 0x7430
movq %rax, %rbp
testl %r12d, %r12d
jle 0x2c1eb
movq 0x30(%rsp), %rax
movq (%rax), %rcx
movl %r14d, %eax
movq 0x38(%rsp), %rdx
addq %rdx, %rcx
incq %rcx
xorl %edx, %edx
leaq 0x18a2b(%rip), %rsi     # 0x44c00
movsbq (%rcx,%rdx), %rdi
movb (%rdi,%rsi), %dil
movb %dil, (%rbp,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x2c1d5
movl 0x98(%rsp), %ebx
movq 0x10(%rsp), %r12
cmpl $0x6, 0x78(%r12)
jle 0x2c2a2
movq 0x27dde(%rip), %r12     # 0x53fe8
leaq 0x18b47(%rip), %rsi     # 0x44d58
movl $0x19, %edx
movq %r12, %rdi
callq 0x7340
movq %r12, %rdi
movl %r14d, %esi
callq 0x75d0
movq %rax, %r12
leaq 0x14c08(%rip), %rsi     # 0x40e3b
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
movq %r12, %rdi
movl %r15d, %esi
callq 0x75d0
movq %rax, %r12
leaq 0x18b1d(%rip), %rsi     # 0x44d72
movl $0xa, %edx
movq %rax, %rdi
callq 0x7340
cmpl %ebx, %r14d
movl %ebx, %esi
cmovll %r14d, %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r12, %rdi
movq 0x10(%rsp), %r12
callq 0x7040
movq %rax, %rdi
callq 0x71d0
cmpl $0x2, 0x78(%r12)
jl 0x2c309
movq 0x27d37(%rip), %r12     # 0x53fe8
leaq 0x18d8f(%rip), %rsi     # 0x45047
movl $0x4, %edx
movq %r12, %rdi
callq 0x7340
cmpl %ebx, %r14d
movl %ebx, %esi
cmovll %r14d, %esi
imull %r15d, %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x72b0
movsbl %al, %esi
movq %r12, %rdi
movq 0x10(%rsp), %r12
callq 0x7040
movq %rax, %rdi
callq 0x71d0
leaq 0x10(%r12), %r9
xorl %r10d, %r10d
xorl %eax, %eax
subl 0x8(%r12), %eax
subl 0xc(%r12), %r10d
cmpl %ebx, %r14d
cmovll %r14d, %ebx
movq 0x90(%rsp), %rcx
movl (%rcx), %r11d
movq %rbx, %r12
leaq 0xc(%rsp), %rbx
movl %r14d, %edi
movq %rbp, %rsi
movl %r15d, %edx
movq %r13, %rcx
movl $0x5, %r8d
leaq 0x54(%rsp), %r14
pushq %r14
movq 0x18(%rsp), %r15
pushq %rbx
leaq 0x2c(%rsp), %rbx
pushq %rbx
leaq 0x38(%rsp), %rbx
pushq %rbx
leaq 0x44(%rsp), %rbx
pushq %rbx
pushq %r11
pushq $0x64
pushq %r12
movq 0xd0(%rsp), %r12
pushq %r10
pushq %rax
callq 0x7bbf
addq $0x50, %rsp
movl %eax, (%r12)
cmpl $0x7, 0x78(%r15)
jl 0x2c3de
movq 0x27c54(%rip), %r14     # 0x53fe8
leaq 0x18cb1(%rip), %rsi     # 0x4504c
movl $0xc, %edx
movq %r14, %rdi
callq 0x7340
movl (%r12), %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
cmpb $0x0, 0x2a(%r15)
movq 0x48(%rsp), %rbx
jne 0x2c4f7
movl 0x4(%r15), %eax
subl (%r15), %eax
leal (%rax,%rax,2), %eax
addl (%r12), %eax
cmpl %eax, 0xc(%rsp)
jge 0x2c4f7
movl 0x24(%rsp), %eax
addl %eax, (%rbx)
movslq 0x20(%rsp), %rax
movq 0x28(%rsp), %r14
addq %rax, (%r14)
cmpl $0x7, 0x78(%r15)
jl 0x2c596
movq 0x27bbd(%rip), %rdi     # 0x53fe8
leaq 0x193aa(%rip), %rsi     # 0x457dc
movl $0x11, %edx
callq 0x7340
jmp 0x2c53c
cmpl %ecx, %eax
jge 0x2c5a6
cmpq %r13, (%r14)
jne 0x2c5a6
cmpb $0x1, 0x2a(%rbx)
jne 0x2c5a6
cmpl $0x7, 0x78(%rbx)
jl 0x2c4d4
movq 0x27b7f(%rip), %r14     # 0x53fe8
movq %rsi, %r15
leaq 0x1937b(%rip), %rsi     # 0x457ee
movl $0xf, %edx
movq %r14, %rdi
callq 0x7340
movslq (%r12), %rsi
notq %rsi
addq 0x8(%r15), %rsi
movq %r14, %rdi
callq 0x71c0
movq %rax, %r14
leaq 0x19319(%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 %r15, %rsi
movl (%r12), %eax
notl %eax
addl 0x8(%rsi), %eax
imull 0xc(%rbx), %eax
movq 0x90(%rsp), %rdx
movl (%rdx), %ecx
addl 0x8(%rbx), %ecx
addl %eax, %ecx
movl %ecx, (%rdx)
jmp 0x2c5a6
movl 0xc(%rsp), %eax
movl %eax, (%r12)
movq 0x30(%rsp), %rax
movl 0x8(%rax), %eax
decl %eax
movl %eax, (%rbx)
movslq 0x1c(%rsp), %rax
movq 0x28(%rsp), %r14
addq %rax, (%r14)
cmpl $0x7, 0x78(%r15)
jl 0x2c596
movq 0x27ac2(%rip), %rdi     # 0x53fe8
leaq 0x19232(%rip), %rsi     # 0x4575f
movl $0x10, %edx
callq 0x7340
leaq 0xc(%rsp), %rbx
movl (%rbx), %esi
movq 0x27aa3(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rbx
leaq 0x1927a(%rip), %rsi     # 0x457ce
movl $0xd, %edx
movq %rax, %rdi
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 %rbp, %rdi
callq 0x7380
movq %r13, %rdi
callq 0x7380
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop