// File: /workspace/github_cpp_makefile_star2_O1/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 0xb6be
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 0xb684
incq %r8
cmpq %rax, %r8
jne 0xb67b
movslq %r10d, %r8
movslq %r9d, %r9
mulsd 0x994c(%rip), %xmm0     # 0x15008
jmp 0xb6c8
xorpd %xmm0, %xmm0
xorl %r8d, %r8d
xorl %r9d, %r9d
leal (%rdx,%rdx), %r10d
subl %ecx, %r10d
leal -0x3(%r10), %eax
testl %eax, %eax
jle 0xb7fc
movslq %edx, %rcx
addl $-0x2, %r10d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %edx
movapd 0x998c(%rip), %xmm1     # 0x15080
movsd 0x992c(%rip), %xmm2     # 0x15028
movq 0x8(%rdi), %r11
cmpq %r8, %r11
je 0xb7d7
cmpq %r9, %r11
je 0xb7d7
movq (%rdi), %r14
cmpq %r8, %r14
je 0xb7d7
cmpq %r9, %r14
je 0xb7d7
cmpq %rcx, %r11
setle %bl
cmpq %rcx, %r14
setle %r15b
orb %bl, %r15b
jne 0xb7ea
movq (%rsi,%r8,8), %rbx
movsd (%rbx,%r11,8), %xmm3
ucomisd %xmm0, %xmm3
ja 0xb75f
movapd %xmm3, %xmm4
subsd %xmm0, %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
jbe 0xb77d
movq (%rsi,%r9,8), %r15
movsd (%r15,%r14,8), %xmm4
ucomisd %xmm0, %xmm4
ja 0xb7b5
subsd %xmm0, %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
ja 0xb7b5
movsd (%rbx,%r14,8), %xmm4
ucomisd %xmm0, %xmm4
ja 0xb797
subsd %xmm0, %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
jbe 0xb7ea
movq (%rsi,%r9,8), %r14
movsd (%r14,%r11,8), %xmm4
ucomisd %xmm0, %xmm4
ja 0xb7b5
subsd %xmm0, %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
jbe 0xb7ea
movsd (%rbx,%r9,8), %xmm4
subsd %xmm3, %xmm4
movq (%rsi,%r11,8), %rax
subsd (%rax,%r9,8), %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
ja 0xb803
movl %edx, %eax
jmp 0xb7ea
movq (%rsi,%r11,8), %r11
movq (%rdi), %rbx
movsd (%r11,%rbx,8), %xmm3
ucomisd %xmm0, %xmm3
jae 0xb803
incq %rdx
addq $0x10, %rdi
cmpq %rdx, %r10
jne 0xb6fc
jmp 0xb805
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xb805
movl %edx, %eax
popq %rbx
popq %r14
popq %r15
popq %rbp
retq