// File: dcarrey[P]hgt-detection/./utils_tree.cpp
// Function: RechercherBipartitionSansRacine(long*, double**, double**, DescTree*, int, int)
void RechercherBipartitionSansRacine(long int *ARETE,double ** DIST,double ** Adjacence2,struct DescTree *DT,const int n,int kt)
{
	/*/===== variables =====*/
	int i,j,k,l,taille,plus,ns=2*n-2;
	double ** Adjacence =(double**)malloc((2*n+1)*sizeof(double*));
	int tab_noeuds[4];
	int tab_fils_1[n];
	int tab_fils_2[n];
	int tab_fils_3[n];
	int tab_fils[4][n];
	struct TNoeud * arbre;
	
	for (i=0;i<=2*n;i++)
		Adjacence[i]=(double*)malloc((2*n+1)*sizeof(double));

	
	
	//== copie de la matrice d'adjacence
	for(i=0;i<=2*n-2;i++){
		//if(i>0) printf("\n%d\t",i);
		for(j=0;j<=2*n-2;j++){
			Adjacence[i][j] = Adjacence2[i][j];
			// if(j>0 && i>0)
				// if(Adjacence2[i][j] >= INFINI){
					// printf("INF\t");
				// }
				// else{
					// printf("%1.1lf\t",Adjacence2[i][j]);
				// }
		}
	}
	
	for(i=n+1;i<=ns;i++){
		//printf("\nNoeud interne %d (nb sommets=%d)",i,ns);	
		//= trouver les 3 noeuds adjacents		
		trouver_3_noeuds(Adjacence,i,n,tab_noeuds);
		//printf("\nnoeud %d : %d,%d,%d",i,tab_noeuds[1],tab_noeuds[2],tab_noeuds[3]);	
		
		//= trouver les feuilles pour chaque fils
		tab_fils[1][0] = tab_fils[2][0] = tab_fils[3][0] = 0;
		
		for(j=1;j<=3;j++){
			if(tab_noeuds[j] <= n){ tab_fils[j][0] = 1; tab_fils[j][tab_fils[j][0]] = tab_noeuds[j];}
			trouver_fils(Adjacence,tab_noeuds[j],i,tab_fils[j],n);
		//	printf("\nfils %d : ", tab_noeuds[j]);
			//for(k=1;k<=tab_fils[j][0];k++)
				//printf("%d ",tab_fils[j][k]);
		}
			
		//== ensemble de feuilles possibles
		creerNoeudDT(3*i-2,DIST,DT,tab_fils[1],tab_fils[2]);
		//printNoeudDT(DT,3*i-2,tab_noeuds[1],tab_noeuds[2]);
		creerNoeudDT(3*i-1,DIST,DT,tab_fils[1],tab_fils[3]);
		//printNoeudDT(DT,3*i-1,tab_noeuds[1],tab_noeuds[3]);
		creerNoeudDT(3*i,DIST,DT,tab_fils[2],tab_fils[3]);
		//printNoeudDT(DT,3*i,tab_noeuds[2],tab_noeuds[3]);
			
	}	
			
			
	//== liberation de la m�moire
	for (i=0;i<=2*n;i++)
		free(Adjacence[i]);
	free(Adjacence);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movl -0x24(%rbp), %ecx
movl %ecx, %eax
leal -0x2(%rax,%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x24(%rbp), %eax
addl %eax, %eax
cltq
leaq 0x8(,%rax,8), %rdi
callq 0x1110
movq %rax, -0x50(%rbp)
movl -0x24(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x68(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, %rsp
movq %rax, -0x70(%rbp)
movl -0x24(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
movl -0x24(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, %rsp
movq %rax, -0x80(%rbp)
movl -0x24(%rbp), %eax
movq %rax, -0xa0(%rbp)
movq %rax, %rdx
shlq $0x4, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x98(%rbp)
movq %rcx, %rsp
movq %rax, -0x88(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x24(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0xb88b
movl -0x24(%rbp), %eax
shll %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x1110
movq %rax, %rdx
movq -0x50(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb851
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x24(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jg 0xb8f9
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x24(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jg 0xb8ec
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x50(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb8a8
jmp 0xb8ee
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb892
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jg 0xbabc
movq -0x50(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x24(%rbp), %edx
leaq -0x60(%rbp), %rcx
callq 0xb230
movq -0xa0(%rbp), %rcx
movq -0x98(%rbp), %rax
imulq $0x3, %rcx, %rdx
movl $0x0, (%rax,%rdx,4)
movq %rcx, %rdx
shlq %rdx
movl $0x0, (%rax,%rdx,4)
shlq $0x0, %rcx
movl $0x0, (%rax,%rcx,4)
movl $0x1, -0x30(%rbp)
cmpl $0x3, -0x30(%rbp)
jg 0xb9f9
movslq -0x30(%rbp), %rax
movl -0x60(%rbp,%rax,4), %eax
cmpl -0x24(%rbp), %eax
jg 0xb9b6
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %rdi
movslq -0x30(%rbp), %rax
imulq %rdi, %rax
movl $0x1, (%rcx,%rax,4)
movslq -0x30(%rbp), %rax
movl -0x60(%rbp,%rax,4), %edx
movslq -0x30(%rbp), %rsi
imulq %rdi, %rsi
shlq $0x2, %rsi
movq %rcx, %rax
addq %rsi, %rax
movslq -0x30(%rbp), %rsi
imulq %rdi, %rsi
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %r8
movq -0x50(%rbp), %rdi
movslq -0x30(%rbp), %rax
movl -0x60(%rbp,%rax,4), %esi
movl -0x2c(%rbp), %edx
movslq -0x30(%rbp), %rax
imulq %r8, %rax
shlq $0x2, %rax
addq %rax, %rcx
movl -0x24(%rbp), %r8d
callq 0xb2b0
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb959
movq -0x98(%rbp), %r8
movq -0xa0(%rbp), %rax
imull $0x3, -0x2c(%rbp), %edi
subl $0x2, %edi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq %rax, %r9
shlq $0x0, %r9
shlq $0x2, %r9
movq %r8, %rcx
addq %r9, %rcx
shlq %rax
shlq $0x2, %rax
addq %rax, %r8
callq 0xb360
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %r8
imull $0x3, -0x2c(%rbp), %edi
subl $0x1, %edi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq %rax, %r9
shlq $0x0, %r9
shlq $0x2, %r9
movq %r8, %rcx
addq %r9, %rcx
imulq $0x3, %rax, %rax
shlq $0x2, %rax
addq %rax, %r8
callq 0xb360
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %r8
imull $0x3, -0x2c(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq %rax, %r9
shlq %r9
shlq $0x2, %r9
movq %r8, %rcx
addq %r9, %rcx
imulq $0x3, %rax, %rax
shlq $0x2, %rax
addq %rax, %r8
callq 0xb360
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb902
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x24(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0xbaeb
movq -0x50(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10e0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xbac3
movq -0x50(%rbp), %rdi
callq 0x10e0
movq -0x68(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq