// File: /workspace/github_c_makefile_star2_O0/asford[P]tmalign/./NW.h
// Function: NWDP_TM(int*, int*, int, int, double, int*)
void NWDP_TM(int *secx, int *secy, int len1, int len2, double gap_open, int j2i[])
{
	//NW dynamic programming for alignment
	//not a standard implementation of NW algorithm
    //Input: secondary structure secx, secy, and gap_open
    //Output: j2i[1:len2] \in {1:len1} U {-1}
	//path[0:len1, 0:len2]=1,2,3, from diagonal, horizontal, vertical

	int i, j;
	double h, v, d;

	//initialization
	val[0][0]=0;
	for(i=0; i<=len1; i++)
	{
		val[i][0]=0;
		path[i][0]=false; //not from diagonal
	}

	for(j=0; j<=len2; j++)
	{
		val[0][j]=0;
		path[0][j]=false; //not from diagonal
		j2i[j]=-1;	//all are not aligned, only use j2i[1:len2]
	}      
	
	//decide matrix and path
	for(i=1; i<=len1; i++)	
	{	
		for(j=1; j<=len2; j++)
		{
			//d=val[i-1][j-1]+score[i][j]; //diagonal			
			if(secx[i-1]==secy[j-1])
			{
				d=val[i-1][j-1] + 1.0;
			}
			else
			{
				d=val[i-1][j-1];
			}

			//symbol insertion in horizontal (= a gap in vertical)
			h=val[i-1][j];
			if(path[i-1][j]) //aligned in last position
				h += gap_open;				

			//symbol insertion in vertical
			v=val[i][j-1];
			if(path[i][j-1]) //aligned in last position
				v += gap_open;


			if(d>=h && d>=v)
			{
				path[i][j]=true; //from diagonal
				val[i][j]=d;
			}
			else 
			{
				path[i][j]=false; //from horizontal
				if(v>=h)
					val[i][j]=v;
				else					
					val[i][j]=h;
			}
		} //for i
	} //for j

	//trace back to extract the alignment
	i=len1;
    j=len2;
	while(i>0 && j>0)
	{
		if(path[i][j]) //from diagonal
		{
			j2i[j-1]=i-1;		
			i--;
			j--;
		}
		else 			
		{
			h=val[i-1][j];
			if(path[i-1][j]) h +=gap_open;

			v=val[i][j-1];
			if(path[i][j-1]) v +=gap_open;

			if(v>=h)
				j--;
			else
				i--;
		}
	}	
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movl %edx, -0x14(%rsp)
movl %ecx, -0x18(%rsp)
movsd %xmm0, -0x20(%rsp)
movq %r8, -0x28(%rsp)
movq 0x203914(%rip), %rax    # 0x60a5a8
movq (%rax), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x0, -0x2c(%rsp)
movl -0x2c(%rsp), %eax
cmpl -0x14(%rsp), %eax
jg 0x406ce7
movq 0x2038f1(%rip), %rax    # 0x60a5a8
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq 0x2038d2(%rip), %rax    # 0x60a5a0
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, (%rax)
movl -0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rsp)
jmp 0x406ca6
movl $0x0, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x18(%rsp), %eax
jg 0x406d41
movq 0x2038a8(%rip), %rax    # 0x60a5a8
movq (%rax), %rax
movslq -0x30(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0x203889(%rip), %rax    # 0x60a5a0
movq (%rax), %rax
movslq -0x30(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x406cef
movl $0x1, -0x2c(%rsp)
movl -0x2c(%rsp), %eax
cmpl -0x14(%rsp), %eax
jg 0x406f85
movl $0x1, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x18(%rsp), %eax
jg 0x406f73
movq -0x8(%rsp), %rax
movl -0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x10(%rsp), %rcx
movl -0x30(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x406dc7
movq 0x20380e(%rip), %rax    # 0x60a5a8
movl -0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0x18524e(%rip), %xmm0   # 0x58c008
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x48(%rsp)
jmp 0x406df1
movq 0x2037da(%rip), %rax    # 0x60a5a8
movl -0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x48(%rsp)
movq 0x2037b0(%rip), %rax    # 0x60a5a8
movl -0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x38(%rsp)
movq 0x203783(%rip), %rax    # 0x60a5a0
movl -0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x406e48
movsd -0x20(%rsp), %xmm0
addsd -0x38(%rsp), %xmm0
movsd %xmm0, -0x38(%rsp)
movq 0x203759(%rip), %rax    # 0x60a5a8
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x40(%rsp)
movq 0x20372c(%rip), %rax    # 0x60a5a0
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
testb $0x1, (%rax,%rcx)
je 0x406e9f
movsd -0x20(%rsp), %xmm0
addsd -0x40(%rsp), %xmm0
movsd %xmm0, -0x40(%rsp)
movsd -0x48(%rsp), %xmm0
ucomisd -0x38(%rsp), %xmm0
jb 0x406ef6
movsd -0x48(%rsp), %xmm0
ucomisd -0x40(%rsp), %xmm0
jb 0x406ef6
movq 0x2036de(%rip), %rax    # 0x60a5a0
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
movb $0x1, (%rax,%rcx)
movsd -0x48(%rsp), %xmm0
movq 0x2036c7(%rip), %rax    # 0x60a5a8
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x406f61
movq 0x2036a3(%rip), %rax    # 0x60a5a0
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movsd -0x40(%rsp), %xmm0
ucomisd -0x38(%rsp), %xmm0
jb 0x406f3f
movsd -0x40(%rsp), %xmm0
movq 0x20367e(%rip), %rax    # 0x60a5a8
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x406f5f
movsd -0x38(%rsp), %xmm0
movq 0x20365c(%rip), %rax    # 0x60a5a8
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x406f61
jmp 0x406f63
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x406d5f
jmp 0x406f75
movl -0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rsp)
jmp 0x406d49
movl -0x14(%rsp), %eax
movl %eax, -0x2c(%rsp)
movl -0x18(%rsp), %eax
movl %eax, -0x30(%rsp)
xorl %eax, %eax
cmpl $0x0, -0x2c(%rsp)
movb %al, -0x49(%rsp)
jle 0x406fae
cmpl $0x0, -0x30(%rsp)
setg %al
movb %al, -0x49(%rsp)
movb -0x49(%rsp), %al
testb $0x1, %al
jne 0x406fbb
jmp 0x4070e5
movq 0x2035de(%rip), %rax    # 0x60a5a0
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x40700a
movl -0x2c(%rsp), %edx
subl $0x1, %edx
movq -0x28(%rsp), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x2c(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rsp)
movl -0x30(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x4070e0
movq 0x203597(%rip), %rax    # 0x60a5a8
movl -0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x38(%rsp)
movq 0x20356a(%rip), %rax    # 0x60a5a0
movl -0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x407061
movsd -0x20(%rsp), %xmm0
addsd -0x38(%rsp), %xmm0
movsd %xmm0, -0x38(%rsp)
movq 0x203540(%rip), %rax    # 0x60a5a8
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x40(%rsp)
movq 0x203513(%rip), %rax    # 0x60a5a0
movslq -0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
testb $0x1, (%rax,%rcx)
je 0x4070b8
movsd -0x20(%rsp), %xmm0
addsd -0x40(%rsp), %xmm0
movsd %xmm0, -0x40(%rsp)
movsd -0x40(%rsp), %xmm0
ucomisd -0x38(%rsp), %xmm0
jb 0x4070d3
movl -0x30(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x4070de
movl -0x2c(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rsp)
jmp 0x4070e0
jmp 0x406f95
retq
nopw %cs:(%rax,%rax)