// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r13
movq %rdi, -0x30(%rbp)
leaq 0x10(%rbp), %rax
movq 0x10(%rax), %r8
movslq (%r8), %r14
movq 0xd0(%rbp), %r12
xorl %eax, %eax
testl %r14d, %r14d
movl $0x0, %ecx
cmovgl %r14d, %ecx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %rcx
je 0xc370
movslq 0x4(%r8,%rdx,4), %rdi
movslq (%r12,%rdi,4), %rdi
imulq $0x18, %rdi, %rdi
movl (%r13,%rdi), %ebx
testl %ebx, %ebx
cmovlel %eax, %ebx
addl %ebx, %esi
incl %ebx
incq %rdx
jmp 0xc34b
movslq %esi, %r15
leaq 0x4(,%r15,4), %rdi
movq %r8, -0x40(%rbp)
callq 0x1130
movq -0x40(%rbp), %r10
movq %rax, %r11
movq -0x30(%rbp), %rax
movq %r11, 0x10(%rax)
movl %r15d, (%r11)
pushq $0x1
popq %rsi
pushq $0x1
popq %rax
movq %rax, %rcx
cmpq %r14, %rcx
jg 0xc3e1
movslq %esi, %r8
movslq (%r10,%rcx,4), %rdx
movslq (%r12,%rdx,4), %rdx
imulq $0x18, %rdx, %rdi
leaq (%rdi,%r13), %rdx
movslq (%r13,%rdi), %rdi
leaq (%r11,%r8,4), %r8
movq %rax, %rbx
cmpq %rdi, %rbx
jg 0xc3dc
movq 0x10(%rdx), %r9
movl (%r9,%rbx,4), %r9d
movl %r9d, -0x4(%r8,%rbx,4)
incq %rbx
incl %esi
jmp 0xc3c3
incq %rcx
jmp 0xc39f
decl %esi
movq %r11, -0x50(%rbp)
movq %r11, %rdi
callq 0x1b8f
leaq 0x10(%rbp), %rax
movq 0x18(%rax), %r15
movslq (%r15), %r8
xorl %eax, %eax
testl %r8d, %r8d
movl $0x0, %ecx
cmovgl %r8d, %ecx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %rcx
je 0xc431
movslq 0x4(%r15,%rdx,4), %rdi
movslq (%r12,%rdi,4), %rdi
imulq $0x18, %rdi, %rdi
movl (%r13,%rdi), %ebx
testl %ebx, %ebx
cmovlel %eax, %ebx
addl %ebx, %esi
incl %ebx
incq %rdx
jmp 0xc40c
movslq %esi, %rax
movq %rax, -0x48(%rbp)
leaq 0x4(,%rax,4), %rdi
movq %r8, %r14
callq 0x1130
movq %r14, %r10
movq %rax, %r14
movq -0x30(%rbp), %rax
movq %r14, 0x18(%rax)
movq -0x48(%rbp), %rax
movl %eax, (%r14)
pushq $0x1
popq %rsi
pushq $0x1
popq %rcx
movq %rcx, %rax
cmpq %r10, %rax
jg 0xc4a8
movslq %esi, %r8
movslq (%r15,%rax,4), %rdx
movslq (%r12,%rdx,4), %rdx
imulq $0x18, %rdx, %rdi
leaq (%rdi,%r13), %rdx
movslq (%r13,%rdi), %rdi
leaq (%r14,%r8,4), %r8
movq %rcx, %rbx
cmpq %rdi, %rbx
jg 0xc4a3
movq 0x10(%rdx), %r9
movl (%r9,%rbx,4), %r9d
movl %r9d, -0x4(%r8,%rbx,4)
incq %rbx
incl %esi
jmp 0xc48a
incq %rax
jmp 0xc466
leaq -0x54(%rbp), %r12
movl %eax, (%r12)
leaq -0x34(%rbp), %rax
movl %ebx, (%rax)
decl %esi
movq %r14, %rdi
callq 0x1b8f
pushq $0xb
popq %r13
movq %r13, %rcx
movq %rsp, %rdi
leaq 0xe0(%rbp), %rbx
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
movq -0x50(%rbp), %rsi
callq 0xc174
movq %r13, %rcx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x34(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0xc174
movslq (%r12), %rax
movq -0x30(%rbp), %rdi
movl %eax, 0x4(%rdi)
movslq (%r13), %rcx
movl %ecx, 0x8(%rdi)
movq 0x30(%rbx), %rdx
shlq $0x4, %rax
movl -0x8(%rdx,%rax), %esi
movl %esi, 0x80(%rdi)
movl -0x10(%rdx,%rax), %eax
movl %eax, 0x84(%rdi)
shlq $0x4, %rcx
movl -0x8(%rdx,%rcx), %eax
movl %eax, 0x88(%rdi)
movl -0x10(%rdx,%rcx), %eax
movl %eax, 0x8c(%rdi)
leaq 0x10(%rbp), %rsi
movl (%rsi), %eax
movl %eax, (%rdi)
addq $0x20, %rsi
addq $0x20, %rdi
pushq $0xc
popq %rcx
rep  movsq (%rsi), %es:(%rdi)
movq -0x40(%rbp), %rdi
callq 0x10f0
movq %r15, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10f0