// File: 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
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x13f24
movl $0x1, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x13f17
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x13f0a
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x20(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x13f0c
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x13ec0
jmp 0x13f19
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x13eb1
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0x14(%rbp), %ecx
shll %ecx
subl $0x3, %ecx
subl -0x18(%rbp), %ecx
cmpl %ecx, %eax
jg 0x1432e
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
shll %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
cmpq %rcx, %rax
je 0x13fb8
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
shll %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
cmpq %rcx, %rax
je 0x13fb8
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
cmpq %rcx, %rax
je 0x13fb8
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jne 0x14012
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x20(%rbp), %xmm1
movsd 0x11010(%rip), %xmm2    # 0x25008
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1400d
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x1432e
jmp 0x1431e
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
shll %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x14(%rbp), %rcx
cmpq %rcx, %rax
jle 0x1431c
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x14(%rbp), %rcx
cmpq %rcx, %rax
jle 0x1431c
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x20(%rbp), %xmm1
movsd 0x10f85(%rip), %xmm2    # 0x25008
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
ja 0x140e3
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x20(%rbp), %xmm0
movsd 0x10f4a(%rip), %xmm2    # 0x25008
divsd %xmm2, %xmm0
subsd %xmm0, %xmm1
movaps 0x10fb3(%rip), %xmm0    # 0x25080
pand %xmm0, %xmm1
movsd 0x10f57(%rip), %xmm0    # 0x25030
ucomisd %xmm1, %xmm0
jbe 0x14178
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x20(%rbp), %xmm1
movsd 0x10ef4(%rip), %xmm2    # 0x25008
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
ja 0x1429a
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x20(%rbp), %xmm0
movsd 0x10eb5(%rip), %xmm2    # 0x25008
divsd %xmm2, %xmm0
subsd %xmm0, %xmm1
movaps 0x10f1e(%rip), %xmm0    # 0x25080
pand %xmm0, %xmm1
movsd 0x10ec2(%rip), %xmm0    # 0x25030
ucomisd %xmm1, %xmm0
ja 0x1429a
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x20(%rbp), %xmm1
movsd 0x10e5f(%rip), %xmm2    # 0x25008
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
ja 0x14209
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x20(%rbp), %xmm0
movsd 0x10e24(%rip), %xmm2    # 0x25008
divsd %xmm2, %xmm0
subsd %xmm0, %xmm1
movaps 0x10e8d(%rip), %xmm0    # 0x25080
pand %xmm0, %xmm1
movsd 0x10e31(%rip), %xmm0    # 0x25030
ucomisd %xmm1, %xmm0
jbe 0x1431a
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x20(%rbp), %xmm1
movsd 0x10dce(%rip), %xmm2    # 0x25008
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
ja 0x1429a
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x20(%rbp), %xmm0
movsd 0x10d93(%rip), %xmm2    # 0x25008
divsd %xmm2, %xmm0
subsd %xmm0, %xmm1
movaps 0x10dfc(%rip), %xmm0    # 0x25080
pand %xmm0, %xmm1
movsd 0x10da0(%rip), %xmm0    # 0x25030
ucomisd %xmm1, %xmm0
jbe 0x1431a
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
subsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movl -0x24(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm1
movaps 0x10d7c(%rip), %xmm0    # 0x25080
pand %xmm0, %xmm1
movsd 0x10d20(%rip), %xmm0    # 0x25030
ucomisd %xmm1, %xmm0
jbe 0x14318
jmp 0x1432e
jmp 0x1431a
jmp 0x1431c
jmp 0x1431e
jmp 0x14320
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x13f32
movl -0x34(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)