// File: /workspace/github_cpp_makefile_star2_O3/dcarrey[P]hgt-detection/./fonctions.cpp
// Function: midPoint(long*, double**, int, int)
int midPoint(long int *ARETE,double **DIST,int n,int kt){

	double max;
	int i,j,i1,j1,P;


	/*/== recherche la plus grande distance*/
	max = 0;
	for(i=1;i<=n;i++){
/*		printf("\n");*/
		for(j=1;j<=n;j++){
		/*	printf("%lf ",DIST[i][j]);*/
			if(DIST[i][j] > max){
				max = DIST[i][j];
				i1=i; j1=j;
			}
		}
	}
//		printf("\nnouvel arbre :  ");
//		printf(" %d-%d, max =%lf",i1,j1,max);
	P = -1;
	for(i=1;i<=2*n-3-kt;i++){
		if(ARETE[2*i-1] == i1 || ARETE[2*i-1] == j1 || ARETE[2*i-2] == i1 || ARETE[2*i-2] == j1 ){
			if(DIST[ARETE[2*i-1]][ARETE[2*i-2]] >= max/2.0){
				P = i;
			//	printf("icit meme ");
				break;
			}
		}
		else{
			if(ARETE[2*i-1] > n && ARETE[2*i-2]> n)
			  if( (((DIST[i1][ARETE[2*i-1]]>(max/2.0)) || (fabs(DIST[i1][ARETE[2*i-1]]-(max/2.0))<0.00001)) && 
				     ((DIST[j1][ARETE[2*i-2]]>(max/2.0)) || (fabs(DIST[j1][ARETE[2*i-2]]-(max/2.0))<0.00001))) ||
		        (((DIST[i1][ARETE[2*i-2]]>(max/2.0)) || (fabs(DIST[i1][ARETE[2*i-2]]-(max/2.0))<0.00001)) && 
				      ((DIST[j1][ARETE[2*i-1]]>(max/2.0)) || (fabs(DIST[j1][ARETE[2*i-1]]-(max/2.0))<0.00001))) 
		     ){
					P = i;
			//		printf("la meme ");

					if( fabs(DIST[i1][j1] - DIST[i1][ARETE[2*i-1]] - DIST[ARETE[2*i-1]][j1]) < 0.00001 )
						break;
			}
		}
	}
//	printf(" ,arete : %d--%d (%d) \n",ARETE[2*(*P)-1],ARETE[2*(*P)-2],(*P));

	return P;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
testl %edx, %edx
jle 0xb643
leal 0x1(%rdx), %eax
xorpd %xmm0, %xmm0
movl $0x1, %r8d
movq (%rsi,%r8,8), %r11
movl $0x1, %ebx
movapd %xmm0, %xmm1
movsd (%r11,%rbx,8), %xmm0
ucomisd %xmm1, %xmm0
cmoval %r8d, %r10d
cmoval %ebx, %r9d
maxsd %xmm1, %xmm0
incq %rbx
cmpq %rbx, %rax
jne 0xb609
incq %r8
cmpq %rax, %r8
jne 0xb600
movslq %r10d, %r8
movslq %r9d, %r9
mulsd 0x99c7(%rip), %xmm0     # 0x15008
jmp 0xb64d
xorpd %xmm0, %xmm0
xorl %r8d, %r8d
xorl %r9d, %r9d
leal (%rdx,%rdx), %r10d
subl %ecx, %r10d
leal -0x3(%r10), %eax
testl %eax, %eax
jle 0xb783
movslq %edx, %rcx
addl $-0x2, %r10d
addq $0x8, %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %edx
movapd 0x9a03(%rip), %xmm1     # 0x15080
movsd 0x99a3(%rip), %xmm2     # 0x15028
movq -0x8(%rdi), %rbx
movq (%rdi), %r11
cmpq %r8, %r11
je 0xb761
cmpq %r9, %r11
je 0xb761
cmpq %r8, %rbx
je 0xb761
cmpq %r9, %rbx
je 0xb761
cmpq %rcx, %r11
setle %r14b
cmpq %rcx, %rbx
setle %r15b
orb %r14b, %r15b
jne 0xb771
movq (%rsi,%r8,8), %r14
movsd (%r14,%r11,8), %xmm3
ucomisd %xmm0, %xmm3
ja 0xb6e9
movapd %xmm3, %xmm4
subsd %xmm0, %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
jbe 0xb707
movq (%rsi,%r9,8), %r15
movsd (%r15,%rbx,8), %xmm4
ucomisd %xmm0, %xmm4
ja 0xb73f
subsd %xmm0, %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
ja 0xb73f
movsd (%r14,%rbx,8), %xmm4
ucomisd %xmm0, %xmm4
ja 0xb721
subsd %xmm0, %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
jbe 0xb771
movq (%rsi,%r9,8), %rbx
movsd (%rbx,%r11,8), %xmm4
ucomisd %xmm0, %xmm4
ja 0xb73f
subsd %xmm0, %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
jbe 0xb771
movsd (%r14,%r9,8), %xmm4
subsd %xmm3, %xmm4
movq (%rsi,%r11,8), %rax
subsd (%rax,%r9,8), %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
ja 0xb78a
movl %edx, %eax
jmp 0xb771
movq (%rsi,%r11,8), %r11
movsd (%r11,%rbx,8), %xmm3
ucomisd %xmm0, %xmm3
jae 0xb78a
incq %rdx
addq $0x10, %rdi
cmpq %rdx, %r10
jne 0xb685
jmp 0xb78c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xb78c
movl %edx, %eax
popq %rbx
popq %r14
popq %r15
popq %rbp
retq