// File: /workspace/github_c_makefile_star2_O1/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
cvtsi2sd %edx, %xmm0
mulsd 0x17b046(%rip), %xmm0   # 0x584010
cvttsd2si %xmm0, %eax
cmpl $0x4, %eax
movl $0x4, %r14d
cmovll %eax, %r14d
testl %eax, %eax
jle 0x409133
movq %rsi, %r12
movq %rdi, %r13
movsd 0x1f959f(%rip), %xmm0   # 0x602590
movsd %xmm0, 0x10(%rsp)
movapd %xmm0, %xmm4
mulsd %xmm0, %xmm4
leal -0x1(%rdx), %r15d
movl %edx, %ebp
movl $0x0, (%rsp)
movapd %xmm4, %xmm0
movq %r8, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movl %r14d, 0x4(%rsp)
movsd %xmm4, 0x8(%rsp)
movl $0x0, %ebx
cmpl $0x2, %edx
jl 0x4090e4
xorl %r10d, %r10d
movl $0x1, %r11d
movl $0x1, %eax
xorl %ebx, %ebx
ucomisd %xmm4, %xmm0
movq -0x8(%r13,%rax,8), %rsi
movq (%r13,%rax,8), %rdi
movsd (%rsi), %xmm2
movsd 0x8(%rsi), %xmm3
subsd (%rdi), %xmm2
subsd 0x8(%rdi), %xmm3
movsd 0x10(%rsi), %xmm1
subsd 0x10(%rdi), %xmm1
mulsd %xmm2, %xmm2
mulsd %xmm3, %xmm3
addsd %xmm2, %xmm3
mulsd %xmm1, %xmm1
addsd %xmm3, %xmm1
ja 0x409090
movl -0x4(%r12,%rax,4), %esi
incl %esi
cmpl %esi, (%r12,%rax,4)
jne 0x4090ac
ucomisd %xmm0, %xmm1
jae 0x4090ac
leal 0x1(%r11), %esi
cmpq %rax, %r15
jne 0x4090d5
movq %rax, %rdi
movl %r10d, %r9d
cmpl %ebx, %r11d
jge 0x4090bb
jmp 0x4090c6
cmpl %ebx, %r11d
jle 0x4090cd
leaq -0x1(%rax), %rdi
movl %r11d, %esi
movl %eax, %r9d
movl %r10d, (%rcx)
movl %edi, (%r8)
movl %esi, %ebx
movl %r9d, %r10d
movl $0x1, %esi
jmp 0x4090d5
movl $0x1, %esi
movl %eax, %r10d
incq %rax
movl %esi, %r11d
cmpq %rax, %rbp
jne 0x409043
cmpl %r14d, %ebx
jge 0x40912a
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x17af88(%rip), %xmm0   # 0x584088
movq %rcx, %r14
callq 0x4ab990
movsd 0x8(%rsp), %xmm4
movq 0x18(%rsp), %rdx
movq %r14, %rcx
movl 0x4(%rsp), %r14d
movq 0x20(%rsp), %r8
mulsd 0x10(%rsp), %xmm0
mulsd %xmm0, %xmm0
cmpl %r14d, %ebx
jl 0x409025
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq