// File: /workspace/github_cpp_makefile_star2_O3/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, -0x50(%rbp)
movq %rdx, -0x70(%rbp)
movl %esi, -0x40(%rbp)
movl %edi, -0x48(%rbp)
leaq 0x10(%rbp), %rax
movslq (%rax), %r13
leaq (,%r13,2), %r14
movq %r13, %rbx
shlq $0x4, %rbx
orq $0x8, %rbx
movq %rbx, %rdi
callq 0x1140
movq %rax, -0xa8(%rbp)
leal -0x2(%r14), %eax
movl %eax, -0x30(%rbp)
movq %r14, -0x98(%rbp)
movslq %r14d, %r15
leaq -0x8(,%r15,4), %r14
movq %r14, %rdi
callq 0x1140
movq %rax, -0x80(%rbp)
movq %r14, %rdi
callq 0x1140
movq %rax, -0x78(%rbp)
leaq -0x10(,%r15,8), %r14
movq %r14, %rdi
callq 0x1140
movq %rax, %r15
movq %r14, %rdi
callq 0x1140
movq %rax, %r12
movl -0x30(%rbp), %eax
movq %rax, -0xa0(%rbp)
movq %r13, -0x38(%rbp)
cmpq $0x2, %r13
jl 0x866f
movq -0x38(%rbp), %rax
leaq (,%rax,4), %r13
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x1140
movq %rax, (%r15,%r14,8)
movq %r13, %rdi
callq 0x1140
movq %rax, (%r12,%r14,8)
movq %rbx, %rdi
callq 0x1140
movq -0xa8(%rbp), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
cmpq %r14, -0xa0(%rbp)
jne 0x8638
movq %r12, -0x60(%rbp)
movq %r15, -0x58(%rbp)
movq -0x98(%rbp), %rax
movl %eax, %edx
leaq 0x10(%rbp), %r11
subl 0x48(%r11), %edx
addl $-0x3, %edx
movq 0x30(%r11), %rax
cmpl $0x1, %edx
jle 0x86d3
movslq 0x20(%r11), %rcx
movl %edx, %edx
leaq 0x8(%rax), %rsi
decq %rdx
movq -0x38(%rbp), %rbx
movq -0x50(%rbp), %r12
movl -0x30(%rbp), %r15d
movq -0x8(%rsi), %rdi
movq (%rsi), %r8
cmpq %rcx, %r8
movl %edi, %r9d
cmovnel %r10d, %r9d
cmpq %rcx, %rdi
movl %r8d, %r10d
cmovnel %r9d, %r10d
addq $0x10, %rsi
decq %rdx
jne 0x86ad
jmp 0x86e3
movslq 0x20(%r11), %rcx
movq -0x38(%rbp), %rbx
movq -0x50(%rbp), %r12
movl -0x30(%rbp), %r15d
movq 0x8(%r11), %rsi
movl -0x48(%rbp), %edx
addl %edx, %edx
movslq %edx, %rdx
movq -0x10(%rax,%rdx,8), %rdi
movq -0x8(%rax,%rdx,8), %rdx
movq (%rsi,%rdx,8), %r8
movq (%rsi,%rdi,8), %r9
movsd (%r9,%rcx,8), %xmm0
ucomisd (%r8,%rcx,8), %xmm0
movq %rdi, %r8
cmovaq %rdx, %r8
movq %r8, -0x90(%rbp)
cmovaq %rdi, %rdx
movl -0x40(%rbp), %edi
addl %edi, %edi
movslq %edi, %rdi
movq -0x10(%rax,%rdi,8), %r8
movq -0x8(%rax,%rdi,8), %rdi
movq (%rsi,%rdi,8), %rax
movq (%rsi,%r8,8), %rsi
movsd (%rsi,%rcx,8), %xmm0
ucomisd (%rax,%rcx,8), %xmm0
cmovaq %r8, %rdi
movl $0x1, %r13d
cmpl %edx, %ebx
movl %r10d, -0x84(%rbp)
jg 0x8863
movq %rdi, -0x68(%rbp)
leal 0x1(%rbx), %eax
cmpl %r15d, %eax
jge 0x8a08
movslq %edx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq -0x70(%rbp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq %rcx, -0x48(%rbp)
movl (%rcx), %r14d
xorl %r13d, %r13d
movslq %eax, %rcx
leaq (%rcx,%rcx,2), %rdx
cmpl (%r12,%rdx,8), %r14d
jne 0x8847
leal 0x1(%r14), %ecx
testl %r14d, %r14d
jle 0x87cb
movq -0x48(%rbp), %rsi
movq 0x10(%rsi), %rsi
movq 0x10(%r12,%rdx,8), %rdi
movl %ecx, %r8d
movl $0x1, %r9d
movl (%rsi,%r9,4), %r10d
cmpl (%rdi,%r9,4), %r10d
jne 0x8847
incq %r9
cmpq %r9, %r8
jne 0x87b5
leaq (%r12,%rdx,8), %rax
movq 0x8(%rax), %rdi
movq -0x58(%rbp), %r15
movq %r15, %rsi
movl %r13d, -0x40(%rbp)
movq -0x80(%rbp), %r13
movq %r13, %rdx
callq 0x2b12
movl %eax, %ebx
movq -0x48(%rbp), %r14
movq 0x8(%r14), %rdi
movl (%r14), %ecx
incl %ecx
movq -0x60(%rbp), %rsi
movq -0x78(%rbp), %r12
movq %r12, %rdx
callq 0x2b12
movl (%r14), %r14d
leal 0x1(%r14), %ecx
movl %ecx, (%rsp)
movq %r15, %rdi
movl -0x30(%rbp), %r15d
movq -0x60(%rbp), %rsi
movq %r13, %rdx
movl -0x40(%rbp), %r13d
movq %r12, %rcx
movq -0x50(%rbp), %r12
movl %ebx, %r8d
movl %eax, %r9d
callq 0x30f0
testl %eax, %eax
movl $0x1, %eax
cmovel %eax, %r13d
movl $0xf423f, %eax          # imm = 0xF423F
incl %eax
cmpl %r15d, %eax
jl 0x8785
testl %r13d, %r13d
movq -0x38(%rbp), %rbx
movq -0x68(%rbp), %rdi
je 0x8a08
movb $0x1, %al
cmpl %edi, %ebx
movq %rdi, %rdx
jg 0x8977
leal 0x1(%rbx), %eax
cmpl %r15d, %eax
jge 0x8a08
movl %r13d, -0x40(%rbp)
movq %rdx, -0x68(%rbp)
movslq %edx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq -0x70(%rbp), %rdx
leaq (%rdx,%rcx,8), %r13
xorl %r11d, %r11d
movq -0x60(%rbp), %rbx
movl (%r13), %esi
movslq %eax, %rcx
leaq (%rcx,%rcx,2), %rdx
cmpl (%r12,%rdx,8), %esi
jne 0x8959
leal 0x1(%rsi), %ecx
testl %esi, %esi
jle 0x88de
movq 0x10(%r13), %rsi
movq 0x10(%r12,%rdx,8), %rdi
movl %ecx, %r8d
movl $0x1, %r9d
movl (%rsi,%r9,4), %r10d
cmpl (%rdi,%r9,4), %r10d
jne 0x8959
incq %r9
cmpq %r9, %r8
jne 0x88c8
leaq (%r12,%rdx,8), %r14
movq 0x8(%r14), %rdi
movq -0x58(%rbp), %rsi
movq -0x80(%rbp), %r15
movq %r15, %rdx
movl %r11d, -0x48(%rbp)
callq 0x2b12
movl %eax, -0x88(%rbp)
movq 0x8(%r13), %rdi
movl (%r13), %ecx
incl %ecx
movq %rbx, %rsi
movq -0x78(%rbp), %r12
movq %r12, %rdx
callq 0x2b12
movl (%r14), %ecx
incl %ecx
movl %ecx, (%rsp)
movq -0x58(%rbp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl -0x30(%rbp), %r15d
movq %r12, %rcx
movq -0x50(%rbp), %r12
movl -0x88(%rbp), %r8d
movl %eax, %r9d
callq 0x30f0
movl -0x48(%rbp), %r11d
testl %eax, %eax
movl $0x1, %eax
cmovel %eax, %r11d
movl $0xf423f, %eax          # imm = 0xF423F
incl %eax
cmpl %r15d, %eax
jl 0x889a
cmpl $0x1, %r11d
sete %al
movq -0x38(%rbp), %rbx
movq -0x68(%rbp), %rdx
movl -0x40(%rbp), %r13d
movl $0x0, -0x30(%rbp)
cmpl $0x1, %r13d
movq -0x70(%rbp), %rcx
jne 0x8b84
testb %al, %al
je 0x8b84
movslq %edx, %rax
leaq (%rax,%rax,2), %r14
movslq (%rcx,%r14,8), %r13
movslq -0x90(%rbp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x40(%rbp)
movl (%rcx,%rax,8), %eax
movq %rax, -0x30(%rbp)
addl %r13d, %eax
movl %eax, -0x50(%rbp)
cltq
leaq 0x4(,%rax,4), %rdi
movq %rcx, %rbx
callq 0x1140
movq %r13, %r8
movq %rax, %r13
testq %r8, %r8
jle 0x8a14
leaq (%rbx,%r14,8), %rax
movq 0x10(%rax), %rsi
leaq 0x4(%r13), %rdi
addq $0x4, %rsi
leaq (,%r8,4), %rdx
movq %r8, %r14
callq 0x1080
movq %r14, %r8
movl %r8d, %eax
leaq 0x4(,%rax,4), %rdi
jmp 0x8a19
movl $0x0, -0x30(%rbp)
jmp 0x8b84
movl $0x4, %edi
movq -0x40(%rbp), %rax
leaq (%rbx,%rax,8), %r14
movq -0x30(%rbp), %rbx
testl %ebx, %ebx
jle 0x8a4f
movq 0x10(%r14), %rsi
addq %r13, %rdi
addq $0x4, %rsi
leaq (,%rbx,4), %rdx
movq %r14, -0x40(%rbp)
movq %r8, %r14
callq 0x1080
movq %r14, %r8
movq -0x40(%rbp), %r14
movl -0x50(%rbp), %r11d
cmpl $0x2, %r11d
movq -0x98(%rbp), %r10
jl 0x8a96
movl %r11d, %eax
movl 0x4(%r13), %ecx
xorl %esi, %esi
movl $0x1, %edx
movl 0x4(%r13,%rdx,4), %edi
cmpl %edi, %ecx
jle 0x8a88
movl %edi, (%r13,%rdx,4)
movl %ecx, 0x4(%r13,%rdx,4)
movl $0x1, %esi
jmp 0x8a8a
movl %edi, %ecx
incq %rdx
cmpq %rdx, %rax
jne 0x8a6e
testl %esi, %esi
jne 0x8a63
xorl %edi, %edi
cmpl %r15d, -0x38(%rbp)
jge 0x8b75
leal (%rbx,%r8), %eax
incl %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
leaq 0x1(%rax), %rdx
decl %r10d
xorl %eax, %eax
movl %eax, %esi
testl %r11d, %r11d
setle %r8b
leaq (%rdx,%rdx,2), %rdi
cmpl (%r12,%rdi,8), %r11d
setne %r9b
movl $0x1, %eax
cmovnel %esi, %eax
orb %r8b, %r9b
jne 0x8aff
movq 0x10(%r12,%rdi,8), %rax
movl $0x1, %edi
movl (%r13,%rdi,4), %r8d
cmpl (%rax,%rdi,4), %r8d
jne 0x8afd
incq %rdi
cmpq %rdi, %rcx
jne 0x8ae3
movl $0x1, %eax
jmp 0x8aff
movl %esi, %eax
incq %rdx
cmpl %edx, %r10d
jne 0x8ab7
movq -0x38(%rbp), %rsi
cmpl %r15d, %esi
jge 0x8b73
movq 0x10(%r14), %rcx
leal 0x1(%rbx), %edx
incq %rsi
testl %ebx, %ebx
setle %r8b
leaq (%rsi,%rsi,2), %rdi
cmpl (%r12,%rdi,8), %ebx
setne %r9b
movl $0x1, %r11d
cmovnel %eax, %r11d
orb %r8b, %r9b
jne 0x8b63
movq 0x10(%r12,%rdi,8), %rdi
movl $0x1, %r8d
movl (%rcx,%r8,4), %r9d
cmpl (%rdi,%r8,4), %r9d
jne 0x8b60
incq %r8
cmpq %r8, %rdx
jne 0x8b46
movl $0x1, %r11d
jmp 0x8b63
movl %eax, %r11d
incq %rsi
movl %r11d, %eax
cmpl %esi, %r10d
movl %r11d, %edi
jne 0x8b1a
jmp 0x8b75
movl %eax, %edi
movl %edi, -0x30(%rbp)
movq %r13, %rdi
callq 0x1100
movq -0x38(%rbp), %rbx
movq -0x80(%rbp), %rdi
callq 0x1100
movq -0x78(%rbp), %rdi
callq 0x1100
cmpl $0x2, %ebx
movq -0xa8(%rbp), %r13
movq -0x60(%rbp), %rbx
movq -0x58(%rbp), %r15
movq -0xa0(%rbp), %r12
jl 0x8bd8
xorl %r14d, %r14d
movq (%r15,%r14,8), %rdi
callq 0x1100
movq (%rbx,%r14,8), %rdi
callq 0x1100
movq (%r13,%r14,8), %rdi
callq 0x1100
incq %r14
cmpq %r14, %r12
jne 0x8bb4
movq %r13, %rdi
callq 0x1100
movq %r15, %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x1100
movq -0x90(%rbp), %rax
cmpl %eax, -0x84(%rbp)
movl $0x1, %ecx
movl -0x30(%rbp), %eax
cmovel %ecx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq