// File: dcarrey[P]hgt-detection/./fonctions.cpp
// Function: expandBestHGT(HGT, HGT*, ReduceTrace, DescTree*, InputTree)
void expandBestHGT(struct HGT bestHGTRed,struct HGT *bestHGT,struct ReduceTrace aMap,struct DescTree * DTSpecies,struct InputTree SpeciesTree){
	
	//bestHGT->source = (int*)malloc(

	int i,j,nbSource=0,nbDest=0,tmp;

	for(i=1;i<=bestHGTRed.listSource[0];i++){
		for(j=1;j<=DTSpecies[aMap.map[bestHGTRed.listSource[i]]].nbSommet;j++){
			nbSource++;
		}
	}

	bestHGT->listSource = (int*)malloc((nbSource+1)*sizeof(int));
	bestHGT->listSource[0] = nbSource;
	tmp=1;
	for(i=1;i<=bestHGTRed.listSource[0];i++){
		for(j=1;j<=DTSpecies[aMap.map[bestHGTRed.listSource[i]]].nbSommet;j++){
			bestHGT->listSource[tmp] = DTSpecies[aMap.map[bestHGTRed.listSource[i]]].Tableau[j];
			tmp++;
		}
	}
	TrierTableau(bestHGT->listSource,tmp-1);
	
/*	printf("\nSource :");
	for(i=1;i<=bestHGT->listSource[0];i++)
		printf(" %d",bestHGT->listSource[i]);
    */

	for(i=1;i<=bestHGTRed.listDestination[0];i++){
		for(j=1;j<=DTSpecies[aMap.map[bestHGTRed.listDestination[i]]].nbSommet;j++){
			nbDest++;
		}
	}

	bestHGT->listDestination = (int*)malloc((nbDest+1)*sizeof(int));
	bestHGT->listDestination[0] = nbDest;
	tmp=1;
	for(i=1;i<=bestHGTRed.listDestination[0];i++){
		for(j=1;j<=DTSpecies[aMap.map[bestHGTRed.listDestination[i]]].nbSommet;j++){
			bestHGT->listDestination[tmp] = DTSpecies[aMap.map[bestHGTRed.listDestination[i]]].Tableau[j];
			tmp++;
		}
	}
	TrierTableau(bestHGT->listDestination,tmp-1);
	
/*	printf("\nDest   :");
	for(i=1;i<=bestHGT->listDestination[0];i++)
		printf(" %d",bestHGT->listDestination[i]);
	*/

	//== find branches
	findBranch(SpeciesTree,&i,bestHGT->listSource);
	findBranch(SpeciesTree,&j,bestHGT->listDestination);
	bestHGT->source = i;
	bestHGT->destination = j;

	bestHGT->source_A = SpeciesTree.ARETE[2*i-1];
	bestHGT->source_B = SpeciesTree.ARETE[2*i-2];
	bestHGT->dest_A = SpeciesTree.ARETE[2*j-1];
	bestHGT->dest_B = SpeciesTree.ARETE[2*j-2];

	bestHGT->valide = bestHGTRed.valide;
	bestHGT->crit = bestHGTRed.crit;

	free(bestHGTRed.listSource);
	free(bestHGTRed.listDestination);
	bestHGTRed.listSource = NULL;
	bestHGTRed.listDestination = NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
leaq 0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq 0xb8(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x1, -0x14(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x10(%rcx), %rcx
cmpl (%rcx), %eax
jg 0x17b3d
movl $0x1, -0x18(%rbp)
movq -0xe0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rdx), %rdx
movq 0x10(%rsi), %rsi
movslq -0x14(%rbp), %rdi
movslq (%rsi,%rdi,4), %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jg 0x17b30
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x17ae8
jmp 0x17b32
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x17acf
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1110
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl %ecx, (%rax)
movl $0x1, -0x24(%rbp)
movl $0x1, -0x14(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x10(%rcx), %rcx
cmpl (%rcx), %eax
jg 0x17c34
movl $0x1, -0x18(%rbp)
movq -0xe0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rdx), %rdx
movq 0x10(%rsi), %rsi
movslq -0x14(%rbp), %rdi
movslq (%rsi,%rdi,4), %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jg 0x17c24
movq -0xe0(%rbp), %rdx
movq -0xe8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rcx), %rcx
movq 0x10(%rdx), %rdx
movslq -0x14(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x17b92
jmp 0x17c26
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x17b75
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x24(%rbp), %esi
subl $0x1, %esi
callq 0x2730
movl $0x1, -0x14(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
jg 0x17cbc
movl $0x1, -0x18(%rbp)
movq -0xe0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rdx), %rdx
movq 0x18(%rsi), %rsi
movslq -0x14(%rbp), %rdi
movslq (%rsi,%rdi,4), %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jg 0x17caf
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x17c67
jmp 0x17cb1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x17c4e
movl -0x20(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1110
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, (%rax)
movl $0x1, -0x24(%rbp)
movl $0x1, -0x14(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
jg 0x17db3
movl $0x1, -0x18(%rbp)
movq -0xe0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rdx), %rdx
movq 0x18(%rsi), %rsi
movslq -0x14(%rbp), %rdi
movslq (%rsi,%rdi,4), %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jg 0x17da3
movq -0xe0(%rbp), %rdx
movq -0xe8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rcx), %rcx
movq 0x18(%rdx), %rdx
movslq -0x14(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x17d11
jmp 0x17da5
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x17cf4
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x24(%rbp), %esi
subl $0x1, %esi
callq 0x2730
movq -0xf0(%rbp), %rsi
leaq -0x80(%rbp), %rdi
movl $0x58, %edx
callq 0x1070
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x50(%rax)
movups -0x40(%rbp), %xmm0
movups %xmm0, 0x40(%rax)
movups -0x80(%rbp), %xmm0
movups -0x70(%rbp), %xmm1
movups -0x60(%rbp), %xmm2
movups -0x50(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x14(%rbp), %rdi
callq 0x17630
movq -0xf0(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
movl $0x58, %edx
callq 0x1070
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x88(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x50(%rax)
movups -0x98(%rbp), %xmm0
movups %xmm0, 0x40(%rax)
movups -0xd8(%rbp), %xmm0
movups -0xc8(%rbp), %xmm1
movups -0xb8(%rbp), %xmm2
movups -0xa8(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x18(%rbp), %rdi
callq 0x17630
movq -0xf0(%rbp), %rax
movq -0xe0(%rbp), %rsi
movl -0x14(%rbp), %edx
movq -0x8(%rbp), %rcx
movl %edx, 0x4(%rcx)
movl -0x18(%rbp), %edx
movq -0x8(%rbp), %rcx
movl %edx, 0x8(%rcx)
movq 0x30(%rax), %rcx
movl -0x14(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
movq -0x8(%rbp), %rcx
movl %edx, 0x80(%rcx)
movq 0x30(%rax), %rcx
movl -0x14(%rbp), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
movq -0x8(%rbp), %rcx
movl %edx, 0x84(%rcx)
movq 0x30(%rax), %rcx
movl -0x18(%rbp), %edx
shll %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
movq -0x8(%rbp), %rcx
movl %edx, 0x88(%rcx)
movq 0x30(%rax), %rax
movl -0x18(%rbp), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8c(%rax)
movl (%rsi), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
addq $0x20, %rsi
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movl $0x60, %edx
callq 0x1070
movq -0xe0(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x10e0
movq -0xe0(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x10e0
movq -0xe0(%rbp), %rax
movq $0x0, 0x10(%rax)
movq $0x0, 0x18(%rax)
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw (%rax,%rax)