// File: 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:
subq $0x48, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
andb $0x1, %cl
movb %cl, 0x37(%rsp)
andb $0x1, %al
movb %al, 0x36(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x18(%rax), %eax
movl %eax, 0x30(%rsp)
movq 0x10(%rsp), %rax
movl 0x24(%rax), %eax
cmpl 0x30(%rsp), %eax
jl 0x3196a
movl 0x30(%rsp), %eax
shll %eax
movl %eax, 0x30(%rsp)
jmp 0x31950
movq 0x10(%rsp), %rax
movl 0x1c(%rax), %eax
movl %eax, 0x2c(%rsp)
movq 0x10(%rsp), %rax
movl 0x20(%rax), %eax
cmpl 0x2c(%rsp), %eax
jl 0x31990
movl 0x2c(%rsp), %eax
shll %eax
movl %eax, 0x2c(%rsp)
jmp 0x31976
movq 0x10(%rsp), %rcx
movl 0x30(%rsp), %eax
cmpl 0x18(%rcx), %eax
jg 0x319b0
movq 0x10(%rsp), %rcx
movl 0x2c(%rsp), %eax
cmpl 0x1c(%rcx), %eax
jle 0x31a90
testb $0x1, 0x36(%rsp)
je 0x31a42
movq 0x6562e(%rip), %rdi     # 0x96ff0
leaq 0x4bea7(%rip), %rsi     # 0x7d870
callq 0x8360
movq %rax, %rdi
movq 0x10(%rsp), %rax
movl 0x18(%rax), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x48493(%rip), %rsi     # 0x79e7b
callq 0x8360
movq %rax, %rdi
movq 0x10(%rsp), %rax
movl 0x1c(%rax), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x4bf46(%rip), %rsi     # 0x7d94d
callq 0x8360
movq %rax, %rdi
movl 0x30(%rsp), %esi
callq 0x8710
movq %rax, %rdi
leaq 0x48459(%rip), %rsi     # 0x79e7b
callq 0x8360
movq %rax, %rdi
movl 0x2c(%rsp), %esi
callq 0x8710
movq %rax, %rdi
movq 0x65573(%rip), %rsi     # 0x96fb0
callq 0x83b0
movq 0x10(%rsp), %rdi
movl 0x30(%rsp), %esi
movl 0x2c(%rsp), %edx
movq 0x38(%rdi), %rax
cmpl $0x0, 0x8(%rax)
setne %al
movzbl %al, %ecx
andl $0x1, %ecx
callq 0x318c0
testb $0x1, 0x36(%rsp)
je 0x31a8e
movq 0x6557d(%rip), %rdi     # 0x96ff0
leaq 0x4be0d(%rip), %rsi     # 0x7d887
callq 0x8360
movq %rax, %rdi
movq 0x65527(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x31a90
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movl $0x0, (%rax)
movl $0x1, 0x28(%rsp)
movq 0x10(%rsp), %rcx
movl 0x28(%rsp), %eax
cmpl 0x24(%rcx), %eax
jg 0x31b13
movq 0x38(%rsp), %rax
testb $0x1, 0x2(%rax)
je 0x31ad1
testb $0x1, 0x37(%rsp)
jne 0x31ad1
xorl %eax, %eax
movl %eax, 0xc(%rsp)
jmp 0x31aef
movq 0x10(%rsp), %rdx
movq 0x38(%rdx), %rax
movl 0x8(%rax), %eax
movl 0x28(%rsp), %ecx
movq 0x38(%rdx), %rdx
imull 0xc(%rdx), %ecx
addl %ecx, %eax
movl %eax, 0xc(%rsp)
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %ecx
movq (%rax), %rax
movslq 0x28(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, (%rax)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x31aa9
movl $0x1, 0x24(%rsp)
movq 0x10(%rsp), %rcx
movl 0x24(%rsp), %eax
cmpl 0x20(%rcx), %eax
jg 0x31b84
movq 0x38(%rsp), %rax
testb $0x1, (%rax)
je 0x31b42
testb $0x1, 0x37(%rsp)
jne 0x31b42
xorl %eax, %eax
movl %eax, 0x8(%rsp)
jmp 0x31b60
movq 0x10(%rsp), %rdx
movq 0x38(%rdx), %rax
movl 0x8(%rax), %eax
movl 0x24(%rsp), %ecx
movq 0x38(%rdx), %rdx
imull 0xc(%rdx), %ecx
addl %ecx, %eax
movl %eax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movl 0x8(%rsp), %edx
movq (%rax), %rax
movq (%rax), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x31b1b
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0x31c98
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rcx
movq (%rcx), %rcx
movl $0x0, (%rcx)
movq 0x8(%rax), %rax
movq (%rax), %rax
movl $0x0, (%rax)
movl $0x1, 0x20(%rsp)
movq 0x10(%rsp), %rcx
movl 0x20(%rsp), %eax
cmpl 0x20(%rcx), %eax
jg 0x31c26
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movq (%rcx), %rcx
movslq 0x20(%rsp), %rdx
movl (%rcx,%rdx,4), %esi
movq 0x38(%rax), %rcx
addl 0x8(%rcx), %esi
movq 0x8(%rax), %rcx
movq (%rcx), %rcx
movslq 0x20(%rsp), %rdx
movl %esi, (%rcx,%rdx,4)
movq (%rax), %rcx
movq (%rcx), %rcx
movslq 0x20(%rsp), %rdx
movl (%rcx,%rdx,4), %edx
movq 0x38(%rax), %rcx
addl 0x8(%rcx), %edx
movq 0x10(%rax), %rax
movq (%rax), %rax
movslq 0x20(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x31bbe
movl $0x1, 0x1c(%rsp)
movq 0x10(%rsp), %rcx
movl 0x1c(%rsp), %eax
cmpl 0x24(%rcx), %eax
jg 0x31c96
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movslq 0x1c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rcx), %edx
movq 0x38(%rax), %rcx
addl 0x8(%rcx), %edx
movq 0x8(%rax), %rcx
movslq 0x1c(%rsp), %rsi
movq (%rcx,%rsi,8), %rcx
movl %edx, (%rcx)
movq (%rax), %rcx
movslq 0x1c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rcx), %ecx
movq 0x38(%rax), %rdx
addl 0x8(%rdx), %ecx
movq 0x10(%rax), %rax
movslq 0x1c(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, (%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x31c2e
jmp 0x31c98
xorl %eax, %eax
addq $0x48, %rsp
retq
nop