// File: /workspace/github_cpp_makefile_star2_O3/dcarrey[P]hgt-detection/./fonctions.cpp
// Function: isAValidHGT(InputTree, int, int)
int isAValidHGT(struct InputTree SpeciesTree,int i, int j){
	
	int d1,d2,d3,d4,root;

	/*if(SpeciesTree.ARETE[2*i-1]==2 && SpeciesTree.ARETE[2*i-2] ==12 && SpeciesTree.ARETE[2*j-1] == 11 && SpeciesTree.ARETE[2*j-2] == 13)
	{	
		printEdges(0,SpeciesTree.ARETE,SpeciesTree.LONGUEUR,SpeciesTree.SpeciesName,SpeciesTree.size);		
		printMatrix(SpeciesTree.SpeciesName,SpeciesTree.Matrix,2*SpeciesTree.size-2);
	}*/
	//== if is the root branch
	if(SpeciesTree.ARETE[2*i-1] == SpeciesTree.Root || SpeciesTree.ARETE[2*i-2] == SpeciesTree.Root || 
	   SpeciesTree.ARETE[2*j-1] == SpeciesTree.Root || SpeciesTree.ARETE[2*j-2] == SpeciesTree.Root )
		return 0;

	//== if there is a direct common ancestor
	if(((SpeciesTree.ARETE[2*i-1] == SpeciesTree.ARETE[2*j-1])&&(SpeciesTree.degre[SpeciesTree.ARETE[2*i-1]]==3)) || 
	   ((SpeciesTree.ARETE[2*i-1] == SpeciesTree.ARETE[2*j-2])&&(SpeciesTree.degre[SpeciesTree.ARETE[2*i-1]]==3)) ||
       ((SpeciesTree.ARETE[2*i-2] == SpeciesTree.ARETE[2*j-1])&&(SpeciesTree.degre[SpeciesTree.ARETE[2*i-2]]==3)) || 
	   ((SpeciesTree.ARETE[2*i-2] == SpeciesTree.ARETE[2*j-2])&&(SpeciesTree.degre[SpeciesTree.ARETE[2*i-2]]==3)) )
		return 0;

	//== if j is a branch connected to the root branch
	if(SpeciesTree.ARETE[2*j-1] == 2*(SpeciesTree.size)-2 || SpeciesTree.ARETE[2*j-2] == 2*(SpeciesTree.size)-2)
		return 0;

	//== if i and j are on the same lineage

	root = SpeciesTree.Root;

	if(SpeciesTree.ADD[root][SpeciesTree.ARETE[2*i-1]] < SpeciesTree.ADD[root][SpeciesTree.ARETE[2*i-2]]){
		d1 = SpeciesTree.ARETE[2*i-1];
		d2 = SpeciesTree.ARETE[2*i-2];
	}
	else{
		d1 = SpeciesTree.ARETE[2*i-2];
		d2 = SpeciesTree.ARETE[2*i-1];
	}

	if(SpeciesTree.ADD[root][SpeciesTree.ARETE[2*j-1]] < SpeciesTree.ADD[root][SpeciesTree.ARETE[2*j-2]]){
		d3 = SpeciesTree.ARETE[2*j-1];
		d4 = SpeciesTree.ARETE[2*j-2];
	}
	else{
		d3 = SpeciesTree.ARETE[2*j-2];
		d4 = SpeciesTree.ARETE[2*j-1];
	}
	
	//printf("\nhgt : i=%d , j=%d => %d-%d-%d-%d-%d",i,j,root,d1,d2,d3,d4);
	if(fabs(SpeciesTree.ADD[root][d4]-SpeciesTree.ADD[root][d1]-SpeciesTree.ADD[d1][d2]-SpeciesTree.ADD[d2][d3]-SpeciesTree.ADD[d3][d4]) < epsilon)
		return 0;
	//printf("\nhgt : cas 1");
	if(fabs(SpeciesTree.ADD[root][d2]-SpeciesTree.ADD[root][d3]-SpeciesTree.ADD[d3][d4]-SpeciesTree.ADD[d4][d1]-SpeciesTree.ADD[d1][d2]) < epsilon)
		return 0;
	//printf("\nhgt : cas 2");
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x40(%rbp), %r9
addl %edi, %edi
movslq %edi, %rdx
movq -0x8(%r9,%rdx,8), %rcx
movslq 0x30(%rbp), %r8
xorl %eax, %eax
cmpq %r8, %rcx
je 0xa46b
movq -0x10(%r9,%rdx,8), %rdi
cmpq %r8, %rdi
je 0xa46b
addl %esi, %esi
movslq %esi, %rsi
movq -0x8(%r9,%rsi,8), %rdx
cmpq %r8, %rdx
je 0xa46b
movq -0x10(%r9,%rsi,8), %rsi
cmpq %r8, %rsi
jne 0xa46d
popq %rbp
retq
leaq 0x10(%rbp), %r9
cmpq %rdx, %rcx
jne 0xa481
movq 0x50(%r9), %r10
cmpl $0x3, (%r10,%rcx,4)
je 0xa46b
cmpq %rsi, %rcx
jne 0xa491
movq 0x50(%r9), %r10
cmpl $0x3, (%r10,%rcx,4)
je 0xa46b
cmpq %rdx, %rdi
jne 0xa4a1
movq 0x50(%r9), %r10
cmpl $0x3, (%r10,%rdi,4)
je 0xa46b
cmpq %rsi, %rdi
jne 0xa4b1
movq 0x50(%r9), %r10
cmpl $0x3, (%r10,%rdi,4)
je 0xa46b
movslq (%r9), %r10
leaq -0x2(,%r10,2), %r10
cmpq %r10, %rdx
je 0xa46b
cmpq %r10, %rsi
je 0xa46b
movq 0x8(%r9), %r9
movq (%r9,%r8,8), %r8
movsd (%r8,%rdi,8), %xmm0
ucomisd (%r8,%rcx,8), %xmm0
movq %rdi, %r10
cmovaq %rcx, %r10
cmovaq %rdi, %rcx
movsd (%r8,%rsi,8), %xmm0
ucomisd (%r8,%rdx,8), %xmm0
movq %rsi, %rdi
cmovaq %rdx, %rdi
cmovaq %rsi, %rdx
movslq %edx, %rdx
movsd (%r8,%rdx,8), %xmm3
movslq %r10d, %rsi
subsd (%r8,%rsi,8), %xmm3
movq (%r9,%rsi,8), %r10
movslq %ecx, %rcx
movsd (%r10,%rcx,8), %xmm0
subsd %xmm0, %xmm3
movq (%r9,%rcx,8), %r10
movslq %edi, %rdi
subsd (%r10,%rdi,8), %xmm3
movq (%r9,%rdi,8), %r10
movsd (%r10,%rdx,8), %xmm2
subsd %xmm2, %xmm3
andpd 0xab3e(%rip), %xmm3     # 0x15080
movsd 0xaade(%rip), %xmm1     # 0x15028
ucomisd %xmm3, %xmm1
ja 0xa46b
movsd (%r8,%rcx,8), %xmm3
subsd (%r8,%rdi,8), %xmm3
subsd %xmm2, %xmm3
movq (%r9,%rdx,8), %rax
subsd (%rax,%rsi,8), %xmm3
subsd %xmm0, %xmm3
andpd 0xab07(%rip), %xmm3     # 0x15080
xorl %eax, %eax
ucomisd %xmm3, %xmm1
setbe %al
jmp 0xa46b