// File: /workspace/github_c_makefile_star2_O3/asford[P]tmalign/./TMalign.h
// Function: get_initial_fgt(double**, double**, int, int, int*, int*, int*)
double get_initial_fgt( double **x, 
						double **y, 
						int x_len,
						int y_len, 
						int *xresno,
						int *yresno,
						int *y2x
						)
{
	int fra_min=4;           //minimum fragment for search
	int fra_min1=fra_min-1;  //cutoff for shift, save time

	int xstart=0, ystart=0, xend=0, yend=0;

	find_max_frag(x, xresno, x_len,  &xstart, &xend);
	find_max_frag(y, yresno, y_len, &ystart, &yend);


	int Lx = xend-xstart+1;
	int Ly = yend-ystart+1;
	int *ifr, *y2x_;
	int L_fr=getmin(Lx, Ly);
	ifr= new int[L_fr];
	y2x_= new int[y_len+1];

	//select what piece will be used (this may araise ansysmetry, but
	//only when L1=L2 and Lfr1=Lfr2 and L1 ne Lfr1
	//if L1=Lfr1 and L2=Lfr2 (normal proteins), it will be the same as initial1

	if(Lx<Ly || (Lx==Ly && x_len<=y_len))
	{		
		for(int i=0; i<L_fr; i++)
		{
			ifr[i]=xstart+i;
		}
	}
	else if(Lx>Ly || (Lx==Ly && x_len>y_len))
	{		
		for(int i=0; i<L_fr; i++)
		{
			ifr[i]=ystart+i;
		}	
	}

	
	int L0=getmin(x_len, y_len); //non-redundant to get_initial1
	if(L_fr==L0)
	{
		int n1= (int)(L0*0.1); //my index starts from 0
		int n2= (int)(L0*0.89);

		int j=0;
		for(int i=n1; i<= n2; i++)
		{
			ifr[j]=ifr[i];
			j++;
		}
		L_fr=j;
	}


	//gapless threading for the extracted fragment
	double tmscore, tmscore_max=-1;

	if(Lx<Ly || (Lx==Ly && x_len<=y_len))
	{
		int L1=L_fr;
	    int min_len=getmin(L1, y_len);    
		int min_ali= (int) (min_len/2.5);              //minimum size of considered fragment 
		if(min_ali<=fra_min1)  min_ali=fra_min1;    
		int n1, n2;
		n1 = -y_len+min_ali; 
		n2 = L1-min_ali;

		int i, j, k;
		for(k=n1; k<=n2; k++)
		{
			//get the map
			for(j=0; j<y_len; j++)
			{
				i=j+k;
				if(i>=0 && i<L1)
				{				
					y2x_[j]=ifr[i];
				}
				else
				{
					y2x_[j]=-1;
				}
			}

			//evaluate the map quickly in three iterations
			tmscore=get_score_fast(x, y, x_len, y_len, y2x_);

			if(tmscore>=tmscore_max)
			{
				tmscore_max=tmscore;
				for(j=0; j<y_len; j++)
				{
					y2x[j]=y2x_[j];
				}
			}
		}
	}
	else
	{
		int L2=L_fr;
	    int min_len=getmin(x_len, L2);    
		int min_ali= (int) (min_len/2.5);              //minimum size of considered fragment 
		if(min_ali<=fra_min1)  min_ali=fra_min1;    
		int n1, n2;
		n1 = -L2+min_ali; 
		n2 = x_len-min_ali;

		int i, j, k;	

		for(k=n1; k<=n2; k++)
		{
			//get the map
			for(j=0; j<y_len; j++)
			{
				y2x_[j]=-1;
			}

			for(j=0; j<L2; j++)
			{
				i=j+k;
				if(i>=0 && i<x_len)
				{
					y2x_[ifr[j]]=i;
				}
			}
        
			//evaluate the map quickly in three iterations
			tmscore=get_score_fast(x, y, x_len, y_len, y2x_);
			if(tmscore>=tmscore_max)
			{
				tmscore_max=tmscore;
				for(j=0; j<y_len; j++)
				{
					y2x[j]=y2x_[j];
				}
			}
		}
	}    


	delete [] ifr;
	delete [] y2x_;
    return tmscore_max;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbx
movl %ecx, %r12d
movl %edx, 0x8(%rsp)
movq %rsi, %r15
xorl %eax, %eax
leaq 0x54(%rsp), %r13
movl %eax, (%r13)
leaq 0x24(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x50(%rsp), %r14
movl %eax, (%r14)
leaq 0x4c(%rsp), %rbp
movl %eax, (%rbp)
movq %rdi, 0x38(%rsp)
movq %r8, %rsi
movq %r13, %rcx
movq %r14, %r8
callq 0x40904d
movq %r15, 0x40(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movl %r12d, %edx
leaq 0x24(%rsp), %rcx
movq %rbp, %r8
callq 0x40904d
movl (%r14), %r14d
movl (%r13), %r15d
subl %r15d, %r14d
movl (%rbp), %r13d
leaq 0x24(%rsp), %rax
movl (%rax), %ebp
subl %ebp, %r13d
cmpl %r13d, %r14d
movl %r13d, %ebx
cmovll %r14d, %ebx
leal 0x1(%rbx), %eax
movq %rax, 0x10(%rsp)
movslq %eax, %rdi
shlq $0x2, %rdi
cmpl $-0x1, %ebx
movq $-0x1, %rax
cmovlq %rax, %rdi
callq 0x40d300
movq %rax, 0x18(%rsp)
leal 0x1(%r12), %edi
shlq $0x2, %rdi
cmpl $-0x1, %r12d
movq $-0x1, %rax
cmovlq %rax, %rdi
callq 0x40d300
movl %r13d, %r10d
movl 0x8(%rsp), %edi
movq %r12, %r8
movq %rax, %r13
cmpl %r10d, %r14d
jl 0x4092e8
cmpl %r8d, %edi
jg 0x40939a
cmpl %r10d, %r14d
jne 0x40939a
testl %ebx, %ebx
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rsi
js 0x40945e
movl %esi, %eax
leaq -0x1(%rax), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq 0x4(,%rax,4), %rax
andq $-0x8, %rax
movdqa 0x17ae22(%rip), %xmm1   # 0x584140
xorl %ecx, %ecx
movdqa 0x17ae28(%rip), %xmm2   # 0x584150
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x17ae28(%rip), %xmm4   # 0x584160
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0x40936d
movl %r15d, (%r12,%rcx)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x409384
leal 0x1(%r15), %edx
movl %edx, 0x4(%r12,%rcx)
paddq %xmm4, %xmm1
addq $0x8, %rcx
addl $0x2, %r15d
cmpq %rcx, %rax
jne 0x409338
jmp 0x40945e
cmpl %r8d, %edi
setg %al
cmpl %r10d, %r14d
sete %dl
setg %cl
testl %ebx, %ebx
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rsi
js 0x40945e
andb %dl, %al
orb %al, %cl
je 0x40945e
movl %esi, %eax
leaq -0x1(%rax), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq 0x4(,%rax,4), %rax
andq $-0x8, %rax
movdqa 0x17ad57(%rip), %xmm1   # 0x584140
xorl %ecx, %ecx
movdqa 0x17ad5d(%rip), %xmm2   # 0x584150
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x17ad5d(%rip), %xmm4   # 0x584160
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0x409438
movl %ebp, (%r12,%rcx)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x40944e
leal 0x1(%rbp), %edx
movl %edx, 0x4(%r12,%rcx)
paddq %xmm4, %xmm1
addq $0x8, %rcx
addl $0x2, %ebp
cmpq %rcx, %rax
jne 0x409403
cmpl %r8d, %edi
movl %r8d, %eax
cmovll %edi, %eax
cmpl %eax, %esi
jne 0x4094b3
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0x17acf2(%rip), %xmm0   # 0x584170
cvttpd2dq %xmm0, %xmm0
movd %xmm0, %eax
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %ecx
xorl %esi, %esi
cmpl %ecx, %eax
jg 0x4094b3
movslq %eax, %rdx
subl %eax, %ecx
movl %ecx, %esi
incl %esi
leaq (%r12,%rdx,4), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movl %edx, (%r12,%rcx,4)
incq %rcx
cmpq %rcx, %rsi
jne 0x4094a4
cmpl %r10d, %r14d
movq %r8, 0x30(%rsp)
jl 0x4094cf
cmpl %r8d, %edi
jg 0x4095d1
cmpl %r10d, %r14d
jne 0x4095d1
cmpl %r8d, %esi
movl %r8d, %eax
cmovll %esi, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x17aba9(%rip), %xmm0   # 0x584090
cvttsd2si %xmm0, %ecx
cmpl $0x4, %ecx
movl $0x3, %eax
cmovgel %ecx, %eax
movl %esi, %ecx
subl %eax, %ecx
subl %r8d, %eax
cmpl %ecx, %eax
jg 0x409600
movslq %esi, %rbx
movl %r8d, %r15d
leaq (,%r15,4), %rdx
movq %rdx, 0x28(%rsp)
movslq %eax, %rbp
incl %ecx
leaq (%r12,%rbp,4), %r14
movsd 0x17ab07(%rip), %xmm1   # 0x584030
movl %ecx, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
testl %r8d, %r8d
jle 0x40955d
xorl %eax, %eax
movq %rbp, %rdx
addq %rax, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
js 0x409550
cmpq %rbx, %rdx
jge 0x409550
movl (%r14,%rax,4), %ecx
movl %ecx, (%r13,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x40953a
testl %r8d, %r8d
setle %r12b
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl %r8d, %ecx
movq %r13, %r8
callq 0x407a58
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
setb %al
orb %r12b, %al
je 0x409591
maxsd %xmm0, %xmm1
jmp 0x4095b2
movq 0x90(%rsp), %rdi
movq %r13, %rsi
movq 0x28(%rsp), %rdx
movsd %xmm0, 0x8(%rsp)
callq 0x401118
movsd 0x8(%rsp), %xmm1
movq 0x18(%rsp), %r12
movl 0x10(%rsp), %ecx
incq %rbp
addq $0x4, %r14
cmpl %ebp, %ecx
movq 0x30(%rsp), %r8
jne 0x40952d
jmp 0x409608
cmpl %edi, %esi
movl %edi, %eax
cmovll %esi, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x17aaa9(%rip), %xmm0   # 0x584090
cvttsd2si %xmm0, %ecx
cmpl $0x4, %ecx
movl $0x3, %eax
cmovgel %ecx, %eax
movl %edi, %ecx
subl %eax, %ecx
subl %esi, %eax
cmpl %ecx, %eax
jle 0x409633
movsd 0x17aa28(%rip), %xmm1   # 0x584030
movsd %xmm1, 0x8(%rsp)
movq %r12, %rdi
callq 0x40c600
movq %r13, %rdi
callq 0x40c600
movsd 0x8(%rsp), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r8d, %edx
shlq $0x2, %rdx
movq %rdx, 0x28(%rsp)
movslq %edi, %rbp
movslq %eax, %r15
incl %ecx
movq %rsi, 0x10(%rsp)
movl %esi, %r14d
movl %eax, %ebx
movsd 0x17a9d7(%rip), %xmm1   # 0x584030
movl %ecx, 0x20(%rsp)
movsd %xmm1, 0x8(%rsp)
testl %r8d, %r8d
jle 0x40967f
movq %r13, %rdi
movl $0xff, %esi
movq 0x28(%rsp), %rdx
callq 0x401060
movq 0x30(%rsp), %r8
cmpl $0x0, 0x10(%rsp)
jle 0x4096af
xorl %eax, %eax
movq %r15, %rcx
addq %rax, %rcx
sets %dl
cmpq %rbp, %rcx
setge %cl
orb %dl, %cl
jne 0x4096a7
movslq (%r12,%rax,4), %rcx
leal (%rbx,%rax), %edx
movl %edx, (%r13,%rcx,4)
incq %rax
cmpq %rax, %r14
jne 0x409688
testl %r8d, %r8d
setle %r12b
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl %r8d, %ecx
movq %r13, %r8
callq 0x407a58
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
setb %al
orb %r12b, %al
je 0x4096e3
maxsd %xmm0, %xmm1
jmp 0x409704
movq 0x90(%rsp), %rdi
movq %r13, %rsi
movq 0x28(%rsp), %rdx
movsd %xmm0, 0x8(%rsp)
callq 0x401118
movsd 0x8(%rsp), %xmm1
movq 0x18(%rsp), %r12
movl 0x20(%rsp), %ecx
incq %r15
incq %rbx
cmpl %r15d, %ecx
movq 0x30(%rsp), %r8
jne 0x40965d
jmp 0x409608