// File: /workspace/github_c_makefile_star2_O1/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 0x2c(%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 0x408fb0
movq %r15, 0x40(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movl %r12d, %edx
leaq 0x2c(%rsp), %rcx
movq %rbp, %r8
callq 0x408fb0
movl (%r14), %r14d
movl (%r13), %r15d
subl %r15d, %r14d
movl (%rbp), %r13d
leaq 0x2c(%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 %ebx, %rax
cmpl $-0x1, %eax
leaq 0x4(,%rax,4), %rdi
movq $-0x1, %rax
cmovlq %rax, %rdi
callq 0x40d060
movq %rax, 0x20(%rsp)
movslq %r12d, %rax
leaq 0x4(,%rax,4), %rdi
cmpl $-0x1, %eax
movq $-0x1, %rax
cmovlq %rax, %rdi
callq 0x40d060
movl %r13d, %r10d
movl %r14d, %r9d
movl 0x8(%rsp), %edi
movl %r12d, %r8d
movq %rax, %r13
cmpl %r10d, %r14d
jl 0x40923f
cmpl %r8d, %edi
jg 0x4092ed
cmpl %r10d, %r9d
jne 0x4092ed
testl %ebx, %ebx
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %r14
js 0x4093ac
movd %ebx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl %ebx
andl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
leaq 0x8(,%rbx,8), %rax
movdqa 0x17ae8e(%rip), %xmm1   # 0x584100
xorl %ecx, %ecx
movdqa 0x17ae94(%rip), %xmm2   # 0x584110
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x17aea4(%rip), %xmm4   # 0x584130
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 0x4092c1
movl %r15d, (%rsi,%rcx)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x4092d7
leal 0x1(%r15), %edx
movl %edx, 0x4(%rsi,%rcx)
paddq %xmm4, %xmm1
addq $0x8, %rcx
addl $0x2, %r15d
cmpq %rcx, %rax
jne 0x40928c
jmp 0x4093ac
cmpl %r8d, %edi
setg %al
cmpl %r10d, %r9d
sete %dl
setg %cl
testl %ebx, %ebx
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %r14
js 0x4093ac
andb %dl, %al
orb %al, %cl
je 0x4093ac
movd %ebx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl %ebx
andl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
leaq 0x8(,%rbx,8), %rax
movdqa 0x17adc7(%rip), %xmm1   # 0x584100
xorl %ecx, %ecx
movdqa 0x17adcd(%rip), %xmm2   # 0x584110
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x17addd(%rip), %xmm4   # 0x584130
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 0x409387
movl %ebp, (%rsi,%rcx)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x40939c
leal 0x1(%rbp), %edx
movl %edx, 0x4(%rsi,%rcx)
paddq %xmm4, %xmm1
addq $0x8, %rcx
addl $0x2, %ebp
cmpq %rcx, %rax
jne 0x409353
cmpl %r8d, %edi
movl %r8d, %eax
cmovll %edi, %eax
cmpl %eax, %r14d
jne 0x409403
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0x17adb3(%rip), %xmm0   # 0x584180
cvttpd2dq %xmm0, %xmm0
movd %xmm0, %ecx
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %eax
xorl %r14d, %r14d
cmpl %eax, %ecx
jg 0x409403
movslq %ecx, %rdx
subl %ecx, %eax
incl %eax
leaq (%rsi,%rdx,4), %rcx
xorl %r14d, %r14d
movl (%rcx,%r14,4), %edx
movl %edx, (%rsi,%r14,4)
incq %r14
cmpq %r14, %rax
jne 0x4093f3
cmpl %r10d, %r9d
movl %r8d, 0x1c(%rsp)
jl 0x40941f
cmpl %r8d, %edi
jg 0x409522
cmpl %r10d, %r9d
jne 0x409522
cmpl %r8d, %r14d
movl %r8d, %eax
cmovll %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x17ac58(%rip), %xmm0   # 0x584090
cvttsd2si %xmm0, %ecx
cmpl $0x4, %ecx
movl $0x3, %eax
cmovgel %ecx, %eax
movl %r14d, %ecx
subl %eax, %ecx
subl %r8d, %eax
cmpl %ecx, %eax
jg 0x409554
movslq %r14d, %r14
movl %r8d, %r15d
leaq (,%r15,4), %rdx
movq %rdx, 0x30(%rsp)
movslq %eax, %r12
incl %ecx
movq 0x20(%rsp), %rax
leaq (%rax,%r12,4), %rbp
movsd 0x17abb0(%rip), %xmm1   # 0x584030
movl %ecx, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
testl %r8d, %r8d
jle 0x4094b4
xorl %eax, %eax
movq %r12, %rdx
addq %rax, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
js 0x4094a7
cmpq %r14, %rdx
jge 0x4094a7
movl (%rbp,%rax,4), %ecx
movl %ecx, (%r13,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x409491
testl %r8d, %r8d
setle %bl
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl %r8d, %ecx
movq %r13, %r8
callq 0x407b41
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
setb %al
orb %bl, %al
je 0x4094e6
maxsd %xmm0, %xmm1
jmp 0x409507
movq 0x90(%rsp), %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rdx
movsd %xmm0, 0x8(%rsp)
callq 0x401118
movsd 0x8(%rsp), %xmm1
movl 0x10(%rsp), %ecx
incq %r12
addq $0x4, %rbp
cmpl %r12d, %ecx
movl 0x1c(%rsp), %r8d
jne 0x409484
jmp 0x40955c
cmpl %edi, %r14d
movl %edi, %eax
cmovll %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x17ab56(%rip), %xmm0   # 0x584090
cvttsd2si %xmm0, %ecx
cmpl $0x4, %ecx
movl $0x3, %eax
cmovgel %ecx, %eax
movl %edi, %ecx
subl %eax, %ecx
subl %r14d, %eax
cmpl %ecx, %eax
jle 0x409589
movsd 0x17aad4(%rip), %xmm1   # 0x584030
movsd %xmm1, 0x8(%rsp)
movq 0x20(%rsp), %rdi
callq 0x40c360
movq %r13, %rdi
callq 0x40c360
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, 0x30(%rsp)
movslq %edi, %rbp
movslq %eax, %r15
incl %ecx
movl %r14d, %ebx
movl %eax, %r12d
movsd 0x17aa85(%rip), %xmm1   # 0x584030
movq %r14, 0x10(%rsp)
movl %ecx, 0x28(%rsp)
movsd %xmm1, 0x8(%rsp)
testl %r8d, %r8d
jle 0x4095d6
movq %r13, %rdi
movl $0xff, %esi
movq 0x30(%rsp), %rdx
callq 0x401060
movl 0x1c(%rsp), %r8d
testl %r14d, %r14d
movq 0x20(%rsp), %rsi
jle 0x40960a
xorl %eax, %eax
movq %r15, %rcx
addq %rax, %rcx
sets %dl
cmpq %rbp, %rcx
setge %cl
orb %dl, %cl
jne 0x409602
movslq (%rsi,%rax,4), %rcx
leal (%r12,%rax), %edx
movl %edx, (%r13,%rcx,4)
incq %rax
cmpq %rax, %rbx
jne 0x4095e2
testl %r8d, %r8d
setle %r14b
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl %r8d, %ecx
movq %r13, %r8
callq 0x407b41
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
setb %al
orb %r14b, %al
je 0x40963e
maxsd %xmm0, %xmm1
jmp 0x40965f
movq 0x90(%rsp), %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rdx
movsd %xmm0, 0x8(%rsp)
callq 0x401118
movsd 0x8(%rsp), %xmm1
movl 0x28(%rsp), %ecx
incq %r15
incq %r12
cmpl %r15d, %ecx
movl 0x1c(%rsp), %r8d
movq 0x10(%rsp), %r14
jne 0x4095b4
jmp 0x40955c