// File: /workspace/github_cpp_makefile_star2_O1/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), %r8
movl $0x0, (%rdi)
movl (%rsi), %eax
cmpq $0x1, %rax
jne 0xd347
movl (%r8), %eax
addl %eax, %eax
subl 0x48(%r8), %eax
leal -0x3(%rax), %ecx
testl %ecx, %ecx
jle 0xd48c
movq 0x30(%r8), %rcx
addl $-0x2, %eax
addq $0x8, %rcx
movl $0x1, %edx
movslq 0x4(%rsi), %r8
cmpq %r8, (%rcx)
je 0xd334
cmpq %r8, -0x8(%rcx)
jne 0xd336
movl %edx, (%rdi)
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %rax
jne 0xd325
jmp 0xd48c
cmpl $0x2, %eax
jge 0xd356
movsd 0x7cf4(%rip), %xmm0     # 0x15048
jmp 0xd3b1
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 0x7ccd(%rip), %xmm3     # 0x15048
movl $0x2, %r9d
movsd 0x7c7f(%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 0xd389
movl (%r8), %eax
addl %eax, %eax
subl 0x48(%r8), %eax
leal -0x3(%rax), %ecx
testl %ecx, %ecx
jle 0xd48c
movq 0x8(%r8), %rcx
movq 0x30(%r8), %rdx
movslq 0x20(%r8), %r8
movq (%rcx,%r8,8), %r8
addl $-0x2, %eax
movl $0x1, %r9d
movapd 0x7c9a(%rip), %xmm1     # 0x15080
movsd 0x7c22(%rip), %xmm2     # 0x15010
movq 0x8(%rdx), %r10
movsd (%r8,%r10,8), %xmm3
movapd %xmm3, %xmm4
subsd %xmm0, %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
jbe 0xd43a
movq (%rdx), %r11
ucomisd (%r8,%r11,8), %xmm3
jbe 0xd43a
movq (%rcx,%r10,8), %r10
movslq 0x4(%rsi), %r11
movsd (%r10,%r11,8), %xmm4
addsd %xmm3, %xmm4
subsd (%r8,%r11,8), %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
jbe 0xd43a
movl %r9d, (%rdi)
movq (%rdx), %r10
movsd (%r8,%r10,8), %xmm4
movapd %xmm4, %xmm5
subsd %xmm0, %xmm5
andpd %xmm1, %xmm5
ucomisd %xmm5, %xmm2
jbe 0xd47c
ucomisd %xmm3, %xmm4
jbe 0xd47c
movq (%rcx,%r10,8), %r10
movslq 0x4(%rsi), %r11
addsd (%r10,%r11,8), %xmm4
subsd (%r8,%r11,8), %xmm4
andpd %xmm1, %xmm4
ucomisd %xmm4, %xmm2
jbe 0xd47c
movl %r9d, (%rdi)
incq %r9
addq $0x10, %rdx
cmpq %r9, %rax
jne 0xd3ee
popq %rbp
retq