// File: /workspace/github_cpp_makefile_star2_O3/readmapping[P]alfalfa/src/dp.cpp
// Function: dynProg::dpTraceBackScore(int&, int&, boundaries const&, dp_output&, 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 dynProg::dpTraceBackScore(int& i, int& j, const boundaries& offset, dp_output& output, const string& ref, const string& query){
    //TODO: after mallocs: change this traversal to row-order
    //change stringstream to char array of length dimensions array
    int qBound = 0; int rBound = 0;
    while( (i > qBound && j > rBound)){
        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){
            i-- ;  j-- ;
        }
        else if(j > 0 && i > 0 && M[ i ][ j ] == M[ i-1 ][ j-1 ] + scores.mismatch){
            output.editDist++;
            i-- ;  j-- ;
        }
        else if(j > 0 && (M[ i ][ j ] == LEFT[ i ][ j ] || i==0)){
            output.editDist++;
            j-- ;
        }
        else if(i > 0 && (M[ i ][ j ] == UP[ i ][ j ] || j==0)){
            output.editDist++;
            i-- ;
        }
        else{
            cerr << "Error in dynamic programming" << endl;
            cerr << "No valid trace position found" << endl;
            cerr << "Position " << i << ", " << j << endl;
            exit(1);
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl (%rsi), %r11d
testl %r11d, %r11d
jle 0x1dee6
movq %rdx, %rbx
movq %rsi, %r14
movq 0x50(%rsp), %rdx
movq (%rcx), %rax
movq (%r9), %rsi
leaq -0x1(%rsi,%rax), %rax
movq (%rdx), %rdx
movq (%rdi), %rsi
movq 0x8(%rdi), %r9
movq %r9, 0x8(%rsp)
movq 0x38(%rdi), %r10
movq 0x10(%rdi), %rdi
movq %rdi, 0x10(%rsp)
movslq (%rbx), %r15
testq %r15, %r15
jle 0x1dee6
movl %r11d, %r12d
movq -0x8(%rsi,%r12,8), %r13
movq (%rsi,%r12,8), %rbp
movl (%rbp,%r15,4), %ebp
movl -0x4(%r13,%r15,4), %r13d
movl (%r10), %r9d
addl %r13d, %r9d
cmpl %r9d, %ebp
jne 0x1de9a
movslq 0x10(%rcx), %r9
movslq %r11d, %rdi
addq %r9, %rdi
movb -0x1(%rdx,%rdi), %dil
cmpb %dil, (%rax,%r15)
jne 0x1de9a
decl %r11d
movl %r11d, (%r14)
jmp 0x1debd
addl 0x4(%r10), %r13d
cmpl %r13d, %ebp
jne 0x1deab
incl (%r8)
decl (%r14)
jmp 0x1debd
movq 0x10(%rsp), %rdi
movq (%rdi,%r12,8), %rdi
cmpl (%rdi,%r15,4), %ebp
jne 0x1dec9
incl (%r8)
decl (%rbx)
movl (%r14), %r11d
testl %r11d, %r11d
jg 0x1de50
jmp 0x1dee6
movq 0x8(%rsp), %rdi
movq (%rdi,%r12,8), %rdi
cmpl (%rdi,%r15,4), %ebp
jne 0x1def7
incl (%r8)
movl (%r14), %r11d
decl %r11d
movl %r11d, (%r14)
jmp 0x1dec2
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x360ea(%rip), %r15     # 0x53fe8
leaq 0x269c3(%rip), %rsi     # 0x448c8
movq %r15, %rdi
callq 0x72c0
movq %rax, %rdi
callq 0x7150
leaq 0x269c9(%rip), %rsi     # 0x448e5
movq %r15, %rdi
callq 0x72c0
movq %rax, %rdi
callq 0x7150
leaq 0x269d0(%rip), %rsi     # 0x44903
movq %r15, %rdi
callq 0x72c0
movl (%r14), %esi
movq %rax, %rdi
callq 0x75d0
leaq 0x269c0(%rip), %rsi     # 0x4490d
movq %rax, %rdi
callq 0x72c0
movl (%rbx), %esi
movq %rax, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movl $0x1, %edi
callq 0x73b0
nop