// File: /workspace/github_cpp_makefile_star2_O3/dcarrey[P]hgt-detection/./fonctions.cpp
// Function: TestSubTreeConstraint(InputTree, int, int, DescTree*, DescTree*)
int TestSubTreeConstraint(struct InputTree aTree,int source, int dest,struct DescTree *DTSpecies, struct DescTree *DTGene){

	int basSource,basDest;
	int etape1=0,etape2=0;
	int LGTpossible = 0;
	int pv,i,y,z,tk,tl;
	int n = aTree.size;
	int mk1,mk2,nbSom;
	struct DescTree DTemp;
	double ** DISTemp =(double **)malloc((2*n+1)*sizeof(double*));

	int * PLACEk1=(int *) malloc((2*n-2)*sizeof(int));
	int * PLACEk2=(int *) malloc((2*n-2)*sizeof(int));
	
	int ** Bk1=(int **) malloc((2*n-2)*sizeof(int*));
	int ** Bk2=(int **) malloc((2*n-2)*sizeof(int*));

	for (i=0;i<2*n-2;i++)
	{
		Bk1[i]=(int *) malloc((n)*sizeof(int));
		Bk2[i]=(int *) malloc((n)*sizeof(int));     
		DISTemp[i]=(double *)malloc((2*n+1)*sizeof(double));  
	}
	
	//== find the node inf for the source branch
	if(aTree.ADD[aTree.ARETE[2*source-1]][aTree.Root] <  aTree.ADD[aTree.ARETE[2*source-2]][aTree.Root])
		basSource = aTree.ARETE[2*source-2];
	else
		basSource = aTree.ARETE[2*source-1];

	//== find the node inf for the dest branch
	if(aTree.ADD[aTree.ARETE[2*dest-1]][aTree.Root] <  aTree.ADD[aTree.ARETE[2*dest-2]][aTree.Root])
		basDest = aTree.ARETE[2*dest-2];
	else
		basDest = aTree.ARETE[2*dest-1];


	if(basSource<n)
		etape1=1;
	else{
		for(pv=n+1;pv<2*n-2;pv++){
			if(vecteursEgaux(DTSpecies[basSource],DTGene[pv]) == 1){	
				/*if(DTSpecies[basSource].nbSommet == 3)
					etape1= 0;
				else*/{
					mk1=Bipartition_Table(DTGene[pv].Matrice,Bk1,PLACEk1,DTGene[pv].nbSommet+1);
					mk2=Bipartition_Table(DTSpecies[basSource].Matrice,Bk2,PLACEk2,DTSpecies[basSource].nbSommet+1);
					if(Table_Comparaison(Bk1,Bk2,PLACEk1,PLACEk2,mk1,mk2,DTSpecies[basSource].nbSommet+1) == 0)
						etape1 = 1;
				}
				pv = (int)INFINI;
			}
		}
	}

	if(etape1){/*/== comparer les sous arbres au niveau destination*/
		if(basDest<n)
			etape2 = 1;
		else{
			for(pv=n+1;pv<2*n-2;pv++){
				//printf("[pv = %d] ",pv);
				if(vecteursEgaux(DTSpecies[basDest],DTGene[pv]) == 1){
					/*if(DTSpecies[basDest].nbSommet == 3)
						etape2 = 0;
					else*/{
						mk1=Bipartition_Table(DTGene[pv].Matrice,Bk1,PLACEk1,DTGene[pv].nbSommet+1);
						mk2=Bipartition_Table(DTSpecies[basDest].Matrice,Bk2,PLACEk2,DTSpecies[basDest].nbSommet+1);
						if(Table_Comparaison(Bk1,Bk2,PLACEk1,PLACEk2,mk1,mk2,DTGene[pv].nbSommet+1) == 0)
							etape2 = 1;
					}
					pv = (int)INFINI;
				}				
			}	
		}
	}

	if(etape1==1 && etape2==1){
		
		nbSom = DTemp.nbSommet = DTSpecies[basDest].nbSommet + DTSpecies[basSource].nbSommet;

		DTemp.Tableau = (int*)malloc((DTemp.nbSommet+1)*sizeof(int));

		for(y=1;y<=DTSpecies[basDest].nbSommet;y++)
			DTemp.Tableau[y] = DTSpecies[basDest].Tableau[y];
		y--;
		for(z=1;z<=DTSpecies[basSource].nbSommet;z++)
			DTemp.Tableau[z+y] = DTSpecies[basSource].Tableau[z];

		TrierTableau(DTemp.Tableau,DTemp.nbSommet);

		for(pv=n+1;pv<=2*n-2;pv++){
			if(vecteursEgaux(DTemp,DTGene[pv])){

				for(tk=1;tk<=DTGene[pv].nbSommet;tk++){
					for(tl=1;tl<=DTGene[pv].nbSommet;tl++)
						DISTemp[tk][tl] = aTree.ADD[DTemp.Tableau[tk]][DTemp.Tableau[tl]];
				}

				//for(tk=1;tk<=DTGene[pv].nbSommet;tk++)
				//	DISTemp[DTGene[pv].nbSommet+1][tk] =  DISTemp[tk][DTGene[pv].nbSommet+1] = ;

				mk1=Bipartition_Table(DTGene[pv].Matrice,Bk1,PLACEk1,DTGene[pv].nbSommet);
				mk2=Bipartition_Table(DISTemp,Bk2,PLACEk2,DTemp.nbSommet);
				if(Table_Comparaison(Bk1,Bk2,PLACEk1,PLACEk2,mk1,mk2,DTGene[pv].nbSommet) == 0)
					LGTpossible = 1;
			}
		}
		free(DTemp.Tableau);	
	}

	free(PLACEk1);
	free(PLACEk2);

	for (i=0;i<2*n-2;i++)
	{
		free(Bk1[i]);
		free(Bk2[i]);
		free(DISTemp[i]);
	}
	free(DISTemp);	
	free(Bk1);
	free(Bk2);

	return LGTpossible;
		
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, -0x60(%rbp)
movq %rdx, -0x68(%rbp)
movl %esi, -0x2c(%rbp)
movl %edi, -0x38(%rbp)
leaq 0x10(%rbp), %rax
movslq (%rax), %r12
leal (%r12,%r12), %r14d
movq %r12, %r13
shlq $0x4, %r13
orq $0x8, %r13
movq %r13, %rdi
callq 0x1140
movq %rax, %rbx
movslq %r14d, %r15
leaq -0x2(%r15), %rax
movq %rax, -0x78(%rbp)
leaq -0x8(,%r15,4), %r14
movq %r14, %rdi
callq 0x1140
movq %rax, -0x70(%rbp)
movq %r14, %rdi
callq 0x1140
movq %rax, -0x80(%rbp)
leaq -0x10(,%r15,8), %r15
movq %r15, %rdi
callq 0x1140
movq %rax, -0x40(%rbp)
movq %r15, %rdi
callq 0x1140
movq %rax, -0x48(%rbp)
movq %r12, -0x50(%rbp)
cmpq $0x2, %r12
jl 0x7fcd
movq -0x50(%rbp), %rax
leaq (,%rax,4), %r12
movl -0x78(%rbp), %r14d
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x1140
movq -0x40(%rbp), %rcx
movq %rax, (%rcx,%r15,8)
movq %r12, %rdi
callq 0x1140
movq -0x48(%rbp), %rcx
movq %rax, (%rcx,%r15,8)
movq %r13, %rdi
callq 0x1140
movq %rax, (%rbx,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x7f99
movq %rbx, -0x98(%rbp)
leaq 0x10(%rbp), %rsi
movq 0x8(%rsi), %r8
movq %r8, -0xa8(%rbp)
movq 0x30(%rsi), %rax
movl -0x38(%rbp), %ecx
addl %ecx, %ecx
movslq %ecx, %rcx
movq -0x10(%rax,%rcx,8), %rdx
movq -0x8(%rax,%rcx,8), %r9
movq (%r8,%r9,8), %rcx
movslq 0x20(%rsi), %rsi
movq (%r8,%rdx,8), %rdi
movsd (%rdi,%rsi,8), %xmm0
ucomisd (%rcx,%rsi,8), %xmm0
cmovaq %rdx, %r9
movl -0x2c(%rbp), %ecx
addl %ecx, %ecx
movslq %ecx, %rcx
movq -0x10(%rax,%rcx,8), %rdx
movq -0x8(%rax,%rcx,8), %rdi
movq (%r8,%rdi,8), %rax
movq (%r8,%rdx,8), %rcx
movsd (%rcx,%rsi,8), %xmm0
ucomisd (%rax,%rsi,8), %xmm0
cmovaq %rdx, %rdi
movq %rdi, %rdx
movl $0x1, %r11d
movq -0x50(%rbp), %rcx
movq %r9, -0xa0(%rbp)
cmpl %r9d, %ecx
movq -0x40(%rbp), %r12
movq -0x48(%rbp), %r13
movq -0x78(%rbp), %rbx
movq -0x60(%rbp), %r15
jg 0x8185
leal 0x1(%rcx), %eax
cmpl %ebx, %eax
jge 0x8333
movq %rdx, -0x88(%rbp)
movslq -0xa0(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq -0x68(%rbp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq %rcx, -0x38(%rbp)
movl (%rcx), %r13d
xorl %r11d, %r11d
movq -0x70(%rbp), %r14
movq -0x80(%rbp), %r12
movslq %eax, %rcx
leaq (%rcx,%rcx,2), %rdx
cmpl (%r15,%rdx,8), %r13d
jne 0x815f
leal 0x1(%r13), %ecx
testl %r13d, %r13d
jle 0x80e5
movq -0x38(%rbp), %rsi
movq 0x10(%rsi), %rsi
movq 0x10(%r15,%rdx,8), %rdi
movl %ecx, %r8d
movl $0x1, %r9d
movl (%rsi,%r9,4), %r10d
cmpl (%rdi,%r9,4), %r10d
jne 0x815f
incq %r9
cmpq %r9, %r8
jne 0x80cf
leaq (%r15,%rdx,8), %rax
movq 0x8(%rax), %rdi
movq -0x40(%rbp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
movl %r11d, -0x2c(%rbp)
callq 0x2b12
movl %eax, -0x58(%rbp)
movq -0x38(%rbp), %r13
movq 0x8(%r13), %rdi
movl (%r13), %ecx
incl %ecx
movq -0x48(%rbp), %r15
movq %r15, %rsi
movq %r12, %rdx
callq 0x2b12
movl (%r13), %r13d
leal 0x1(%r13), %ecx
movl %ecx, (%rsp)
movq %rbx, %rdi
movq -0x78(%rbp), %rbx
movq %r15, %rsi
movq -0x60(%rbp), %r15
movq %r14, %rdx
movq %r12, %rcx
movl -0x58(%rbp), %r8d
movl %eax, %r9d
callq 0x30f0
movl -0x2c(%rbp), %r11d
testl %eax, %eax
movl $0x1, %eax
cmovel %eax, %r11d
movl $0xf423f, %eax          # imm = 0xF423F
incl %eax
cmpl %ebx, %eax
jl 0x809f
testl %r11d, %r11d
movq -0x40(%rbp), %r12
movq -0x48(%rbp), %r13
movq -0x50(%rbp), %rcx
movq -0x88(%rbp), %rdx
je 0x8333
movl %r11d, -0x2c(%rbp)
movb $0x1, %al
cmpl %edx, %ecx
jg 0x82ab
movq -0x50(%rbp), %rax
incl %eax
cmpl %ebx, %eax
jge 0x8333
movq %rdx, -0x88(%rbp)
movslq %edx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq -0x68(%rbp), %rdx
leaq (%rdx,%rcx,8), %r12
xorl %r14d, %r14d
movq %r12, -0x90(%rbp)
movq -0x80(%rbp), %r13
movl (%r12), %esi
movslq %eax, %rcx
leaq (%rcx,%rcx,2), %rdx
cmpl (%r15,%rdx,8), %esi
jne 0x828b
leal 0x1(%rsi), %ecx
testl %esi, %esi
jle 0x820a
movq 0x10(%r12), %rsi
movq 0x10(%r15,%rdx,8), %rdi
movl %ecx, %r8d
movl $0x1, %r9d
movl (%rsi,%r9,4), %r10d
cmpl (%rdi,%r9,4), %r10d
jne 0x828b
incq %r9
cmpq %r9, %r8
jne 0x81f4
movq -0x60(%rbp), %rax
leaq (%rax,%rdx,8), %r15
movq 0x8(%r15), %rdi
movq -0x40(%rbp), %rbx
movq %rbx, %rsi
movq -0x70(%rbp), %rdx
callq 0x2b12
movl %eax, -0x58(%rbp)
movq 0x8(%r12), %rdi
movl (%r12), %ecx
incl %ecx
movl %r14d, -0x38(%rbp)
movq -0x48(%rbp), %r14
movq %r14, %rsi
movq %r13, %rdx
callq 0x2b12
movl (%r15), %ecx
movq -0x60(%rbp), %r15
incl %ecx
movl %ecx, (%rsp)
movq %rbx, %rdi
movq -0x78(%rbp), %rbx
movq %r14, %rsi
movl -0x38(%rbp), %r14d
movq -0x70(%rbp), %rdx
movq %r13, %rcx
movl -0x58(%rbp), %r8d
movl %eax, %r9d
callq 0x30f0
movq -0x90(%rbp), %r12
testl %eax, %eax
movl $0x1, %eax
cmovel %eax, %r14d
movl $0xf423f, %eax          # imm = 0xF423F
incl %eax
cmpl %ebx, %eax
jl 0x81c5
cmpl $0x1, %r14d
sete %al
movq -0x40(%rbp), %r12
movq -0x48(%rbp), %r13
movq -0x88(%rbp), %rdx
movl $0x0, -0x38(%rbp)
cmpl $0x1, -0x2c(%rbp)
movq -0x68(%rbp), %r14
jne 0x8502
testb %al, %al
je 0x8502
movslq %edx, %rax
leaq (%rax,%rax,2), %r15
movslq (%r14,%r15,8), %r12
movslq -0xa0(%rbp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x58(%rbp)
movl (%r14,%rax,8), %eax
movq %rax, -0x38(%rbp)
addl %r12d, %eax
incl %eax
movl %eax, -0x90(%rbp)
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1140
movq %rax, %r13
testq %r12, %r12
jle 0x833f
leaq (%r14,%r15,8), %rax
movq 0x10(%rax), %rsi
leaq 0x4(%r13), %rdi
addq $0x4, %rsi
leaq (,%r12,4), %rdx
callq 0x1080
movl %r12d, %eax
leaq 0x4(,%rax,4), %rdi
jmp 0x8344
movl $0x0, -0x38(%rbp)
jmp 0x8502
movl $0x4, %edi
movq -0x38(%rbp), %rdx
leal (%rdx,%r12), %eax
testl %edx, %edx
movl %eax, -0x2c(%rbp)
jle 0x8376
movq -0x68(%rbp), %rax
movq -0x58(%rbp), %rcx
leaq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rsi
addq %r13, %rdi
addq $0x4, %rsi
shlq $0x2, %rdx
callq 0x1080
movl -0x2c(%rbp), %eax
cmpl $0x2, %eax
movq -0x50(%rbp), %r8
movq -0xa8(%rbp), %r9
jl 0x83bc
movl -0x2c(%rbp), %eax
movl 0x4(%r13), %ecx
xorl %esi, %esi
movl $0x1, %edx
movl 0x4(%r13,%rdx,4), %edi
cmpl %edi, %ecx
jle 0x83ae
movl %edi, (%r13,%rdx,4)
movl %ecx, 0x4(%r13,%rdx,4)
movl $0x1, %esi
jmp 0x83b0
movl %edi, %ecx
incq %rdx
cmpq %rdx, %rax
jne 0x8394
testl %esi, %esi
jne 0x8389
xorl %r11d, %r11d
cmpl %ebx, %r8d
movl -0x2c(%rbp), %r15d
jge 0x84ee
movl -0x90(%rbp), %r12d
xorl %r11d, %r11d
movq -0x50(%rbp), %r14
incq %r14
leaq (%r14,%r14,2), %rax
movq -0x60(%rbp), %rcx
cmpl (%rcx,%rax,8), %r15d
jne 0x84e5
testl %r15d, %r15d
movq -0x98(%rbp), %r10
jle 0x845c
movq -0x60(%rbp), %rcx
movq 0x10(%rcx,%rax,8), %rcx
movl $0x1, %edx
movl (%r13,%rdx,4), %esi
cmpl (%rcx,%rdx,4), %esi
jne 0x84e1
incq %rdx
cmpq %rdx, %r12
jne 0x8409
cmpl $0x0, -0x2c(%rbp)
jle 0x845c
movl $0x1, %ecx
movslq (%r13,%rcx,4), %rdx
movq (%r9,%rdx,8), %rdx
movq (%r10,%rcx,8), %rsi
movl $0x1, %edi
movslq (%r13,%rdi,4), %r8
movsd (%rdx,%r8,8), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %r12
jne 0x843c
incq %rcx
cmpq %r12, %rcx
jne 0x842a
movq -0x60(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, -0x68(%rbp)
movq 0x8(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl -0x2c(%rbp), %r15d
movl %r15d, %ecx
movl %r11d, -0x38(%rbp)
callq 0x2b12
movl %eax, -0x58(%rbp)
movq -0x98(%rbp), %rdi
movq -0x48(%rbp), %rbx
movq %rbx, %rsi
movq -0x80(%rbp), %rdx
movl %r15d, %ecx
callq 0x2b12
movq -0x68(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, (%rsp)
movq -0x40(%rbp), %rdi
movq %rbx, %rsi
movq -0x78(%rbp), %rbx
movq -0x70(%rbp), %rdx
movq -0x80(%rbp), %rcx
movl -0x58(%rbp), %r8d
movl %eax, %r9d
callq 0x30f0
movl -0x38(%rbp), %r11d
movq -0xa8(%rbp), %r9
testl %eax, %eax
movl $0x1, %eax
cmovel %eax, %r11d
jmp 0x84e5
movl -0x2c(%rbp), %r15d
cmpq %rbx, %r14
jne 0x83da
movl %r11d, -0x38(%rbp)
movq %r13, %rdi
callq 0x1100
movq -0x40(%rbp), %r12
movq -0x48(%rbp), %r13
movq %rbx, %r14
movq -0x70(%rbp), %rdi
callq 0x1100
movq -0x80(%rbp), %rdi
callq 0x1100
cmpl $0x2, -0x50(%rbp)
movq -0x98(%rbp), %rbx
jl 0x854e
movl %r14d, %r14d
xorl %r15d, %r15d
movq (%r12,%r15,8), %rdi
callq 0x1100
movq (%r13,%r15,8), %rdi
callq 0x1100
movq (%rbx,%r15,8), %rdi
callq 0x1100
incq %r15
cmpq %r15, %r14
jne 0x852a
movq %rbx, %rdi
callq 0x1100
movq %r12, %rdi
callq 0x1100
movq %r13, %rdi
callq 0x1100
movl -0x38(%rbp), %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq