// File: /workspace/github_cpp_makefile_star2_O1/dcarrey[P]hgt-detection/./utils_tree.cpp
// Function: Bipartition_Table(double**, int**, int*, int)
int Bipartition_Table (double **D, int **B, int *PLACE, int n)
{
	int i,j,k,l,l1,*MaxCol,*X,EdgeNumberPath,m,uv,PlaceNumber,edge,*Path,M,F;
	double S,DIS,DIS1,*LengthPath;
	double EPS=1.e-5;
	double EPS1=1.e-2;

	/* Memory allocation */

	MaxCol=(int *)malloc((2*n)*sizeof(int));
	X=(int *)malloc((2*n+1)*sizeof(int));
	LengthPath=(double *)malloc((2*n)*sizeof(double));
	Path=(int *)malloc((2*n)*sizeof(int));

	/* Computation of a circular order X for D */     

	i=1; j=n; odp1(D,X,&i,&j,n);

	/* Initialization */ 
	for (i=1; i<=2*n-3; i++)
	{
		MaxCol[i]=0;
		PLACE[i]=0;
		for (j=1;j<=n;j++)
			B[i][j]=0;  
	}
	B[1][X[2]]=1; MaxCol[1]=X[2]; Path[1]=1; PlaceNumber=1;
	PLACE[1]=1; LengthPath[1]=D[X[1]][X[2]]; EdgeNumberPath=1; m=1;

	/* The main loop */

	for(k=2;k<=n-1;k++)
	{  
		/* Point 2.1 of the algorithm (see the referenced article by Makarenkov and Leclerc) */

		DIS=(D[X[1]][X[k]]+D[X[k]][X[k+1]]-D[X[1]][X[k+1]])/2; 
		DIS1=(D[X[1]][X[k+1]]+D[X[k]][X[k+1]]-D[X[1]][X[k]])/2;
		
		//printf("\n\n%d,%d,%d\n\n",X[1],X[k],X[k+1]);
		if ((DIS<=-EPS1)||(DIS1<=-EPS1)) { printf("\n This is not an additive distance \n");
		free(MaxCol);free(X);free(LengthPath);free(Path);exit(1);return 0; }
		if (DIS<=EPS) DIS=0.0; if (DIS1<=EPS) DIS1=0.0;

		S=0.0; i=EdgeNumberPath; if (LengthPath[i]==0.0) i--;
		while (S<=DIS-EPS)
		{
			if (i==0) { S=DIS; break; }  /* checking the limit */  
			S=S+LengthPath[i];
			i--;
		}

		/* Point 2.2 of the algorithm */

		if (fabs(S-DIS)<=EPS) 
		{ 
			M=m+2; DIS=S;      
			if (i==0) F=1; 
			else if (i==EdgeNumberPath) F=2;
			else { M--; F=3; }   
		}    
		else {M=m+2; F=0;}


		if (M==m+2)
		{
			if (F==0) { uv=Path[i+1]; EdgeNumberPath=i+2; LengthPath[i+1]=S-DIS; LengthPath[i+2]=DIS1; 
			Path[i+1]=m+2; Path[i+2]=m+1;}
			else if (F==1) { uv=Path[1]; EdgeNumberPath=2; LengthPath[1]=0.0; LengthPath[2]=DIS1; 
			Path[1]=m+2; Path[2]=m+1;}
			else if (F==2) { uv=Path[EdgeNumberPath]; EdgeNumberPath=EdgeNumberPath+1;LengthPath[EdgeNumberPath]=DIS1; 
			Path[EdgeNumberPath-1]=m+2; Path[EdgeNumberPath]=m+1; } 

			for (j=1;j<=n;j++)
				B[m+2][j]=B[uv][j];   
			MaxCol[m+2]=MaxCol[uv];      
		}

		else 
		{
			EdgeNumberPath=i+1; LengthPath[i+1]=DIS1; Path[i+1]=m+1;
		}

		/* Point 2.3 of the algorithm */

		for (j=1;j<=EdgeNumberPath;j++)
			B[Path[j]][X[k+1]]=1;

		/* Point 2.4 of the algorithm */

		for (j=1;j<=EdgeNumberPath;j++)
			if (MaxCol[Path[j]]<X[k+1]) MaxCol[Path[j]]=X[k+1];  

		/* Point 2.5 of the algorithm */

		for (j=PlaceNumber;j>=1;j--) 
			PLACE[j+1]=PLACE[j];
		PLACE[1]=m+1; PlaceNumber++;

		if (M==m+2) {
			i=2; 
			while (PLACE[i]!=uv)
				i++;          
			for (j=PlaceNumber;j>=i+1;j--) 
				PLACE[j+1]=PLACE[j];
			PLACE[i+1]=m+2; PlaceNumber++;}

		i=M-1; edge=2;
		do 
		{
			if (PLACE[i]==Path[edge]) 
			{
				edge++; j=i+1; 
				while (X[k+1]>MaxCol[PLACE[j]]) 
					j++; 
				if (j>i+1) 
				{            
					l1=PLACE[i];
					for (l=i+1;l<=j-1;l++) 
						PLACE[l-1]=PLACE[l];              
					PLACE[j-1]=l1;

				} 
			}
			i--;
		} while (i!=0); 

		m=M;
	}


	/* memeory liberation */

	free(MaxCol);
	free(X);
	free(LengthPath);
	free(Path);

	return m;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %ecx, %r13d
movq %rdx, -0x40(%rbp)
movq %rsi, -0x48(%rbp)
movq %rdi, -0x78(%rbp)
leal (%r13,%r13), %eax
movl %eax, -0x30(%rbp)
movslq %eax, %r14
leaq (,%r14,4), %r15
movq %r15, %rdi
callq 0x1140
movq %rax, %rbx
leal 0x1(,%r13,2), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1140
movq %rax, %r12
shlq $0x3, %r14
movq %r14, %rdi
callq 0x1140
movq %rax, -0x90(%rbp)
movq %r15, %rdi
callq 0x1140
movq %rax, %r15
leaq -0x38(%rbp), %rdx
movl $0x1, (%rdx)
leaq -0x34(%rbp), %rcx
movl %r13d, (%rcx)
movq -0x78(%rbp), %rdi
movq %r12, -0x60(%rbp)
movq %r12, %rsi
movl %r13d, %r8d
callq 0x234d
movl %r13d, %eax
movq %rax, -0x88(%rbp)
movl %r13d, %eax
movl $0x1, %r12d
cmpl $0x2, %r13d
jl 0x2cf1
movq -0x88(%rbp), %rax
leaq (,%rax,4), %rax
movq %rax, -0x50(%rbp)
movl -0x30(%rbp), %eax
cmpl $0x5, %eax
movl $0x4, %ecx
cmovgel %eax, %ecx
movq %r13, -0x70(%rbp)
leal 0x1(%r13), %eax
movl %eax, -0x68(%rbp)
addl $-0x2, %ecx
movq %rcx, -0x30(%rbp)
movl $0x1, %r12d
movq -0x40(%rbp), %r14
movq -0x48(%rbp), %r13
xorl %eax, %eax
movl %eax, (%rbx,%r12,4)
movl %eax, (%r14,%r12,4)
movq (%r13,%r12,8), %rdi
addq $0x4, %rdi
xorl %esi, %esi
movq -0x50(%rbp), %rdx
callq 0x1060
incq %r12
cmpq %r12, -0x30(%rbp)
jne 0x2cc3
movq -0x70(%rbp), %r13
movl -0x68(%rbp), %eax
movl %r12d, -0x38(%rbp)
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rdx
movslq 0x8(%rdx), %rcx
movl $0x1, %esi
movl %esi, (%rax,%rcx,4)
movl %ecx, 0x4(%rbx)
movl %esi, 0x4(%r15)
movq -0x40(%rbp), %rdi
movl %esi, 0x4(%rdi)
movslq 0x4(%rdx), %rax
movq -0x78(%rbp), %rdx
movq (%rdx,%rax,8), %rax
movq %rax, -0xa8(%rbp)
movsd (%rax,%rcx,8), %xmm0
movq -0x90(%rbp), %r14
movsd %xmm0, 0x8(%r14)
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %r8d
cmpl $0x3, %r13d
jl 0x31b7
movq %r13, %r12
movq %r15, %rcx
addq $0x4, %rcx
movq %rcx, -0x98(%rbp)
movabsq $0x100000000, %rsi      # imm = 0x100000000
incl %r12d
leaq 0x4(%rdi), %rcx
movq %rcx, -0xa0(%rbp)
movl $0x1, %ecx
movq %rcx, -0x30(%rbp)
movl $0x2, %r11d
movsd 0x12274(%rip), %xmm0    # 0x15008
movsd 0x12294(%rip), %xmm1    # 0x15030
movsd 0x12284(%rip), %xmm2    # 0x15028
movsd 0x12274(%rip), %xmm3    # 0x15020
movapd 0x122cc(%rip), %xmm4    # 0x15080
movl $0x1, %edi
movl $0x1, %ecx
movq %rcx, -0x80(%rbp)
movq %r12, -0x70(%rbp)
movq %r15, -0xb0(%rbp)
movq -0x60(%rbp), %r9
movslq (%r9,%r11,4), %rcx
movq -0xa8(%rbp), %r10
movsd (%r10,%rcx,8), %xmm7
movq -0x78(%rbp), %rdx
movq (%rdx,%rcx,8), %rdx
movq %r11, -0x50(%rbp)
movl 0x4(%r9,%r11,4), %ecx
movslq %ecx, %r13
movsd (%rdx,%r13,8), %xmm5
movapd %xmm7, %xmm6
addsd %xmm5, %xmm6
movsd (%r10,%r13,8), %xmm8
subsd %xmm8, %xmm6
mulsd %xmm0, %xmm6
ucomisd %xmm6, %xmm1
jae 0x31fa
addsd %xmm8, %xmm5
subsd %xmm7, %xmm5
mulsd %xmm0, %xmm5
ucomisd %xmm5, %xmm1
jae 0x31fa
movapd %xmm6, %xmm7
cmpnlesd %xmm2, %xmm7
andpd %xmm6, %xmm7
movq -0x30(%rbp), %rax
movslq %eax, %r11
xorpd %xmm6, %xmm6
movsd (%r14,%r11,8), %xmm8
cmpeqsd %xmm6, %xmm8
movq %xmm8, %r9
addl %eax, %r9d
movapd %xmm7, %xmm8
addsd %xmm3, %xmm8
ucomisd %xmm6, %xmm8
jb 0x2e96
movslq %r9d, %rax
movq %rax, %r9
subq $0x1, %r9
jb 0x2e8f
addsd (%r14,%rax,8), %xmm6
ucomisd %xmm6, %xmm8
movq %r9, %rax
jae 0x2e77
jmp 0x2e96
xorl %r9d, %r9d
movapd %xmm7, %xmm6
movapd %xmm6, %xmm8
subsd %xmm7, %xmm8
andpd %xmm4, %xmm8
leal 0x2(%rdi), %eax
ucomisd %xmm8, %xmm2
jae 0x2eb9
xorl %r10d, %r10d
movl %eax, %r8d
xorl %edx, %edx
jmp 0x2ede
testl %r9d, %r9d
je 0x2ed2
leal 0x1(%rdi), %r8d
cmpl -0x30(%rbp), %r9d
sete %dl
cmovel %eax, %r8d
xorl %r10d, %r10d
jmp 0x2eda
movb $0x1, %r10b
xorl %edx, %edx
movl %eax, %r8d
movapd %xmm6, %xmm7
movapd %xmm5, %xmm9
cmpnlesd %xmm2, %xmm9
andpd %xmm5, %xmm9
movq %r8, -0x68(%rbp)
cmpl %eax, %r8d
jne 0x2f30
ucomisd %xmm8, %xmm2
jae 0x2f55
movslq %r9d, %rdx
movl 0x4(%r15,%rdx,4), %r10d
addl $0x2, %r9d
subsd %xmm7, %xmm6
movsd %xmm6, 0x8(%r14,%rdx,8)
movsd %xmm9, 0x10(%r14,%rdx,8)
movl %eax, 0x4(%r15,%rdx,4)
leal 0x1(%rdi), %r8d
movl %r8d, 0x8(%r15,%rdx,4)
movq %r9, -0x30(%rbp)
jmp 0x2fad
leal 0x1(%r9), %r12d
movslq %r9d, %rdx
movsd %xmm9, 0x8(%r14,%rdx,8)
leal 0x1(%rdi), %edx
movq -0x98(%rbp), %r8
movq -0x40(%rbp), %r14
movq -0x48(%rbp), %r10
jmp 0x2fee
testb %r10b, %r10b
je 0x2f82
movl 0x4(%r15), %r10d
movq $0x0, 0x8(%r14)
movsd %xmm9, 0x10(%r14)
movl %eax, 0x4(%r15)
leal 0x1(%rdi), %edx
movl %edx, 0x8(%r15)
movl $0x2, %edx
movq %rdx, -0x30(%rbp)
jmp 0x2fad
testb %dl, %dl
je 0x2fa9
movl (%r15,%r11,4), %r10d
movq -0x30(%rbp), %rdx
incl %edx
movq %rdx, -0x30(%rbp)
movsd %xmm9, 0x8(%r14,%r11,8)
movl %eax, (%r15,%r11,4)
leal 0x1(%rdi), %edx
movl %edx, 0x4(%r15,%r11,4)
jmp 0x2fad
movl -0x54(%rbp), %r10d
movl %r10d, -0x54(%rbp)
movslq %r10d, %rdx
movq -0x48(%rbp), %r10
movq (%r10,%rdx,8), %r8
movslq %eax, %r9
movq (%r10,%r9,8), %r9
movl $0x1, %r10d
movq -0x40(%rbp), %r14
movl (%r8,%r10,4), %r11d
movl %r11d, (%r9,%r10,4)
incq %r10
cmpq %r10, %r12
jne 0x2fcd
movl (%rbx,%rdx,4), %edx
movl %eax, %r9d
movq %rbx, %r8
movq -0x48(%rbp), %r10
movq -0x30(%rbp), %r12
movslq %r9d, %r9
movl %edx, (%r8,%r9,4)
testl %r12d, %r12d
movq -0x50(%rbp), %r11
jle 0x3021
leal 0x1(%r12), %edx
movl $0x1, %r8d
movslq (%r15,%r8,4), %r9
movq (%r10,%r9,8), %r9
movl $0x1, (%r9,%r13,4)
incq %r8
cmpq %r8, %rdx
jne 0x3009
movq %r12, -0x30(%rbp)
testl %r12d, %r12d
movq -0x80(%rbp), %r10
movl -0x54(%rbp), %r12d
movq -0x68(%rbp), %r13
jle 0x3058
movq -0x30(%rbp), %rdx
incl %edx
movl $0x1, %r8d
movslq (%r15,%r8,4), %r9
cmpl %ecx, (%rbx,%r9,4)
jge 0x3050
movl %ecx, (%rbx,%r9,4)
incq %r8
cmpq %r8, %rdx
jne 0x3042
movl %r10d, %r8d
testl %r10d, %r10d
jle 0x307b
movl %r10d, %edx
incq %rdx
movl -0x4(%r14,%rdx,4), %r8d
movl %r8d, (%r14,%rdx,4)
decq %rdx
cmpq $0x1, %rdx
jg 0x3066
xorl %r8d, %r8d
incl %edi
leal 0x1(%r10), %r9d
movl %edi, 0x4(%r14)
cmpl %eax, %r13d
jne 0x30d3
movl $0x1, %edx
movq %rsi, %rdi
movq %rdx, %r8
incq %rdx
addq %rsi, %rdi
cmpl %r12d, 0x4(%r14,%r8,4)
jne 0x3092
cmpl %edx, %r10d
jl 0x30bf
movslq %r9d, %r9
sarq $0x20, %rdi
movl (%r14,%r9,4), %r8d
movl %r8d, 0x4(%r14,%r9,4)
decq %r9
cmpq %rdi, %r9
jg 0x30ae
movl %edx, %edx
movl %eax, 0x4(%r14,%rdx,4)
addl $0x2, %r10d
movq %r10, -0x80(%rbp)
movl %r9d, %r8d
jmp 0x30d7
movq %r9, -0x80(%rbp)
incq %r11
movq %r11, -0x50(%rbp)
leal -0x1(%r13), %eax
cltq
movq %rax, %r10
shlq $0x20, %r10
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
addq %rdx, %r10
movl $0x1, %r12d
subl %r13d, %r12d
movq -0xa0(%rbp), %rdx
leaq (%rdx,%rax,4), %r11
movl $0x2, %r13d
movl (%r14,%rax,4), %edx
movslq %r13d, %rdi
cmpl (%r15,%rdi,4), %edx
jne 0x3177
movq %r10, %rdi
xorl %r8d, %r8d
movq %r8, %r9
movslq (%r11,%r8,4), %r14
incq %r8
addq %rsi, %rdi
cmpl (%rbx,%r14,4), %ecx
jg 0x3125
incl %r13d
subq %r12, %r8
movq %rdi, %r14
sarq $0x20, %r14
cmpq %rax, %r14
jle 0x3173
xorl %r14d, %r14d
movl (%r11,%r14,4), %r15d
movl %r15d, -0x4(%r11,%r14,4)
incq %r14
cmpl %r14d, %r9d
jne 0x314d
sarq $0x1e, %rdi
movq -0x40(%rbp), %r14
movl %edx, (%r14,%rdi)
movq -0xb0(%rbp), %r15
jmp 0x3177
movq -0x40(%rbp), %r14
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
addq %rdx, %r10
incq %r12
addq $-0x4, %r11
decq %rax
jne 0x3112
xorl %eax, %eax
movq -0x68(%rbp), %r13
movl %r13d, %edi
movq -0x50(%rbp), %r11
cmpq -0x88(%rbp), %r11
movq -0x90(%rbp), %r14
movq -0x70(%rbp), %r12
jne 0x2dcd
jmp 0x31bd
movl $0x1, %r13d
movl %eax, -0x38(%rbp)
movl %r8d, -0x34(%rbp)
movq %rbx, %rdi
callq 0x1100
movq -0x60(%rbp), %rdi
callq 0x1100
movq %r14, %rdi
callq 0x1100
movq %r15, %rdi
callq 0x1100
movl %r13d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, -0x38(%rbp)
movl %r8d, -0x34(%rbp)
leaq 0x13d87(%rip), %rdi     # 0x16f8f
callq 0x1190
movq %rbx, %rdi
callq 0x1100
movq -0x60(%rbp), %rdi
callq 0x1100
movq %r14, %rdi
callq 0x1100
movq %r15, %rdi
callq 0x1100
movl $0x1, %edi
callq 0x1110