// File: /workspace/github_cpp_makefile_star2_O3/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, 0x48(%rsp)
movq %rcx, %rbx
movq %rdx, 0x18(%rsp)
movq %rsi, 0x10(%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, 0x8(%rsp)
movq %r8, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a78e
movq (%r14), %rax
movq (%rax), %rcx
movl $0x0, (%rcx)
movl 0x24(%r14), %r12d
testl %r12d, %r12d
jle 0x1e1dc
movq 0x8(%rsp), %rdx
movb 0x2(%rdx), %dl
movq 0x38(%r14), %rsi
movl $0x1, %edi
xorl %r8d, %r8d
testb %dl, %dl
jne 0x1e1c5
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), %r12
cmpq %r12, %rdi
movq %r8, %rdi
jl 0x1e1b2
movl 0x20(%r14), %r15d
testl %r15d, %r15d
jle 0x1e220
movq 0x8(%rsp), %rdx
movb (%rdx), %dl
movq 0x38(%r14), %rsi
movl $0x1, %edi
xorl %r8d, %r8d
testb %dl, %dl
jne 0x1e208
movl 0xc(%rsi), %r8d
imull %edi, %r8d
addl 0x8(%rsi), %r8d
movl %r8d, (%rcx,%rdi,4)
leaq 0x1(%rdi), %r8
movslq 0x20(%r14), %r15
cmpq %r15, %rdi
movq %r8, %rdi
jl 0x1e1f5
movl 0x24(%r14), %r12d
testl %r12d, %r12d
jle 0x1e2cd
movq 0x38(%r14), %rcx
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
addq (%rbx), %rdx
leaq 0x10(%rcx), %rsi
movq 0x18(%rsp), %rdi
movq (%rdi), %rdi
decq %rdi
movq %rdi, (%rsp)
movl $0x1, %r8d
testl %r15d, %r15d
jle 0x1e2bc
movq (%rsp), %rdi
leaq (%rdi,%r8), %r9
movq -0x8(%rax,%r8,8), %r10
movq (%rax,%r8,8), %r11
movl (%r11), %ebp
xorl %r12d, %r12d
movsbq (%rdx,%r12), %r15
movslq 0x10(%rbx), %r13
movsbq (%r9,%r13), %r13
imulq $0x1fc, %r15, %r15      # imm = 0x1FC
addq %rsi, %r15
movl (%r10,%r12,4), %edi
addl (%r15,%r13,4), %edi
addl 0xc(%rcx), %ebp
cmpl %ebp, %edi
cmovgl %edi, %ebp
movl %ebp, 0x4(%r11,%r12,4)
movl 0xc(%rcx), %edi
addl 0x4(%r10,%r12,4), %edi
cmpl %edi, %ebp
cmovlel %edi, %ebp
movl %ebp, 0x4(%r11,%r12,4)
movslq 0x20(%r14), %r15
incq %r12
cmpq %r15, %r12
jl 0x1e26d
movl 0x24(%r14), %r12d
leaq 0x1(%r8), %r10
movslq %r12d, %r9
cmpq %r9, %r8
movq %r10, %r8
jl 0x1e251
jmp 0x1e2d0
movslq %r12d, %r9
movq 0x210(%rsp), %r13
movq (%rax,%r9,8), %rcx
movslq %r15d, %rdx
movl (%rcx,%rdx,4), %eax
testl %edx, %edx
js 0x1e301
movl %r15d, %edx
movl (%rcx,%rdx,4), %esi
cmpl %eax, %esi
cmovgl %edx, %r15d
cmovgl %esi, %eax
addq $-0x1, %rdx
jb 0x1e2e9
movslq %r15d, %rdx
movl (%rcx,%rdx,4), %eax
movl %eax, 0x4(%r13)
movq 0x48(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x1e61c
movq 0x8(%rsp), %rax
cmpb $0x1, 0x1(%rax)
jne 0x1e331
cmpl 0x20(%r14), %r15d
jge 0x1e331
movq (%rbx), %rax
addq %rdx, %rax
decq %rax
movq %rax, 0x8(%rbx)
leaq 0x50(%rsp), %rdi
callq 0x71e0
testl %r12d, %r12d
jle 0x1e471
movq (%r14), %rcx
testl %r15d, %r15d
jle 0x1e3ba
movl %r15d, %edx
movl %r12d, %ebp
movq -0x8(%rcx,%rbp,8), %rax
movq (%rcx,%rbp,8), %rcx
movl (%rcx,%rdx,4), %esi
movl -0x4(%rax,%rdx,4), %r8d
movq 0x38(%r14), %rdi
movl (%rdi), %r9d
addl %r8d, %r9d
cmpl %r9d, %esi
jne 0x1e410
movq 0x10(%rsp), %r9
movq (%r9), %r9
addq (%rbx), %r9
movslq 0x10(%rbx), %r10
movslq %r12d, %r11
addq %r10, %r11
movq 0x18(%rsp), %r10
movq (%r10), %r10
movb -0x1(%r10,%r11), %r10b
cmpb %r10b, -0x1(%rdx,%r9)
jne 0x1e410
movb $0x3d, 0x20(%rsp)
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7340
jmp 0x1e436
movl %r12d, %ebp
movq -0x8(%rcx,%rbp,8), %rax
movq (%rcx,%rbp,8), %rcx
movq 0x38(%r14), %rdx
movl 0xc(%rdx), %edi
movslq %r15d, %r13
addl (%rax,%r13,4), %edi
cmpl %edi, (%rcx,%r13,4)
je 0x1e3e3
testl %r15d, %r15d
jne 0x1e645
movb $0x49, 0x20(%rsp)
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7340
movq 0x210(%rsp), %r13
incl (%r13)
decl %r12d
jmp 0x1e33b
addl 0x4(%rdi), %r8d
cmpl %r8d, %esi
jne 0x1e441
movb $0x58, 0x20(%rsp)
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7340
incl (%r13)
decl %r12d
decl %r15d
jmp 0x1e33b
movl 0xc(%rdi), %edi
movl -0x4(%rcx,%rdx,4), %edx
addl %edi, %edx
cmpl %edx, %esi
jne 0x1e3cd
movb $0x44, 0x20(%rsp)
movl $0x1, %edx
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7340
incl (%r13)
jmp 0x1e439
testl %r15d, %r15d
jle 0x1e484
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x1e484
addl %r15d, (%r13)
movq 0x48(%rsp), %rax
movl (%rax), %eax
addl $-0x3, %eax
cmpl $0x1, %eax
ja 0x1e5fe
leaq 0x68(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x7540
testl %r15d, %r15d
jle 0x1e4ce
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x1e4ce
movl %r15d, %ecx
leaq 0x20(%rsp), %rdi
movq 0x8(%rdi), %rsi
xorl %edx, %edx
movl $0x44, %r8d
callq 0x7670
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %r8
testq %r8, %r8
setne %dl
leaq (%rax,%r8), %rcx
decq %rcx
cmpq %rax, %rcx
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x1e518
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 0x1e4f8
movq 0x28(%rsp), %r8
testl %r8d, %r8d
jle 0x1e5e3
movq 0x210(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
addq $0x20, %rax
movq %rax, 0x10(%rsp)
movl %r8d, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq %r8, (%rsp)
movl %r14d, %r12d
movq 0x20(%rsp), %rax
movslq %r14d, %rcx
leaq (%rax,%rcx), %rdx
leal 0x1(%rcx), %esi
cmpl %r8d, %esi
cmovlel %r8d, %esi
incq %rcx
cmpq %r13, %rcx
jge 0x1e57e
movb (%rax,%rcx), %dil
incl %r14d
incq %rcx
cmpb (%rdx), %dil
je 0x1e568
jmp 0x1e581
movl %esi, %r14d
movq 0x210(%rsp), %rbp
movq 0x10(%rbp), %rsi
cmpq 0x18(%rbp), %rsi
je 0x1e59d
movb (%rdx), %al
movb %al, (%rsi)
incq 0x10(%rbp)
jmp 0x1e5a7
movq 0x18(%rsp), %rdi
callq 0x1e8b4
movl %r14d, %eax
subl %r12d, %eax
movl %eax, 0x44(%rsp)
movq 0x28(%rbp), %rsi
cmpq 0x30(%rbp), %rsi
je 0x1e5c7
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rbp)
jmp 0x1e5d6
movq 0x10(%rsp), %rdi
leaq 0x44(%rsp), %rdx
callq 0x1e9a6
movq (%rsp), %r8
cmpl %r8d, %r14d
jl 0x1e54c
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1e5fe
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72f0
movq 0x35993(%rip), %rsi     # 0x53f98
leaq 0x50(%rsp), %rdi
callq 0x7210
leaq 0xd0(%rsp), %rdi
callq 0x7100
testl %r15d, %r15d
jle 0x1e631
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x1e631
movl %r15d, %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 0x3599c(%rip), %rdi     # 0x53fe8
leaq 0x26275(%rip), %rsi     # 0x448c8
movl $0x1c, %edx
callq 0x7340
movq 0x35984(%rip), %rdi     # 0x53fe8
callq 0x7150
movq 0x35978(%rip), %rdi     # 0x53fe8
leaq 0x2626e(%rip), %rsi     # 0x448e5
movl $0x1d, %edx
callq 0x7340
movq 0x35960(%rip), %rdi     # 0x53fe8
callq 0x7150
movq 0x35954(%rip), %rdi     # 0x53fe8
leaq 0x26268(%rip), %rsi     # 0x44903
movl $0x9, %edx
callq 0x7340
movq 0x3593c(%rip), %rdi     # 0x53fe8
movl %r12d, %esi
callq 0x75d0
movq %rax, (%rsp)
leaq 0x2624e(%rip), %rsi     # 0x4490d
movl $0x2, %edx
movq (%rsp), %rdi
callq 0x7340
movq (%rsp), %rdi
movl %r15d, %esi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movq 0x35900(%rip), %rdi     # 0x53fe8
leaq 0x26221(%rip), %rsi     # 0x44910
movl $0x10, %edx
callq 0x7340
movq (%r14), %rax
movq (%rax,%rbp,8), %rax
movl (%rax,%r13,4), %esi
movq 0x358dd(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rdi
callq 0x7150
testl %r15d, %r15d
jle 0x1e821
movq 0x358c0(%rip), %rdi     # 0x53fe8
leaq 0x261f2(%rip), %rsi     # 0x44921
movl $0xd, %edx
callq 0x7340
movq (%r14), %rax
movq -0x8(%rax,%rbp,8), %rax
movl %r15d, %r15d
movl -0x4(%rax,%r15,4), %esi
movq 0x35898(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movq 0x35884(%rip), %rdi     # 0x53fe8
leaq 0x261c4(%rip), %rsi     # 0x4492f
movl $0xb, %edx
callq 0x7340
movq 0x10(%rsp), %rax
movq (%rax), %rax
addq (%rbx), %rax
movb -0x1(%r13,%rax), %al
leaq 0x20(%rsp), %rsi
movb %al, (%rsi)
movq 0x35855(%rip), %rdi     # 0x53fe8
movl $0x1, %edx
callq 0x7340
movq %rax, (%rsp)
leaq 0x261c1(%rip), %rsi     # 0x44969
movl $0x2, %edx
movq (%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 (%rsp), %rdi
callq 0x7340
movq %rax, %rdi
callq 0x7150
movq 0x357f8(%rip), %rdi     # 0x53fe8
leaq 0x2614e(%rip), %rsi     # 0x44945
movl $0xd, %edx
callq 0x7340
movq (%r14), %rax
movq (%rax,%rbp,8), %rax
movl -0x4(%rax,%r15,4), %esi
movq 0x357d4(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movq 0x357c0(%rip), %rdi     # 0x53fe8
leaq 0x26124(%rip), %rsi     # 0x44953
movl $0xb, %edx
callq 0x7340
movq (%r14), %rax
movq -0x8(%rax,%rbp,8), %rax
movl (%rax,%r13,4), %esi
movq 0x3579c(%rip), %rdi     # 0x53fe8
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movl $0x1, %edi
callq 0x73b0
jmp 0x1e869
jmp 0x1e88b
jmp 0x1e869
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1e88e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72f0
jmp 0x1e88e
jmp 0x1e88b
movq %rax, %rbx
movq 0x35703(%rip), %rsi     # 0x53f98
leaq 0x50(%rsp), %rdi
callq 0x7210
leaq 0xd0(%rsp), %rdi
callq 0x7100
movq %rbx, %rdi
callq 0x7600