// File: /workspace/github_cpp_makefile_star2_O1/readmapping[P]alfalfa/src/dp.cpp
// Function: dynProg::dpBasic(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&, boundaries&, dp_type const&, outputType const&, dp_output&)
int dynProg::dpBasic( const string& ref, 
        const string&     query,
        boundaries& offset,
        const dp_type&    type,
        const outputType& oType,
        dp_output&  output){
    L1 = offset.refE-offset.refB+1;
    L2 = offset.queryE-offset.queryB+1;
    assert(L1 >=0 && L2 >= 0);
    //build matrices
    updateMatrix(type, false, false);
    M[0][0] = 0;
    for(int i = 1; i <= L2; i++)
        M[i][0] = type.freeQueryB ? 0 : scores.openGap + i*scores.extendGap;
    for(int i = 1; i <= L1; i++)
        M[0][i] = type.freeRefB ? 0 : scores.openGap + i*scores.extendGap;
    //dp
    int        d = 0;
    for(long i = 1L; i <= L2; i++ ){
        for(long j = 1L; j <= L1; j++ ){
            //here insert substitution matrix!
            d = scores.scoreMatrix[size_t(ref[offset.refB+j-1])][size_t(query[offset.queryB+i-1])];
            M[ i ][ j ] = max(M[ i-1 ][ j-1 ] + d, M[ i ][ j-1 ] + scores.extendGap);
            M[ i ][ j ] = max(M[ i ][ j ], M[ i-1 ][ j ] + scores.extendGap);
        }
    }
    //traceback and output
    int        i = L2, j = L1;
    //find beginPosition for traceBack and find dpScore
    int maximum = M[i][j];
    for(int idx = L1; idx >= 0; idx--){
        if(M[i][idx] > maximum){
            maximum = M[i][idx];
            j = idx;
        }
    }
    output.dpScore = M[i][j];
    //Next is for output only
    if(oType>DPSCORE){
        //Alter boundaries to return the new positions when free gaps were introduced.
        if(type.freeRefE && j < L1)
            offset.refE = offset.refB+j-1;
        //traceBack
        std::stringstream ss;
        while( i > 0 ){
            bool equal = false;
            if(j > 0 && i > 0)
                equal = ref[offset.refB+j-1] == query[offset.queryB+i-1];
            if( j > 0 && i > 0 && M[ i ][ j ] == M[ i-1 ][ j-1 ] + scores.match && equal){
                ss << '=';
                i-- ;  j-- ;
            }
            else if(j > 0 && i > 0 && M[ i ][ j ] == M[ i-1 ][ j-1 ] + scores.mismatch){
                ss << 'X';
                output.editDist++;
                i-- ;  j-- ;
            }
            else if(j > 0 && (M[ i ][ j ] == M[ i ][ j-1 ] + scores.extendGap || i==0)){
                ss << 'D';
                output.editDist++;
                j-- ;
            }
            else if(i > 0 && (M[ i ][ j ] == M[ i-1 ][ j ] + scores.extendGap || j==0)){
                ss << 'I';
                output.editDist++;
                i-- ;
            }
            else{
                cerr << "Error in dynamic programming" << endl;
                cerr << "No valid trace position found" << endl;
                cerr << "Position " << i << ", " << j << endl;
                cerr << "Scores: Current " << M[ i ][ j ] << endl;
                if(j > 0 && i > 0){
                    cerr << "Scores: Diag "    << M[ i-1 ][ j-1 ] << endl;
                    cerr << "Characters "    << ref[offset.refB+j-1] << "  " << query[offset.queryB+i-1] << endl; 
                }
                if(j > 0)
                    cerr << "Scores: Left "    << M[ i ][ j-1 ] << endl;
                if(i > 0)
                    cerr << "Scores: Up "    << M[ i-1 ][ j ] << endl;
                exit(1);
            }
        }
        //Edit Dist ouput
        if( i > 0 && !type.freeQueryB)
            output.editDist += i;
        if(j > 0 && !type.freeRefB)
            output.editDist += j;
        //Errorstring output
        if(oType == ERRORSTRING || oType == ALL){
            string errorString = ss.str();
            if(i > 0 && !type.freeQueryB)
                errorString.append(i,'I');
            else if(j > 0 && !type.freeRefB)
                errorString.append(j, 'D');
            reverse( errorString.begin(), errorString.end() );
            //create output: errorString
            int iter = 0;
            int temp;
            int errorStringLength = errorString.length();
            while(iter < errorStringLength){
                temp = iter;
                while(iter+1 < errorStringLength && errorString[iter+1]==errorString[temp])
                    iter++;
                iter++;
                output.cigarChars.push_back(errorString[temp]);
                output.cigarLengths.push_back(iter-temp);
            }
        }
    }
    if(type.freeRefB && j > 0)
        offset.refB = offset.refB+j;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %r9, 0x40(%rsp)
movq %r8, %r15
movq %rcx, %rbx
movq %rdx, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movl 0x8(%rcx), %eax
subl (%rcx), %eax
movq %rdi, %r14
incl %eax
movl %eax, 0x20(%rdi)
movl 0x14(%rcx), %eax
subl 0x10(%rcx), %eax
incl %eax
movl %eax, 0x24(%rdi)
movq %r8, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1aa00
movq (%r14), %rax
movq (%rax), %rcx
movl $0x0, (%rcx)
cmpl $0x0, 0x24(%r14)
jle 0x1e4c6
movb 0x2(%r15), %dl
movq 0x38(%r14), %rsi
movl $0x1, %edi
xorl %r8d, %r8d
testb %dl, %dl
jne 0x1e4af
movl 0xc(%rsi), %r8d
imull %edi, %r8d
addl 0x8(%rsi), %r8d
movq (%rax,%rdi,8), %r9
movl %r8d, (%r9)
leaq 0x1(%rdi), %r8
movslq 0x24(%r14), %r9
cmpq %r9, %rdi
movq %r8, %rdi
jl 0x1e49c
cmpl $0x0, 0x20(%r14)
jle 0x1e500
movb (%r15), %dl
movq 0x38(%r14), %rsi
movl $0x1, %edi
xorl %r8d, %r8d
testb %dl, %dl
jne 0x1e4ec
movl 0xc(%rsi), %r8d
imull %edi, %r8d
addl 0x8(%rsi), %r8d
movl %r8d, (%rcx,%rdi,4)
leaq 0x1(%rdi), %r8
movslq 0x20(%r14), %r9
cmpq %r9, %rdi
movq %r8, %rdi
jl 0x1e4d9
movq %r15, 0x10(%rsp)
movslq 0x24(%r14), %r9
testq %r9, %r9
jle 0x1e5b6
movq 0x38(%r14), %rcx
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
addq (%rbx), %rdx
leaq 0x10(%rcx), %rsi
movq 0x18(%rsp), %rdi
movq (%rdi), %rdi
decq %rdi
movl $0x1, %r8d
cmpl $0x0, 0x20(%r14)
jle 0x1e5a1
leaq (%rdi,%r8), %r9
movq -0x8(%rax,%r8,8), %r10
movq (%rax,%r8,8), %r11
xorl %r15d, %r15d
movsbq (%rdx,%r15), %r12
movslq 0x10(%rbx), %r13
movsbq (%r9,%r13), %r13
imulq $0x1fc, %r12, %r12      # imm = 0x1FC
addq %rsi, %r12
movl (%r10,%r15,4), %ebp
addl (%r12,%r13,4), %ebp
movl 0xc(%rcx), %r12d
addl (%r11,%r15,4), %r12d
cmpl %r12d, %ebp
cmovgl %ebp, %r12d
movl %r12d, 0x4(%r11,%r15,4)
movl 0xc(%rcx), %ebp
addl 0x4(%r10,%r15,4), %ebp
cmpl %ebp, %r12d
cmovgl %r12d, %ebp
movl %ebp, 0x4(%r11,%r15,4)
movslq 0x20(%r14), %r12
incq %r15
cmpq %r12, %r15
jl 0x1e54d
leaq 0x1(%r8), %r10
movl 0x24(%r14), %r12d
movslq %r12d, %r9
cmpq %r9, %r8
movq %r10, %r8
jl 0x1e536
jmp 0x1e5b9
movl %r9d, %r12d
movq 0x210(%rsp), %r15
movslq 0x20(%r14), %rcx
movq (%rax,%r9,8), %rax
testq %rcx, %rcx
js 0x1e5ec
movl (%rax,%rcx,4), %edx
movl %ecx, %ebp
movl (%rax,%rcx,4), %esi
cmpl %edx, %esi
cmovgl %ecx, %ebp
cmovgl %esi, %edx
leaq -0x1(%rcx), %rsi
testq %rcx, %rcx
movq %rsi, %rcx
jg 0x1e5d3
jmp 0x1e5ee
movl %ecx, %ebp
movslq %ebp, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x4(%r15)
movq 0x40(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x1e920
movq 0x10(%rsp), %rax
cmpb $0x1, 0x1(%rax)
jne 0x1e624
cmpl 0x20(%r14), %ebp
jge 0x1e624
movq (%rbx), %rax
addq %rcx, %rax
decq %rax
movq %rax, 0x8(%rbx)
leaq 0x50(%rsp), %rdi
callq 0x71e0
testl %r12d, %r12d
jle 0x1e76b
testl %ebp, %ebp
jle 0x1e667
movl %ebp, %eax
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
addq (%rbx), %rcx
movb -0x1(%rax,%rcx), %al
movslq 0x10(%rbx), %rcx
movslq %r12d, %rdx
addq %rcx, %rdx
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
cmpb -0x1(%rcx,%rdx), %al
setne %al
jmp 0x1e669
movb $0x1, %al
movl %r12d, %r13d
testl %ebp, %ebp
jle 0x1e717
movq (%r14), %rcx
movq 0x38(%r14), %rdx
movq -0x8(%rcx,%r13,8), %r8
movq (%rcx,%r13,8), %rcx
movl %ebp, %esi
movl (%rcx,%rsi,4), %edi
movl -0x4(%r8,%rsi,4), %r8d
movl (%rdx), %r9d
addl %r8d, %r9d
cmpl %r9d, %edi
setne %r9b
orb %al, %r9b
testb $0x1, %r9b
je 0x1e6cb
addl 0x4(%rdx), %r8d
cmpl %r8d, %edi
jne 0x1e6ee
movb $0x58, 0x20(%rsp)
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7340
incl (%r15)
jmp 0x1e6e4
movb $0x3d, 0x20(%rsp)
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7340
decl %r12d
decl %ebp
jmp 0x1e62e
movl 0xc(%rdx), %eax
addl -0x4(%rcx,%rsi,4), %eax
cmpl %eax, %edi
jne 0x1e717
movb $0x44, 0x20(%rsp)
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7340
incl (%r15)
jmp 0x1e6e7
movq (%r14), %rax
movq 0x38(%r14), %rcx
movq -0x8(%rax,%r13,8), %rdx
movq (%rax,%r13,8), %rax
movslq %ebp, %r15
movl 0xc(%rcx), %ecx
addl (%rdx,%r15,4), %ecx
cmpl %ecx, (%rax,%r15,4)
je 0x1e73f
testl %ebp, %ebp
jne 0x1e948
movb $0x49, 0x20(%rsp)
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7340
movq 0x210(%rsp), %r15
incl (%r15)
decl %r12d
jmp 0x1e62e
testl %ebp, %ebp
movq 0x10(%rsp), %r14
jle 0x1e77d
cmpb $0x0, (%r14)
jne 0x1e77d
addl %ebp, (%r15)
movq 0x40(%rsp), %rax
movl (%rax), %eax
addl $-0x3, %eax
cmpl $0x1, %eax
ja 0x1e900
leaq 0x68(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x7540
testl %ebp, %ebp
jle 0x1e7c1
cmpb $0x0, (%r14)
jne 0x1e7c1
movl %ebp, %ecx
leaq 0x20(%rsp), %rdi
movq 0x8(%rdi), %rsi
xorl %edx, %edx
movl $0x44, %r8d
callq 0x7670
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
testq %rcx, %rcx
setne %dl
addq %rax, %rcx
decq %rcx
cmpq %rax, %rcx
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x1e805
incq %rax
movb -0x1(%rax), %dl
movb (%rcx), %sil
movb %sil, -0x1(%rax)
movb %dl, (%rcx)
decq %rcx
leaq 0x1(%rax), %rdx
cmpq %rcx, %rax
movq %rdx, %rax
jb 0x1e7ea
movq 0x28(%rsp), %r8
testl %r8d, %r8d
jle 0x1e8e0
movq 0x210(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
addq $0x20, %rax
movq %rax, 0x40(%rsp)
movl %r8d, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq %r8, 0x18(%rsp)
movl %r14d, %r13d
movq 0x20(%rsp), %rax
movslq %r14d, %rdx
leal 0x1(%rdx), %ecx
cmpl %r8d, %ecx
cmovlel %r8d, %ecx
leaq 0x1(%rdx), %rsi
cmpq %r15, %rsi
jge 0x1e86f
movb (%rax,%rsi), %dil
incl %r14d
incq %rsi
cmpb (%rax,%rdx), %dil
je 0x1e858
jmp 0x1e872
movl %ecx, %r14d
addq 0x20(%rsp), %rdx
movq 0x210(%rsp), %r12
movq 0x10(%r12), %rsi
cmpq 0x18(%r12), %rsi
je 0x1e896
movb (%rdx), %al
movb %al, (%rsi)
incq 0x10(%r12)
jmp 0x1e8a0
movq 0x8(%rsp), %rdi
callq 0x1ebb8
movl %r14d, %eax
subl %r13d, %eax
movl %eax, 0x4c(%rsp)
movq 0x28(%r12), %rsi
cmpq 0x30(%r12), %rsi
je 0x1e8c3
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%r12)
jmp 0x1e8d2
movq 0x40(%rsp), %rdi
leaq 0x4c(%rsp), %rdx
callq 0x1ecaa
movq 0x18(%rsp), %r8
cmpl %r8d, %r14d
jl 0x1e83f
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1e8fb
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72f0
movq 0x10(%rsp), %r14
movq 0x35691(%rip), %rsi     # 0x53f98
leaq 0x50(%rsp), %rdi
callq 0x7210
leaq 0xd0(%rsp), %rdi
callq 0x7100
jmp 0x1e925
movq 0x10(%rsp), %r14
testl %ebp, %ebp
jle 0x1e934
cmpb $0x0, (%r14)
je 0x1e934
movl %ebp, %eax
addq %rax, (%rbx)
xorl %eax, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x35699(%rip), %rdi     # 0x53fe8
leaq 0x25f72(%rip), %rsi     # 0x448c8
movl $0x1c, %edx
callq 0x7340
movq 0x35681(%rip), %rdi     # 0x53fe8
callq 0x7150
movq 0x35675(%rip), %rdi     # 0x53fe8
leaq 0x25f6b(%rip), %rsi     # 0x448e5
movl $0x1d, %edx
callq 0x7340
movq 0x3565d(%rip), %rdi     # 0x53fe8
callq 0x7150
movq 0x35651(%rip), %rdi     # 0x53fe8
leaq 0x25f65(%rip), %rsi     # 0x44903
movl $0x9, %edx
callq 0x7340
movq 0x35639(%rip), %rdi     # 0x53fe8
movl %r12d, %esi
callq 0x75d0
movq %rax, 0x10(%rsp)
leaq 0x25f4a(%rip), %rsi     # 0x4490d
movl $0x2, %edx
movq 0x10(%rsp), %rdi
callq 0x7340
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movq 0x355fb(%rip), %rdi     # 0x53fe8
leaq 0x25f1c(%rip), %rsi     # 0x44910
movl $0x10, %edx
callq 0x7340
movq (%r14), %rax
movq (%rax,%r13,8), %rax
movl (%rax,%r15,4), %esi
movq 0x355d8(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rdi
callq 0x7150
testl %ebp, %ebp
jle 0x1eb25
movq 0x355bc(%rip), %rdi     # 0x53fe8
leaq 0x25eee(%rip), %rsi     # 0x44921
movl $0xd, %edx
callq 0x7340
movq (%r14), %rax
movq -0x8(%rax,%r13,8), %rax
movl %ebp, %ebp
movl -0x4(%rax,%rbp,4), %esi
movq 0x35596(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movq 0x35582(%rip), %rdi     # 0x53fe8
leaq 0x25ec2(%rip), %rsi     # 0x4492f
movl $0xb, %edx
callq 0x7340
movq 0x8(%rsp), %rax
movq (%rax), %rax
addq (%rbx), %rax
movb -0x1(%r15,%rax), %al
leaq 0x20(%rsp), %rsi
movb %al, (%rsi)
movq 0x35553(%rip), %rdi     # 0x53fe8
movl $0x1, %edx
callq 0x7340
movq %rax, 0x8(%rsp)
leaq 0x25ebe(%rip), %rsi     # 0x44969
movl $0x2, %edx
movq 0x8(%rsp), %rdi
callq 0x7340
movslq 0x10(%rbx), %rax
movslq %r12d, %rcx
addq %rax, %rcx
movq 0x18(%rsp), %rax
movq (%rax), %rax
movb -0x1(%rax,%rcx), %al
leaq 0x20(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq 0x8(%rsp), %rdi
callq 0x7340
movq %rax, %rdi
callq 0x7150
movq 0x354f3(%rip), %rdi     # 0x53fe8
leaq 0x25e49(%rip), %rsi     # 0x44945
movl $0xd, %edx
callq 0x7340
movq (%r14), %rax
movq (%rax,%r13,8), %rax
movl -0x4(%rax,%rbp,4), %esi
movq 0x354d0(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movq 0x354bc(%rip), %rdi     # 0x53fe8
leaq 0x25e20(%rip), %rsi     # 0x44953
movl $0xb, %edx
callq 0x7340
movq (%r14), %rax
movq -0x8(%rax,%r13,8), %rax
movl (%rax,%r15,4), %esi
movq 0x35498(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movl $0x1, %edi
callq 0x73b0
jmp 0x1eb6d
jmp 0x1eb8f
jmp 0x1eb6d
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1eb92
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72f0
jmp 0x1eb92
jmp 0x1eb8f
movq %rax, %rbx
movq 0x353ff(%rip), %rsi     # 0x53f98
leaq 0x50(%rsp), %rdi
callq 0x7210
leaq 0xd0(%rsp), %rdi
callq 0x7100
movq %rbx, %rdi
callq 0x7600