// File: /workspace/github_cpp_makefile_star2_O2/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, -0x78(%rbp)
movl %esi, -0x48(%rbp)
movl %edi, -0x30(%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 0x1130
movq %rax, -0x90(%rbp)
movq %r14, -0x40(%rbp)
movslq %r14d, %r15
leaq -0x2(%r15), %r12
leal -0x2(%r15), %eax
movq %rax, -0x70(%rbp)
leaq -0x8(,%r15,4), %r14
movq %r14, %rdi
callq 0x1130
movq %rax, -0x68(%rbp)
movq %r14, %rdi
callq 0x1130
movq %rax, -0x88(%rbp)
leaq -0x10(,%r15,8), %r15
movq %r15, %rdi
callq 0x1130
movq %rax, -0x58(%rbp)
movq %r15, %rdi
callq 0x1130
movq %rax, %r15
movq %r13, -0x80(%rbp)
shlq $0x2, %r13
xorl %r14d, %r14d
movq -0x70(%rbp), %rax
testl %eax, %eax
cmovlel %r14d, %eax
movq %rax, -0x70(%rbp)
cmpq %r14, -0x70(%rbp)
je 0x7a4c
movq %r13, %rdi
callq 0x1130
movq -0x58(%rbp), %rcx
movq %rax, (%rcx,%r14,8)
movq %r13, %rdi
callq 0x1130
movq %rax, (%r15,%r14,8)
movq %rbx, %rdi
callq 0x1130
movq -0x90(%rbp), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
jmp 0x7a12
leaq 0x10(%rbp), %r11
movq -0x40(%rbp), %rdx
subl 0x48(%r11), %edx
addl $-0x3, %edx
movq 0x30(%r11), %rcx
movslq 0x20(%r11), %rax
movslq %edx, %rdx
leaq 0x8(%rcx), %rsi
pushq $0x1
popq %rdi
movq -0x50(%rbp), %r10
cmpq %rdx, %rdi
jge 0x7a97
movq -0x8(%rsi), %r8
movq (%rsi), %r9
cmpq %rax, %r9
cmovel %r8d, %r14d
cmpq %rax, %r8
cmovnel %r14d, %r9d
incq %rdi
addq $0x10, %rsi
movl %r9d, %r14d
jmp 0x7a71
movq 0x8(%r11), %rsi
movl -0x30(%rbp), %edx
addl %edx, %edx
movslq %edx, %rdx
movq -0x10(%rcx,%rdx,8), %rdi
movq -0x8(%rcx,%rdx,8), %rdx
movq (%rsi,%rdx,8), %r8
movq (%rsi,%rdi,8), %r9
movsd (%r9,%rax,8), %xmm0
ucomisd (%r8,%rax,8), %xmm0
movq %rdi, %r8
cmovaq %rdx, %r8
movq %r8, -0xa0(%rbp)
cmovaq %rdi, %rdx
movl -0x48(%rbp), %edi
addl %edi, %edi
movslq %edi, %rdi
movq -0x10(%rcx,%rdi,8), %r8
movq -0x8(%rcx,%rdi,8), %rdi
movq (%rsi,%rdi,8), %rcx
movq (%rsi,%r8,8), %rsi
movsd (%rsi,%rax,8), %xmm0
ucomisd (%rcx,%rax,8), %xmm0
cmovaq %r8, %rdi
movq -0x80(%rbp), %rcx
cmpl %edx, %ecx
movq %r15, -0x48(%rbp)
movq %r12, -0x40(%rbp)
movq %rdi, -0x98(%rbp)
jle 0x7b1a
pushq $0x1
popq %rdx
jmp 0x7c18
movslq %edx, %rax
imulq $0x18, %rax, %r13
addq -0x78(%rbp), %r13
movq $0x0, -0x30(%rbp)
movl %ecx, %eax
movq -0x68(%rbp), %rbx
incl %eax
cmpl %r12d, %eax
jge 0x7c01
movl (%r13), %ecx
movslq %eax, %rdx
imulq $0x18, %rdx, %rdi
cmpl (%r10,%rdi), %ecx
jne 0x7b33
movq 0x10(%r13), %rsi
leaq (%r10,%rdi), %rdx
movq 0x10(%r10,%rdi), %rdi
testl %ecx, %ecx
movl $0x0, %r8d
cmovgl %ecx, %r8d
xorl %r9d, %r9d
cmpq %r9, %r8
je 0x7b85
movl 0x4(%rsi,%r9,4), %r10d
leaq 0x1(%r9), %r11
cmpl 0x4(%rdi,%r9,4), %r10d
movq %r11, %r9
je 0x7b6b
jmp 0x7bf8
movq 0x8(%rdx), %rdi
incl %ecx
movq -0x58(%rbp), %r15
movq %r15, %rsi
movq %rbx, %rdx
callq 0x288f
movl %eax, -0x38(%rbp)
movq 0x8(%r13), %rdi
movl (%r13), %ecx
incl %ecx
movq -0x48(%rbp), %rsi
movq -0x88(%rbp), %r12
movq %r12, %rdx
callq 0x288f
movl (%r13), %ecx
incl %ecx
movl %ecx, (%rsp)
movq %r15, %rdi
movq -0x48(%rbp), %r15
movq %r15, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movq -0x40(%rbp), %r12
movl -0x38(%rbp), %r8d
movl %eax, %r9d
callq 0x2dd8
testl %eax, %eax
movq -0x30(%rbp), %rax
pushq $0x1
popq %rcx
cmovel %ecx, %eax
movq %rax, -0x30(%rbp)
movl $0xf423f, %eax          # imm = 0xF423F
movq -0x50(%rbp), %r10
jmp 0x7b33
movq -0x30(%rbp), %rdx
testl %edx, %edx
movq -0x80(%rbp), %rcx
movq -0x98(%rbp), %rdi
je 0x7ea5
movb $0x1, %al
cmpl %edi, %ecx
jg 0x7d2a
movq %rdx, -0x30(%rbp)
movslq %edi, %rax
imulq $0x18, %rax, %r13
addq -0x78(%rbp), %r13
xorl %r11d, %r11d
movl %ecx, %eax
incl %eax
cmpl %r12d, %eax
jge 0x7d18
movl (%r13), %ecx
movslq %eax, %rdx
imulq $0x18, %rdx, %rsi
cmpl (%r10,%rsi), %ecx
jne 0x7c36
movq 0x10(%r13), %rdx
leaq (%r10,%rsi), %rbx
movq 0x10(%r10,%rsi), %rsi
testl %ecx, %ecx
movl $0x0, %edi
cmovgl %ecx, %edi
xorl %r8d, %r8d
cmpq %r8, %rdi
je 0x7c8e
movl 0x4(%rdx,%r8,4), %r9d
leaq 0x1(%r8), %r10
cmpl 0x4(%rsi,%r8,4), %r9d
movq %r10, %r8
je 0x7c6c
movq -0x48(%rbp), %r15
movq -0x50(%rbp), %r10
jmp 0x7c36
movq 0x8(%rbx), %rdi
incl %ecx
movq %rbx, -0xa8(%rbp)
movq -0x58(%rbp), %rbx
movq %rbx, %rsi
movq -0x68(%rbp), %rdx
movq %r11, -0x38(%rbp)
callq 0x288f
movl %eax, -0x60(%rbp)
movq 0x8(%r13), %rdi
movl (%r13), %ecx
incl %ecx
movq -0x48(%rbp), %r15
movq %r15, %rsi
movq -0x88(%rbp), %r12
movq %r12, %rdx
callq 0x288f
movq -0xa8(%rbp), %rcx
movl (%rcx), %ecx
incl %ecx
movl %ecx, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq -0x68(%rbp), %rdx
movq %r12, %rcx
movq -0x40(%rbp), %r12
movl -0x60(%rbp), %r8d
movl %eax, %r9d
callq 0x2dd8
movq -0x38(%rbp), %r11
testl %eax, %eax
pushq $0x1
popq %rax
cmovel %eax, %r11d
movl $0xf423f, %eax          # imm = 0xF423F
movq -0x50(%rbp), %r10
jmp 0x7c36
cmpl $0x1, %r11d
sete %al
movq -0x98(%rbp), %rdi
movq -0x30(%rbp), %rdx
xorl %r13d, %r13d
cmpl $0x1, %edx
jne 0x7ea8
testb %al, %al
je 0x7ea8
movslq %edi, %rax
imulq $0x18, %rax, %rax
movq -0x78(%rbp), %rcx
leaq (%rcx,%rax), %rbx
movl (%rcx,%rax), %r15d
movslq -0xa0(%rbp), %rax
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %rdx
movq %rdx, -0x60(%rbp)
movl (%rcx,%rax), %eax
movq %rax, -0x40(%rbp)
addl %r15d, %eax
movl %eax, -0x30(%rbp)
cltq
leaq 0x4(,%rax,4), %rdi
callq 0x1130
movq %rax, %r13
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
cmpq %rax, %r15
je 0x7da3
movq 0x10(%rbx), %rcx
movl 0x4(%rcx,%rax,4), %ecx
movl %ecx, 0x4(%r13,%rax,4)
incq %rax
jmp 0x7d8c
xorl %eax, %eax
movq -0x40(%rbp), %rcx
testl %ecx, %ecx
movl $0x0, %ebx
cmovgl %ecx, %ebx
leaq 0x4(,%r15,4), %rcx
addq %r13, %rcx
movq -0x48(%rbp), %r15
movq -0x60(%rbp), %rsi
cmpq %rax, %rbx
je 0x7ddb
movq 0x10(%rsi), %rdx
movl 0x4(%rdx,%rax,4), %edx
movl %edx, (%rcx,%rax,4)
incq %rax
jmp 0x7dc6
movq %r13, %rdi
movl -0x30(%rbp), %esi
callq 0x1b8f
movq $0x0, -0x38(%rbp)
movl -0x30(%rbp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq -0x80(%rbp), %rax
incl %eax
cltq
pushq $0x1
popq %rdx
movq %rax, %rsi
movq -0x50(%rbp), %r11
cmpq %r12, %rsi
jg 0x7e4d
imulq $0x18, %rsi, %rdi
movl -0x30(%rbp), %r8d
cmpl (%r11,%rdi), %r8d
jne 0x7e48
movq 0x10(%r11,%rdi), %rdi
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x7e42
movl 0x4(%r13,%r8,4), %r9d
leaq 0x1(%r8), %r10
cmpl 0x4(%rdi,%r8,4), %r9d
movq %r10, %r8
je 0x7e28
jmp 0x7e48
movl %edx, %edi
movq %rdi, -0x38(%rbp)
incq %rsi
jmp 0x7e0d
pushq $0x1
popq %rcx
movq -0x60(%rbp), %r10
cmpq %r12, %rax
jg 0x7e97
imulq $0x18, %rax, %rsi
movq -0x40(%rbp), %rdx
cmpl (%r11,%rsi), %edx
jne 0x7e92
movq 0x10(%r10), %rdx
movq 0x10(%r11,%rsi), %rsi
xorl %edi, %edi
cmpq %rdi, %rbx
je 0x7e8c
movl 0x4(%rdx,%rdi,4), %r8d
leaq 0x1(%rdi), %r9
cmpl 0x4(%rsi,%rdi,4), %r8d
movq %r9, %rdi
je 0x7e72
jmp 0x7e92
movl %ecx, %edx
movq %rdx, -0x38(%rbp)
incq %rax
jmp 0x7e54
movq %r13, %rdi
callq 0x10f0
movq -0x38(%rbp), %r13
jmp 0x7ea8
xorl %r13d, %r13d
movq -0x68(%rbp), %rdi
callq 0x10f0
movq -0x88(%rbp), %rdi
callq 0x10f0
xorl %ebx, %ebx
cmpq %rbx, -0x70(%rbp)
je 0x7ef0
movq -0x58(%rbp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x10f0
movq (%r15,%rbx,8), %rdi
callq 0x10f0
movq -0x90(%rbp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x10f0
incq %rbx
jmp 0x7ebf
movq -0x90(%rbp), %rdi
callq 0x10f0
movq -0x58(%rbp), %rdi
callq 0x10f0
movq %r15, %rdi
callq 0x10f0
cmpl -0xa0(%rbp), %r14d
pushq $0x1
popq %rax
cmovel %eax, %r13d
movl %r13d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq