// File: /workspace/github_cpp_makefile_star2_O3/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 0x1aaab
cmpb $0x0, 0x1(%rcx)
jne 0x1aac4
movb 0x2(%rcx), %r14b
cmpb $0x1, %r14b
jne 0x1aaba
cmpb $0x0, (%rcx)
jne 0x1aac4
cmpb $0x1, 0x4(%rcx)
jne 0x1ab96
movl 0x24(%rdi), %ecx
cmpb $0x0, 0x34(%rdi)
je 0x1ab53
testl %ecx, %ecx
js 0x1acb3
leal (%rcx,%r10), %r11d
xorl %ebx, %ebx
movl 0x20(%rdi), %r14d
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
jge 0x1ab02
movl %r8d, %r12d
jmp 0x1ab3c
cmpl %r11d, %r14d
cmovgel %r11d, %r14d
leaq (,%r14,4), %r15
addq (%rax,%rcx,8), %r15
movl (%r15), %r12d
cmpl %r8d, %r12d
jle 0x1ab2a
movl %ecx, (%rsi)
movl %r14d, (%rdx)
movl %r14d, %r13d
movl %r12d, %r8d
jmp 0x1ab30
movl %r14d, %r13d
movl %r8d, %r12d
decq %r14
addq $-0x4, %r15
cmpl %ebp, %r13d
jg 0x1ab15
leaq -0x1(%rcx), %r14
decl %r11d
movl %r12d, %r8d
testq %rcx, %rcx
movq %r14, %rcx
jg 0x1aadf
jmp 0x1acb3
testl %ecx, %ecx
js 0x1acb3
movslq 0x20(%rdi), %r9
testq %r9, %r9
js 0x1ab85
movq (%rax,%rcx,8), %r10
movl (%r10,%r9,4), %r11d
cmpl %r8d, %r11d
jle 0x1ab79
movl %ecx, (%rsi)
movl %r9d, (%rdx)
movl %r11d, %r8d
leaq -0x1(%r9), %r11
testq %r9, %r9
movq %r11, %r9
jg 0x1ab68
leaq -0x1(%rcx), %r9
testq %rcx, %rcx
movq %r9, %rcx
jg 0x1ab5b
jmp 0x1acb3
orb %r14b, %bpl
cmpb $0x1, %bpl
jne 0x1ac2a
movl 0x20(%rdi), %ecx
movl 0x24(%rdi), %ebp
addl %ecx, %r10d
movl %ecx, %r15d
subl %r9d, %r15d
xorl %r14d, %r14d
testl %r15d, %r15d
cmovlel %r14d, %r15d
cmpl %ebp, %r15d
cmovgel %ebp, %r15d
cmpl %r15d, %r10d
jl 0x1acb3
movslq %ecx, %r15
movslq %ebp, %r12
cmpl %ebx, %r11d
cmovgl %r11d, %ebx
movslq %ebx, %r10
addq %r15, %r10
cmpq %r12, %r10
cmovgeq %r12, %r10
movq (%rax,%r10,8), %r11
movslq (%rdx), %rbx
movl (%r11,%rbx,4), %r11d
cmpl %r8d, %r11d
jle 0x1ac02
movl %r10d, (%rsi)
movl 0x20(%rdi), %ecx
movl 0x24(%rdi), %ebp
movl %r11d, %r8d
movl %ecx, %r11d
subl %r9d, %r11d
testl %r11d, %r11d
cmovlel %r14d, %r11d
cmpl %ebp, %r11d
cmovgel %ebp, %r11d
leaq -0x1(%r10), %rbx
movslq %r11d, %r11
cmpq %r11, %r10
movq %rbx, %r10
jg 0x1abe6
jmp 0x1acb3
cmpb $0x0, 0x1(%rcx)
jne 0x1ac35
cmpb $0x1, (%rcx)
jne 0x1acb3
movl 0x20(%rdi), %ecx
movl 0x24(%rdi), %ebp
addl %ebp, %r10d
movl %ebp, %r15d
subl %r9d, %r15d
xorl %r14d, %r14d
testl %r15d, %r15d
cmovlel %r14d, %r15d
cmpl %ecx, %r15d
cmovgel %ecx, %r15d
cmpl %r15d, %r10d
jl 0x1acb3
movslq %ebp, %r15
movslq %ecx, %r12
cmpl %ebx, %r11d
cmovgl %r11d, %ebx
movslq %ebx, %r10
addq %r15, %r10
cmpq %r12, %r10
cmovgeq %r12, %r10
movslq (%rsi), %r11
movq (%rax,%r11,8), %r11
movl (%r11,%r10,4), %r11d
cmpl %r8d, %r11d
jle 0x1ac90
movl %r10d, (%rdx)
movl 0x20(%rdi), %ecx
movl 0x24(%rdi), %ebp
movl %r11d, %r8d
movl %ebp, %r11d
subl %r9d, %r11d
testl %r11d, %r11d
cmovlel %r14d, %r11d
cmpl %ecx, %r11d
cmovgel %ecx, %r11d
leaq -0x1(%r10), %rbx
movslq %r11d, %r11
cmpq %r11, %r10
movq %rbx, %r10
jg 0x1ac74
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq