// File: /workspace/github_c_makefile_star2_O2/asford[P]tmalign/./TMalign.h
// Function: get_initial_local(double**, double**, int, int, int*)
bool get_initial_local(  double **x, 
						 double **y, 
						 int x_len,
						 int y_len, 
						 int *y2x
						 )
{
    double GL, rmsd;    
    double t[3];
    double u[3][3];

	double d01=d0+1.5;
	if(d01 < D0_MIN) d01=D0_MIN;
	double d02=d01*d01;
	
	double GLmax=0;
	int n_frag=20; //length of fragment for superposition
	int ns=20; //tail length to discard
	int *invmap=new int[y_len+1];
      
	int aL=getmin(x_len, y_len);
	if(aL>250)
	{
		n_frag=50;
	}
	else if(aL>200)
	{
		n_frag=40;
	}
	else if(aL>150)
	{
		n_frag=30;
	}
	else
	{
		n_frag=20;
	}
	
	int smallest=aL/3; // I change here from aL/2 to aL/3

	if(n_frag>smallest) n_frag=smallest; 
	if(ns>smallest) ns=smallest;
    
	int m1=x_len-n_frag-ns;
	int m2=y_len-n_frag-ns;

	bool flag=false;

	for(int ii=0; ii<y_len; ii++) 
	{                
		y2x[ii]=-1;
	}

	int count=0;
	for(int i=ns-1; i<m1; i=i+n_frag) //index starts from 0, different from FORTRAN
	{
		for(int j=ns-1; j<m2; j=j+n_frag)
		{
			for(int k=0; k<n_frag; k++) //fragment in y
			{ 
				r1[k][0]=x[k+i][0];  
				r1[k][1]=x[k+i][1]; 
				r1[k][2]=x[k+i][2]; 													
                        
                r2[k][0]=y[k+j][0];  
                r2[k][1]=y[k+j][1]; 
                r2[k][2]=y[k+j][2];
			}


			Kabsch(r1, r2, n_frag, 1, &rmsd, t, u);			
			count++;

			double gap_open=0.0;			
			NWDP_TM(x, y, x_len, y_len, t, u, d02, gap_open, invmap);
			GL=get_score_fast(x, y, x_len, y_len, invmap);
			if(GL>GLmax)
			{
				GLmax=GL;
				for(int ii=0; ii<y_len; ii++) 
				{                
					y2x[ii]=invmap[ii];
				}
				flag=true;
			}
		}
	}	


	delete [] invmap;
	return flag;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r8, %rbx
movl %ecx, %r14d
movl %edx, %ebp
movq %rsi, 0x40(%rsp)
movq %rdi, 0x38(%rsp)
movsd 0x1fa693(%rip), %xmm0   # 0x602580
addsd 0x17b18b(%rip), %xmm0   # 0x583080
maxsd 0x1fa66b(%rip), %xmm0   # 0x602568
movsd %xmm0, 0x18(%rsp)
leal 0x1(%r14), %eax
shlq $0x2, %rax
cmpl $-0x1, %ecx
pushq $-0x1
popq %rdi
cmovgeq %rax, %rdi
callq 0x40be00
movq %rax, %r13
cmpl %r14d, %ebp
movq %r14, 0x20(%rsp)
movl %r14d, %ecx
movl %ebp, 0x14(%rsp)
cmovll %ebp, %ecx
pushq $0x14
popq %rsi
cmpl $0xfa, %ecx
jle 0x407f3e
pushq $0x32
jmp 0x407f48
cmpl $0xc8, %ecx
jle 0x407f4b
pushq $0x28
popq %rdi
jmp 0x407f57
cmpl $0x97, %ecx
pushq $0x1e
popq %rdi
cmovll %esi, %edi
pushq $0x3
popq %r8
movl %ecx, %eax
cltd
idivl %r8d
cmpl %eax, %edi
movl %eax, %edx
cmovll %edi, %edx
movsd 0x18(%rsp), %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
cmpl $0x3c, %ecx
cmovll %eax, %esi
movq %rdx, 0x30(%rsp)
addl %esi, %edx
movl 0x14(%rsp), %ecx
subl %edx, %ecx
xorl %r8d, %r8d
movq 0x20(%rsp), %r9
testl %r9d, %r9d
movl $0x0, %r10d
cmovgl %r9d, %r10d
cmpq %r8, %r10
je 0x407faf
orl $-0x1, (%rbx,%r8,4)
incq %r8
jmp 0x407fa0
movq 0x20(%rsp), %r8
subl %edx, %r8d
movq $0x0, 0x28(%rsp)
movq 0x30(%rsp), %rdx
testl %edx, %edx
movl $0x0, %r14d
cmovgl %edx, %r14d
leal -0x1(%rsi), %edx
movslq %edx, %rdx
cltq
movl %edi, %edi
cmpq %rdi, %rax
cmovlq %rax, %rdi
movslq %r8d, %rax
movq %rax, 0x98(%rsp)
movslq %ecx, %rax
movq %rax, 0x70(%rsp)
movslq %esi, %rax
movq 0x40(%rsp), %rcx
leaq -0x8(%rcx,%rax,8), %rcx
movq %rcx, 0x60(%rsp)
movq %rdi, 0x50(%rsp)
leaq (,%rdi,8), %rcx
movq %rcx, 0x48(%rsp)
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,8), %r15
addq $-0x8, %r15
shlq $0x3, %r14
xorpd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
movq %rdx, 0x68(%rsp)
movq %rbx, 0x90(%rsp)
movq %r13, 0x88(%rsp)
movq %r10, 0x80(%rsp)
movq 0x38(%rsp), %rbp
cmpq 0x70(%rsp), %rdx
jge 0x4081d4
movq %rdx, 0x78(%rsp)
movq 0x60(%rsp), %r12
movq 0x68(%rsp), %rax
cmpq 0x98(%rsp), %rax
jge 0x4081c0
movq %rax, 0xa0(%rsp)
movq 0x1fa58b(%rip), %rax    # 0x602618
movq 0x1fa58c(%rip), %rcx    # 0x602620
xorl %edx, %edx
cmpq %rdx, %r14
je 0x4080e9
movq (%r15,%rdx), %rsi
movsd (%rsi), %xmm0
movq (%rax,%rdx), %rdi
movsd %xmm0, (%rdi)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x8(%rdi)
movsd 0x10(%rsi), %xmm0
movsd %xmm0, 0x10(%rdi)
movq (%r12,%rdx), %rsi
movsd (%rsi), %xmm0
movq (%rcx,%rdx), %rdi
movsd %xmm0, (%rdi)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x8(%rdi)
movsd 0x10(%rsi), %xmm0
movsd %xmm0, 0x10(%rdi)
addq $0x8, %rdx
jmp 0x408096
movq 0x1fa528(%rip), %rdi    # 0x602618
movq 0x1fa529(%rip), %rsi    # 0x602620
leaq 0xd0(%rsp), %rax
movq %rax, (%rsp)
movq 0x30(%rsp), %rdx
pushq $0x1
popq %rcx
leaq 0xa8(%rsp), %r8
leaq 0xb0(%rsp), %r9
callq 0x405c40
movq %r13, (%rsp)
xorps %xmm1, %xmm1
movq %rbp, %rdi
movq 0x40(%rsp), %r13
movq %r13, %rsi
movl 0x14(%rsp), %edx
movq 0x20(%rsp), %rbx
movl %ebx, %ecx
leaq 0xb0(%rsp), %r8
leaq 0xd0(%rsp), %r9
movsd 0x18(%rsp), %xmm0
callq 0x40584b
movq %rbp, %rdi
movq %r13, %rsi
movq 0x88(%rsp), %r13
movl %ebx, %ecx
movq 0x90(%rsp), %rbx
movq %r13, %r8
callq 0x40747b
movq 0x80(%rsp), %r10
ucomisd 0x58(%rsp), %xmm0
jbe 0x4081a9
xorl %eax, %eax
cmpq %rax, %r10
je 0x40819c
movl (%r13,%rax,4), %ecx
movl %ecx, (%rbx,%rax,4)
incq %rax
jmp 0x40818a
movb $0x1, %al
movq %rax, 0x28(%rsp)
movsd %xmm0, 0x58(%rsp)
movq 0xa0(%rsp), %rax
addq 0x50(%rsp), %rax
addq 0x48(%rsp), %r12
jmp 0x408070
movq 0x78(%rsp), %rdx
addq 0x50(%rsp), %rdx
addq 0x48(%rsp), %r15
jmp 0x408056
movq %r13, %rdi
callq 0x40b100
movq 0x28(%rsp), %rax
andb $0x1, %al
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq