// File: /workspace/github_cpp_makefile_star2_O1/readmapping[P]alfalfa/src/dp.cpp
// Function: dynProg::dpTraceBackFull(int&, int&, dp_output&, std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char>>&, boundaries const&, bool, 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::dpTraceBackFull(int& i, int& j, dp_output& output, std::stringstream & ss, 
        const boundaries& offset, bool forward, 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;
    int bandL = max(bandLeft, bandSize);
    int bandR = max(bandRight, bandSize);
    int bandCorrection = 0;
    while( (i > qBound && j > rBound)){
        bool equal = false;
        if(j > 0 && i > 0)
            equal = forward ? ref[offset.refB+j-1] == query[offset.queryB+i-1] : ref[offset.refE-j+1] == query[offset.queryE-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 && j > i+bandCorrection - bandL && (M[ i ][ j ] == LEFT[ i ][ j ] || i==0)){
            ss << 'D';
            output.editDist++;
            j-- ;
        }
        else if(i > 0 && j < i+bandCorrection + bandR && (M[ i ][ j ] == UP[ i ][ j ] || 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; 
            }
            cerr << "BandSize " << max(max(bandSize, bandL), bandRight) << 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);
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, 0x10(%rsp)
movl 0x28(%rdi), %ebp
movl 0x2c(%rdi), %eax
cmpl %ebp, %eax
cmovlel %ebp, %eax
movl %eax, 0xc(%rsp)
movl 0x30(%rdi), %eax
cmpl %ebp, %eax
cmovgl %eax, %ebp
movl (%rsi), %eax
testl %eax, %eax
jle 0x1bbce
movq %r9, %r12
movq %r8, %r13
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
addq $0x10, %r13
movslq (%rbx), %rcx
testq %rcx, %rcx
jle 0x1bbce
cmpb $0x0, 0x50(%rsp)
je 0x1ba87
movq 0x58(%rsp), %rdx
movq (%rdx), %rdx
addq (%r12), %rdx
leaq (%rcx,%rdx), %rsi
decq %rsi
movl 0x10(%r12), %edi
addl %eax, %edi
movq $-0x1, %r8
jmp 0x1baaa
movq 0x8(%r12), %rdx
subq %rcx, %rdx
movq 0x58(%rsp), %rsi
movq (%rsi), %rsi
addq %rdx, %rsi
incq %rsi
movl 0x14(%r12), %edi
subl %eax, %edi
movl $0x1, %r8d
movl %eax, %edx
movq (%r15), %r9
movq 0x38(%r15), %r10
movq -0x8(%r9,%rdx,8), %r11
movq (%r9,%rdx,8), %r9
movl (%r10), %r10d
addl -0x4(%r11,%rcx,4), %r10d
cmpl %r10d, (%r9,%rcx,4)
jne 0x1baf7
movslq %edi, %rdi
movq 0x60(%rsp), %r9
addq (%r9), %rdi
movb (%r8,%rdi), %dil
cmpb %dil, (%rsi)
jne 0x1baf7
movb $0x3d, 0x6(%rsp)
movl $0x1, %edx
movq %r13, %rdi
leaq 0x6(%rsp), %rsi
callq 0x7340
jmp 0x1bb32
movq (%r15), %rsi
movq 0x38(%r15), %rdi
movq -0x8(%rsi,%rdx,8), %r8
movq (%rsi,%rdx,8), %rsi
movl 0x4(%rdi), %edi
addl -0x4(%r8,%rcx,4), %edi
cmpl %edi, (%rsi,%rcx,4)
jne 0x1bb4a
movb $0x58, 0x7(%rsp)
movl $0x1, %edx
movq %r13, %rdi
leaq 0x7(%rsp), %rsi
callq 0x7340
movq 0x10(%rsp), %rax
incl (%rax)
decl (%r14)
movq %rbx, %rax
decl (%rax)
movl (%r14), %eax
testl %eax, %eax
jg 0x1ba51
jmp 0x1bbce
movl %eax, %esi
subl 0xc(%rsp), %esi
cmpl %esi, %ecx
jle 0x1bb8b
movq (%r15), %rsi
movq 0x10(%r15), %rdi
movq (%rsi,%rdx,8), %rsi
movl (%rsi,%rcx,4), %esi
movq (%rdi,%rdx,8), %rdi
cmpl (%rdi,%rcx,4), %esi
jne 0x1bb8b
movb $0x44, 0x8(%rsp)
movl $0x1, %edx
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x7340
movq 0x10(%rsp), %rax
incl (%rax)
jmp 0x1bb35
addl %ebp, %eax
cmpl %eax, %ecx
jge 0x1bbdf
movq (%r15), %rax
movq 0x8(%r15), %rsi
movq (%rax,%rdx,8), %rax
movl (%rax,%rcx,4), %eax
movq (%rsi,%rdx,8), %rdx
cmpl (%rdx,%rcx,4), %eax
jne 0x1bbdf
movb $0x49, 0x9(%rsp)
movl $0x1, %edx
movq %r13, %rdi
leaq 0x9(%rsp), %rsi
callq 0x7340
movq 0x10(%rsp), %rax
incl (%rax)
movq %r14, %rax
jmp 0x1bb38
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38402(%rip), %r13     # 0x53fe8
leaq 0x28cdb(%rip), %rsi     # 0x448c8
movl $0x1c, %edx
movq %r13, %rdi
callq 0x7340
movq %r13, %rdi
callq 0x7150
leaq 0x28cdc(%rip), %rsi     # 0x448e5
movl $0x1d, %edx
movq %r13, %rdi
callq 0x7340
movq %r13, %rdi
callq 0x7150
leaq 0x28cde(%rip), %rsi     # 0x44903
movl $0x9, %edx
movq %r13, %rdi
callq 0x7340
movl (%r14), %esi
movq %r13, %rdi
callq 0x75d0
movq %rax, %rbp
leaq 0x28cc6(%rip), %rsi     # 0x4490d
movl $0x2, %edx
movq %rax, %rdi
callq 0x7340
movl (%rbx), %esi
movq %rbp, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
leaq 0x28ca3(%rip), %rsi     # 0x44910
movl $0x10, %edx
movq %r13, %rdi
callq 0x7340
movq (%r15), %rax
movslq (%r14), %rcx
movq (%rax,%rcx,8), %rax
movslq (%rbx), %rcx
movl (%rax,%rcx,4), %esi
movq %r13, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
cmpl $0x0, (%rbx)
jle 0x1bd6f
cmpl $0x0, (%r14)
jle 0x1bd6f
movq 0x38334(%rip), %r13     # 0x53fe8
leaq 0x28c66(%rip), %rsi     # 0x44921
movl $0xd, %edx
movq %r13, %rdi
callq 0x7340
movq (%r15), %rax
movslq (%r14), %rcx
movq -0x8(%rax,%rcx,8), %rax
movslq (%rbx), %rcx
movl -0x4(%rax,%rcx,4), %esi
movq %r13, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
leaq 0x28c3e(%rip), %rsi     # 0x4492f
movl $0xb, %edx
movq %r13, %rdi
callq 0x7340
movq 0x58(%rsp), %rax
movq (%rax), %rax
addq (%r12), %rax
movslq (%rbx), %rcx
movb -0x1(%rcx,%rax), %al
leaq 0xa(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r13, %rdi
callq 0x7340
movq %rax, %r13
leaq 0x28c3a(%rip), %rsi     # 0x44969
movl $0x2, %edx
movq %rax, %rdi
callq 0x7340
movslq 0x10(%r12), %rax
movslq (%r14), %rcx
addq %rax, %rcx
movq 0x60(%rsp), %rax
movq (%rax), %rax
movb -0x1(%rax,%rcx), %al
leaq 0xb(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r13, %rdi
callq 0x7340
movq %rax, %rdi
callq 0x7150
movq 0x38272(%rip), %r12     # 0x53fe8
leaq 0x28bbe(%rip), %rsi     # 0x4493b
movl $0x9, %edx
movq %r12, %rdi
callq 0x7340
movl 0x28(%r15), %eax
movl 0xc(%rsp), %esi
cmpl %esi, %eax
cmovgl %eax, %esi
movl 0x30(%r15), %eax
cmpl %eax, %esi
cmovlel %eax, %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
cmpl $0x0, (%rbx)
jle 0x1bdf1
movq 0x3822c(%rip), %r12     # 0x53fe8
leaq 0x28b82(%rip), %rsi     # 0x44945
movl $0xd, %edx
movq %r12, %rdi
callq 0x7340
movq (%r15), %rax
movslq (%r14), %rcx
movq (%rax,%rcx,8), %rax
movslq (%rbx), %rcx
movl -0x4(%rax,%rcx,4), %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
cmpl $0x0, (%r14)
jle 0x1be33
movq 0x381ea(%rip), %r12     # 0x53fe8
leaq 0x28b4e(%rip), %rsi     # 0x44953
movl $0xb, %edx
movq %r12, %rdi
callq 0x7340
movq (%r15), %rax
movslq (%r14), %rcx
movq -0x8(%rax,%rcx,8), %rax
movslq (%rbx), %rcx
movl (%rax,%rcx,4), %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movl $0x1, %edi
callq 0x73b0
nop