// File: /workspace/github_c_makefile_star2_O3/asford[P]tmalign/./TMalign.h
// Function: find_max_frag(double**, int*, int, int*, int*)
void find_max_frag(double **x, int *resno, int len, int *start_max, int *end_max)
{
	int r_min, fra_min=4;           //minimum fragment for search
	double d;
	int start;
	int Lfr_max=0, flag;

	r_min= (int) (len*1.0/3.0); //minimum fragment, in case too small protein
	if(r_min > fra_min) r_min=fra_min;
	
	int inc=0;
	double dcu0_cut=dcu0*dcu0;;
	double dcu_cut=dcu0_cut;

	while(Lfr_max < r_min)
	{		
		Lfr_max=0;			
		int j=1;    //number of residues at nf-fragment
		start=0;
		for(int i=1; i<len; i++)
		{			
			d = dist(x[i-1], x[i]);
			flag=0;
			if(dcu_cut>dcu0_cut)
			{
				if(d<dcu_cut)
				{
					flag=1;
				}
			}
			else if(resno[i] == (resno[i-1]+1)) //necessary??
			{
				if(d<dcu_cut)
				{
					flag=1;
				}
			}

			if(flag==1)
			{
				j++;

				if(i==(len-1))
				{
					if(j > Lfr_max) 
					{
						Lfr_max=j;
						*start_max=start;
						*end_max=i;						
					}
					j=1;
				}
			}
			else
			{
				if(j>Lfr_max) 
				{
					Lfr_max=j;
					*start_max=start;
					*end_max=i-1;										
				}

				j=1;
				start=i;
			}
		}// for i;
		
		if(Lfr_max < r_min)
		{
			inc++;
			double dinc=pow(1.1, (double) inc) * dcu0;
			dcu_cut= dinc*dinc;
		}
	}//while <;	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, 0x8(%rsp)
cvtsi2sd %edx, %xmm0
mulsd 0x17afa4(%rip), %xmm0   # 0x584010
cvttsd2si %xmm0, %eax
cmpl $0x4, %eax
movl $0x4, %edx
cmovll %eax, %edx
movl %edx, (%rsp)
testl %eax, %eax
jle 0x4091e4
movq %rcx, %r15
movq %rsi, %r12
movq %rdi, %r13
movsd 0x1f94f9(%rip), %xmm0   # 0x602590
movsd %xmm0, 0x20(%rsp)
movapd %xmm0, %xmm7
mulsd %xmm0, %xmm7
movq 0x8(%rsp), %rax
leal -0x1(%rax), %r9d
movl %eax, %ebp
leaq -0x1(%r9), %rbx
decq %rbp
xorl %r14d, %r14d
movapd %xmm7, %xmm0
movsd %xmm7, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movl $0x0, %edx
cmpl $0x2, 0x8(%rsp)
jl 0x409197
movq (%r13), %rax
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm2
movsd 0x10(%rax), %xmm3
xorl %eax, %eax
movl $0x1, %esi
xorl %r11d, %r11d
xorl %edx, %edx
movapd %xmm1, %xmm5
movapd %xmm2, %xmm6
movapd %xmm3, %xmm4
ucomisd %xmm7, %xmm0
movq 0x8(%r13,%rax,8), %rdi
movsd (%rdi), %xmm1
movsd 0x8(%rdi), %xmm2
subsd %xmm1, %xmm5
subsd %xmm2, %xmm6
movsd 0x10(%rdi), %xmm3
subsd %xmm3, %xmm4
mulsd %xmm5, %xmm5
mulsd %xmm6, %xmm6
addsd %xmm5, %xmm6
mulsd %xmm4, %xmm4
addsd %xmm6, %xmm4
ja 0x409149
movl (%r12,%rax,4), %edi
incl %edi
cmpl %edi, 0x4(%r12,%rax,4)
jne 0x409163
ucomisd %xmm0, %xmm4
jae 0x409163
leal 0x1(%rsi), %edi
cmpq %rax, %rbx
jne 0x409189
cmpl %edx, %esi
jl 0x40917a
movl %r11d, (%r15)
movl %r9d, %edx
jmp 0x409175
leaq 0x1(%rax), %r10
cmpl %edx, %esi
jle 0x409181
movl %r11d, (%r15)
movl %eax, %edx
movl %esi, %edi
movl %r10d, %r11d
movl %edx, (%r8)
movl %edi, %edx
movl $0x1, %edi
jmp 0x409189
movl $0x1, %edi
movl %r10d, %r11d
incq %rax
movl %edi, %esi
cmpq %rax, %rbp
jne 0x4090f7
cmpl (%rsp), %edx
jge 0x4091e4
incl %r14d
movl %r14d, 0x4(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x17aed4(%rip), %xmm0   # 0x584088
movq %r9, %rbx
movq %r8, %r14
callq 0x4abc30
movq %r14, %r8
movl 0x4(%rsp), %r14d
movq %rbx, %r9
movq 0x10(%rsp), %rbx
movsd 0x18(%rsp), %xmm7
mulsd 0x20(%rsp), %xmm0
mulsd %xmm0, %xmm0
jmp 0x4090c9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq