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

	int basSource,hautSource,basDest,noeudRacine;
	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));  
	}
	
	for (i=1;i<2*n-3-aTree.kt;i++){
		if(aTree.ARETE[2*i-1] == aTree.Root)
			noeudRacine = aTree.ARETE[2*i-2];
		if(aTree.ARETE[2*i-2] == aTree.Root)
			noeudRacine = aTree.ARETE[2*i-1];
	}
			
	//== 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];
		hautSource = aTree.ARETE[2*source-1];
	}
	else{
		basSource = aTree.ARETE[2*source-1];
		hautSource = aTree.ARETE[2*source-2];
	}
	//== 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];
		
		
	//printf("\n===========> DANS SUBTREELEAF");
	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[hautSource].nbSommet;
		
		//printf("\n===========> nbSom = %d , basSource = %d , basDest = %d",nbSom,DTSpecies[basSource].nbSommet,DTSpecies[basDest].nbSommet);
		
		DTemp.Tableau = (int*)malloc((DTemp.nbSommet+1)*sizeof(int));
		
		//printf("\n");
		for(y=1;y<=DTSpecies[basDest].nbSommet;y++){
			DTemp.Tableau[y] = DTSpecies[basDest].Tableau[y];
			//printf("%d ",DTSpecies[basDest].Tableau[y]);
		}
		
		y--;
		
		//printf("\n");
		for(z=1;z<=DTSpecies[hautSource].nbSommet;z++){
			DTemp.Tableau[z+y] = DTSpecies[hautSource].Tableau[z];
			//printf("%d ",DTSpecies[hautSource].Tableau[z]);
		}
	
		
		TrierTableau(DTemp.Tableau,DTemp.nbSommet);

		for(pv=n+1;pv<=2*n-2;pv++){
			if(vecteursEgaux(DTemp,DTGene[pv])){
				LGTpossible = 1;
			}
		}
		
		for(pv=n+1;pv<=2*n-2;pv++){
			if(vecteursEgaux(DTSpecies[hautSource],DTGene[pv])){
				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);

	//printf("\n===========> LGTpossible = %d",LGTpossible);
	
	if(hautSource == noeudRacine)
		LGTpossible = 1;
	
	return LGTpossible;
		
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, -0x40(%rbp)
movq %rdx, -0x60(%rbp)
movl %esi, -0x50(%rbp)
movl %edi, -0x54(%rbp)
leaq 0x10(%rbp), %rax
movslq (%rax), %r13
leaq (,%r13,2), %rbx
movq %r13, %rdi
shlq $0x4, %rdi
orq $0x8, %rdi
movq %rdi, -0x38(%rbp)
callq 0x1140
movq %rax, -0xa0(%rbp)
leal -0x2(%rbx), %eax
movl %eax, -0x2c(%rbp)
movq %rbx, -0x88(%rbp)
movslq %ebx, %r15
leaq -0x8(,%r15,4), %r14
movq %r14, %rdi
callq 0x1140
movq %rax, -0x98(%rbp)
movq %r14, %rdi
callq 0x1140
movq %rax, -0x90(%rbp)
leaq -0x10(,%r15,8), %r15
movq %r15, %rdi
callq 0x1140
movq %rax, %r12
movq %r15, %rdi
callq 0x1140
movq %rax, %rbx
movq %r13, -0x48(%rbp)
cmpq $0x2, %r13
jl 0x878e
movq -0x48(%rbp), %rax
leaq (,%rax,4), %r13
movl -0x2c(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %r14d
cmovgel %eax, %r14d
xorl %r15d, %r15d
movq %r13, %rdi
callq 0x1140
movq %rax, (%r12,%r15,8)
movq %r13, %rdi
callq 0x1140
movq %rax, (%rbx,%r15,8)
movq -0x38(%rbp), %rdi
callq 0x1140
movq -0xa0(%rbp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x875a
movq %r12, -0x78(%rbp)
movq -0x88(%rbp), %rax
movl %eax, %edx
leaq 0x10(%rbp), %r8
subl 0x48(%r8), %edx
addl $-0x3, %edx
cmpl $0x2, %edx
movq %rbx, %r12
movq -0x48(%rbp), %r10
movl -0x2c(%rbp), %ebx
jl 0x87e0
movq 0x30(%r8), %rax
movslq 0x20(%r8), %rcx
movl %edx, %edx
decq %rdx
movq 0x8(%rax), %r14
cmpq %rcx, %r14
jne 0x87cd
movl (%rax), %esi
cmpq %rcx, (%rax)
cmovnel %esi, %r14d
addq $0x10, %rax
movl %r14d, %esi
decq %rdx
jne 0x87c2
movq 0x8(%r8), %rax
movq 0x30(%r8), %rdx
movl -0x54(%rbp), %ecx
addl %ecx, %ecx
movslq %ecx, %rcx
movq -0x10(%rdx,%rcx,8), %rsi
movq -0x8(%rdx,%rcx,8), %rcx
movq (%rax,%rcx,8), %rdi
movslq 0x20(%r8), %r8
movq (%rax,%rsi,8), %r9
movsd (%r9,%r8,8), %xmm0
ucomisd (%rdi,%r8,8), %xmm0
movq %rsi, %rdi
cmovaq %rcx, %rdi
movq %rdi, -0xa8(%rbp)
cmovaq %rsi, %rcx
movl -0x50(%rbp), %esi
addl %esi, %esi
movslq %esi, %rsi
movq -0x10(%rdx,%rsi,8), %rdi
movq -0x8(%rdx,%rsi,8), %rsi
movq (%rax,%rsi,8), %rdx
movq (%rax,%rdi,8), %rax
movsd (%rax,%r8,8), %xmm0
ucomisd (%rdx,%r8,8), %xmm0
cmovaq %rdi, %rsi
movq %rsi, -0x80(%rbp)
movl $0x1, -0x38(%rbp)
cmpl %ecx, %r10d
movq %r12, -0x68(%rbp)
jg 0x8960
movq -0x48(%rbp), %rax
incl %eax
movl $0x0, -0x38(%rbp)
cmpl %ebx, %eax
jge 0x8960
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq -0x60(%rbp), %rdx
leaq (%rdx,%rcx,8), %r15
movl $0x0, -0x38(%rbp)
movq -0x98(%rbp), %r13
movl (%r15), %edx
movslq %eax, %rcx
leaq (%rcx,%rcx,2), %r11
movq -0x40(%rbp), %rcx
movl (%rcx,%r11,8), %ecx
cmpl %ecx, %edx
jne 0x8956
testl %edx, %edx
movq -0x78(%rbp), %rsi
jle 0x88e2
movq 0x10(%r15), %rdi
movq -0x40(%rbp), %r8
movq 0x10(%r8,%r11,8), %r8
incq %rdx
movl $0x1, %r9d
movl (%rdi,%r9,4), %r10d
cmpl (%r8,%r9,4), %r10d
jne 0x8956
incq %r9
cmpq %r9, %rdx
jne 0x88d0
movq -0x40(%rbp), %rax
leaq (%rax,%r11,8), %rax
movq 0x8(%rax), %rdi
incl %ecx
movq %r13, %rdx
movq %rsi, %r12
callq 0x2bcf
movl %eax, -0x50(%rbp)
movq 0x8(%r15), %rdi
movl (%r15), %ecx
incl %ecx
movq -0x68(%rbp), %rsi
movq -0x90(%rbp), %rbx
movq %rbx, %rdx
callq 0x2bcf
movl (%r15), %ecx
incl %ecx
movl %ecx, (%rsp)
movq %r12, %rdi
movq -0x68(%rbp), %r12
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %rcx
movl -0x50(%rbp), %r8d
movl -0x2c(%rbp), %ebx
movl %eax, %r9d
callq 0x3238
testl %eax, %eax
movl -0x38(%rbp), %eax
movl $0x1, %ecx
cmovel %ecx, %eax
movl %eax, -0x38(%rbp)
movl $0xf423f, %eax          # imm = 0xF423F
incl %eax
cmpl %ebx, %eax
jl 0x8898
movl $0x0, -0x6c(%rbp)
movl -0x38(%rbp), %ecx
testl %ecx, %ecx
je 0x8a94
movb $0x1, %sil
movq -0x48(%rbp), %r13
cmpl -0x80(%rbp), %r13d
movq -0x60(%rbp), %rdx
jg 0x8a9e
leal 0x1(%r13), %eax
xorl %esi, %esi
cmpl %ebx, %eax
jge 0x8a9e
movl $0x0, -0x50(%rbp)
movslq -0x80(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %r15
movq -0x98(%rbp), %r13
movl (%r15), %edx
movslq %eax, %rcx
leaq (%rcx,%rcx,2), %r11
movq -0x40(%rbp), %rcx
movl (%rcx,%r11,8), %ecx
cmpl %ecx, %edx
jne 0x8a75
testl %edx, %edx
movq -0x78(%rbp), %rsi
jle 0x89fd
movq 0x10(%r15), %rdi
movq -0x40(%rbp), %r8
movq 0x10(%r8,%r11,8), %r8
incq %rdx
movl $0x1, %r9d
movl (%rdi,%r9,4), %r10d
cmpl (%r8,%r9,4), %r10d
jne 0x8a75
incq %r9
cmpq %r9, %rdx
jne 0x89e7
movq -0x40(%rbp), %rax
leaq (%rax,%r11,8), %r12
movq 0x8(%r12), %rdi
incl %ecx
movq %r13, %rdx
callq 0x2bcf
movl %eax, -0x54(%rbp)
movq 0x8(%r15), %rdi
movl (%r15), %ecx
incl %ecx
movq -0x68(%rbp), %rsi
movq -0x90(%rbp), %rbx
movq %rbx, %rdx
callq 0x2bcf
movl (%r12), %ecx
movq -0x68(%rbp), %r12
incl %ecx
movl %ecx, (%rsp)
movq -0x78(%rbp), %rdi
movl -0x2c(%rbp), %r8d
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %rcx
movl %r8d, %ebx
movl -0x54(%rbp), %r8d
movl %eax, %r9d
callq 0x3238
testl %eax, %eax
movl -0x50(%rbp), %eax
movl $0x1, %ecx
cmovel %ecx, %eax
movl %eax, -0x50(%rbp)
movl $0xf423f, %eax          # imm = 0xF423F
incl %eax
cmpl %ebx, %eax
jl 0x89af
cmpl $0x1, -0x50(%rbp)
sete %sil
movq -0x60(%rbp), %rdx
movl -0x38(%rbp), %ecx
movq -0x48(%rbp), %r13
jmp 0x8a9e
xorl %esi, %esi
movq -0x48(%rbp), %r13
movq -0x60(%rbp), %rdx
cmpl $0x1, %ecx
jne 0x8cb6
testb %sil, %sil
je 0x8cb6
movslq -0x80(%rbp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x38(%rbp)
movslq (%rdx,%rax,8), %rbx
movslq -0xa8(%rbp), %rax
leaq (%rax,%rax,2), %r12
movl (%rdx,%r12,8), %r15d
leal (%r15,%rbx), %r13d
movslq %r13d, %rax
leaq 0x4(,%rax,4), %rdi
callq 0x1140
movq %rbx, %rcx
movq %rax, %rbx
testq %rcx, %rcx
movq %rcx, -0x50(%rbp)
jle 0x8b2f
movq -0x60(%rbp), %rax
movq -0x38(%rbp), %rdx
leaq (%rax,%rdx,8), %rax
movq 0x10(%rax), %rsi
leaq 0x4(%rbx), %rdi
addq $0x4, %rsi
leaq (,%rcx,4), %rdx
movq %r12, -0x38(%rbp)
movq %rcx, %r12
callq 0x1080
movl %r12d, %eax
movq -0x38(%rbp), %r12
leaq 0x4(,%rax,4), %rdi
jmp 0x8b34
movl $0x4, %edi
movq -0x40(%rbp), %r11
movq -0x60(%rbp), %rax
leaq (%rax,%r12,8), %r12
testl %r15d, %r15d
jle 0x8b62
movq 0x10(%r12), %rsi
addq %rbx, %rdi
addq $0x4, %rsi
leaq (,%r15,4), %rdx
callq 0x1080
movq -0x40(%rbp), %r11
movq %r12, -0x40(%rbp)
cmpl $0x2, %r13d
movq -0x68(%rbp), %r12
jl 0x8bad
movl %r13d, %eax
xorl %ecx, %ecx
movl $0x1, %edx
movl (%rbx,%rdx,4), %esi
movl 0x4(%rbx,%rdx,4), %edi
cmpl %edi, %esi
jle 0x8b91
movl %edi, (%rbx,%rdx,4)
movl %esi, 0x4(%rbx,%rdx,4)
movl $0x1, %ecx
incq %rdx
cmpq %rax, %rdx
jne 0x8b7a
cmpl $0x2, %r13d
jl 0x8bad
movl $0x1, %edx
testl %ecx, %ecx
movl $0x0, %ecx
jne 0x8b7a
xorl %eax, %eax
movl -0x2c(%rbp), %ecx
cmpl %ecx, -0x48(%rbp)
jge 0x8c25
movq -0x50(%rbp), %rax
addl %r15d, %eax
incl %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
leaq 0x1(%rax), %rdx
movq -0x88(%rbp), %rax
leal -0x1(%rax), %esi
xorl %edi, %edi
testl %r13d, %r13d
setle %r9b
leaq (%rdx,%rdx,2), %r8
cmpl (%r11,%r8,8), %r13d
setne %r10b
movl $0x1, %eax
cmovnel %edi, %eax
orb %r9b, %r10b
jne 0x8c1c
movq 0x10(%r11,%r8,8), %rax
movl $0x1, %r8d
movl (%rbx,%r8,4), %r9d
cmpl (%rax,%r8,4), %r9d
jne 0x8c1a
incq %r8
cmpq %r8, %rcx
jne 0x8c01
movl $0x1, %eax
jmp 0x8c1c
movl %edi, %eax
incq %rdx
movl %eax, %edi
cmpl %edx, %esi
jne 0x8bd6
movq -0x48(%rbp), %r13
cmpl -0x2c(%rbp), %r13d
jge 0x8ca0
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
leal 0x1(%r15), %edx
leaq 0x1(%r13), %rsi
movq -0x88(%rbp), %r10
decl %r10d
testl %r15d, %r15d
setle %r8b
leaq (%rsi,%rsi,2), %rdi
cmpl (%r11,%rdi,8), %r15d
setne %r9b
movl $0x1, %r13d
cmovnel %eax, %r13d
orb %r8b, %r9b
jne 0x8c93
movq 0x10(%r11,%rdi,8), %rdi
movl $0x1, %r8d
movl (%rcx,%r8,4), %r9d
cmpl (%rdi,%r8,4), %r9d
jne 0x8c90
incq %r8
cmpq %r8, %rdx
jne 0x8c76
movl $0x1, %r13d
jmp 0x8c93
movl %eax, %r13d
incq %rsi
movl %r13d, %eax
cmpl %esi, %r10d
jne 0x8c49
jmp 0x8ca3
movl %eax, %r13d
movl %r13d, -0x6c(%rbp)
movq %rbx, %rdi
callq 0x1100
movl -0x2c(%rbp), %ebx
movq -0x48(%rbp), %r13
movq -0x98(%rbp), %rdi
callq 0x1100
movq -0x90(%rbp), %rdi
callq 0x1100
cmpl $0x2, %r13d
movq %r12, %r13
movq -0x78(%rbp), %r12
jl 0x8d16
cmpl $0x2, %ebx
movl %ebx, %eax
movl $0x1, %ebx
cmovgel %eax, %ebx
xorl %r15d, %r15d
movq (%r12,%r15,8), %rdi
callq 0x1100
movq (%r13,%r15,8), %rdi
callq 0x1100
movq -0xa0(%rbp), %rax
movq (%rax,%r15,8), %rdi
callq 0x1100
incq %r15
cmpq %r15, %rbx
jne 0x8ceb
movq -0xa0(%rbp), %rdi
callq 0x1100
movq %r12, %rdi
callq 0x1100
movq %r13, %rdi
callq 0x1100
cmpl -0xa8(%rbp), %r14d
movl $0x1, %ecx
movl -0x6c(%rbp), %eax
cmovel %ecx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq