// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movl %ecx, %r13d
movq %rdx, %rbx
movq %rsi, -0x78(%rbp)
movq %rdi, -0x50(%rbp)
leal (%r13,%r13), %eax
movslq %eax, %r12
leaq (,%r12,4), %rdi
movq %rdi, -0x38(%rbp)
movq %r12, -0x30(%rbp)
callq 0x1130
movq %rax, %r15
leal 0x1(,%r13,2), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1130
movq %rax, %r14
leaq (,%r12,8), %rdi
callq 0x1130
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rdi
callq 0x1130
movq %rax, %r12
leaq -0xa0(%rbp), %rdx
movl $0x1, (%rdx)
leaq -0x9c(%rbp), %rcx
movl %r13d, (%rcx)
movq -0x50(%rbp), %rdi
movq %r14, -0x48(%rbp)
movq %r14, %rsi
movl %r13d, %r8d
callq 0x214f
movq %r13, %r9
xorl %edi, %edi
testl %r9d, %r9d
cmovgl %r9d, %edi
movq -0x30(%rbp), %rax
cmpl $0x4, %eax
pushq $0x3
popq %rcx
cmovgel %eax, %ecx
movq -0x78(%rbp), %r14
addl $-0x2, %ecx
pushq $0x1
popq %rdx
cmpq %rcx, %rdx
je 0x2977
andl $0x0, (%r15,%rdx,4)
andl $0x0, (%rbx,%rdx,4)
xorl %eax, %eax
cmpq %rax, %rdi
je 0x2972
movq (%r14,%rdx,8), %rsi
andl $0x0, 0x4(%rsi,%rax,4)
incq %rax
jmp 0x295f
incq %rdx
jmp 0x294f
movq %rdi, -0x80(%rbp)
movabsq $0x100000000, %rdx      # imm = 0x100000000
movq 0x8(%r14), %rax
movq -0x48(%rbp), %rsi
movslq 0x8(%rsi), %rcx
pushq $0x1
popq %r8
movl %r8d, (%rax,%rcx,4)
movl %ecx, 0x4(%r15)
movl %r8d, 0x4(%r12)
leaq 0x4(%rbx), %rdi
movl %r8d, 0x4(%rbx)
movslq 0x4(%rsi), %rax
movq -0x50(%rbp), %rsi
movq (%rsi,%rax,8), %rax
movq %rax, -0x88(%rbp)
movsd (%rax,%rcx,8), %xmm0
movq -0x70(%rbp), %r13
movsd %xmm0, 0x8(%r13)
movslq %r9d, %rax
movq %rax, -0x90(%rbp)
pushq $0x2
popq %r11
movsd 0x11626(%rip), %xmm0    # 0x14008
movsd 0x11646(%rip), %xmm1    # 0x14030
movsd 0x11636(%rip), %xmm2    # 0x14028
movsd 0x11626(%rip), %xmm3    # 0x14020
movapd 0x1167e(%rip), %xmm4    # 0x14080
movl %r8d, %ecx
movq %r8, -0x58(%rbp)
movl %r8d, -0x38(%rbp)
movq %rcx, -0x30(%rbp)
cmpq -0x90(%rbp), %r11
jge 0x2d6f
movq -0x48(%rbp), %rsi
movslq (%rsi,%r11,4), %rax
movq -0x88(%rbp), %r8
movsd (%r8,%rax,8), %xmm6
movq -0x50(%rbp), %rcx
movq (%rcx,%rax,8), %rax
movl 0x4(%rsi,%r11,4), %r9d
movslq %r9d, %r10
movsd (%rax,%r10,8), %xmm7
movapd %xmm6, %xmm5
addsd %xmm7, %xmm5
movsd (%r8,%r10,8), %xmm8
subsd %xmm8, %xmm5
mulsd %xmm0, %xmm5
ucomisd %xmm5, %xmm1
jae 0x2da3
addsd %xmm8, %xmm7
subsd %xmm6, %xmm7
mulsd %xmm0, %xmm7
ucomisd %xmm7, %xmm1
jae 0x2da3
incq %r11
movapd %xmm5, %xmm6
cmpnlesd %xmm2, %xmm6
andpd %xmm5, %xmm6
movapd %xmm7, %xmm5
cmpnlesd %xmm2, %xmm5
andpd %xmm7, %xmm5
movl -0x38(%rbp), %ecx
movslq %ecx, %r8
xorpd %xmm7, %xmm7
movsd (%r13,%r8,8), %xmm8
cmpeqsd %xmm7, %xmm8
movq %xmm8, %rax
addl %ecx, %eax
movapd %xmm6, %xmm8
addsd %xmm3, %xmm8
movslq %eax, %rsi
ucomisd %xmm7, %xmm8
jb 0x2aeb
movq %rsi, %rax
subq $0x1, %rax
jb 0x2ae5
addsd (%r13,%rsi,8), %xmm7
movq %rax, %rsi
jmp 0x2ac9
xorl %esi, %esi
movapd %xmm6, %xmm7
subsd %xmm6, %xmm7
movapd %xmm7, %xmm6
andpd %xmm4, %xmm6
ucomisd %xmm6, %xmm2
movslq %esi, %rcx
movq %r11, -0x98(%rbp)
jae 0x2b36
movq -0x30(%rbp), %rax
leal 0x2(%rax), %r11d
movl 0x4(%r12,%rcx,4), %r8d
addl $0x2, %esi
movsd %xmm7, 0x8(%r13,%rcx,8)
movsd %xmm5, 0x10(%r13,%rcx,8)
movl %r11d, 0x4(%r12,%rcx,4)
incl %eax
movl %eax, 0x8(%r12,%rcx,4)
movl %esi, -0x38(%rbp)
jmp 0x2ba1
testl %esi, %esi
je 0x2b77
movq -0x30(%rbp), %rax
addl $0x2, %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
cmpl %eax, %esi
jne 0x2d4c
movl (%r12,%r8,4), %ecx
incl %eax
movl %eax, -0x38(%rbp)
movsd %xmm5, 0x8(%r13,%r8,8)
movl -0x3c(%rbp), %r11d
movl %r11d, (%r12,%r8,4)
movq -0x30(%rbp), %rax
incl %eax
movl %eax, 0x4(%r12,%r8,4)
movl %ecx, %r8d
jmp 0x2ba1
movq -0x30(%rbp), %rax
leal 0x2(%rax), %r11d
movl 0x4(%r12), %r8d
andq $0x0, 0x8(%r13)
movsd %xmm5, 0x10(%r13)
movl %r11d, 0x4(%r12)
incl %eax
movl %eax, 0x8(%r12)
pushq $0x2
popq %rax
movl %eax, -0x38(%rbp)
movl %r8d, -0x64(%rbp)
movslq %r8d, %rcx
movl %r11d, -0x3c(%rbp)
movslq %r11d, %rsi
xorl %r8d, %r8d
movq -0x80(%rbp), %r13
cmpq %r8, %r13
je 0x2bd2
movq (%r14,%rcx,8), %rax
movl 0x4(%rax,%r8,4), %eax
movq (%r14,%rsi,8), %r11
movl %eax, 0x4(%r11,%r8,4)
incq %r8
jmp 0x2bb6
movq -0x30(%rbp), %rax
addl $0x2, %eax
movq %rax, -0x60(%rbp)
movl (%r15,%rcx,4), %eax
movl %eax, (%r15,%rsi,4)
movb $0x1, %r8b
movl -0x38(%rbp), %r13d
testl %r13d, %r13d
movl $0x0, %ecx
cmovgl %r13d, %ecx
xorl %eax, %eax
movq -0x58(%rbp), %r11
cmpq %rax, %rcx
je 0x2c19
movslq 0x4(%r12,%rax,4), %rsi
movq (%r14,%rsi,8), %rsi
movl $0x1, (%rsi,%r10,4)
incq %rax
jmp 0x2bfe
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x2c34
movslq 0x4(%r12,%rsi,4), %rax
cmpl %r9d, (%r15,%rax,4)
jge 0x2c2f
movl %r9d, (%r15,%rax,4)
incq %rsi
jmp 0x2c1b
movl %r11d, %ecx
testl %ecx, %ecx
jle 0x2c47
movl (%rbx,%rcx,4), %eax
movl %eax, 0x4(%rbx,%rcx,4)
decq %rcx
jmp 0x2c37
movq -0x30(%rbp), %rax
incl %eax
movl %eax, 0x4(%rbx)
leal 0x1(%r11), %r10d
testb %r8b, %r8b
movl %r13d, -0x38(%rbp)
je 0x2c91
movq %rdx, %rcx
pushq $0x1
popq %rsi
movl -0x64(%rbp), %r8d
movq %rsi, %rax
incq %rsi
addq %rdx, %rcx
cmpl %r8d, 0x4(%rbx,%rax,4)
jne 0x2c67
movslq %r10d, %r8
sarq $0x20, %rcx
cmpq %rcx, %r8
jle 0x2c9a
movl (%rbx,%r8,4), %eax
movl %eax, 0x4(%rbx,%r8,4)
decq %r8
jmp 0x2c7e
movl %r10d, %eax
movq %rax, -0x58(%rbp)
jmp 0x2cab
movl %esi, %eax
movl -0x3c(%rbp), %ecx
movl %ecx, 0x4(%rbx,%rax,4)
addl $0x2, %r11d
movq %r11, -0x58(%rbp)
movq -0x60(%rbp), %rax
decl %eax
movslq %eax, %rsi
movq %rsi, %r11
shlq $0x20, %r11
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rax, %r11
leaq (%rdi,%rsi,4), %rax
pushq $0x2
popq %r13
movl (%rbx,%rsi,4), %ecx
movslq %r13d, %r8
cmpl (%r12,%r8,4), %ecx
jne 0x2d1e
movq %r12, %r14
movq %rax, %r10
movq %r11, %r8
movslq (%r10), %r12
addq %rdx, %r8
addq $0x4, %r10
cmpl (%r15,%r12,4), %r9d
jg 0x2ce5
incl %r13d
sarq $0x20, %r8
cmpq %rsi, %r8
jle 0x2d1b
movq %rsi, %r10
cmpq %r8, %r10
jge 0x2d17
movl (%rdi,%r10,4), %r12d
movl %r12d, -0x4(%rdi,%r10,4)
incq %r10
jmp 0x2d04
movl %ecx, (%rbx,%r8,4)
movq %r14, %r12
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %r11
addq $-0x4, %rax
decq %rsi
jne 0x2cd0
movq -0x60(%rbp), %rcx
movq -0x78(%rbp), %r14
movq -0x70(%rbp), %r13
movq -0x98(%rbp), %r11
jmp 0x2a0d
movq -0x30(%rbp), %rax
incl %eax
incl %esi
movsd %xmm5, 0x8(%r13,%rcx,8)
movq %rax, -0x60(%rbp)
movl %eax, 0x4(%r12,%rcx,4)
xorl %r8d, %r8d
movl %esi, %r13d
jmp 0x2bec
movq %r15, %rdi
callq 0x10f0
movq -0x48(%rbp), %rdi
callq 0x10f0
movq %r13, %rdi
callq 0x10f0
movq %r12, %rdi
callq 0x10f0
movq -0x30(%rbp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x131e5(%rip), %rdi     # 0x15f8f
callq 0x1180
movq %r15, %rdi
callq 0x10f0
movq -0x48(%rbp), %rdi
callq 0x10f0
movq %r13, %rdi
callq 0x10f0
movq %r12, %rdi
callq 0x10f0
pushq $0x1
popq %rdi
callq 0x1100