// File: /workspace/github_cpp_makefile_star2_O1/readmapping[P]alfalfa/src/dp.cpp
// Function: dynProg::dpTraceBackOptFull(int&, int&, dp_type const&, 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::dpTraceBackOptFull(int& i, int& j, const dp_type& type, 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);
    bool local = type.local || (type.freeQueryB && type.freeRefB);
    int bandCorrection = 0;
    while( (i > qBound && j > rBound) || local){
        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 ] == M[ i ][ j-1 ] + scores.extendGap || i==0)){
            ss << 'D';
            output.editDist++;
            j-- ;
        }
        else if(i > 0 && j < i+bandCorrection + bandR && (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; 
            }
            cerr << "BandSize " << max(max(bandSize, bandL), bandR) << 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 %r9, %r12
movq %r8, 0x20(%rsp)
movq %rdx, %rbx
movq %rdi, %r14
movl 0x28(%rdi), %edx
movl 0x2c(%rdi), %eax
cmpl %edx, %eax
cmovlel %edx, %eax
movl %eax, 0x1c(%rsp)
movl 0x30(%rdi), %eax
cmpl %edx, %eax
cmovgl %eax, %edx
movl %edx, 0x18(%rsp)
movq %rsi, %r15
movb $0x1, %bpl
cmpb $0x0, 0x4(%rcx)
jne 0x1c34c
cmpb $0x1, 0x2(%rcx)
jne 0x1c34a
movb (%rcx), %bpl
jmp 0x1c34c
xorl %ebp, %ebp
movl (%r15), %edx
testl %edx, %edx
setg %cl
movl (%rbx), %eax
testl %eax, %eax
setg %sil
movl %ecx, %edi
andb %sil, %dil
orb %bpl, %dil
testb $0x1, %dil
je 0x1c56c
addq $0x10, %r12
movq %rbx, 0x10(%rsp)
movl %ecx, %r8d
andb %sil, %r8b
testb $0x1, %r8b
je 0x1c3b2
movl %eax, %edi
cmpb $0x0, 0x68(%rsp)
je 0x1c3b7
movq 0x70(%rsp), %r9
movq (%r9), %r9
movq 0x60(%rsp), %r10
addq (%r10), %r9
addq %r9, %rdi
decq %rdi
movl 0x10(%r10), %r9d
addl %edx, %r9d
movq $-0x1, %r10
jmp 0x1c3de
xorl %r9d, %r9d
jmp 0x1c3f4
movq 0x60(%rsp), %r10
movq 0x8(%r10), %r9
subq %rdi, %r9
movq 0x70(%rsp), %rdi
movq (%rdi), %rdi
addq %r9, %rdi
incq %rdi
movl 0x14(%r10), %r9d
subl %edx, %r9d
movl $0x1, %r10d
movslq %r9d, %r9
movq 0x78(%rsp), %r11
addq (%r11), %r9
movb (%rdi), %dil
cmpb (%r10,%r9), %dil
sete %r9b
movl %edx, %edi
testb $0x1, %r8b
je 0x1c445
movq (%r14), %r10
movq 0x38(%r14), %r11
movq -0x8(%r10,%rdi,8), %r13
movq (%r10,%rdi,8), %r10
movl %eax, %ebx
movl (%r11), %r11d
addl -0x4(%r13,%rbx,4), %r11d
cmpl %r11d, (%r10,%rbx,4)
movq 0x10(%rsp), %rbx
sete %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x1c445
movb $0x3d, 0xa(%rsp)
movl $0x1, %edx
movq %r12, %rdi
leaq 0xa(%rsp), %rsi
callq 0x7340
jmp 0x1c48b
testb $0x1, %r8b
je 0x1c493
movq (%r14), %r8
movq 0x38(%r14), %r9
movq -0x8(%r8,%rdi,8), %r10
movq (%r8,%rdi,8), %r8
movl %eax, %r11d
movl 0x4(%r9), %r9d
addl -0x4(%r10,%r11,4), %r9d
cmpl %r9d, (%r8,%r11,4)
jne 0x1c493
movb $0x58, 0xb(%rsp)
movl $0x1, %edx
movq %r12, %rdi
leaq 0xb(%rsp), %rsi
callq 0x7340
movq 0x20(%rsp), %rax
incl (%rax)
decl (%r15)
jmp 0x1c545
movl %edx, %r8d
subl 0x1c(%rsp), %r8d
cmpl %r8d, %eax
setg %r8b
andb %r8b, %sil
cmpb $0x1, %sil
jne 0x1c4cf
testl %edx, %edx
je 0x1c527
movslq %edx, %rsi
movq (%r14), %r8
movq 0x38(%r14), %r9
movq (%r8,%rsi,8), %rsi
movl %eax, %r8d
movl 0xc(%r9), %r9d
addl -0x4(%rsi,%r8,4), %r9d
cmpl %r9d, (%rsi,%r8,4)
je 0x1c527
addl 0x18(%rsp), %edx
cmpl %edx, %eax
setl %dl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x1c57d
testl %eax, %eax
je 0x1c504
movq (%r14), %rcx
movq 0x38(%r14), %rdx
movq -0x8(%rcx,%rdi,8), %rsi
movq (%rcx,%rdi,8), %rcx
cltq
movl 0xc(%rdx), %edx
addl (%rsi,%rax,4), %edx
cmpl %edx, (%rcx,%rax,4)
jne 0x1c57d
movb $0x49, 0xd(%rsp)
movl $0x1, %edx
movq %r12, %rdi
leaq 0xd(%rsp), %rsi
callq 0x7340
movq 0x20(%rsp), %rax
incl (%rax)
movq %r15, %rax
jmp 0x1c548
movb $0x44, 0xc(%rsp)
movl $0x1, %edx
movq %r12, %rdi
leaq 0xc(%rsp), %rsi
callq 0x7340
movq 0x20(%rsp), %rax
incl (%rax)
movq %rbx, %rax
decl (%rax)
movl (%r15), %edx
testl %edx, %edx
setg %cl
movl (%rbx), %eax
testl %eax, %eax
setg %sil
movl %ecx, %edi
andb %sil, %dil
orb %bpl, %dil
testb $0x1, %dil
jne 0x1c377
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x37a64(%rip), %r12     # 0x53fe8
leaq 0x2833d(%rip), %rsi     # 0x448c8
movl $0x1c, %edx
movq %r12, %rdi
callq 0x7340
movq %r12, %rdi
callq 0x7150
leaq 0x2833e(%rip), %rsi     # 0x448e5
movl $0x1d, %edx
movq %r12, %rdi
callq 0x7340
movq %r12, %rdi
callq 0x7150
leaq 0x28340(%rip), %rsi     # 0x44903
movl $0x9, %edx
movq %r12, %rdi
callq 0x7340
movl (%r15), %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %r13
leaq 0x28328(%rip), %rsi     # 0x4490d
movl $0x2, %edx
movq %rax, %rdi
callq 0x7340
movl (%rbx), %esi
movq %r13, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
leaq 0x28305(%rip), %rsi     # 0x44910
movl $0x10, %edx
movq %r12, %rdi
callq 0x7340
movq (%r14), %rax
movslq (%r15), %rcx
movq (%rax,%rcx,8), %rax
movslq (%rbx), %rcx
movl (%rax,%rcx,4), %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
cmpl $0x0, (%rbx)
jle 0x1c716
cmpl $0x0, (%r15)
jle 0x1c716
movq 0x37996(%rip), %r12     # 0x53fe8
leaq 0x282c8(%rip), %rsi     # 0x44921
movl $0xd, %edx
movq %r12, %rdi
callq 0x7340
movq (%r14), %rax
movslq (%r15), %rcx
movq -0x8(%rax,%rcx,8), %rax
movq 0x10(%rsp), %rbx
movslq (%rbx), %rcx
movl -0x4(%rax,%rcx,4), %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
leaq 0x2829b(%rip), %rsi     # 0x4492f
movl $0xb, %edx
movq %r12, %rdi
callq 0x7340
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq 0x60(%rsp), %r13
addq (%r13), %rax
movslq (%rbx), %rcx
movb -0x1(%rcx,%rax), %al
leaq 0xe(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r12, %rdi
callq 0x7340
movq %rax, %r12
leaq 0x28292(%rip), %rsi     # 0x44969
movl $0x2, %edx
movq %rax, %rdi
callq 0x7340
movslq 0x10(%r13), %rax
movslq (%r15), %rcx
addq %rax, %rcx
movq 0x78(%rsp), %rax
movq (%rax), %rax
movb -0x1(%rax,%rcx), %al
leaq 0xf(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r12, %rdi
callq 0x7340
movq %rax, %rdi
callq 0x7150
movq 0x378cb(%rip), %r12     # 0x53fe8
leaq 0x28217(%rip), %rsi     # 0x4493b
movl $0x9, %edx
movq %r12, %rdi
callq 0x7340
movl 0x28(%r14), %eax
movl 0x1c(%rsp), %esi
cmpl %esi, %eax
cmovgl %eax, %esi
movl 0x18(%rsp), %eax
cmpl %eax, %esi
cmovlel %eax, %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x1c7a2
movq 0x37880(%rip), %r12     # 0x53fe8
leaq 0x281d6(%rip), %rsi     # 0x44945
movl $0xd, %edx
movq %r12, %rdi
callq 0x7340
movq (%r14), %rax
movslq (%r15), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rsp), %rcx
movslq (%rcx), %rcx
movl -0x4(%rax,%rcx,4), %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
cmpl $0x0, (%r15)
jle 0x1c7e9
movq 0x37839(%rip), %r12     # 0x53fe8
leaq 0x2819d(%rip), %rsi     # 0x44953
movl $0xb, %edx
movq %r12, %rdi
callq 0x7340
movq (%r14), %rax
movslq (%r15), %rcx
movq -0x8(%rax,%rcx,8), %rax
movq 0x10(%rsp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %esi
movq %r12, %rdi
callq 0x75d0
movq %rax, %rdi
callq 0x7150
movl $0x1, %edi
callq 0x73b0
nop