// File: 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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl 0x160(%rsp), %eax
movl 0x158(%rsp), %eax
movq 0x150(%rsp), %rax
movq %rdi, 0x110(%rsp)
movq %rsi, 0x108(%rsp)
movq %rdx, 0x100(%rsp)
movq %rcx, 0xf8(%rsp)
movq %r8, 0xf0(%rsp)
movq %r9, 0xe8(%rsp)
movq 0x100(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x4d4a8
movq 0xf8(%rsp), %rax
movq (%rax), %rax
cmpq 0xf0(%rsp), %rax
jle 0x4d4a8
movl $0x64, 0xe4(%rsp)
movq 0xe8(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4cf0c
movq 0x4a0ff(%rip), %rdi     # 0x96ff0
leaq 0x316a9(%rip), %rsi     # 0x7e5a1
callq 0x8360
movq %rax, %rdi
movq 0x4a0a9(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0xf8(%rsp), %rax
movq (%rax), %rax
movq 0x100(%rsp), %rcx
movslq (%rcx), %rcx
subq %rcx, %rax
movslq 0x160(%rsp), %rcx
subq %rcx, %rax
movq %rax, 0xb8(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x1ec80
movq (%rax), %rax
movq %rax, 0xc0(%rsp)
movq 0xf8(%rsp), %rax
movq (%rax), %rax
subq 0xc0(%rsp), %rax
movl %eax, 0xb4(%rsp)
movslq 0xb4(%rsp), %rdi
callq 0x8560
movq %rax, 0xc8(%rsp)
movl $0x0, 0xb0(%rsp)
movl 0xb0(%rsp), %eax
cmpl 0xb4(%rsp), %eax
jge 0x4cffd
movq 0x110(%rsp), %rdi
movq 0xf8(%rsp), %rax
movq (%rax), %rsi
movslq 0xb0(%rsp), %rax
subq %rax, %rsi
subq $0x1, %rsi
callq 0x8410
movsbq (%rax), %rcx
leaq 0x317cc(%rip), %rax     # 0x7e7a0
movb (%rax,%rcx), %dl
movq 0xc8(%rsp), %rax
movslq 0xb0(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0xb0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb0(%rsp)
jmp 0x4cf92
movq 0x100(%rsp), %rax
movslq (%rax), %rdi
callq 0x8560
movq %rax, 0xa8(%rsp)
movl $0x0, 0xa4(%rsp)
movl 0xa4(%rsp), %eax
movq 0x100(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x4d08b
movq 0x108(%rsp), %rdi
movq 0x100(%rsp), %rax
movl (%rax), %eax
subl 0xa4(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8410
movsbq (%rax), %rcx
leaq 0x3173e(%rip), %rax     # 0x7e7a0
movb (%rax,%rcx), %dl
movq 0xa8(%rsp), %rax
movslq 0xa4(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0xa4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa4(%rsp)
jmp 0x4d020
movq 0xe8(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4d12a
movq 0x49f4c(%rip), %rdi     # 0x96ff0
leaq 0x30b0d(%rip), %rsi     # 0x7dbb8
callq 0x8360
movq %rax, %rdi
movq 0x100(%rsp), %rax
movl (%rax), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x2cdaf(%rip), %rsi     # 0x79e7b
callq 0x8360
movq %rax, %rdi
movl 0xb4(%rsp), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x30ae8(%rip), %rsi     # 0x7dbd2
callq 0x8360
movq %rax, 0x98(%rsp)
movq 0x100(%rsp), %rsi
leaq 0x158(%rsp), %rdi
callq 0xc080
movq 0x98(%rsp), %rdi
movl (%rax), %esi
callq 0x8710
movq %rax, %rdi
movq 0x49e8b(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0xe8(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jl 0x4d18e
movq 0x49eb1(%rip), %rdi     # 0x96ff0
leaq 0x30d61(%rip), %rsi     # 0x7dea7
callq 0x8360
movq %rax, 0x90(%rsp)
movq 0x100(%rsp), %rsi
leaq 0x158(%rsp), %rdi
callq 0xc080
movq 0x90(%rsp), %rdi
movl (%rax), %esi
imull 0xb4(%rsp), %esi
callq 0x8710
movq %rax, %rdi
movq 0x49e27(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0x100(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x5c(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x60(%rsp)
movl 0xb4(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xe8(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x78(%rsp)
movq 0xe8(%rsp), %rax
imull $0xffffffff, 0x8(%rax), %eax # imm = 0xFFFFFFFF
movl %eax, 0x84(%rsp)
movq 0xe8(%rsp), %rax
imull $0xffffffff, 0xc(%rax), %r13d # imm = 0xFFFFFFFF
movq 0x100(%rsp), %rsi
leaq 0x158(%rsp), %rdi
callq 0xc080
movl 0x5c(%rsp), %edi
movq 0x60(%rsp), %rsi
movl 0x6c(%rsp), %edx
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %r9
movl (%rax), %r12d
movl 0xe4(%rsp), %r15d
movq 0x150(%rsp), %rax
movl (%rax), %ebp
movl $0x5, %r8d
leaq 0xe0(%rsp), %r14
leaq 0xdc(%rsp), %rbx
leaq 0xd8(%rsp), %r11
leaq 0xd4(%rsp), %r10
leaq 0xd0(%rsp), %rax
movq %rax, 0x88(%rsp)
movl 0x84(%rsp), %eax
movl %eax, (%rsp)
movq 0x88(%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 0x150(%rsp), %rax
movl %ecx, (%rax)
movq 0xe8(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4d300
movq 0x49d1d(%rip), %rdi     # 0x96ff0
leaq 0x30bd2(%rip), %rsi     # 0x7deac
callq 0x8360
movq %rax, %rdi
movq 0x150(%rsp), %rax
movl (%rax), %esi
callq 0x8710
movq %rax, %rdi
movq 0x49cb5(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0xe8(%rsp), %rax
testb $0x1, 0x2a(%rax)
jne 0x4d341
movl 0xd4(%rsp), %eax
movq 0x150(%rsp), %rcx
movl (%rcx), %ecx
movq 0xe8(%rsp), %rdx
movl 0x4(%rdx), %edx
movq 0xe8(%rsp), %rsi
subl (%rsi), %edx
imull $0x3, %edx, %edx
addl %edx, %ecx
cmpl %ecx, %eax
jl 0x4d3e7
movl 0xd4(%rsp), %ecx
movq 0x150(%rsp), %rax
movl %ecx, (%rax)
movq 0x100(%rsp), %rax
movl $0x0, (%rax)
movq 0xf8(%rsp), %rax
movq (%rax), %rcx
movslq 0xd8(%rsp), %rax
subq %rax, %rcx
movq 0xf8(%rsp), %rax
movq %rcx, (%rax)
movq 0xe8(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4d3e2
movq 0x49c5a(%rip), %rdi     # 0x96ff0
leaq 0x31222(%rip), %rsi     # 0x7e5bf
callq 0x8360
movq %rax, %rdi
movl 0xd4(%rsp), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x31215(%rip), %rsi     # 0x7e5d0
callq 0x8360
movq %rax, %rdi
movq 0xf8(%rsp), %rax
movq (%rax), %rsi
callq 0x8790
movq %rax, %rdi
movq 0x49bd3(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4d489
movq 0x100(%rsp), %rax
movl (%rax), %ecx
subl 0xe0(%rsp), %ecx
movq 0x100(%rsp), %rax
movl %ecx, (%rax)
movq 0xf8(%rsp), %rax
movq (%rax), %rcx
movslq 0xdc(%rsp), %rax
subq %rax, %rcx
movq 0xf8(%rsp), %rax
movq %rcx, (%rax)
movq 0xe8(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4d487
movq 0x49bb8(%rip), %rdi     # 0x96ff0
leaq 0x311a1(%rip), %rsi     # 0x7e5e0
callq 0x8360
movq %rax, %rdi
movq 0x100(%rsp), %rax
movl (%rax), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x31194(%rip), %rsi     # 0x7e5f4
callq 0x8360
movq %rax, %rdi
movq 0xf8(%rsp), %rax
movq (%rax), %rsi
callq 0x8790
movq %rax, %rdi
movq 0x49b2e(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x4d489
movq 0xa8(%rsp), %rdi
callq 0x8470
movq 0xc8(%rsp), %rdi
callq 0x8470
jmp 0x4d566
movq 0x100(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x4d564
movq 0xf8(%rsp), %rax
movq (%rax), %rax
cmpq 0xf0(%rsp), %rax
jne 0x4d564
movq 0xe8(%rsp), %rax
testb $0x1, 0x2a(%rax)
je 0x4d564
movq 0xe8(%rsp), %rax
cmpl $0x7, 0x78(%rax)
jl 0x4d535
movq 0x49af7(%rip), %rdi     # 0x96ff0
leaq 0x31104(%rip), %rsi     # 0x7e604
callq 0x8360
movq %rax, %rdi
movq 0x100(%rsp), %rax
movl (%rax), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x310f5(%rip), %rsi     # 0x7e616
callq 0x8360
movq %rax, %rdi
movq 0x49a80(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0xe8(%rsp), %rax
movl 0x8(%rax), %ecx
movq 0xe8(%rsp), %rax
movl 0xc(%rax), %eax
movq 0x100(%rsp), %rdx
imull (%rdx), %eax
addl %eax, %ecx
movq 0x150(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x4d566
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)