// File: /workspace/github_cpp_makefile_star2_O1/readmapping[P]alfalfa/src/dp.cpp
// Function: dynProg::findTraceBackPosStatic(int*, int*, dp_type const&)
int dynProg::findTraceBackPosStatic(int* const i, int* const j,const dp_type& type){
    //find beginPosition for traceBack and find dpScore
    int maximum = M[*i][*j];
    int bandCorrection = 0;
    int bandL = max(bandLeft, bandSize);
    int bandR = max(bandRight, bandSize);
    if((type.freeQueryE && type.freeRefE) || (type.freeQueryB && type.freeRefB) || type.local){//local
        if(!banded){
            for(int idx = L2; idx >= 0; idx--){
                for(int idx2 = L1; idx2 >= 0; idx2--){
                    if(M[idx][idx2] > maximum){
                        maximum = M[idx][idx2];
                        *i = idx;
                        *j = idx2;
                    }
                }
            }
        }
        else{
            for(int idx = L2; idx >= 0; idx--){
                for(int idx2 = min(bandCorrection+idx+bandR,L1); idx2 >= max(0,bandCorrection+idx-bandL); idx2--){
                    if(M[idx][idx2] > maximum){
                        maximum = M[idx][idx2];
                        *i = idx;
                        *j = idx2;
                    }
                }
            }
        }
    }
    else if(type.freeQueryE || type.freeQueryB){//banded update
        for(int idx = min(L2, bandCorrection + L1 + bandR); 
                idx >= min(L2, max(0, bandCorrection + L1 - bandL)); 
                idx--){
            if(M[idx][*j] > maximum){
                maximum = M[idx][*j];
                *i = idx;
            }
        }
    }
    else if(type.freeRefE || type.freeRefB){
        for(int idx = min(L1, bandCorrection + L2 + bandR); 
                idx >= min(L1, max(0, bandCorrection + L2 - bandL)); 
                idx--){
            if(M[*i][idx] > maximum){
                maximum = M[*i][idx];
                *j = idx;
            }
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rdi), %rax
movslq (%rsi), %r8
movq (%rax,%r8,8), %r8
movslq (%rdx), %r10
movl 0x2c(%rdi), %r9d
movl 0x28(%rdi), %r11d
cmpl %r11d, %r9d
cmovlel %r11d, %r9d
movl (%r8,%r10,4), %r8d
movl 0x30(%rdi), %ebx
cmpl %r11d, %ebx
movl %r11d, %r10d
cmovgl %ebx, %r10d
movb 0x3(%rcx), %bpl
cmpb $0x1, %bpl
jne 0x1ad19
cmpb $0x0, 0x1(%rcx)
jne 0x1ad32
movb 0x2(%rcx), %r14b
cmpb $0x1, %r14b
jne 0x1ad28
cmpb $0x0, (%rcx)
jne 0x1ad32
cmpb $0x1, 0x4(%rcx)
jne 0x1adec
movl 0x24(%rdi), %ecx
cmpb $0x0, 0x34(%rdi)
je 0x1ada9
testl %ecx, %ecx
js 0x1aef3
leal (%rcx,%r10), %r11d
movslq %r11d, %r11
xorl %ebx, %ebx
movslq 0x20(%rdi), %r14
leal (%r10,%rcx), %r15d
cmpl %r15d, %r14d
cmovll %r14d, %r15d
movl %ecx, %ebp
subl %r9d, %ebp
testl %ebp, %ebp
cmovlel %ebx, %ebp
cmpl %ebp, %r15d
jl 0x1ad95
movq (%rax,%rcx,8), %r15
cmpq %r14, %r11
cmovlq %r11, %r14
movl %ebp, %r12d
movl (%r15,%r14,4), %ebp
cmpl %r8d, %ebp
jle 0x1ad89
movl %ecx, (%rsi)
movl %r14d, (%rdx)
movl %ebp, %r8d
leaq -0x1(%r14), %r13
cmpq %r12, %r14
movq %r13, %r14
jg 0x1ad78
leaq -0x1(%rcx), %r14
decq %r11
testq %rcx, %rcx
movq %r14, %rcx
jg 0x1ad4c
jmp 0x1aef3
testl %ecx, %ecx
js 0x1aef3
movslq 0x20(%rdi), %r9
testq %r9, %r9
js 0x1addb
movq (%rax,%rcx,8), %r10
movl (%r10,%r9,4), %r11d
cmpl %r8d, %r11d
jle 0x1adcf
movl %ecx, (%rsi)
movl %r9d, (%rdx)
movl %r11d, %r8d
leaq -0x1(%r9), %r11
testq %r9, %r9
movq %r11, %r9
jg 0x1adbe
leaq -0x1(%rcx), %r9
testq %rcx, %rcx
movq %r9, %rcx
jg 0x1adb1
jmp 0x1aef3
orb %r14b, %bpl
cmpb $0x1, %bpl
jne 0x1ae73
movslq 0x20(%rdi), %r14
addl %r14d, %r10d
movslq 0x24(%rdi), %r15
movl %r14d, %ebp
subl %r9d, %ebp
xorl %ecx, %ecx
testl %ebp, %ebp
cmovlel %ecx, %ebp
cmpl %r15d, %ebp
cmovgel %r15d, %ebp
cmpl %ebp, %r10d
jl 0x1aef3
cmpl %ebx, %r11d
cmovgl %r11d, %ebx
movslq %ebx, %r10
addq %r14, %r10
cmpq %r15, %r10
cmovgeq %r15, %r10
movq (%rax,%r10,8), %r11
movslq (%rdx), %rbx
movl (%r11,%rbx,4), %r11d
cmpl %r8d, %r11d
jle 0x1ae47
movl %r10d, (%rsi)
movl %r11d, %r8d
movl 0x20(%rdi), %r11d
subl %r9d, %r11d
testl %r11d, %r11d
cmovlel %ecx, %r11d
movl 0x24(%rdi), %ebx
cmpl %ebx, %r11d
cmovgel %ebx, %r11d
leaq -0x1(%r10), %rbx
movslq %r11d, %r11
cmpq %r11, %r10
movq %rbx, %r10
jg 0x1ae31
jmp 0x1aef3
cmpb $0x0, 0x1(%rcx)
jne 0x1ae7e
cmpb $0x1, (%rcx)
jne 0x1aef3
movslq 0x24(%rdi), %r14
addl %r14d, %r10d
movslq 0x20(%rdi), %r15
movl %r14d, %ebp
subl %r9d, %ebp
xorl %ecx, %ecx
testl %ebp, %ebp
cmovlel %ecx, %ebp
cmpl %r15d, %ebp
cmovgel %r15d, %ebp
cmpl %ebp, %r10d
jl 0x1aef3
cmpl %ebx, %r11d
cmovgl %r11d, %ebx
movslq %ebx, %r10
addq %r14, %r10
cmpq %r15, %r10
cmovgeq %r15, %r10
movslq (%rsi), %r11
movq (%rax,%r11,8), %r11
movl (%r11,%r10,4), %r11d
cmpl %r8d, %r11d
jle 0x1aecc
movl %r10d, (%rdx)
movl %r11d, %r8d
movl 0x24(%rdi), %r11d
subl %r9d, %r11d
testl %r11d, %r11d
cmovlel %ecx, %r11d
movl 0x20(%rdi), %ebx
cmpl %ebx, %r11d
cmovgel %ebx, %r11d
leaq -0x1(%r10), %rbx
movslq %r11d, %r11
cmpq %r11, %r10
movq %rbx, %r10
jg 0x1aeb6
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq