// File: /workspace/github_cpp_makefile_star2_O2/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, -0x70(%rbp)
movq %r8, -0x50(%rbp)
movq %rcx, -0x40(%rbp)
movq %rdx, %rbx
movq %rsi, -0x48(%rbp)
movq %rdi, -0x38(%rbp)
leaq 0x10(%rbp), %rax
movslq (%rax), %r14
movl %r14d, %eax
movq %rax, -0x78(%rbp)
leaq -0xd8(%rbp), %rdi
movl %r14d, %esi
callq 0xa979
leal (%r14,%r14), %r15d
shlq $0x3, %r14
movq %r14, %rdi
callq 0x1130
movq %rax, %r12
movq %rax, 0x8(%rbx)
movq %r14, %rdi
callq 0x1130
movq %rax, %r13
movq %rax, 0x10(%rbx)
movq %r14, %rdi
callq 0x1130
movq %rbx, %r10
movq %rax, 0x18(%rbx)
andl $0x0, (%rbx)
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %ecx
movq %r15, -0x30(%rbp)
cmovgl %r15d, %ecx
cmpq %rax, %rcx
je 0xc7c0
andl $0x0, (%r12,%rax,4)
andl $0x0, (%r13,%rax,4)
incq %rax
jmp 0xc7ab
leaq 0x10(%rbp), %rax
movl 0x48(%rax), %edx
movq -0x30(%rbp), %rax
movl %eax, %ecx
movl %edx, -0x6c(%rbp)
subl %edx, %ecx
addl $-0x2, %ecx
leaq 0x68(%rbp), %rax
movl (%rax), %r13d
movslq %r13d, %rax
leaq -0x2(,%rax,2), %r12
movq %rcx, -0x58(%rbp)
movslq %ecx, %rax
movq %rax, -0x60(%rbp)
pushq $0x1
popq %r15
movq %r10, -0x68(%rbp)
movq -0x50(%rbp), %r11
cmpq -0x60(%rbp), %r15
jge 0xc8c2
imulq $0x18, %r15, %rbx
addq -0x40(%rbp), %rbx
pushq $0x1
popq %r14
cmpq %r12, %r14
jge 0xc8ba
cmpq %r13, %r14
je 0xc89a
cmpq -0x78(%rbp), %r15
je 0xc89a
movl (%rbx), %edx
cmpl $0x2, %edx
jl 0xc89a
imulq $0x18, %r14, %rax
cmpl (%r11,%rax), %edx
jne 0xc89a
addq %r11, %rax
movq 0x10(%rbx), %rcx
movq 0x10(%rax), %rsi
incq %rdx
pushq $0x1
popq %rdi
cmpq %rdi, %rdx
je 0xc862
movl (%rcx,%rdi,4), %r8d
leaq 0x1(%rdi), %r9
cmpl (%rsi,%rdi,4), %r8d
movq %r9, %rdi
je 0xc84a
jmp 0xc89a
movq 0x8(%rbx), %rdi
movq 0x8(%rax), %rsi
leaq -0xd8(%rbp), %rcx
callq 0x7f5c
movq -0x50(%rbp), %r11
movq -0x68(%rbp), %r10
cmpl $0x0, -0xa8(%rbp)
jne 0xc89a
movq 0x8(%r10), %rax
pushq $0x1
popq %rcx
movl %ecx, (%rax,%r15,4)
movq 0x10(%r10), %rax
movl %ecx, (%rax,%r14,4)
cmpl $0x1, (%rbx)
jne 0xc8b2
movq 0x8(%r10), %rax
pushq $0x1
popq %rcx
movl %ecx, (%rax,%r15,4)
movq 0x10(%r10), %rax
movl %ecx, (%rax,%r15,4)
incq %r14
jmp 0xc814
incq %r15
jmp 0xc7fe
leaq 0x10(%rbp), %rax
movl 0x20(%rax), %r13d
movl -0x6c(%rbp), %ecx
notl %ecx
movq -0x30(%rbp), %rax
addl %ecx, %eax
movq %rax, -0x30(%rbp)
xorl %eax, %eax
movq -0x58(%rbp), %rdx
testl %edx, %edx
cmovlel %eax, %edx
movslq %r13d, %rcx
movq %rcx, -0x50(%rbp)
movq %rdx, -0x58(%rbp)
leal 0x1(%rdx), %ecx
pushq $0x1
popq %rdx
movq %rdx, %rsi
cmpq %rcx, %rsi
je 0xc987
imulq $0x18, %rsi, %rdi
addq -0x40(%rbp), %rdi
movq %rdx, %r8
cmpq -0x30(%rbp), %r8
je 0xc97f
movq 0x8(%r10), %r9
cmpl $0x0, (%r9,%rsi,4)
je 0xc976
cmpq %r8, %rsi
je 0xc976
cmpl $0x0, (%r9,%r8,4)
je 0xc976
cmpq %r13, %rsi
je 0xc976
cmpq %r13, %r8
je 0xc976
movl (%rdi), %r10d
imulq $0x18, %r8, %rbx
movq -0x40(%rbp), %r11
cmpl (%r11,%rbx), %r10d
jle 0xc976
addq -0x40(%rbp), %rbx
movq 0x10(%rdi), %r11
movq 0x10(%rbx), %rbx
testl %r10d, %r10d
cmovlel %eax, %r10d
xorl %r14d, %r14d
cmpq %r14, %r10
je 0xc976
movl 0x4(%rbx), %r15d
leaq 0x1(%r14), %r12
cmpl 0x4(%r11,%r14,4), %r15d
movq %r12, %r14
jne 0xc95a
andl $0x0, (%r9,%r8,4)
incq %r8
movq -0x68(%rbp), %r10
jmp 0xc90c
incq %rsi
jmp 0xc8f8
movl -0x58(%rbp), %eax
negq %rax
xorl %ebx, %ebx
pushq $0x1
popq %rcx
leaq (%rax,%rcx), %rdx
cmpq $0x1, %rdx
je 0xc9b8
movq 0x8(%r10), %rdx
cmpl $0x0, (%rdx,%rcx,4)
je 0xc9b3
movq 0x18(%r10), %rdx
movslq %ebx, %rsi
incl %ebx
movl %ecx, 0x4(%rdx,%rsi,4)
incq %rcx
jmp 0xc992
leal 0x1(%rbx), %eax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xcb6a
leaq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
leaq 0x68(%rbp), %rcx
movq 0x8(%rcx), %rcx
xorl %edx, %edx
testl %ebx, %ebx
cmovgl %ebx, %edx
movq %rdx, -0x60(%rbp)
leal 0x1(%rdx), %esi
movl -0x30(%rbp), %edi
pushq $0x1
popq %r8
movq %r8, %r9
cmpq %rsi, %r9
movq -0x68(%rbp), %rdx
je 0xca86
movq 0x18(%rdx), %r10
movslq (%r10,%r9,4), %r11
cmpl %r13d, %r11d
jne 0xca15
incq %r9
jmp 0xc9f6
imulq $0x18, %r11, %r11
movq -0x40(%rbp), %rbx
addq %rbx, %r11
addq $0x10, %r11
movq %r8, %rbx
cmpq %rbx, %rdi
je 0xca10
movq (%r11), %r14
movslq 0x4(%r14), %r14
movq (%rax,%r14,8), %r15
movslq (%r10,%rbx,4), %r12
imulq $0x18, %r12, %r12
movq -0x40(%rbp), %rdx
movq 0x10(%rdx,%r12), %r12
movslq 0x4(%r12), %r12
movsd (%r15,%r12,8), %xmm0
movq -0x38(%rbp), %r15
movq 0x8(%r15), %r15
movq (%r15,%r9,8), %r15
movsd %xmm0, (%r15,%rbx,8)
movq (%rcx,%r14,8), %r14
movsd (%r14,%r12,8), %xmm0
movq -0x48(%rbp), %r14
movq 0x8(%r14), %r14
movq (%r14,%r9,8), %r14
movsd %xmm0, (%r14,%rbx,8)
incq %rbx
jmp 0xca27
movq 0x8(%rdx), %rsi
movq -0x50(%rbp), %rbx
movl $0x1, (%rsi,%rbx,4)
movq 0x18(%rdx), %rsi
movslq -0x30(%rbp), %rdi
movl %r13d, (%rsi,%rdi,4)
movl -0x60(%rbp), %edx
shlq $0x2, %rdx
xorl %r8d, %r8d
cmpq %r8, %rdx
je 0xcb1c
movq (%rax,%rbx,8), %r9
movslq 0x4(%rsi,%r8), %r10
imulq $0x18, %r10, %r10
movq -0x40(%rbp), %r11
movq 0x10(%r11,%r10), %r10
movslq 0x4(%r10), %r10
movsd (%r9,%r10,8), %xmm0
movq -0x38(%rbp), %r9
movq 0x8(%r9), %r9
movq (%r9,%rdi,8), %r11
movsd %xmm0, 0x8(%r11,%r8,2)
movq 0x8(%r9,%r8,2), %r9
movsd %xmm0, (%r9,%rdi,8)
movq (%rcx,%rbx,8), %r9
movsd (%r9,%r10,8), %xmm0
movq -0x48(%rbp), %r9
movq 0x8(%r9), %r9
movq (%r9,%rdi,8), %r10
movsd %xmm0, 0x8(%r10,%r8,2)
movq 0x8(%r9,%r8,2), %r9
movsd %xmm0, (%r9,%rdi,8)
addq $0x4, %r8
jmp 0xcaab
movq -0x48(%rbp), %rbx
movq -0x30(%rbp), %rax
movl %eax, (%rbx)
movq -0x38(%rbp), %rdi
movl %eax, (%rdi)
movl %eax, 0x20(%rbx)
movl %eax, 0x20(%rdi)
movl -0x70(%rbp), %edx
callq 0xc5b5
movq %rbx, %rdi
movl 0xc0(%rbp), %edx
callq 0xc5b5
leaq -0xd8(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0xaa34
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x30(%rbp), %rcx
leal (%rcx,%rcx), %eax
leal -0x1(,%rcx,2), %r15d
cltq
leaq -0x8(,%rax,8), %r14
movq %r14, %rdi
callq 0x1130
movq -0x38(%rbp), %rcx
movq %rax, 0x8(%rcx)
movq %r14, %rdi
callq 0x1130
movq -0x48(%rbp), %r12
movq %rax, 0x8(%r12)
movq %r14, %rdi
callq 0x1130
movq -0x38(%rbp), %rcx
movq %rax, 0x40(%rcx)
movq %r14, %rdi
callq 0x1130
movq %rax, 0x40(%r12)
xorl %r12d, %r12d
testl %r15d, %r15d
cmovlel %r12d, %r15d
cmpq %r12, %r15
je 0xcbfd
movq %r14, %rdi
callq 0x1130
movq -0x38(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq %rax, (%rcx,%r12,8)
movq %r14, %rdi
callq 0x1130
movq -0x48(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
jmp 0xcbcb
xorl %r12d, %r12d
cmpq %r12, %r15
je 0xc9ce
movq %r14, %rdi
callq 0x1130
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, (%rcx,%r12,8)
movq %r14, %rdi
callq 0x1130
movq -0x48(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
jmp 0xcc00