// File: /workspace/github_cpp_makefile_star2_O3/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, %ebx
movq %rdx, -0x48(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdi, -0x60(%rbp)
leal (%rbx,%rbx), %eax
movl %eax, -0x30(%rbp)
movslq %eax, %r13
leaq (,%r13,4), %r14
movq %r14, %rdi
callq 0x1140
movq %rax, %r15
leal 0x1(,%rbx,2), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1140
movq %rax, %r12
shlq $0x3, %r13
movq %r13, %rdi
movq -0x38(%rbp), %r13
callq 0x1140
movq %rax, -0x58(%rbp)
movq %r14, %rdi
callq 0x1140
movq %rax, -0x78(%rbp)
leaq -0xa0(%rbp), %rdx
movl $0x1, (%rdx)
leaq -0x9c(%rbp), %rcx
movl %ebx, (%rcx)
movq -0x60(%rbp), %rdi
movq %r12, -0x50(%rbp)
movq %r12, %rsi
movl %ebx, %r8d
callq 0x22c1
movl %ebx, %eax
movq %rax, -0x88(%rbp)
cmpl $0x2, %ebx
jl 0x2c11
movl -0x30(%rbp), %eax
cmpl $0x5, %eax
movl $0x4, %r14d
cmovgel %eax, %r14d
movq -0x88(%rbp), %rax
leaq (,%rax,4), %rax
movq %rax, -0x30(%rbp)
addl $-0x2, %r14d
movl $0x1, %r12d
xorl %ecx, %ecx
movl %ecx, (%r15,%r12,4)
movq -0x48(%rbp), %rax
movl %ecx, (%rax,%r12,4)
movq (%r13,%r12,8), %rdi
addq $0x4, %rdi
xorl %esi, %esi
movq -0x30(%rbp), %rdx
callq 0x1060
incq %r12
cmpq %r12, %r14
jne 0x2be7
movq 0x8(%r13), %rcx
movq -0x50(%rbp), %rsi
movslq 0x8(%rsi), %rax
movl $0x1, %r9d
movl %r9d, (%rcx,%rax,4)
movl %eax, 0x4(%r15)
movq -0x78(%rbp), %r14
movl %r9d, 0x4(%r14)
movq -0x48(%rbp), %r10
movl %r9d, 0x4(%r10)
movslq 0x4(%rsi), %rcx
movq -0x60(%rbp), %rsi
movq (%rsi,%rcx,8), %rcx
movq %rcx, -0x98(%rbp)
movsd (%rcx,%rax,8), %xmm6
movq -0x58(%rbp), %rcx
movsd %xmm6, 0x8(%rcx)
cmpl $0x3, %ebx
jl 0x3080
movabsq $0x100000000, %rsi      # imm = 0x100000000
incl %ebx
leaq 0x4(%r10), %rcx
movq %rcx, -0x90(%rbp)
movl $0x1, %ecx
movq %rcx, -0x30(%rbp)
movl $0x2, %r8d
movsd 0x12375(%rip), %xmm0    # 0x15008
movsd 0x12395(%rip), %xmm1    # 0x15030
movsd 0x12385(%rip), %xmm2    # 0x15028
movsd 0x12375(%rip), %xmm3    # 0x15020
movapd 0x123cd(%rip), %xmm4    # 0x15080
movl $0x1, %edi
movl $0x1, %ecx
movq %rcx, -0x68(%rbp)
cltq
movq -0x60(%rbp), %rcx
movq (%rcx,%rax,8), %rdx
movq -0x50(%rbp), %rax
movq %r8, -0x38(%rbp)
movl 0x4(%rax,%r8,4), %eax
movslq %eax, %rcx
movsd (%rdx,%rcx,8), %xmm7
movapd %xmm6, %xmm9
addsd %xmm7, %xmm9
movq -0x98(%rbp), %rdx
movsd (%rdx,%rcx,8), %xmm5
subsd %xmm5, %xmm9
mulsd %xmm0, %xmm9
ucomisd %xmm9, %xmm1
movq -0x58(%rbp), %r8
jae 0x30b6
addsd %xmm5, %xmm7
subsd %xmm6, %xmm7
mulsd %xmm0, %xmm7
ucomisd %xmm7, %xmm1
jae 0x30b6
movapd %xmm9, %xmm8
cmpnlesd %xmm2, %xmm8
andpd %xmm9, %xmm8
movapd %xmm7, %xmm6
cmpnlesd %xmm2, %xmm6
andpd %xmm7, %xmm6
movq -0x30(%rbp), %rdx
movslq %edx, %r9
xorpd %xmm7, %xmm7
movsd (%r8,%r9,8), %xmm9
cmpeqsd %xmm7, %xmm9
movq %xmm9, %r11
addl %edx, %r11d
movapd %xmm8, %xmm9
addsd %xmm3, %xmm9
ucomisd %xmm7, %xmm9
jb 0x2d8e
movslq %r11d, %rdx
movq %rdx, %r11
subq $0x1, %r11
jb 0x2de4
addsd (%r8,%rdx,8), %xmm7
ucomisd %xmm7, %xmm9
movq %r11, %rdx
jae 0x2d78
subsd %xmm8, %xmm7
movapd %xmm7, %xmm8
andpd %xmm4, %xmm8
ucomisd %xmm8, %xmm2
jb 0x2e00
testl %r11d, %r11d
je 0x2e36
leal 0x2(%rdi), %r12d
movq -0x30(%rbp), %rdx
cmpl %edx, %r11d
jne 0x305e
movl (%r14,%r9,4), %r10d
incl %edx
movq %rdx, -0x30(%rbp)
movsd %xmm6, 0x8(%r8,%r9,8)
movl %r12d, (%r14,%r9,4)
movq %rdi, -0x40(%rbp)
leal 0x1(%rdi), %edx
movl %edx, 0x4(%r14,%r9,4)
jmp 0x2e64
subsd %xmm8, %xmm8
movapd %xmm8, %xmm7
andpd %xmm4, %xmm7
xorl %r11d, %r11d
ucomisd %xmm7, %xmm2
movapd %xmm8, %xmm7
jae 0x2e36
leal 0x2(%rdi), %r12d
movslq %r11d, %rdx
movl 0x4(%r14,%rdx,4), %r10d
leal 0x2(%rdx), %r9d
movq %r9, -0x30(%rbp)
movsd %xmm7, 0x8(%r8,%rdx,8)
movsd %xmm6, 0x10(%r8,%rdx,8)
movl %r12d, 0x4(%r14,%rdx,4)
movq %rdi, -0x40(%rbp)
leal 0x1(%rdi), %r9d
movl %r9d, 0x8(%r14,%rdx,4)
jmp 0x2e64
leal 0x2(%rdi), %r12d
movl 0x4(%r14), %r10d
movq $0x0, 0x8(%r8)
movsd %xmm6, 0x10(%r8)
movl %r12d, 0x4(%r14)
movq %rdi, -0x40(%rbp)
leal 0x1(%rdi), %edx
movl %edx, 0x8(%r14)
movl $0x2, %edx
movq %rdx, -0x30(%rbp)
movl %r10d, -0x7c(%rbp)
movslq %r10d, %rdx
movq (%r13,%rdx,8), %r11
movl %r12d, %edi
movslq %r12d, %r9
movq (%r13,%r9,8), %r12
movl $0x1, %r10d
movl (%r11,%r10,4), %r8d
movl %r8d, (%r12,%r10,4)
incq %r10
cmpq %r10, %rbx
jne 0x2e81
movl (%r15,%rdx,4), %edx
movl %edx, (%r15,%r9,4)
movb $0x1, %r9b
movl %edi, %r12d
movl %edi, %edx
movq %rdx, -0x70(%rbp)
movq -0x48(%rbp), %r10
movq -0x30(%rbp), %r11
movq -0x40(%rbp), %rdi
testl %r11d, %r11d
movq %r11, -0x30(%rbp)
jle 0x2efc
incl %r11d
movl $0x1, %edx
movslq (%r14,%rdx,4), %r8
movq (%r13,%r8,8), %r8
movl $0x1, (%r8,%rcx,4)
incq %rdx
cmpq %rdx, %r11
jne 0x2ec2
cmpl $0x0, -0x30(%rbp)
jle 0x2efc
movl $0x1, %ecx
movslq (%r14,%rcx,4), %rdx
cmpl %eax, (%r15,%rdx,4)
jge 0x2ef4
movl %eax, (%r15,%rdx,4)
incq %rcx
cmpq %rcx, %r11
jne 0x2ee6
movq -0x68(%rbp), %r11
testl %r11d, %r11d
jle 0x2f1d
movl %r11d, %ecx
incq %rcx
movl -0x4(%r10,%rcx,4), %edx
movl %edx, (%r10,%rcx,4)
decq %rcx
cmpq $0x1, %rcx
ja 0x2f0b
incl %edi
movl %edi, 0x4(%r10)
leal 0x1(%r11), %edi
testb %r9b, %r9b
je 0x2f81
movl %r12d, -0x40(%rbp)
movl $0x1, %ecx
movq %rsi, %rdx
movq -0x38(%rbp), %r9
movl -0x7c(%rbp), %r12d
movq %rcx, %r8
incq %rcx
addq %rsi, %rdx
cmpl %r12d, 0x4(%r10,%r8,4)
jne 0x2f40
cmpl %ecx, %r11d
jl 0x2f6d
movslq %edi, %rdi
sarq $0x20, %rdx
movl (%r10,%rdi,4), %r8d
movl %r8d, 0x4(%r10,%rdi,4)
decq %rdi
cmpq %rdx, %rdi
jg 0x2f5c
movl %ecx, %ecx
movl -0x40(%rbp), %edx
movl %edx, 0x4(%r10,%rcx,4)
addl $0x2, %r11d
movq %r11, -0x68(%rbp)
jmp 0x2f8b
movl %edi, %ecx
movq %rcx, -0x68(%rbp)
movq -0x38(%rbp), %r9
incq %r9
movq %r9, -0x38(%rbp)
movq -0x70(%rbp), %rcx
decl %ecx
movslq %ecx, %rcx
movq %rcx, %rdx
shlq $0x20, %rdx
movabsq $-0x100000000, %rdi     # imm = 0xFFFFFFFF00000000
addq %rdi, %rdx
movq -0x90(%rbp), %rdi
leaq (%rdi,%rcx,4), %r8
movl $0x2, %r9d
movl (%r10,%rcx,4), %r11d
movslq %r9d, %rdi
cmpl (%r14,%rdi,4), %r11d
jne 0x302a
movq %r13, %r14
movq %rbx, %r13
movq %rdx, %rdi
xorl %r10d, %r10d
movq %r10, %r12
movslq (%r8,%r10,4), %rbx
incq %r10
addq %rsi, %rdi
cmpl (%r15,%rbx,4), %eax
jg 0x2fd9
incl %r9d
sarq $0x20, %rdi
cmpq %rcx, %rdi
jle 0x301c
xorl %r10d, %r10d
movl (%r8,%r10,4), %ebx
movl %ebx, -0x4(%r8,%r10,4)
incq %r10
cmpl %r10d, %r12d
jne 0x2ffb
movq -0x48(%rbp), %r10
movl %r11d, (%r10,%rdi,4)
movq %r13, %rbx
movq %r14, %r13
jmp 0x3026
movq %r13, %rbx
movq %r14, %r13
movq -0x48(%rbp), %r10
movq -0x78(%rbp), %r14
movabsq $-0x100000000, %rdi     # imm = 0xFFFFFFFF00000000
addq %rdi, %rdx
addq $-0x4, %r8
decq %rcx
jne 0x2fc0
movapd %xmm5, %xmm6
movq -0x70(%rbp), %r9
movl %r9d, %edi
movq -0x38(%rbp), %r8
cmpq -0x88(%rbp), %r8
jne 0x2cc1
jmp 0x3080
leal 0x1(%rdi), %r9d
movslq %r11d, %rdx
incl %r11d
movsd %xmm6, 0x8(%r8,%rdx,8)
movq %r9, -0x70(%rbp)
movl %r9d, 0x4(%r14,%rdx,4)
xorl %r9d, %r9d
jmp 0x2eb1
movq %r15, %rdi
movq %r9, %rbx
callq 0x1100
movq -0x50(%rbp), %rdi
callq 0x1100
movq -0x58(%rbp), %rdi
callq 0x1100
movq %r14, %rdi
callq 0x1100
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13ed2(%rip), %rdi     # 0x16f8f
movq %r8, %rbx
callq 0x1190
movq %r15, %rdi
callq 0x1100
movq -0x50(%rbp), %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x1100
movq %r14, %rdi
callq 0x1100
movl $0x1, %edi
callq 0x1110