// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/mapper.cpp
// Function: leftExtension(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 leftExtension(const string& S, const string& P, int & tmpQB, long & tmpRB, 
        long chrStart, const align_opt & alnOptions, int & curScore, int bandSize, int editDist){
    if(tmpQB>0 && tmpRB > chrStart){
        int zdrop = 100;
        if(alnOptions.print >= 7) cerr << "dp required before first seed" << endl;
        int qle, tle, gtle, gscore, max_off;
        uint8_t *target;
        long alignmentBoundLeft = max(tmpRB-tmpQB-(editDist),chrStart);
        int tLen = tmpRB-alignmentBoundLeft;
        target = (uint8_t *)malloc(tLen);
        for (int j = 0; j < tLen; ++j) // convert to the nt4 encoding
            target[j] = Utils::ORDVALUE[(size_t)S[tmpRB-j-1]];
        uint8_t *query;
        query = (uint8_t *)malloc(tmpQB);
        for (int j = 0; j < tmpQB; ++j)
            query[j] = Utils::ORDVALUE[(size_t)P[tmpQB-j-1]];
        if(alnOptions.print >= 7) cerr << "dp called with dimension " << (tmpQB) << "x" << (tLen) << " and band " << min(bandSize,tmpQB) << endl;
        if(alnOptions.print >= 2) cerr << "#DP " << (min(bandSize,tmpQB)*tLen) << endl;
        curScore = ksw_extend(tmpQB, query, tLen, target, 5, alnOptions.mat, 
            -1*alnOptions.openGap, -1*alnOptions.extendGap, 
            min(bandSize,tmpQB), 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;
            tmpQB = 0;
            tmpRB = tmpRB-gtle;
            if(alnOptions.print >= 7) cerr << "global score is " << gscore << " with refbegin " << tmpRB << endl;
        }
        else{
            tmpQB = tmpQB-qle;
            tmpRB = tmpRB-tle;
            if(alnOptions.print >= 7) cerr << "local begin pos is " << tmpQB << " with refBegin " << tmpRB << endl;
        }
        free(query);
        free(target);
    }
    else if(tmpQB>0 && tmpRB == chrStart && alnOptions.global){
        if(alnOptions.print >= 7) cerr << "begin of refseq: " << tmpQB << " insert" << endl;
        curScore += alnOptions.openGap + alnOptions.extendGap*tmpQB;
    }
}

// Assembly:
movl (%rdx), %eax
testl %eax, %eax
jle 0x225e0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %r12
movq %rcx, %r15
movq %rdx, %rbp
movq %r9, %r13
movq (%rcx), %r14
cmpq %r8, %r14
jle 0x222f1
movq %rdi, 0x8(%rsp)
movq %rsi, 0x30(%rsp)
movq %rbp, 0x18(%rsp)
movl 0x90(%rsp), %ebp
cmpl $0x7, 0x78(%r13)
jl 0x22280
movq 0x27d86(%rip), %rdi     # 0x49fe8
leaq 0x15498(%rip), %rsi     # 0x37701
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq (%r15), %r14
movq 0x18(%rsp), %rax
movl (%rax), %eax
movq %r15, 0x38(%rsp)
movslq %eax, %r15
movslq %ebp, %rax
addq %r15, %rax
movq %r14, %rcx
subq %rax, %rcx
cmpq %r12, %rcx
cmovleq %r12, %rcx
movq %r14, %rbx
subq %rcx, %rbx
movslq %ebx, %rbp
movq %rbp, %rdi
callq 0x7430
movq %rax, %r12
movq 0x8(%rsp), %rax
movq (%rax), %rdx
xorl %eax, %eax
testl %ebp, %ebp
movl $0x0, %ecx
movq %rbx, 0x8(%rsp)
cmovgl %ebx, %ecx
addq %r14, %rdx
decq %rdx
leaq 0x1491b(%rip), %rbp     # 0x36bf0
movq %r13, %r14
cmpq %rax, %rcx
je 0x22359
movsbq (%rdx), %rsi
movb (%rsi,%rbp), %sil
movb %sil, (%r12,%rax)
incq %rax
decq %rdx
jmp 0x222d8
jne 0x225d2
cmpb $0x1, 0x2a(%r13)
jne 0x225d2
cmpl $0x7, 0x78(%r13)
jl 0x22341
movq 0x27cd8(%rip), %rdi     # 0x49fe8
leaq 0x1544d(%rip), %rsi     # 0x37764
callq 0x72b0
movl (%rbp), %esi
movq %rax, %rdi
callq 0x75c0
leaq 0x15448(%rip), %rsi     # 0x37776
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movl (%rbp), %eax
imull 0xc(%r13), %eax
addl 0x8(%r13), %eax
movq 0x80(%rsp), %rcx
addl %eax, (%rcx)
jmp 0x225d2
movq %r15, %rdi
callq 0x7430
movq %rax, %r13
movq 0x30(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
testl %r15d, %r15d
movl $0x0, %edx
cmovgl %r15d, %edx
decl %r15d
cmpq %rcx, %rdx
je 0x22398
movslq %r15d, %r15
movsbq (%rax,%r15), %rsi
movb (%rsi,%rbp), %sil
movb %sil, (%r13,%rcx)
incq %rcx
jmp 0x2237a
movl 0x78(%r14), %eax
cmpl $0x6, %eax
movq 0x18(%rsp), %rbx
jle 0x22410
movq 0x27c3b(%rip), %rdi     # 0x49fe8
leaq 0x14964(%rip), %rsi     # 0x36d18
callq 0x72b0
movl (%rbx), %esi
movq %rax, %rdi
callq 0x75c0
leaq 0x10af1(%rip), %rsi     # 0x32ebb
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x75c0
leaq 0x1494c(%rip), %rsi     # 0x36d32
movq %rax, %rdi
callq 0x72b0
movl (%rbx), %esi
movl 0x88(%rsp), %ecx
cmpl %ecx, %esi
cmovgel %ecx, %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
movl 0x78(%r14), %eax
cmpl $0x2, %eax
jl 0x2244b
movq 0x27bcc(%rip), %rdi     # 0x49fe8
leaq 0x14be4(%rip), %rsi     # 0x37007
callq 0x72b0
movl (%rbx), %esi
movl 0x88(%rsp), %ecx
cmpl %ecx, %esi
cmovgel %ecx, %esi
imull 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
movl (%rbx), %edi
leaq 0x10(%r14), %r9
xorl %r10d, %r10d
xorl %eax, %eax
subl 0x8(%r14), %eax
subl 0xc(%r14), %r10d
movl 0x88(%rsp), %ebp
cmpl %ebp, %edi
cmovll %edi, %ebp
movq 0x80(%rsp), %rcx
movl (%rcx), %r11d
leaq 0x44(%rsp), %rbx
leaq 0x14(%rsp), %r15
pushq $0x5
popq %r8
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rcx
pushq %rbx
pushq %r15
leaq 0x34(%rsp), %rbx
pushq %rbx
leaq 0x40(%rsp), %rbx
pushq %rbx
leaq 0x4c(%rsp), %rbx
pushq %rbx
pushq %r11
pushq $0x64
pushq %rbp
pushq %r10
pushq %rax
callq 0x30dc9
addq $0x50, %rsp
movq 0x80(%rsp), %rcx
movl %eax, (%rcx)
cmpl $0x7, 0x78(%r14)
jl 0x224f2
movq 0x27b1c(%rip), %rdi     # 0x49fe8
leaq 0x14b39(%rip), %rsi     # 0x3700c
callq 0x72b0
movq 0x80(%rsp), %rcx
movl (%rcx), %esi
movq %rax, %rdi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
movl 0x14(%rsp), %eax
cmpb $0x0, 0x2a(%r14)
movq 0x38(%rsp), %rbx
jne 0x22560
movl 0x4(%r14), %ecx
subl (%r14), %ecx
leal (%rcx,%rcx,2), %ecx
movq 0x80(%rsp), %rdx
addl (%rdx), %ecx
cmpl %ecx, %eax
jge 0x22560
movl 0x2c(%rsp), %eax
movq 0x18(%rsp), %r15
subl %eax, (%r15)
movslq 0x28(%rsp), %rax
subq %rax, (%rbx)
cmpl $0x7, 0x78(%r14)
jl 0x225c2
movq 0x27aa8(%rip), %rdi     # 0x49fe8
leaq 0x151f9(%rip), %rsi     # 0x37740
callq 0x72b0
movl (%r15), %esi
movq %rax, %rdi
callq 0x75c0
leaq 0x151f6(%rip), %rsi     # 0x37754
jmp 0x225a7
movq 0x80(%rsp), %rcx
movl %eax, (%rcx)
movq 0x18(%rsp), %rax
andl $0x0, (%rax)
movslq 0x24(%rsp), %rax
subq %rax, (%rbx)
cmpl $0x7, 0x78(%r14)
jl 0x225c2
movq 0x27a60(%rip), %rdi     # 0x49fe8
leaq 0x15190(%rip), %rsi     # 0x3771f
callq 0x72b0
movl 0x14(%rsp), %esi
movq %rax, %rdi
callq 0x75c0
leaq 0x15189(%rip), %rsi     # 0x37730
movq %rax, %rdi
callq 0x72b0
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x72a0
movq %rax, %rdi
callq 0x7160
movq %r13, %rdi
callq 0x7360
movq %r12, %rdi
callq 0x7360
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq