// File: /workspace/github_c_makefile_star2_O0/asford[P]tmalign/./NW.h
// Function: NWDP_TM(int, int, double, int*)
void NWDP_TM(int len1, int len2, double gap_open, int j2i[])
{
	//NW dynamic programming for alignment
	//not a standard implementation of NW algorithm
    //Input: score[1:len1, 1:len2], 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

			//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:
movl %edi, -0x4(%rsp)
movl %esi, -0x8(%rsp)
movsd %xmm0, -0x10(%rsp)
movq %rdx, -0x18(%rsp)
movq 0x20420e(%rip), %rax    # 0x60a5a8
movq (%rax), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x0, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
cmpl -0x4(%rsp), %eax
jg 0x4063ed
movq 0x2041eb(%rip), %rax    # 0x60a5a8
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq 0x2041cc(%rip), %rax    # 0x60a5a0
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, (%rax)
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x4063ac
movl $0x0, -0x20(%rsp)
movl -0x20(%rsp), %eax
cmpl -0x8(%rsp), %eax
jg 0x406447
movq 0x2041a2(%rip), %rax    # 0x60a5a8
movq (%rax), %rax
movslq -0x20(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0x204183(%rip), %rax    # 0x60a5a0
movq (%rax), %rax
movslq -0x20(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x18(%rsp), %rax
movslq -0x20(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0x4063f5
movl $0x1, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
cmpl -0x4(%rsp), %eax
jg 0x40664b
movl $0x1, -0x20(%rsp)
movl -0x20(%rsp), %eax
cmpl -0x8(%rsp), %eax
jg 0x406639
movq 0x20412e(%rip), %rax    # 0x60a5a8
movl -0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x20(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x2040fa(%rip), %rax    # 0x60a598
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x38(%rsp)
movq 0x2040ea(%rip), %rax    # 0x60a5a8
movl -0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x28(%rsp)
movq 0x2040bd(%rip), %rax    # 0x60a5a0
movl -0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x40650e
movsd -0x10(%rsp), %xmm0
addsd -0x28(%rsp), %xmm0
movsd %xmm0, -0x28(%rsp)
movq 0x204093(%rip), %rax    # 0x60a5a8
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x20(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x30(%rsp)
movq 0x204066(%rip), %rax    # 0x60a5a0
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x20(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
testb $0x1, (%rax,%rcx)
je 0x406565
movsd -0x10(%rsp), %xmm0
addsd -0x30(%rsp), %xmm0
movsd %xmm0, -0x30(%rsp)
movsd -0x38(%rsp), %xmm0
ucomisd -0x28(%rsp), %xmm0
jb 0x4065bc
movsd -0x38(%rsp), %xmm0
ucomisd -0x30(%rsp), %xmm0
jb 0x4065bc
movq 0x204018(%rip), %rax    # 0x60a5a0
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
movb $0x1, (%rax,%rcx)
movsd -0x38(%rsp), %xmm0
movq 0x204001(%rip), %rax    # 0x60a5a8
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x406627
movq 0x203fdd(%rip), %rax    # 0x60a5a0
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movsd -0x30(%rsp), %xmm0
ucomisd -0x28(%rsp), %xmm0
jb 0x406605
movsd -0x30(%rsp), %xmm0
movq 0x203fb8(%rip), %rax    # 0x60a5a8
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x406625
movsd -0x28(%rsp), %xmm0
movq 0x203f96(%rip), %rax    # 0x60a5a8
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x406627
jmp 0x406629
movl -0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0x406465
jmp 0x40663b
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x40644f
movl -0x4(%rsp), %eax
movl %eax, -0x1c(%rsp)
movl -0x8(%rsp), %eax
movl %eax, -0x20(%rsp)
xorl %eax, %eax
cmpl $0x0, -0x1c(%rsp)
movb %al, -0x39(%rsp)
jle 0x406674
cmpl $0x0, -0x20(%rsp)
setg %al
movb %al, -0x39(%rsp)
movb -0x39(%rsp), %al
testb $0x1, %al
jne 0x406681
jmp 0x4067ab
movq 0x203f18(%rip), %rax    # 0x60a5a0
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x4066d0
movl -0x1c(%rsp), %edx
subl $0x1, %edx
movq -0x18(%rsp), %rax
movl -0x20(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rsp)
movl -0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0x4067a6
movq 0x203ed1(%rip), %rax    # 0x60a5a8
movl -0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x28(%rsp)
movq 0x203ea4(%rip), %rax    # 0x60a5a0
movl -0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x406727
movsd -0x10(%rsp), %xmm0
addsd -0x28(%rsp), %xmm0
movsd %xmm0, -0x28(%rsp)
movq 0x203e7a(%rip), %rax    # 0x60a5a8
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x20(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x30(%rsp)
movq 0x203e4d(%rip), %rax    # 0x60a5a0
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x20(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
testb $0x1, (%rax,%rcx)
je 0x40677e
movsd -0x10(%rsp), %xmm0
addsd -0x30(%rsp), %xmm0
movsd %xmm0, -0x30(%rsp)
movsd -0x30(%rsp), %xmm0
ucomisd -0x28(%rsp), %xmm0
jb 0x406799
movl -0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0x4067a4
movl -0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x4067a6
jmp 0x40665b
retq
nopl (%rax)