// File: /workspace/github_cpp_makefile_star2_O2/readmapping[P]alfalfa/src/dp.cpp
// Function: dynProg::updateMatrix(dp_type const&, bool, bool)
int dynProg::updateMatrix(const dp_type& type, bool backward, bool print){
    //TODO: change this to mallocs and initialize once per thread + realloc if nec.
    assert(L1 >=0 && L2 >= 0);
    int newDimL2 = DP_L2;
    while(L2 >= newDimL2){
        newDimL2 = 2*newDimL2;
    }
    int newDimL1 = DP_L1;
    while(L1 >= newDimL1){
        newDimL1 = 2*newDimL1;
    }
    if(newDimL2 > DP_L2 || newDimL1 > DP_L1){
        if(print) cerr << "resize DP matrix from " << DP_L2 << "x" << DP_L1 << " to " << newDimL2 << "x" << newDimL1 << endl;
        resizeDPMatrix(newDimL2, newDimL1, scores.openGap != 0);
        if(print) cerr << "resize succesful" << endl;
    }
    M[0][0] = 0;
    for(int i = 1; i <= L2; i++)
        M[i][0] = (type.freeQueryB && !backward) ? 0 : scores.openGap + i*scores.extendGap;
    for(int i = 1; i <= L1; i++)
        M[0][i] = (type.freeRefB && !backward) ? 0 : scores.openGap + i*scores.extendGap;
    if(scores.openGap != 0){//affine gap penalties
        UP[0][0] = LEFT[0][0] = 0;
        for(int i = 1; i <= L1; i++){
            UP[0][i] = M[0][i] + scores.openGap;
            LEFT[0][i] = M[0][i] + scores.openGap;
        }
        for(int i = 1; i <= L2; i++){
            UP[i][0] = M[i][0] + scores.openGap;
            LEFT[i][0] = M[i][0] + scores.openGap;
        }
    }
    return 0;//return is not really used, maybe for future use
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl 0x18(%rdi), %eax
movl 0x24(%rdi), %edx
movl %eax, %esi
movl %esi, %r15d
leal (%r15,%r15), %esi
cmpl %r15d, %edx
jge 0x1583d
movl 0x1c(%rbx), %edx
movl 0x20(%rbx), %esi
movl %edx, %edi
movl %edi, %r12d
leal (%r12,%r12), %edi
cmpl %r12d, %esi
jge 0x15851
cmpl %eax, %r15d
setg %al
cmpl %edx, %r12d
setg %dl
orb %al, %dl
cmpb $0x1, %dl
jne 0x15942
testb %cl, %cl
je 0x15927
movq 0x34765(%rip), %rdi     # 0x49fe8
leaq 0x21016(%rip), %rsi     # 0x368a0
callq 0x72b0
movl 0x18(%rbx), %esi
movq %rax, %rdi
callq 0x75c0
leaq 0x1d61a(%rip), %r13     # 0x32ebb
movq %rax, %rdi
movq %r13, %rsi
callq 0x72b0
movl 0x1c(%rbx), %esi
movq %rax, %rdi
callq 0x75c0
leaq 0x210bf(%rip), %rsi     # 0x3697d
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
movl %r15d, %esi
callq 0x75c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x72b0
movq %rax, %rdi
movl %r12d, %esi
callq 0x75c0
movq %rax, %rdi
callq 0x7160
movq 0x38(%rbx), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x8(%rax)
setne %cl
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x157f0
leaq 0x20fa6(%rip), %rsi     # 0x368b7
movq 0x346d0(%rip), %rdi     # 0x49fe8
callq 0x72b0
movq %rax, %rdi
callq 0x7160
jmp 0x15942
movq 0x38(%rbx), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x8(%rax)
setne %cl
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x157f0
movq (%rbx), %rax
movq (%rax), %rcx
andl $0x0, (%rcx)
movb 0x2(%r14), %dl
xorb $0x1, %dl
orb %bpl, %dl
movq 0x38(%rbx), %rsi
pushq $0x1
popq %rdi
movslq 0x24(%rbx), %r8
cmpq %r8, %rdi
jg 0x15985
xorl %r8d, %r8d
testb $0x1, %dl
je 0x15979
movl 0xc(%rsi), %r8d
imull %edi, %r8d
addl 0x8(%rsi), %r8d
movq (%rax,%rdi,8), %r9
movl %r8d, (%r9)
incq %rdi
jmp 0x1595c
movb (%r14), %sil
xorb $0x1, %sil
orb %bpl, %sil
movq 0x38(%rbx), %rdx
pushq $0x1
popq %rdi
movslq 0x20(%rbx), %r8
cmpq %r8, %rdi
jg 0x159bd
xorl %r8d, %r8d
testb $0x1, %sil
je 0x159b4
movl 0xc(%rdx), %r8d
imull %edi, %r8d
addl 0x8(%rdx), %r8d
movl %r8d, (%rcx,%rdi,4)
incq %rdi
jmp 0x15996
cmpl $0x0, 0x8(%rdx)
je 0x15a34
movq 0x10(%rbx), %rsi
movq (%rsi), %r8
andl $0x0, (%r8)
movq 0x8(%rbx), %rdi
movq (%rdi), %r9
andl $0x0, (%r9)
pushq $0x1
popq %r10
movslq 0x20(%rbx), %r11
cmpq %r11, %r10
jg 0x15a03
movl 0x8(%rdx), %r11d
addl (%rcx,%r10,4), %r11d
movl %r11d, (%r9,%r10,4)
movl 0x8(%rdx), %r11d
addl (%rcx,%r10,4), %r11d
movl %r11d, (%r8,%r10,4)
incq %r10
jmp 0x159dd
pushq $0x1
popq %rcx
movslq 0x24(%rbx), %r8
cmpq %r8, %rcx
jg 0x15a34
movq (%rax,%rcx,8), %r8
movl 0x8(%rdx), %r9d
addl (%r8), %r9d
movq (%rdi,%rcx,8), %r10
movl %r9d, (%r10)
movl 0x8(%rdx), %r9d
addl (%r8), %r9d
movq (%rsi,%rcx,8), %r8
movl %r9d, (%r8)
incq %rcx
jmp 0x15a06
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop