// File: /workspace/github_cpp_makefile_star2_O3/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, -0x78(%rbp)
movq %r8, -0x40(%rbp)
movq %rcx, -0x60(%rbp)
movq %rdx, %rbx
movq %rsi, -0x58(%rbp)
movq %rdi, -0x38(%rbp)
leaq 0x10(%rbp), %rax
movslq (%rax), %r14
leaq -0xd8(%rbp), %rdi
movl %r14d, %esi
callq 0xb8ba
leal (%r14,%r14), %r15d
leaq (,%r14,8), %r13
movq %r13, %rdi
callq 0x1140
movq %rax, %r12
movq %rax, 0x8(%rbx)
movq %r13, %rdi
callq 0x1140
movq %rax, -0x30(%rbp)
movq %rax, 0x10(%rbx)
movq %r13, %rdi
callq 0x1140
movq %rbx, %r10
movl %r14d, %r9d
movq %rax, 0x18(%rbx)
movl $0x0, (%rbx)
testq %r14, %r14
movq %r9, -0x70(%rbp)
movq %rbx, -0x48(%rbp)
jle 0xd98d
movl %r15d, %ebx
shlq $0x2, %rbx
movq %r12, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1060
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1060
movq -0x48(%rbp), %r10
movq -0x70(%rbp), %r9
leaq 0x10(%rbp), %rax
movl 0x48(%rax), %ecx
movl %r15d, %eax
movl %ecx, -0x74(%rbp)
subl %ecx, %eax
addl $-0x2, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x2, %eax
movq -0x40(%rbp), %r11
jl 0xdaa9
leaq 0x68(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x30(%rbp)
leal -0x2(,%rax,2), %eax
cmpl $0x3, %eax
movl $0x2, %r13d
cmovgel %eax, %r13d
movl -0x4c(%rbp), %eax
movq %rax, -0x68(%rbp)
movl $0x1, %r12d
cmpl $0x2, -0x30(%rbp)
jl 0xda9c
leaq (%r12,%r12,2), %rax
movq -0x60(%rbp), %rcx
leaq (%rcx,%rax,8), %rbx
movl $0x1, %r14d
cmpq -0x30(%rbp), %r14
je 0xda76
cmpq %r9, %r12
je 0xda76
movl (%rbx), %edx
cmpl $0x2, %edx
jl 0xda76
leaq (%r14,%r14,2), %rax
cmpl (%r11,%rax,8), %edx
jne 0xda76
leaq (%r11,%rax,8), %rax
movq 0x10(%rbx), %rcx
movq 0x10(%rax), %rsi
incq %rdx
movl $0x1, %edi
movl (%rcx,%rdi,4), %r8d
cmpl (%rsi,%rdi,4), %r8d
jne 0xda76
incq %rdi
cmpq %rdi, %rdx
jne 0xda26
movq 0x8(%rbx), %rdi
movq 0x8(%rax), %rsi
leaq -0xd8(%rbp), %rcx
callq 0x8c46
movq -0x40(%rbp), %r11
movq -0x48(%rbp), %r10
movq -0x70(%rbp), %r9
cmpl $0x0, -0xa8(%rbp)
jne 0xda76
movq 0x8(%r10), %rax
movl $0x1, %ecx
movl %ecx, (%rax,%r12,4)
movq 0x10(%r10), %rax
movl %ecx, (%rax,%r14,4)
cmpl $0x1, (%rbx)
jne 0xda90
movq 0x8(%r10), %rax
movl $0x1, %ecx
movl %ecx, (%rax,%r12,4)
movq 0x10(%r10), %rax
movl %ecx, (%rax,%r12,4)
incq %r14
cmpq %r13, %r14
jne 0xd9f6
incq %r12
cmpq -0x68(%rbp), %r12
jne 0xd9da
xorl %r14d, %r14d
movl -0x4c(%rbp), %r12d
testl %r12d, %r12d
jle 0xdb8a
leaq 0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl -0x74(%rbp), %ecx
notl %ecx
addl %ecx, %r15d
movq 0x8(%r10), %rcx
movl $0x1, %edx
movq -0x58(%rbp), %r13
movq -0x60(%rbp), %rbx
leaq (%rdx,%rdx,2), %rsi
leaq (%rbx,%rsi,8), %rsi
movl $0x1, %edi
cmpl $0x0, (%rcx,%rdx,4)
je 0xdb43
cmpq %rdi, %rdx
je 0xdb43
cmpl $0x0, (%rcx,%rdi,4)
je 0xdb43
cmpq %rax, %rdx
je 0xdb43
cmpq %rax, %rdi
je 0xdb43
movl (%rsi), %r8d
leaq (%rdi,%rdi,2), %r9
cmpl (%rbx,%r9,8), %r8d
jle 0xdb43
testl %r8d, %r8d
jle 0xdb43
leaq (%rbx,%r9,8), %r10
movq 0x10(%rsi), %r9
movq 0x10(%r10), %r10
movl 0x4(%r10), %r10d
incq %r8
movl $0x1, %r11d
cmpl (%r9,%r11,4), %r10d
je 0xdb3c
incq %r11
cmpq %r11, %r8
jne 0xdb2c
jmp 0xdb43
movl $0x0, (%rcx,%rdi,4)
incq %rdi
cmpq %r15, %rdi
jne 0xdae6
incq %rdx
cmpq %r15, %rdx
jne 0xdad9
testl %r12d, %r12d
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %r8
jle 0xdb92
movq 0x8(%r8), %rax
xorl %r14d, %r14d
movl $0x1, %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0xdb80
movq 0x18(%r8), %rdx
movslq %r14d, %rsi
incl %r14d
movl %ecx, 0x4(%rdx,%rsi,4)
incq %rcx
cmpq %rcx, %r15
jne 0xdb6c
jmp 0xdb92
movq -0x58(%rbp), %r13
movq -0x38(%rbp), %rdi
movq %r14, -0x40(%rbp)
leal 0x1(%r14), %eax
movq %rax, -0x30(%rbp)
cmpq $0x0, 0x8(%rdi)
je 0xdd02
cmpl $0x0, -0x40(%rbp)
jle 0xdde9
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
leaq 0x10(%rbp), %rcx
movl 0x20(%rcx), %esi
movslq %esi, %rdx
movq 0x8(%rcx), %rdi
leaq 0x68(%rbp), %rcx
movq 0x8(%rcx), %r8
movl -0x30(%rbp), %ecx
movl $0x1, %r9d
movq -0x60(%rbp), %r15
movslq (%rax,%r9,4), %r10
cmpl %esi, %r10d
je 0xdc4c
leaq (%r10,%r10,2), %r10
movq 0x10(%r15,%r10,8), %r10
movslq 0x4(%r10), %rbx
movq (%rdi,%rbx,8), %r10
movq -0x38(%rbp), %r11
movq 0x8(%r11), %r11
movq (%r11,%r9,8), %r11
movq (%r8,%rbx,8), %rbx
movq -0x58(%rbp), %r14
movq 0x8(%r14), %r14
movq (%r14,%r9,8), %r14
movl $0x1, %r12d
movslq (%rax,%r12,4), %r13
leaq (%r13,%r13,2), %r13
movq 0x10(%r15,%r13,8), %r13
movslq 0x4(%r13), %r13
movsd (%r10,%r13,8), %xmm0
movsd %xmm0, (%r11,%r12,8)
movsd (%rbx,%r13,8), %xmm0
movsd %xmm0, (%r14,%r12,8)
incq %r12
cmpq %r12, %rcx
jne 0xdc1a
incq %r9
cmpq %rcx, %r9
jne 0xdbde
movq -0x48(%rbp), %rdi
movq 0x8(%rdi), %rdi
movl $0x1, (%rdi,%rdx,4)
movslq -0x30(%rbp), %rdi
movl %esi, (%rax,%rdi,4)
cmpl $0x0, -0x40(%rbp)
movq -0x58(%rbp), %r13
movq -0x60(%rbp), %r15
jle 0xde0b
leaq 0x10(%rbp), %rsi
movq 0x8(%rsi), %rsi
movq (%rsi,%rdx,8), %rsi
movq -0x38(%rbp), %r8
movq 0x8(%r8), %r8
movq (%r8,%rdi,8), %r9
leaq 0x68(%rbp), %r10
movq 0x8(%r10), %r10
movq (%r10,%rdx,8), %rdx
movq 0x8(%r13), %r10
movq (%r10,%rdi,8), %r11
leaq -0x4(,%rcx,4), %rcx
xorl %ebx, %ebx
movslq 0x4(%rax,%rbx), %r14
leaq (%r14,%r14,2), %r14
movq 0x10(%r15,%r14,8), %r14
movslq 0x4(%r14), %r14
movsd (%rsi,%r14,8), %xmm0
movsd %xmm0, 0x8(%r9,%rbx,2)
movq 0x8(%r8,%rbx,2), %r12
movsd %xmm0, (%r12,%rdi,8)
movsd (%rdx,%r14,8), %xmm0
movsd %xmm0, 0x8(%r11,%rbx,2)
movq 0x8(%r10,%rbx,2), %r14
movsd %xmm0, (%r14,%rdi,8)
addq $0x4, %rbx
cmpq %rbx, %rcx
jne 0xdcb2
jmp 0xde0b
movq %rdi, %r14
movq -0x30(%rbp), %rax
addl %eax, %eax
cltq
leaq -0x8(,%rax,8), %rbx
movq %rbx, %rdi
callq 0x1140
movq %rax, 0x8(%r14)
movq %rbx, %rdi
callq 0x1140
movq %rax, 0x8(%r13)
movq %rbx, %rdi
callq 0x1140
movq %rax, 0x40(%r14)
movq %rbx, %rdi
callq 0x1140
movq %rax, 0x40(%r13)
cmpl $0x0, -0x40(%rbp)
js 0xdde9
movq -0x30(%rbp), %rax
leal -0x1(,%rax,2), %eax
cmpl $0x2, %eax
movl $0x1, %r12d
movl %eax, -0x68(%rbp)
cmovgel %eax, %r12d
movq %r13, %r14
xorl %r13d, %r13d
movq -0x38(%rbp), %r15
movq %rbx, %rdi
callq 0x1140
movq 0x40(%r15), %rcx
movq %rax, (%rcx,%r13,8)
movq %rbx, %rdi
callq 0x1140
movq 0x40(%r14), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
cmpq %r13, %r12
jne 0xdd74
cmpl $0x0, -0x40(%rbp)
movq %r14, %r13
js 0xdde9
movl -0x68(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %r12d
cmovgel %eax, %r12d
xorl %r14d, %r14d
movq -0x38(%rbp), %r15
movq %rbx, %rdi
callq 0x1140
movq 0x8(%r15), %rcx
movq %rax, (%rcx,%r14,8)
movq %rbx, %rdi
callq 0x1140
movq 0x8(%r13), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
cmpq %r14, %r12
jne 0xddbc
jmp 0xdba9
leaq 0x10(%rbp), %rax
movslq 0x20(%rax), %rax
movq -0x48(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq 0x18(%rdx), %rdx
movl $0x1, (%rcx,%rax,4)
movslq -0x30(%rbp), %rcx
movl %eax, (%rdx,%rcx,4)
movq -0x30(%rbp), %rax
movl %eax, (%r13)
movq -0x38(%rbp), %rdi
movl %eax, (%rdi)
movl %eax, 0x20(%r13)
movl %eax, 0x20(%rdi)
movl -0x78(%rbp), %edx
callq 0xd768
movq %r13, %rdi
movl 0xc0(%rbp), %edx
callq 0xd768
leaq -0xd8(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0xb982
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq