// File: dcarrey[P]hgt-detection/./fonctions.cpp
// Function: findBranch(InputTree, int*, int*)
void findBranch(struct InputTree aTree,int *branch, int * elt){
	
	double max = INFINI; //= disctance between root and intersection
	int j;

	(*branch) = 0;
	
	if(elt[0]==1){
		for(j=1;j<=2*aTree.size-3-aTree.kt;j++)
			if(aTree.ARETE[2*j-1]==elt[1] || aTree.ARETE[2*j-2]==elt[1])
				(*branch) = j;
	}
	else{
		for(j=2;j<=elt[0];j++){		
			if(max > ( (aTree.ADD[aTree.Root][elt[1]] + aTree.ADD[aTree.Root][elt[j]] - aTree.ADD[elt[1]][elt[j]]) / 2.0 ) )
				max = (aTree.ADD[aTree.Root][elt[1]] + aTree.ADD[aTree.Root][elt[j]] - aTree.ADD[elt[1]][elt[j]]) / 2.0 ;  
		}
		//printf("\nmax=%lf",max);	

		for(j=1;j<=2*aTree.size-3-aTree.kt;j++){
			if( (fabs(aTree.ADD[aTree.Root][aTree.ARETE[2*j-1]]- max) < 2*epsilon) && (aTree.ADD[aTree.Root][aTree.ARETE[2*j-2]] < aTree.ADD[aTree.Root][aTree.ARETE[2*j-1]]) && (fabs(aTree.ADD[aTree.Root][aTree.ARETE[2*j-1]]+aTree.ADD[aTree.ARETE[2*j-1]][elt[1]] - aTree.ADD[aTree.Root][elt[1]]) < 2*epsilon)  )
				(*branch) = j;
			if( (fabs(aTree.ADD[aTree.Root][aTree.ARETE[2*j-2]]- max) < 2*epsilon) && (aTree.ADD[aTree.Root][aTree.ARETE[2*j-1]] < aTree.ADD[aTree.Root][aTree.ARETE[2*j-2]]) && (fabs(aTree.ADD[aTree.Root][aTree.ARETE[2*j-2]]+aTree.ADD[aTree.ARETE[2*j-2]][elt[1]] - aTree.ADD[aTree.Root][elt[1]]) < 2*epsilon))
				(*branch) = j;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq 0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd 0xd9dc(%rip), %xmm0     # 0x25028
movsd %xmm0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x176e3
movl $0x1, -0x1c(%rbp)
movq -0x28(%rbp), %rdx
movl -0x1c(%rbp), %eax
movl (%rdx), %ecx
shll %ecx
subl $0x3, %ecx
subl 0x48(%rdx), %ecx
cmpl %ecx, %eax
jg 0x176de
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movslq 0x4(%rcx), %rcx
cmpq %rcx, %rax
je 0x176c8
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movslq 0x4(%rcx), %rcx
cmpq %rcx, %rax
jne 0x176d1
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
jmp 0x176d3
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1766b
jmp 0x17a6f
movl $0x2, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jg 0x177e7
movq -0x28(%rbp), %rax
movsd -0x18(%rbp), %xmm0
movq 0x8(%rax), %rcx
movslq 0x20(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x10(%rbp), %rdx
movslq 0x4(%rdx), %rdx
movsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rcx
movslq 0x20(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x10(%rbp), %rdx
movslq -0x1c(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
addsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
subsd (%rax,%rcx,8), %xmm1
movsd 0xd8a7(%rip), %xmm2     # 0x25008
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x177d7
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movslq 0x20(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x10(%rbp), %rdx
movslq 0x4(%rdx), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x8(%rax), %rcx
movslq 0x20(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x10(%rbp), %rdx
movslq -0x1c(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
addsd (%rcx,%rdx,8), %xmm0
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
subsd (%rax,%rcx,8), %xmm0
movsd 0xd83a(%rip), %xmm1     # 0x25008
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x177d9
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x176ea
movl $0x1, -0x1c(%rbp)
movq -0x28(%rbp), %rdx
movl -0x1c(%rbp), %eax
movl (%rdx), %ecx
shll %ecx
subl $0x3, %ecx
subl 0x48(%rdx), %ecx
cmpl %ecx, %eax
jg 0x17a6d
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0x1c(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm1
subsd -0x18(%rbp), %xmm1
movaps 0xd845(%rip), %xmm0     # 0x25080
pand %xmm0, %xmm1
movsd 0xd7c9(%rip), %xmm0     # 0x25010
ucomisd %xmm1, %xmm0
jbe 0x17932
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rdx
movl -0x1c(%rbp), %esi
shll %esi
subl $0x2, %esi
movslq %esi, %rsi
movq (%rdx,%rsi,8), %rdx
movsd (%rax,%rdx,8), %xmm1
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0x1c(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x17932
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rdx
movl -0x1c(%rbp), %esi
shll %esi
subl $0x1, %esi
movslq %esi, %rsi
movq (%rdx,%rsi,8), %rdx
movsd (%rax,%rdx,8), %xmm1
movq 0x8(%rcx), %rax
movq 0x30(%rcx), %rdx
movl -0x1c(%rbp), %esi
shll %esi
subl $0x1, %esi
movslq %esi, %rsi
movq (%rdx,%rsi,8), %rdx
movq (%rax,%rdx,8), %rax
movq -0x10(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addsd (%rax,%rdx,8), %xmm1
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movslq 0x4(%rcx), %rcx
subsd (%rax,%rcx,8), %xmm1
movaps 0xd769(%rip), %xmm0     # 0x25080
pand %xmm0, %xmm1
movsd 0xd6ed(%rip), %xmm0     # 0x25010
ucomisd %xmm1, %xmm0
jbe 0x17932
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0x1c(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm1
subsd -0x18(%rbp), %xmm1
movaps 0xd71a(%rip), %xmm0     # 0x25080
pand %xmm0, %xmm1
movsd 0xd69e(%rip), %xmm0     # 0x25010
ucomisd %xmm1, %xmm0
jbe 0x17a5d
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rdx
movl -0x1c(%rbp), %esi
shll %esi
subl $0x1, %esi
movslq %esi, %rsi
movq (%rdx,%rsi,8), %rdx
movsd (%rax,%rdx,8), %xmm1
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0x1c(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x17a5d
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rdx
movl -0x1c(%rbp), %esi
shll %esi
subl $0x2, %esi
movslq %esi, %rsi
movq (%rdx,%rsi,8), %rdx
movsd (%rax,%rdx,8), %xmm1
movq 0x8(%rcx), %rax
movq 0x30(%rcx), %rdx
movl -0x1c(%rbp), %esi
shll %esi
subl $0x2, %esi
movslq %esi, %rsi
movq (%rdx,%rsi,8), %rdx
movq (%rax,%rdx,8), %rax
movq -0x10(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addsd (%rax,%rdx,8), %xmm1
movq 0x8(%rcx), %rax
movslq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movslq 0x4(%rcx), %rcx
subsd (%rax,%rcx,8), %xmm1
movaps 0xd63e(%rip), %xmm0     # 0x25080
pand %xmm0, %xmm1
movsd 0xd5c2(%rip), %xmm0     # 0x25010
ucomisd %xmm1, %xmm0
jbe 0x17a5d
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
jmp 0x17a5f
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x177ee
jmp 0x17a6f
popq %rbp
retq
nopw %cs:(%rax,%rax)