// File: /workspace/github_cpp_makefile_star2_O1/dcarrey[P]hgt-detection/./fonctions.cpp
// Function: ReduceTree(InputTree, InputTree, InputTree*, InputTree*, ReduceTrace*, DescTree*, DescTree*, int, int)
void ReduceTree(struct InputTree SpeciesTree,struct InputTree GeneTree,struct InputTree *SpeciesTreeRed,struct InputTree *GeneTreeRed,struct ReduceTrace *aTrace,struct DescTree *DTSpecies,struct DescTree *DTGene,int binaireSpecies,int binaireGene){


	int i,j,l=1,tmp,pos; //k;
	struct CRITERIA aCrit;

	InitCriteria(&aCrit,SpeciesTree.size);

	aTrace->species  = (int *)malloc((2*SpeciesTree.size)*sizeof(int));
	aTrace->gene     = (int *)malloc((2*SpeciesTree.size)*sizeof(int));
	aTrace->map		 = (int *)malloc((2*SpeciesTree.size)*sizeof(int));
	//aTrace->speciesToGene = (int *)malloc((2*SpeciesTree.size-1)*sizeof(int));
	aTrace->size = 0;

	for(i=0;i<2*SpeciesTree.size;i++){
		aTrace->species[i] = 0;
		aTrace->gene[i] = 0;
	}
	
	for(i=1;i<2*(SpeciesTree.size)-2-SpeciesTree.kt;i++)
		for(j=1;j<2*(GeneTree.size)-2;j++){
		
			if(DTSpecies[i].nbSommet == DTGene[j].nbSommet && DTSpecies[i].nbSommet > 1 && i!= SpeciesTree.size && j!= GeneTree.size){
				if(vecteursEgaux(DTSpecies[i],DTGene[j]) == 1){
				
						computeCriteria(DTSpecies[i].Matrice,DTGene[j].Matrice,DTSpecies[i].nbSommet+1,&aCrit,NULL,NULL,NULL,NULL);
						if(aCrit.RF == 0){
							aTrace->species[i] = 1;
							aTrace->gene[j] = 1;
						}
				}
			}
			if(DTSpecies[i].nbSommet == 1 ){
				aTrace->species[i] = 1;
				aTrace->gene[i] =1;
				//aTrace->speciesToGene[i] = i;
			}
		}

		
		//== ici on test les sous-ensembles 2 par 2, si un est le sous-ensemble de l'autre, il n'est pas necessaire de consid�rer
		//== ce dernier.
		for(i=1;i<=2*SpeciesTree.size-2-SpeciesTree.kt;i++){
			for(j=1;j<=2*SpeciesTree.size-2-SpeciesTree.kt;j++){
				if(aTrace->species[i] != 0 && aTrace->species[j] != 0 && i!=j && i!=SpeciesTree.Root && j!=SpeciesTree.Root)
					if(DTSpecies[i].nbSommet > DTSpecies[j].nbSommet && isInside(DTSpecies[i],DTSpecies[j])==1){
						aTrace->species[j] = 0;
					}
			}
		}



		//== creer les matrices de distances
		tmp=0;
		pos=0;
		for(i=1;i<=2*SpeciesTree.size-2-SpeciesTree.kt;i++){
			if(aTrace->species[i] != 0){
				pos++;
				aTrace->map[pos] = i; //DTSpecies[i].Tableau[1];
	//			printf("<br> %d-%d",pos,i);
			}
		}
	/*	printf("\n");
		for(i=1;i<=pos;i++){
			printf("\n%d-->%d (%d)",i,aTrace->map[i],DTSpecies[aTrace->map[i]].Tableau[1]);
		}*/

		pos++; //= racine
		if(SpeciesTreeRed->ADD == NULL){
			SpeciesTreeRed->ADD = (double**)malloc((2*pos-1)*sizeof(double*));
			GeneTreeRed->ADD = (double**)malloc((2*pos-1)*sizeof(double*));
			SpeciesTreeRed->W = (double**)malloc((2*pos-1)*sizeof(double*));
			GeneTreeRed->W = (double**)malloc((2*pos-1)*sizeof(double*));
			for(i=0;i<2*pos-1;i++){
				SpeciesTreeRed->W[i] = (double*)malloc((2*pos-1)*sizeof(double));
				GeneTreeRed->W[i] = (double*)malloc((2*pos-1)*sizeof(double));
			}
			for(i=0;i<2*pos-1;i++){
				SpeciesTreeRed->ADD[i] = (double*)malloc((2*pos-1)*sizeof(double));
				GeneTreeRed->ADD[i] = (double*)malloc((2*pos-1)*sizeof(double));
			}
		}
		for(i=1;i<pos;i++)
			if(aTrace->map[i] != SpeciesTree.Root){
				for(j=1;j<pos;j++){
					if(aTrace->map[i] != SpeciesTree.Root){
						SpeciesTreeRed->ADD[i][j] = SpeciesTree.ADD[DTSpecies[aTrace->map[i]].Tableau[1]][DTSpecies[aTrace->map[j]].Tableau[1]];
						GeneTreeRed->ADD[i][j] = GeneTree.ADD[DTSpecies[aTrace->map[i]].Tableau[1]][DTSpecies[aTrace->map[j]].Tableau[1]];
					}
				}
			}
		
		aTrace->species[SpeciesTree.Root] = 1;
		aTrace->map[pos] = SpeciesTree.Root;
		for(i=1;i<pos;i++){
			SpeciesTreeRed->ADD[i][pos] = SpeciesTreeRed->ADD[pos][i] = SpeciesTree.ADD[aTrace->map[pos]][DTSpecies[aTrace->map[i]].Tableau[1]];
			GeneTreeRed->ADD[i][pos] = GeneTreeRed->ADD[pos][i] = GeneTree.ADD[aTrace->map[pos]][DTSpecies[aTrace->map[i]].Tableau[1]];
		}
		
		SpeciesTreeRed->size = GeneTreeRed->size = pos;
		SpeciesTreeRed->Root = GeneTreeRed->Root = pos;
		
		CreateSubStructures(SpeciesTreeRed,0,binaireSpecies);
		CreateSubStructures(GeneTreeRed,0,binaireGene);

		FreeCriteria(&aCrit,SpeciesTree.size);
	//	printf("\n");
	//	printMatrix(SpeciesTree.SpeciesName,SpeciesTreeRed->ADD,SpeciesTreeRed->size);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r9d, -0x64(%rbp)
movq %r8, -0x48(%rbp)
movq %rcx, -0x58(%rbp)
movq %rdx, %r14
movq %rsi, -0x80(%rbp)
movq %rdi, -0x60(%rbp)
leaq 0x10(%rbp), %rax
movslq (%rax), %rbx
leaq -0xe0(%rbp), %rdi
movl %ebx, %esi
callq 0xb933
leal (%rbx,%rbx), %r15d
leaq (,%rbx,8), %r13
movq %r13, %rdi
callq 0x1140
movq %rax, %r12
movq %rax, 0x8(%r14)
movq %r13, %rdi
callq 0x1140
movq %rax, -0x38(%rbp)
movq %rax, 0x10(%r14)
movq %r13, %rdi
callq 0x1140
movl %ebx, %ecx
movq %rcx, -0x70(%rbp)
movq %rax, 0x18(%r14)
movq %r14, -0x40(%rbp)
movl $0x0, (%r14)
testq %rbx, %rbx
jle 0xda95
cmpl $0x2, %r15d
movl $0x1, %ebx
cmovgel %r15d, %ebx
shlq $0x2, %rbx
movq %r12, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1060
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1060
leaq 0x10(%rbp), %rax
movl 0x48(%rax), %ecx
movq %r15, -0x78(%rbp)
movl %r15d, %edx
movq %rcx, -0x30(%rbp)
subl %ecx, %edx
addl $-0x2, %edx
movl %edx, -0x4c(%rbp)
cmpl $0x2, %edx
jl 0xdbce
leaq 0x68(%rbp), %rax
movl (%rax), %r15d
leal -0x2(,%r15,2), %eax
cmpl $0x3, %eax
movl $0x2, %r13d
cmovgel %eax, %r13d
movl -0x4c(%rbp), %eax
movq %rax, -0x38(%rbp)
movl $0x1, %r14d
cmpl $0x2, %r15d
jl 0xdbc1
leaq (%r14,%r14,2), %rax
movq -0x58(%rbp), %rcx
leaq (%rcx,%rax,8), %r12
movl $0x1, %ebx
cmpq %r15, %rbx
je 0xdb95
cmpq -0x70(%rbp), %r14
je 0xdb95
movl (%r12), %edx
cmpl $0x2, %edx
jl 0xdb95
leaq (%rbx,%rbx,2), %rax
movq -0x48(%rbp), %rcx
cmpl (%rcx,%rax,8), %edx
jne 0xdb95
movq -0x48(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
movq 0x10(%r12), %rcx
movq 0x10(%rax), %rsi
leaq -0x1(%rdx), %rdi
xorl %r8d, %r8d
movl 0x4(%rcx,%r8,4), %r9d
movl 0x4(%rsi,%r8,4), %r10d
cmpl %r10d, %r9d
jne 0xdb58
leaq 0x1(%r8), %r11
cmpq %r8, %rdi
movq %r11, %r8
jne 0xdb3d
cmpl %r10d, %r9d
jne 0xdb95
movq 0x8(%r12), %rdi
movq 0x8(%rax), %rsi
incl %edx
leaq -0xe0(%rbp), %rcx
callq 0x8d82
cmpl $0x0, -0xb0(%rbp)
jne 0xdb95
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rax
movl $0x1, %edx
movl %edx, (%rax,%r14,4)
movq 0x10(%rcx), %rax
movl %edx, (%rax,%rbx,4)
cmpl $0x1, (%r12)
jne 0xdbb5
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rax
movl $0x1, %edx
movl %edx, (%rax,%r14,4)
movq 0x10(%rcx), %rax
movl %edx, (%rax,%r14,4)
incq %rbx
cmpq %r13, %rbx
jne 0xdafc
incq %r14
cmpq -0x38(%rbp), %r14
jne 0xdae1
movq -0x30(%rbp), %rax
notl %eax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x4c(%rbp)
movq -0x80(%rbp), %r13
movq -0x60(%rbp), %r12
movq -0x58(%rbp), %r14
movq -0x78(%rbp), %r15
jle 0xdc89
leaq 0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x30(%rbp), %rcx
addl %r15d, %ecx
movq -0x40(%rbp), %rdx
movq 0x8(%rdx), %rdx
movl $0x1, %esi
leaq (%rsi,%rsi,2), %rdi
leaq (%r14,%rdi,8), %rdi
movl $0x1, %r8d
cmpl $0x0, (%rdx,%rsi,4)
je 0xdc79
cmpq %r8, %rsi
je 0xdc79
cmpl $0x0, (%rdx,%r8,4)
je 0xdc79
cmpq %rax, %rsi
je 0xdc79
cmpq %rax, %r8
je 0xdc79
movl (%rdi), %r9d
leaq (%r8,%r8,2), %r10
cmpl (%r14,%r10,8), %r9d
jle 0xdc79
testl %r9d, %r9d
jle 0xdc79
leaq (%r14,%r10,8), %r11
movq 0x10(%rdi), %r10
movq 0x10(%r11), %r11
movl 0x4(%r11), %r11d
incq %r9
movl $0x1, %ebx
cmpl (%r10,%rbx,4), %r11d
je 0xdc71
incq %rbx
cmpq %rbx, %r9
jne 0xdc61
jmp 0xdc79
movl $0x0, (%rdx,%r8,4)
incq %r8
cmpq %rcx, %r8
jne 0xdc1b
incq %rsi
cmpq %rcx, %rsi
jne 0xdc0d
cmpl $0x0, -0x4c(%rbp)
jle 0xdcc3
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
addl -0x30(%rbp), %r15d
xorl %edi, %edi
movl $0x1, %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0xdcb9
movq -0x40(%rbp), %rdx
movq 0x18(%rdx), %rdx
movslq %edi, %rsi
incl %edi
movl %ecx, 0x4(%rdx,%rsi,4)
incq %rcx
cmpq %rcx, %r15
jne 0xdca2
jmp 0xdcc5
xorl %edi, %edi
movq %rdi, -0x30(%rbp)
leal 0x1(%rdi), %eax
movq %rax, -0x38(%rbp)
cmpq $0x0, 0x8(%r12)
jne 0xddb2
movq -0x38(%rbp), %rcx
leal (%rcx,%rcx), %eax
leal -0x1(,%rcx,2), %ecx
movl %ecx, -0x48(%rbp)
cltq
leaq -0x8(,%rax,8), %rbx
movq %rbx, %rdi
callq 0x1140
movq %rax, 0x8(%r12)
movq %rbx, %rdi
callq 0x1140
movq %rax, 0x8(%r13)
movq %rbx, %rdi
callq 0x1140
movq %rax, 0x40(%r12)
movq %rbx, %rdi
callq 0x1140
movq %rax, 0x40(%r13)
cmpl $0x0, -0x30(%rbp)
movq %r12, %r14
js 0xdd6d
movl -0x48(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %r15d
cmovgel %eax, %r15d
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x1140
movq 0x40(%r14), %rcx
movq %rax, (%rcx,%r12,8)
movq %rbx, %rdi
callq 0x1140
movq 0x40(%r13), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
cmpq %r12, %r15
jne 0xdd45
cmpl $0x0, -0x30(%rbp)
movq %r14, %r12
js 0xddb2
movl -0x48(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %r15d
cmovgel %eax, %r15d
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x1140
movq 0x8(%r12), %rcx
movq %rax, (%rcx,%r14,8)
movq %rbx, %rdi
callq 0x1140
movq 0x8(%r13), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
cmpq %r14, %r15
jne 0xdd89
movl -0x38(%rbp), %eax
cmpl $0x0, -0x30(%rbp)
movq -0x58(%rbp), %r14
jle 0xde7c
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
leaq 0x10(%rbp), %rsi
movl 0x20(%rsi), %edx
movq 0x8(%rsi), %rsi
movq %rsi, -0x48(%rbp)
leaq 0x68(%rbp), %rdi
movq 0x8(%rdi), %rdi
movl $0x1, %r8d
movslq (%rcx,%r8,4), %r9
cmpl %edx, %r9d
je 0xde70
leaq (%r9,%r9,2), %r10
leaq (%r14,%r10,8), %r10
addq $0x10, %r10
movl $0x1, %r11d
cmpl %edx, %r9d
je 0xde68
movq (%r10), %rbx
movslq 0x4(%rbx), %rbx
movq -0x48(%rbp), %rsi
movq (%rsi,%rbx,8), %r14
movslq (%rcx,%r11,4), %r15
leaq (%r15,%r15,2), %r15
movq %r12, %rsi
movq %r13, %r12
movq -0x58(%rbp), %r13
movq 0x10(%r13,%r15,8), %r15
movq %r12, %r13
movq %rsi, %r12
movslq 0x4(%r15), %r15
movsd (%r14,%r15,8), %xmm0
movq 0x8(%rsi), %r14
movq (%r14,%r8,8), %r14
movsd %xmm0, (%r14,%r11,8)
movq -0x58(%rbp), %r14
movq (%rdi,%rbx,8), %rbx
movsd (%rbx,%r15,8), %xmm0
movq 0x8(%r13), %rbx
movq (%rbx,%r8,8), %rbx
movsd %xmm0, (%rbx,%r11,8)
incq %r11
cmpq %r11, %rax
jne 0xde03
incq %r8
cmpq %rax, %r8
jne 0xdde8
movq -0x40(%rbp), %rdx
movq 0x8(%rdx), %rcx
leaq 0x10(%rbp), %rsi
movslq 0x20(%rsi), %r9
movl $0x1, (%rcx,%r9,4)
movq 0x18(%rdx), %rcx
movslq -0x38(%rbp), %rdx
movl %r9d, (%rcx,%rdx,4)
cmpl $0x0, -0x30(%rbp)
jle 0xdf2b
movq %r14, %rbx
movq 0x8(%rsi), %rsi
movq (%rsi,%r9,8), %rsi
movq -0x60(%rbp), %rdi
movq 0x8(%rdi), %rdi
movq (%rdi,%rdx,8), %r8
leaq 0x68(%rbp), %r10
movq 0x8(%r10), %r10
movq (%r10,%r9,8), %r9
movq 0x8(%r13), %r10
movq (%r10,%rdx,8), %r11
leaq -0x4(,%rax,4), %rax
xorl %r14d, %r14d
movslq 0x4(%rcx,%r14), %r15
leaq (%r15,%r15,2), %r15
movq 0x10(%rbx,%r15,8), %r15
movslq 0x4(%r15), %r15
movsd (%rsi,%r15,8), %xmm0
movsd %xmm0, 0x8(%r8,%r14,2)
movq 0x8(%rdi,%r14,2), %r12
movsd %xmm0, (%r12,%rdx,8)
movsd (%r9,%r15,8), %xmm0
movsd %xmm0, 0x8(%r11,%r14,2)
movq 0x8(%r10,%r14,2), %r15
movsd %xmm0, (%r15,%rdx,8)
addq $0x4, %r14
cmpq %r14, %rax
jne 0xdee0
movq -0x38(%rbp), %rax
movl %eax, (%r13)
movq -0x60(%rbp), %rdi
movl %eax, (%rdi)
movl %eax, 0x20(%r13)
movl %eax, 0x20(%rdi)
movl -0x64(%rbp), %edx
callq 0xd87e
movq %r13, %rdi
movl 0xc0(%rbp), %edx
callq 0xd87e
leaq -0xe0(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0xb9fb
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq