// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movq %rcx, 0x18(%rsp)
movl 0x28(%rdi), %ecx
movl 0x2c(%rdi), %eax
cmpl %ecx, %eax
cmovlel %ecx, %eax
movl %eax, 0x14(%rsp)
movl 0x30(%rdi), %eax
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x24(%rsp)
movl (%rsi), %eax
testl %eax, %eax
jle 0x1b96a
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 0x1b96a
cmpb $0x0, 0x60(%rsp)
je 0x1b846
movq 0x68(%rsp), %rdx
movq (%rdx), %rdx
addq (%r12), %rdx
leaq (%rcx,%rdx), %rdi
decq %rdi
movl 0x10(%r12), %r8d
addl %eax, %r8d
movq $-0x1, %r9
jmp 0x1b86b
movq 0x8(%r12), %rdx
subq %rcx, %rdx
movq 0x68(%rsp), %rsi
movq (%rsi), %rsi
leaq (%rsi,%rdx), %rdi
incq %rdi
movl 0x14(%r12), %r8d
subl %eax, %r8d
movl $0x1, %r9d
movl %eax, %edx
movq (%r15), %rsi
movq 0x38(%r15), %r10
movq -0x8(%rsi,%rdx,8), %r11
movq (%rsi,%rdx,8), %rsi
movl (%rsi,%rcx,4), %esi
movl -0x4(%r11,%rcx,4), %r11d
movl (%r10), %ebp
addl %r11d, %ebp
cmpl %ebp, %esi
jne 0x1b8bd
movslq %r8d, %r8
movq 0x70(%rsp), %rbp
addq (%rbp), %r8
movb (%r9,%r8), %r8b
cmpb %r8b, (%rdi)
jne 0x1b8bd
movb $0x3d, 0xe(%rsp)
movl $0x1, %edx
movq %r13, %rdi
leaq 0xe(%rsp), %rsi
callq 0x7340
jmp 0x1b8e4
addl 0x4(%r10), %r11d
cmpl %r11d, %esi
jne 0x1b8f6
movb $0x58, 0xf(%rsp)
movl $0x1, %edx
movq %r13, %rdi
leaq 0xf(%rsp), %rsi
callq 0x7340
movq 0x18(%rsp), %rax
incl (%rax)
decl (%r14)
decl (%rbx)
movl (%r14), %eax
testl %eax, %eax
jg 0x1b80f
jmp 0x1b96a
movl %eax, %edi
subl 0x14(%rsp), %edi
cmpl %edi, %ecx
jle 0x1b92d
movq 0x10(%r15), %rdi
movq (%rdi,%rdx,8), %rdi
cmpl (%rdi,%rcx,4), %esi
jne 0x1b92d
movb $0x44, 0x10(%rsp)
movl $0x1, %edx
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
callq 0x7340
movq 0x18(%rsp), %rax
incl (%rax)
jmp 0x1b8e7
addl 0x24(%rsp), %eax
cmpl %eax, %ecx
jge 0x1b97b
movq 0x8(%r15), %rax
movq (%rax,%rdx,8), %rax
cmpl (%rax,%rcx,4), %esi
jne 0x1b97b
movb $0x49, 0x11(%rsp)
movl $0x1, %edx
movq %r13, %rdi
leaq 0x11(%rsp), %rsi
callq 0x7340
movq 0x18(%rsp), %rax
incl (%rax)
movl (%r14), %eax
decl %eax
movl %eax, (%r14)
jmp 0x1b8ec
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38666(%rip), %r13     # 0x53fe8
leaq 0x28f3f(%rip), %rsi     # 0x448c8
movl $0x1c, %edx
movq %r13, %rdi
callq 0x7340
movq %r13, %rdi
callq 0x7150
leaq 0x28f40(%rip), %rsi     # 0x448e5
movl $0x1d, %edx
movq %r13, %rdi
callq 0x7340
movq %r13, %rdi
callq 0x7150
leaq 0x28f42(%rip), %rsi     # 0x44903
movl $0x9, %edx
movq %r13, %rdi
callq 0x7340
movl (%r14), %esi
movq %r13, %rdi
callq 0x75d0
movq %rax, %rbp
leaq 0x28f2a(%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 0x28f07(%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 0x1bb0b
cmpl $0x0, (%r14)
jle 0x1bb0b
movq 0x38598(%rip), %r13     # 0x53fe8
leaq 0x28eca(%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 0x28ea2(%rip), %rsi     # 0x4492f
movl $0xb, %edx
movq %r13, %rdi
callq 0x7340
movq 0x68(%rsp), %rax
movq (%rax), %rax
addq (%r12), %rax
movslq (%rbx), %rcx
movb -0x1(%rcx,%rax), %al
leaq 0x12(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r13, %rdi
callq 0x7340
movq %rax, %r13
leaq 0x28e9e(%rip), %rsi     # 0x44969
movl $0x2, %edx
movq %rax, %rdi
callq 0x7340
movslq 0x10(%r12), %rax
movslq (%r14), %rcx
addq %rax, %rcx
movq 0x70(%rsp), %rax
movq (%rax), %rax
movb -0x1(%rax,%rcx), %al
leaq 0x13(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r13, %rdi
callq 0x7340
movq %rax, %rdi
callq 0x7150
movq 0x384d6(%rip), %r12     # 0x53fe8
leaq 0x28e22(%rip), %rsi     # 0x4493b
movl $0x9, %edx
movq %r12, %rdi
callq 0x7340
movl 0x28(%r15), %eax
movl 0x14(%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 0x1bb8d
movq 0x38490(%rip), %r12     # 0x53fe8
leaq 0x28de6(%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 0x1bbcf
movq 0x3844e(%rip), %r12     # 0x53fe8
leaq 0x28db2(%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