// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r8d, %r14d
movq %rcx, -0x88(%rbp)
movq %rdx, -0x40(%rbp)
movq %rsi, -0x80(%rbp)
leal (%r14,%r14), %eax
movq %rax, -0x48(%rbp)
leal -0x2(%r14,%r14), %eax
movl %eax, -0x2c(%rbp)
leal 0x1(,%r14,2), %eax
movslq %eax, %r12
shlq $0x3, %r12
movq %r12, %rdi
callq 0x1140
movq %rax, %r15
movq %rsp, -0x68(%rbp)
movl %r14d, %eax
movq %rsp, %rcx
movq %rax, -0x60(%rbp)
shlq $0x4, %rax
subq %rax, %rcx
movq %rcx, -0x38(%rbp)
movq %rcx, %rsp
testl %r14d, %r14d
js 0x6e82
movq -0x48(%rbp), %rbx
orl $0x1, %ebx
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x1140
movq %rax, (%r15,%r13,8)
incq %r13
cmpq %r13, %rbx
jne 0x6e6e
movl -0x2c(%rbp), %r8d
testl %r8d, %r8d
movq -0x40(%rbp), %r9
js 0x6ebb
movq -0x48(%rbp), %rax
decl %eax
xorl %ecx, %ecx
movq (%r9,%rcx,8), %rdx
movq (%r15,%rcx,8), %rsi
xorl %edi, %edi
movsd (%rdx,%rdi,8), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x6ea1
incq %rcx
cmpq %rax, %rcx
jne 0x6e97
movq %r15, -0x40(%rbp)
cmpl %r14d, %r8d
jle 0x7015
cmpl $0x2, %r8d
movl $0x1, %edi
cmovgel %r8d, %edi
movq -0x60(%rbp), %r15
leaq (%r15,%r15,2), %rax
movq -0x38(%rbp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, -0x58(%rbp)
leaq (%rcx,%r15,8), %rax
movq %rax, -0x50(%rbp)
leaq (%rcx,%r15,4), %rax
movq %rax, -0x38(%rbp)
movslq %r14d, %r13
movslq %r8d, %rax
movq %rax, -0x70(%rbp)
negq %rdi
shlq $0x2, %r15
movsd 0xe136(%rip), %xmm0     # 0x15048
movq %rdi, -0x78(%rbp)
incq %r13
cmpl $0x2, %r14d
jl 0x6f54
movq -0x40(%rbp), %rax
movq (%rax,%r13,8), %rax
movl $0x1, %ecx
movl $0x1, %edx
ucomisd (%rax,%rdx,8), %xmm0
jbe 0x6f44
movslq %ecx, %rsi
incl %ecx
movl %edx, -0xa0(%rbp,%rsi,4)
leaq (%rdi,%rdx), %rsi
incq %rsi
incq %rdx
cmpq $0x1, %rsi
jne 0x6f31
movq -0x58(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %r12
movl %ecx, (%r12)
movl $0x1, %ebx
movl -0xa0(%rbp,%rbx,4), %esi
cmpl %r14d, %esi
jg 0x6f88
movl $0x1, (%r12)
movl %esi, 0x4(%r12)
movq -0x40(%rbp), %rdi
movl %r13d, %edx
movq %r12, %rcx
movl %r14d, %r8d
callq 0x6ad3
incq %rbx
addq %r15, %r12
cmpq $0x4, %rbx
jne 0x6f6f
leal (%r13,%r13,2), %eax
movl %eax, -0x2c(%rbp)
leal -0x2(%r13,%r13,2), %edi
movq -0x80(%rbp), %r12
movq %r12, %rsi
movq -0x88(%rbp), %rbx
movq %rbx, %rdx
movq -0x38(%rbp), %rcx
movq -0x50(%rbp), %r8
callq 0x6ba4
leal -0x1(%r13,%r13,2), %edi
movq %r12, %rsi
movq %rbx, %rdx
movq -0x38(%rbp), %rcx
movq -0x58(%rbp), %r8
callq 0x6ba4
movl -0x2c(%rbp), %edi
movq %r12, %rsi
movq %rbx, %rdx
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %r8
callq 0x6ba4
cmpq -0x70(%rbp), %r13
movq -0x78(%rbp), %rdi
movsd 0xe039(%rip), %xmm0     # 0x15048
jne 0x6f16
testl %r14d, %r14d
movq -0x48(%rbp), %r14
movq -0x40(%rbp), %r15
js 0x7039
orl $0x1, %r14d
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
callq 0x1100
incq %rbx
cmpq %rbx, %r14
jne 0x7028
movq %r15, %rdi
callq 0x1100
movq -0x68(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq