// File: /workspace/github_cpp_makefile_star2_O2/dcarrey[P]hgt-detection/./fonctions.cpp
// Function: bestRFNeighbor(InputTree*, InputTree*, int)
int	bestRFNeighbor(struct InputTree *geneTree,struct InputTree *speciesTree,int position){
	int choix=position;
	int v1=-1,v2=-1,v3=-1,v4=-1,i;
	struct InputTree tmpTree;	//= arbre temporaire qui va etre modifier pour calculer RF
	struct CRITERIA aCrit;		//== struture of all the criteria
	int min= (int) INFINI;

	initInputTree(&tmpTree);	

	//== recherche des voisins
	for(i=1;i<=2*geneTree->size-3-geneTree->kt;i++){

		if( (geneTree->ARETE[2*i-1] == geneTree->ARETE[2*position-1] || geneTree->ARETE[2*i-2] == geneTree->ARETE[2*position-1] || 
		     geneTree->ARETE[2*i-1] == geneTree->ARETE[2*position-2] || geneTree->ARETE[2*i-2] == geneTree->ARETE[2*position-2] ) && (i!=position) && (v1==-1)){
		
			v1 = i; //printf("\n(v1=%d,",i);
		}
		else if( (geneTree->ARETE[2*i-1] == geneTree->ARETE[2*position-1] || geneTree->ARETE[2*i-2] == geneTree->ARETE[2*position-1] || 
		     geneTree->ARETE[2*i-1] == geneTree->ARETE[2*position-2] || geneTree->ARETE[2*i-2] == geneTree->ARETE[2*position-2] ) && (i!=position) && (v2==-1)){
		
			v2 = i; //printf("v2=%d,",i);
		}
		else if( (geneTree->ARETE[2*i-1] == geneTree->ARETE[2*position-1] || geneTree->ARETE[2*i-2] == geneTree->ARETE[2*position-1] || 
		     geneTree->ARETE[2*i-1] == geneTree->ARETE[2*position-2] || geneTree->ARETE[2*i-2] == geneTree->ARETE[2*position-2] ) && (i!=position) && (v3==-1)){
		
			v3 = i; //printf("v2=%d,",i);
		}
		else if( (geneTree->ARETE[2*i-1] == geneTree->ARETE[2*position-1] || geneTree->ARETE[2*i-2] == geneTree->ARETE[2*position-1] || 
		     geneTree->ARETE[2*i-1] == geneTree->ARETE[2*position-2] || geneTree->ARETE[2*i-2] == geneTree->ARETE[2*position-2] ) && (i!=position) && (v4==-1)){
		
			v4 = i; //printf("v3=%d)",i);
		}
	}
	
	//printf("\n Selection de la racine :");

	copyInputTree(&tmpTree,(*geneTree),1,1);
	addLeafAndUpdate(&tmpTree,position);
	tmpTree.Root = tmpTree.size;
		
	InitCriteria(&aCrit,tmpTree.size);
	computeCriteria(speciesTree->ADD,tmpTree.ADD,tmpTree.size,&aCrit,speciesTree->LONGUEUR,speciesTree->ARETE,tmpTree.LONGUEUR,tmpTree.ARETE);

	//printf("\n(%d), %d--%d = %d",position,geneTree->ARETE[2*position-1],geneTree->ARETE[2*position-2],aCrit.RF);
	if(aCrit.RF < min){
		min=aCrit.RF;
		choix = position;
	}
		
	copyInputTree(&tmpTree,(*geneTree),1,0);
	addLeafAndUpdate(&tmpTree,v1);
	tmpTree.Root = tmpTree.size;
		
	FreeCriteria(&aCrit,tmpTree.size);
	InitCriteria(&aCrit,tmpTree.size);

	computeCriteria(speciesTree->ADD,tmpTree.ADD,tmpTree.size,&aCrit,speciesTree->LONGUEUR,speciesTree->ARETE,tmpTree.LONGUEUR,tmpTree.ARETE);

	//printf("\n(%d), %d--%d = %d",v1,geneTree->ARETE[2*v1-1],geneTree->ARETE[2*v1-2],aCrit.RF);
	if(aCrit.RF < min){
		min=aCrit.RF;
		choix = v1;
	}
	
	copyInputTree(&tmpTree,(*geneTree),1,0);
	addLeafAndUpdate(&tmpTree,v2);
	tmpTree.Root = tmpTree.size;
		
	FreeCriteria(&aCrit,tmpTree.size);
	InitCriteria(&aCrit,tmpTree.size);
	computeCriteria(speciesTree->ADD,tmpTree.ADD,tmpTree.size,&aCrit,speciesTree->LONGUEUR,speciesTree->ARETE,tmpTree.LONGUEUR,tmpTree.ARETE);

	//printf("\n(%d), %d--%d = %d",v2,geneTree->ARETE[2*v2-1],geneTree->ARETE[2*v2-2],aCrit.RF);
	if(aCrit.RF < min){
		min=aCrit.RF;
		choix = v2;
	}
		
	copyInputTree(&tmpTree,(*geneTree),1,0);
	addLeafAndUpdate(&tmpTree,v3);
	tmpTree.Root = tmpTree.size;
		
	FreeCriteria(&aCrit,tmpTree.size);
	InitCriteria(&aCrit,tmpTree.size);
	computeCriteria(speciesTree->ADD,tmpTree.ADD,tmpTree.size,&aCrit,speciesTree->LONGUEUR,speciesTree->ARETE,tmpTree.LONGUEUR,tmpTree.ARETE);
	//printf("\n(%d), %d--%d = %d",v3,geneTree->ARETE[2*v3-1],geneTree->ARETE[2*v3-2],aCrit.RF);
	if(aCrit.RF < min){
		min=aCrit.RF;
		choix = v3;
	}
	
	copyInputTree(&tmpTree,(*geneTree),1,0);
	addLeafAndUpdate(&tmpTree,v4);
	tmpTree.Root = tmpTree.size;
		
	FreeCriteria(&aCrit,tmpTree.size);
	InitCriteria(&aCrit,tmpTree.size);
	computeCriteria(speciesTree->ADD,tmpTree.ADD,tmpTree.size,&aCrit,speciesTree->LONGUEUR,speciesTree->ARETE,tmpTree.LONGUEUR,tmpTree.ARETE);
	//printf("\n(%d), %d--%d = %d",v4,geneTree->ARETE[2*v4-1],geneTree->ARETE[2*v4-2],aCrit.RF);
	if(aCrit.RF < min){
		min=aCrit.RF;
		choix = v4;
	}
	
	
	FreeCriteria(&aCrit,tmpTree.size);
	return choix;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
andq $0x0, -0x90(%rbp)
xorps %xmm0, %xmm0
andq $0x0, -0x60(%rbp)
movups %xmm0, -0x70(%rbp)
orl $-0x1, -0x78(%rbp)
movq %rdi, %r12
orl $-0x1, -0x98(%rbp)
andl $0x0, -0x50(%rbp)
movups %xmm0, -0x88(%rbp)
movl (%rdi), %edi
addl %edi, %edi
subl 0x48(%r12), %edi
movq %rsi, -0x38(%rbp)
addl $-0x3, %edi
leal (%rdx,%rdx), %eax
cltq
xorl %ecx, %ecx
testl %edi, %edi
cmovgl %edi, %ecx
movq %rdx, -0x40(%rbp)
movl %edx, %ebx
negq %rcx
pushq $-0x1
popq %r14
pushq $0x1
popq %rdx
pushq $0x8
popq %rsi
movl %r14d, %r15d
movl %r14d, -0x2c(%rbp)
movl %r14d, -0x30(%rbp)
leaq (%rcx,%rdx), %rdi
cmpq $0x1, %rdi
je 0xdd61
movq 0x30(%r12), %rdi
movq (%rdi,%rsi), %r8
movq -0x8(%rdi,%rax,8), %r9
cmpq %r9, %r8
jne 0xdc10
cmpq %rdx, %rbx
setne %dil
cmpl $-0x1, %r14d
sete %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
je 0xdc32
cmpq %rdx, %rbx
setne %r10b
cmpl $-0x1, %r15d
sete %dil
andb %r10b, %dil
cmpb $0x1, %dil
je 0xdcab
jmp 0xdcb8
movq -0x8(%rdi,%rsi), %r10
cmpq %r9, %r10
jne 0xdc3a
cmpq %rdx, %rbx
setne %r10b
cmpl $-0x1, %r14d
sete %r11b
andb %r10b, %r11b
cmpb $0x1, %r11b
jne 0xdc93
movl %edx, %r14d
jmp 0xdd55
movl %r15d, %r13d
movq -0x10(%rdi,%rax,8), %r11
cmpq %r11, %r8
sete %r15b
cmpq %r11, %r10
sete %r11b
orb %r15b, %r11b
je 0xdc78
cmpq %rdx, %rbx
setne %r11b
cmpl $-0x1, %r14d
sete %r15b
andb %r11b, %r15b
cmpb $0x1, %r15b
jne 0xdc78
movl %edx, %r14d
movl %r13d, %r15d
jmp 0xdd55
movq -0x10(%rdi,%rax,8), %r11
cmpq %r11, %r8
setne %r15b
cmpq %r11, %r10
setne %r11b
testb %r11b, %r15b
movl %r13d, %r15d
jne 0xdcd0
cmpq %rdx, %rbx
setne %r10b
cmpl $-0x1, %r15d
sete %r11b
andb %r10b, %r11b
cmpb $0x1, %r11b
jne 0xdcb3
movl %edx, %r15d
jmp 0xdd55
cmpq %r9, %r8
jne 0xdccb
cmpl $-0x1, -0x2c(%rbp)
sete %dil
andb %r10b, %dil
cmpb $0x1, %dil
je 0xdd1f
jmp 0xdd3c
movq -0x8(%rdi,%rsi), %r10
cmpq %r9, %r10
jne 0xdcef
cmpq %rdx, %rbx
setne %dil
cmpl $-0x1, -0x2c(%rbp)
sete %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
je 0xdd1f
jmp 0xdd3c
movq -0x10(%rdi,%rax,8), %r9
cmpq %r9, %r8
sete %r11b
cmpq %r9, %r10
sete %r9b
orb %r11b, %r9b
je 0xdd24
cmpq %rdx, %rbx
setne %r9b
cmpl $-0x1, -0x2c(%rbp)
sete %r11b
andb %r9b, %r11b
cmpb $0x1, %r11b
jne 0xdd24
movl %edx, -0x2c(%rbp)
jmp 0xdd55
movq -0x10(%rdi,%rax,8), %rdi
cmpq %rdi, %r8
setne %r8b
cmpq %rdi, %r10
setne %dil
testb %dil, %r8b
jne 0xdd55
movl -0x30(%rbp), %r8d
cmpl $-0x1, %r8d
movl %edx, %edi
cmovnel %r8d, %edi
cmpq %rdx, %rbx
cmovnel %edi, %r8d
movl %r8d, -0x30(%rbp)
incq %rdx
addq $0x10, %rsi
jmp 0xdbb6
pushq $0xb
popq %rcx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x98(%rbp), %r13
pushq $0x1
popq %rdx
movq %r13, %rdi
movl %edx, %esi
callq 0x976c
movq %r13, %rdi
movq -0x40(%rbp), %rsi
callq 0x6697
movl %r15d, -0x40(%rbp)
movl (%r13), %r15d
movl %r15d, 0x20(%r13)
leaq -0xf8(%rbp), %rdi
movl %r15d, %esi
callq 0xa979
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x8(%r13), %rsi
movl %r15d, %edx
leaq -0xf8(%rbp), %r15
movq %r15, %rcx
callq 0x7f5c
movl 0x30(%r15), %eax
movl $0xf423f, %r13d         # imm = 0xF423F
cmpl %r13d, %eax
cmovll %eax, %r13d
pushq $0xb
popq %rcx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x98(%rbp), %r15
movq %r15, %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x976c
movq %r15, %rdi
movl %r14d, %esi
callq 0x6697
movq %r15, %rax
movl (%r15), %r15d
movl %r15d, 0x20(%rax)
leaq -0xf8(%rbp), %rdi
movl %r15d, %esi
callq 0xaa34
leaq -0xf8(%rbp), %rdi
movl %r15d, %esi
callq 0xa979
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x98(%rbp), %rax
movq 0x8(%rax), %rsi
movl %r15d, %edx
leaq -0xf8(%rbp), %r15
movq %r15, %rcx
callq 0x7f5c
movl 0x30(%r15), %eax
cmpl %r13d, %eax
cmovll %r14d, %ebx
cmovll %eax, %r13d
pushq $0xb
popq %rcx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x98(%rbp), %r15
movq %r15, %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x976c
movq %r15, %rdi
movl -0x40(%rbp), %esi
callq 0x6697
movl (%r15), %r14d
movl %r14d, 0x20(%r15)
leaq -0xf8(%rbp), %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0xaa34
movq %r15, %rdi
movl %r14d, %esi
callq 0xa979
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x98(%rbp), %rax
movq 0x8(%rax), %rsi
movl %r14d, %edx
movq %r15, %rcx
callq 0x7f5c
movl 0x30(%r15), %eax
cmpl %r13d, %eax
cmovll -0x40(%rbp), %ebx
cmovll %eax, %r13d
pushq $0xb
popq %rcx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x98(%rbp), %r15
movq %r15, %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x976c
movq %r15, %rdi
movl -0x2c(%rbp), %esi
callq 0x6697
movl (%r15), %r14d
movl %r14d, 0x20(%r15)
leaq -0xf8(%rbp), %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0xaa34
movq %r15, %rdi
movl %r14d, %esi
callq 0xa979
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x98(%rbp), %rax
movq 0x8(%rax), %rsi
movl %r14d, %edx
movq %r15, %rcx
callq 0x7f5c
movl 0x30(%r15), %eax
cmpl %r13d, %eax
cmovll -0x2c(%rbp), %ebx
cmovll %eax, %r13d
pushq $0xb
popq %rcx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x98(%rbp), %r14
movq %r14, %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x976c
movq %r14, %rdi
movl -0x30(%rbp), %r15d
movl %r15d, %esi
callq 0x6697
movl (%r14), %r14d
leaq -0xf8(%rbp), %r12
movq %r12, %rdi
movl %r14d, %esi
callq 0xaa34
movq %r12, %rdi
movl %r14d, %esi
callq 0xa979
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x98(%rbp), %rax
movq 0x8(%rax), %rsi
movl %r14d, %edx
movq %r12, %rcx
callq 0x7f5c
cmpl %r13d, 0x30(%r12)
cmovll %r15d, %ebx
movq %r12, %rdi
movl %r14d, %esi
callq 0xaa34
movl %ebx, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq