// File: 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
leaq 0x10(%rbp), %rcx
movq %rcx, -0x28(%rbp)
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq 0x30(%rcx), %rax
movl -0x8(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movslq 0x20(%rcx), %rcx
cmpq %rcx, %rax
je 0x120de
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rax
movl -0x8(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movslq 0x20(%rcx), %rcx
cmpq %rcx, %rax
je 0x120de
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rax
movl -0xc(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movslq 0x20(%rcx), %rcx
cmpq %rcx, %rax
je 0x120de
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rax
movl -0xc(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movslq 0x20(%rcx), %rcx
cmpq %rcx, %rax
jne 0x120ea
movl $0x0, -0x4(%rbp)
jmp 0x12520
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rax
movl -0x8(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0xc(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jne 0x1213b
movq -0x28(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x30(%rcx), %rcx
movl -0x8(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
cmpl $0x3, (%rax,%rcx,4)
je 0x12226
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rax
movl -0x8(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0xc(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jne 0x1218c
movq -0x28(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x30(%rcx), %rcx
movl -0x8(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
cmpl $0x3, (%rax,%rcx,4)
je 0x12226
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rax
movl -0x8(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0xc(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jne 0x121d9
movq -0x28(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x30(%rcx), %rcx
movl -0x8(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
cmpl $0x3, (%rax,%rcx,4)
je 0x12226
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rax
movl -0x8(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0xc(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jne 0x12232
movq -0x28(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x30(%rcx), %rcx
movl -0x8(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
cmpl $0x3, (%rax,%rcx,4)
jne 0x12232
movl $0x0, -0x4(%rbp)
jmp 0x12520
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rax
movl -0xc(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movl (%rcx), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x1227e
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rax
movl -0xc(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movl (%rcx), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0x1228a
movl $0x0, -0x4(%rbp)
jmp 0x12520
movq -0x28(%rbp), %rcx
movl 0x20(%rcx), %eax
movl %eax, -0x20(%rbp)
movq 0x8(%rcx), %rax
movslq -0x20(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rdx
movl -0x8(%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(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0x8(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x12314
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
movl -0x8(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, -0x10(%rbp)
movq 0x30(%rax), %rax
movl -0x8(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x14(%rbp)
jmp 0x12344
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
movl -0x8(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, -0x10(%rbp)
movq 0x30(%rax), %rax
movl -0x8(%rbp), %ecx
shll %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x14(%rbp)
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq -0x20(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rdx
movl -0xc(%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(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x30(%rcx), %rcx
movl -0xc(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x123c8
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
movl -0xc(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, -0x18(%rbp)
movq 0x30(%rax), %rax
movl -0xc(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x1c(%rbp)
jmp 0x123f8
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
movl -0xc(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, -0x18(%rbp)
movq 0x30(%rax), %rax
movl -0xc(%rbp), %ecx
shll %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movslq -0x20(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x1c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rcx
movslq -0x20(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x10(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rcx
movslq -0x10(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x14(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x18(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm1
movaps 0x12c14(%rip), %xmm0    # 0x25080
pand %xmm0, %xmm1
movsd 0x12bb8(%rip), %xmm0    # 0x25030
ucomisd %xmm1, %xmm0
jbe 0x1248a
movl $0x0, -0x4(%rbp)
jmp 0x12520
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movslq -0x20(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x14(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rcx
movslq -0x20(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x18(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rcx
movslq -0x18(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x1c(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x10(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm1
movq 0x8(%rax), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x14(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm1
movaps 0x12b82(%rip), %xmm0    # 0x25080
pand %xmm0, %xmm1
movsd 0x12b26(%rip), %xmm0    # 0x25030
ucomisd %xmm1, %xmm0
jbe 0x12519
movl $0x0, -0x4(%rbp)
jmp 0x12520
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)