// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movl %r8d, %r13d
movq %rcx, -0x78(%rbp)
movq %rdx, %r14
movq %rsi, -0x70(%rbp)
leal (%r13,%r13), %eax
movq %rax, -0x40(%rbp)
leal 0x1(%r13,%r13), %eax
cltq
movq %rax, -0x48(%rbp)
leaq (,%rax,8), %r12
movq %r12, %rdi
callq 0x1130
movq %rax, -0x30(%rbp)
movq %rsp, -0x68(%rbp)
movl %r13d, %r15d
movq %rsp, %rcx
movq %r15, %rax
shlq $0x4, %rax
subq %rax, %rcx
movq %rcx, -0x38(%rbp)
movq %rcx, %rsp
xorl %ebx, %ebx
movq -0x48(%rbp), %rax
testl %eax, %eax
cmovlel %ebx, %eax
movq %rax, -0x48(%rbp)
cmpq %rbx, -0x48(%rbp)
je 0x6459
movq %r12, %rdi
callq 0x1130
movq -0x30(%rbp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x643e
movq -0x40(%rbp), %rax
decl %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
cmpq %rdx, %rcx
je 0x649a
movq (%r14,%rcx,8), %rsi
movq -0x30(%rbp), %rdi
movq (%rdi,%rcx,8), %rdi
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x6495
movsd (%rsi,%r8,8), %xmm0
movsd %xmm0, (%rdi,%r8,8)
incq %r8
jmp 0x647f
incq %rcx
jmp 0x646b
movq -0x40(%rbp), %rax
addl $-0x2, %eax
movq %rax, -0x40(%rbp)
imulq $0xc, %r15, %rax
movq -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
leaq (%rcx,%r15,8), %rax
movq %rax, -0x50(%rbp)
leaq (%rcx,%r15,4), %rax
movq %rax, -0x38(%rbp)
shlq $0x2, %r15
movl %r13d, %r14d
cmpl -0x40(%rbp), %r14d
jge 0x659e
incl %r14d
movq -0x30(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
leaq -0x90(%rbp), %rcx
callq 0x60a1
movq -0x58(%rbp), %rax
andl $0x0, (%rax)
movq -0x50(%rbp), %rax
andl $0x0, (%rax)
movq -0x38(%rbp), %r12
andl $0x0, (%r12)
pushq $0x1
popq %rbx
cmpq $0x4, %rbx
je 0x6541
movl -0x90(%rbp,%rbx,4), %esi
cmpl %r13d, %esi
jg 0x6527
movl $0x1, (%r12)
movl %esi, 0x4(%r12)
movq -0x30(%rbp), %rdi
movl %r14d, %edx
movq %r12, %rcx
movl %r13d, %r8d
callq 0x60e7
incq %rbx
addq %r15, %r12
jmp 0x6508
leal (%r14,%r14,2), %eax
movl %eax, -0x5c(%rbp)
leal (%r14,%r14,2), %edi
addl $-0x2, %edi
movq -0x70(%rbp), %r12
movq %r12, %rsi
movq -0x78(%rbp), %rbx
movq %rbx, %rdx
movq -0x38(%rbp), %rcx
movq -0x50(%rbp), %r8
callq 0x6190
leal (%r14,%r14,2), %edi
decl %edi
movq %r12, %rsi
movq %rbx, %rdx
movq -0x38(%rbp), %rcx
movq -0x58(%rbp), %r8
callq 0x6190
movl -0x5c(%rbp), %edi
movq %r12, %rsi
movq %rbx, %rdx
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %r8
callq 0x6190
jmp 0x64cb
xorl %ebx, %ebx
cmpq %rbx, -0x48(%rbp)
je 0x65b8
movq -0x30(%rbp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x10f0
incq %rbx
jmp 0x65a0
movq -0x30(%rbp), %rdi
callq 0x10f0
movq -0x68(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq