// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rbx
leaq 0x10(%rbp), %r8
movl $0x0, (%rdi)
movl (%rsi), %eax
cmpq $0x1, %rax
jne 0xd28f
movl (%r8), %eax
addl %eax, %eax
subl 0x48(%r8), %eax
leal -0x3(%rax), %ecx
testl %ecx, %ecx
jle 0xd3d3
movq 0x30(%r8), %rcx
addl $-0x2, %eax
addq $0x8, %rcx
movl $0x1, %edx
movslq 0x4(%rsi), %r8
cmpq %r8, (%rcx)
je 0xd27c
cmpq %r8, -0x8(%rcx)
jne 0xd27e
movl %edx, (%rdi)
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %rax
jne 0xd26d
jmp 0xd3d3
cmpl $0x2, %eax
jge 0xd29e
movsd 0x7dac(%rip), %xmm0     # 0x15048
jmp 0xd2f9
movq 0x8(%r8), %rdx
movslq 0x20(%r8), %rcx
movq (%rdx,%rcx,8), %rcx
movslq 0x4(%rsi), %r9
movsd (%rcx,%r9,8), %xmm1
movq (%rdx,%r9,8), %rdx
incq %rax
movsd 0x7d85(%rip), %xmm3     # 0x15048
movl $0x2, %r9d
movsd 0x7d37(%rip), %xmm2     # 0x15008
movslq (%rsi,%r9,4), %r10
movsd (%rcx,%r10,8), %xmm0
addsd %xmm1, %xmm0
subsd (%rdx,%r10,8), %xmm0
mulsd %xmm2, %xmm0
minsd %xmm3, %xmm0
incq %r9
movapd %xmm0, %xmm3
cmpq %r9, %rax
jne 0xd2d1
movl (%r8), %eax
addl %eax, %eax
subl 0x48(%r8), %eax
leal -0x3(%rax), %ecx
testl %ecx, %ecx
jle 0xd3d3
movq 0x8(%r8), %rcx
movq 0x30(%r8), %rdx
movslq 0x20(%r8), %r8
movq (%rcx,%r8,8), %r8
addl $-0x2, %eax
addq $0x8, %rdx
movl $0x1, %r9d
movapd 0x7d4e(%rip), %xmm1     # 0x15080
movsd 0x7cd6(%rip), %xmm2     # 0x15010
movq -0x8(%rdx), %r10
movq (%rdx), %r11
movsd (%r8,%r11,8), %xmm4
movapd %xmm4, %xmm3
subsd %xmm0, %xmm3
andpd %xmm1, %xmm3
ucomisd %xmm3, %xmm2
movsd (%r8,%r10,8), %xmm3
jbe 0xd38a
ucomisd %xmm3, %xmm4
jbe 0xd38a
movq (%rcx,%r11,8), %r11
movslq 0x4(%rsi), %rbx
movsd (%r11,%rbx,8), %xmm5
addsd %xmm4, %xmm5
subsd (%r8,%rbx,8), %xmm5
andpd %xmm1, %xmm5
ucomisd %xmm5, %xmm2
jbe 0xd38a
movl %r9d, (%rdi)
movapd %xmm3, %xmm5
subsd %xmm0, %xmm5
andpd %xmm1, %xmm5
ucomisd %xmm5, %xmm2
jbe 0xd3c3
ucomisd %xmm4, %xmm3
jbe 0xd3c3
movq (%rcx,%r10,8), %r10
movslq 0x4(%rsi), %r11
addsd (%r10,%r11,8), %xmm3
subsd (%r8,%r11,8), %xmm3
andpd %xmm1, %xmm3
ucomisd %xmm3, %xmm2
jbe 0xd3c3
movl %r9d, (%rdi)
incq %r9
addq $0x10, %rdx
cmpq %r9, %rax
jne 0xd33a
popq %rbx
popq %rbp
retq