// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xe8, %rsp
movq 0xf0(%rsp), %rax
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movl %edx, 0xd4(%rsp)
movl %ecx, 0xd0(%rsp)
movq %r8, 0xc8(%rsp)
movq %r9, 0xc0(%rsp)
movl $0x4, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
subl $0x1, %eax
movl %eax, 0xb8(%rsp)
movl $0x0, 0xb4(%rsp)
movl $0x0, 0xb0(%rsp)
movl $0x0, 0xac(%rsp)
movl $0x0, 0xa8(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movl 0xd4(%rsp), %edx
leaq 0xb4(%rsp), %rcx
leaq 0xac(%rsp), %r8
callq 0x40c0e0
movq 0xd8(%rsp), %rdi
movq 0xc0(%rsp), %rsi
movl 0xd0(%rsp), %edx
leaq 0xb0(%rsp), %rcx
leaq 0xa8(%rsp), %r8
callq 0x40c0e0
movl 0xac(%rsp), %eax
subl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa4(%rsp)
movl 0xa8(%rsp), %eax
subl 0xb0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa0(%rsp)
movl 0xa4(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jle 0x40c46a
movl 0xa0(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x40c475
movl 0xa4(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x8c(%rsp)
movslq 0x8c(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x411b60
movq %rax, 0x98(%rsp)
movl 0xd0(%rsp), %eax
addl $0x1, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x411b60
movq %rax, 0x90(%rsp)
movl 0xa4(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jl 0x40c516
movl 0xa4(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jne 0x40c56a
movl 0xd4(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jg 0x40c56a
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jge 0x40c565
movl 0xb4(%rsp), %edx
addl 0x88(%rsp), %edx
movq 0x98(%rsp), %rax
movslq 0x88(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0x40c521
jmp 0x40c5ed
movl 0xa4(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jg 0x40c59a
movl 0xa4(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jne 0x40c5eb
movl 0xd4(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jle 0x40c5eb
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jge 0x40c5e9
movl 0xb0(%rsp), %edx
addl 0x84(%rsp), %edx
movq 0x98(%rsp), %rax
movslq 0x84(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x40c5a5
jmp 0x40c5eb
jmp 0x40c5ed
movl 0xd4(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jle 0x40c60a
movl 0xd0(%rsp), %eax
movl %eax, 0x18(%rsp)
jmp 0x40c615
movl 0xd4(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x80(%rsp)
movl 0x8c(%rsp), %eax
cmpl 0x80(%rsp), %eax
jne 0x40c6cb
cvtsi2sdl 0x80(%rsp), %xmm0
movsd 0x17fa63(%rip), %xmm1   # 0x58c0a8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x7c(%rsp)
cvtsi2sdl 0x80(%rsp), %xmm0
movsd 0x17fa3e(%rip), %xmm1   # 0x58c0a0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x78(%rsp)
movl $0x0, 0x74(%rsp)
movl 0x7c(%rsp), %eax
movl %eax, 0x70(%rsp)
movl 0x70(%rsp), %eax
cmpl 0x78(%rsp), %eax
jg 0x40c6c0
movq 0x98(%rsp), %rax
movslq 0x70(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x98(%rsp), %rax
movslq 0x74(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0x40c67e
movl 0x74(%rsp), %eax
movl %eax, 0x8c(%rsp)
movsd 0x17f96d(%rip), %xmm0   # 0x58c040
movsd %xmm0, 0x60(%rsp)
movl 0xa4(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jl 0x40c711
movl 0xa4(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jne 0x40c8c8
movl 0xd4(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jg 0x40c8c8
movl 0x8c(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jle 0x40c736
movl 0xd0(%rsp), %eax
movl %eax, 0x14(%rsp)
jmp 0x40c73e
movl 0x5c(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x58(%rsp)
cvtsi2sdl 0x58(%rsp), %xmm0
movsd 0x17f95c(%rip), %xmm1   # 0x58c0b0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0xb8(%rsp), %eax
jg 0x40c778
movl 0xb8(%rsp), %eax
movl %eax, 0x54(%rsp)
xorl %eax, %eax
subl 0xd0(%rsp), %eax
addl 0x54(%rsp), %eax
movl %eax, 0x50(%rsp)
movl 0x5c(%rsp), %eax
subl 0x54(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x50(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jg 0x40c8c3
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jge 0x40c822
movl 0x44(%rsp), %eax
addl 0x40(%rsp), %eax
movl %eax, 0x48(%rsp)
cmpl $0x0, 0x48(%rsp)
jl 0x40c7ff
movl 0x48(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jge 0x40c7ff
movq 0x98(%rsp), %rax
movslq 0x48(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x90(%rsp), %rax
movslq 0x44(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x40c813
movq 0x90(%rsp), %rax
movslq 0x44(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x40c815
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x40c7b3
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl 0xd4(%rsp), %edx
movl 0xd0(%rsp), %ecx
movq 0x90(%rsp), %r8
callq 0x40a1f0
movsd %xmm0, 0x68(%rsp)
movsd 0x68(%rsp), %xmm0
ucomisd 0x60(%rsp), %xmm0
jb 0x40c8b1
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jge 0x40c8af
movq 0x90(%rsp), %rax
movslq 0x44(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0xf0(%rsp), %rax
movslq 0x44(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x40c875
jmp 0x40c8b1
jmp 0x40c8b3
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x40c79d
jmp 0x40ca9c
movl 0x8c(%rsp), %eax
movl %eax, 0x3c(%rsp)
movl 0xd4(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jle 0x40c8ea
movl 0x3c(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0x40c8f5
movl 0xd4(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x38(%rsp)
cvtsi2sdl 0x38(%rsp), %xmm0
movsd 0x17f7a5(%rip), %xmm1   # 0x58c0b0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
cmpl 0xb8(%rsp), %eax
jg 0x40c92f
movl 0xb8(%rsp), %eax
movl %eax, 0x34(%rsp)
xorl %eax, %eax
subl 0x3c(%rsp), %eax
addl 0x34(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0xd4(%rsp), %eax
subl 0x34(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jg 0x40ca9a
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jge 0x40c998
movq 0x90(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x40c96a
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0x40c9f9
movl 0x24(%rsp), %eax
addl 0x20(%rsp), %eax
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x28(%rsp)
jl 0x40c9ea
movl 0x28(%rsp), %eax
cmpl 0xd4(%rsp), %eax
jge 0x40c9ea
movl 0x28(%rsp), %edx
movq 0x90(%rsp), %rax
movq 0x98(%rsp), %rcx
movslq 0x24(%rsp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x40c9ec
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x40c9a0
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl 0xd4(%rsp), %edx
movl 0xd0(%rsp), %ecx
movq 0x90(%rsp), %r8
callq 0x40a1f0
movsd %xmm0, 0x68(%rsp)
movsd 0x68(%rsp), %xmm0
ucomisd 0x60(%rsp), %xmm0
jb 0x40ca88
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jge 0x40ca86
movq 0x90(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0xf0(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x40ca4c
jmp 0x40ca88
jmp 0x40ca8a
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x40c954
jmp 0x40ca9c
movq 0x98(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x40cab9
movq 0x8(%rsp), %rdi
callq 0x410cc0
movq 0x90(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x40cad4
movq (%rsp), %rdi
callq 0x410cc0
movsd 0x60(%rsp), %xmm0
addq $0xe8, %rsp
retq
nopw %cs:(%rax,%rax)