// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movq %rsi, %r15
movq %rdi, -0x38(%rbp)
leaq 0xb8(%rbp), %rcx
movq 0x20(%rbp), %rbx
movl (%rbx), %eax
movl $0x1, %r14d
testl %eax, %eax
jle 0xd507
movq 0x18(%rcx), %rdx
leaq 0x1(%rax), %rsi
xorl %edi, %edi
movl $0x1, %r8d
xorl %ecx, %ecx
movslq (%rbx,%r8,4), %r9
movslq (%rdx,%r9,4), %r9
leaq (%r9,%r9,2), %r9
movl (%r15,%r9,8), %r9d
testl %r9d, %r9d
movl %r9d, %r10d
cmovlel %edi, %r10d
addl %r10d, %ecx
incq %r8
cmpq %r8, %rsi
jne 0xd4cf
leal 0x1(%r9), %esi
testl %r9d, %r9d
movl $0x1, %edx
cmovgl %esi, %edx
incl %eax
jmp 0xd511
movl -0x2c(%rbp), %edx
xorl %ecx, %ecx
movl $0x1, %eax
movl %eax, -0x30(%rbp)
movl %edx, -0x2c(%rbp)
movslq %ecx, %r13
leaq 0x4(,%r13,4), %rdi
callq 0x1140
movq %rax, %r12
movq -0x38(%rbp), %rax
movq %r12, 0x10(%rax)
movl %r13d, (%r12)
movl $0x1, -0x30(%rbp)
cmpl $0x0, (%rbx)
leaq 0xb8(%rbp), %r9
jle 0xd5bd
movq 0x18(%r9), %rax
movl $0x1, %r14d
movl $0x1, %ecx
movslq (%rbx,%rcx,4), %rdx
movslq (%rax,%rdx,4), %rsi
leaq (%rsi,%rsi,2), %rdx
cmpl $0x0, (%r15,%rdx,8)
jle 0xd5a3
movslq %r14d, %rdx
leaq (%r12,%rdx,4), %rdi
xorl %edx, %edx
leaq (%rsi,%rsi,2), %rsi
movq 0x10(%r15,%rsi,8), %rsi
movl 0x4(%rsi,%rdx,4), %esi
movl %esi, (%rdi,%rdx,4)
movslq (%rbx,%rcx,4), %rsi
movslq (%rax,%rsi,4), %rsi
leaq (%rsi,%rsi,2), %r8
movslq (%r15,%r8,8), %r8
incq %rdx
cmpq %r8, %rdx
jl 0xd574
addl %edx, %r14d
incl %edx
jmp 0xd5a8
movl $0x1, %edx
leaq 0x1(%rcx), %rsi
movslq (%rbx), %rdi
cmpq %rdi, %rcx
movq %rsi, %rcx
jl 0xd558
movl %edx, -0x2c(%rbp)
movl %esi, -0x30(%rbp)
leaq 0x10(%rbp), %r8
cmpl $0x3, %r14d
jl 0xd609
leal -0x1(%r14), %eax
xorl %ecx, %ecx
movl $0x1, %edx
movl (%r12,%rdx,4), %esi
movl 0x4(%r12,%rdx,4), %edi
cmpl %edi, %esi
jle 0xd5ed
movl %edi, (%r12,%rdx,4)
movl %esi, 0x4(%r12,%rdx,4)
movl $0x1, %ecx
incq %rdx
cmpq %rax, %rdx
jne 0xd5d2
cmpl $0x3, %r14d
jl 0xd609
movl $0x1, %edx
testl %ecx, %ecx
movl $0x0, %ecx
jne 0xd5d2
movq 0x18(%r8), %r13
movl (%r13), %eax
testl %eax, %eax
jle 0xd660
movq 0x18(%r9), %rdx
leaq 0x1(%rax), %rsi
xorl %edi, %edi
movl $0x1, %r8d
xorl %ecx, %ecx
movslq (%r13,%r8,4), %r9
movslq (%rdx,%r9,4), %r9
leaq (%r9,%r9,2), %r9
movl (%r15,%r9,8), %r9d
testl %r9d, %r9d
movl %r9d, %r10d
cmovlel %edi, %r10d
addl %r10d, %ecx
incq %r8
cmpq %r8, %rsi
jne 0xd627
leal 0x1(%r9), %esi
testl %r9d, %r9d
movl $0x1, %edx
cmovgl %esi, %edx
incl %eax
jmp 0xd66a
movl -0x2c(%rbp), %edx
xorl %ecx, %ecx
movl $0x1, %eax
movl %eax, -0x30(%rbp)
movl %edx, -0x2c(%rbp)
movslq %ecx, %rax
movq %rax, -0x40(%rbp)
leaq 0x4(,%rax,4), %rdi
callq 0x1140
movq %rax, %r14
movq -0x38(%rbp), %rax
movq %r14, 0x18(%rax)
movq -0x40(%rbp), %rax
movl %eax, (%r14)
movl $0x1, -0x30(%rbp)
cmpl $0x0, (%r13)
movl $0x1, %r9d
jle 0xd728
leaq 0xb8(%rbp), %rax
movq 0x18(%rax), %rax
movl $0x1, %r9d
movl $0x1, %ecx
movslq (%r13,%rcx,4), %rdx
movslq (%rax,%rdx,4), %rsi
leaq (%rsi,%rsi,2), %rdx
cmpl $0x0, (%r15,%rdx,8)
jle 0xd70d
movslq %r9d, %rdx
leaq (%r14,%rdx,4), %rdi
xorl %edx, %edx
leaq (%rsi,%rsi,2), %rsi
movq 0x10(%r15,%rsi,8), %rsi
movl 0x4(%rsi,%rdx,4), %esi
movl %esi, (%rdi,%rdx,4)
movslq (%r13,%rcx,4), %rsi
movslq (%rax,%rsi,4), %rsi
leaq (%rsi,%rsi,2), %r8
movslq (%r15,%r8,8), %r8
incq %rdx
cmpq %r8, %rdx
jl 0xd6dd
addl %edx, %r9d
incl %edx
jmp 0xd712
movl $0x1, %edx
leaq 0x1(%rcx), %rsi
movslq (%r13), %rdi
cmpq %rdi, %rcx
movq %rsi, %rcx
jl 0xd6c0
movl %edx, -0x2c(%rbp)
movl %esi, -0x30(%rbp)
leaq 0xe0(%rbp), %r8
cmpl $0x3, %r9d
jl 0xd777
leal -0x1(%r9), %eax
xorl %ecx, %ecx
movl $0x1, %edx
movl (%r14,%rdx,4), %esi
movl 0x4(%r14,%rdx,4), %edi
cmpl %edi, %esi
jle 0xd75b
movl %edi, (%r14,%rdx,4)
movl %esi, 0x4(%r14,%rdx,4)
movl $0x1, %ecx
incq %rdx
cmpq %rax, %rdx
jne 0xd740
cmpl $0x3, %r9d
jl 0xd777
movl $0x1, %edx
testl %ecx, %ecx
movl $0x0, %ecx
jne 0xd740
movl $0xb, %ecx
movq %rsp, %rdi
movq %r8, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x30(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r8, %r12
callq 0xd2eb
movl $0xb, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x2c(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0xd2eb
movslq (%r15), %rax
movq -0x38(%rbp), %rdi
movl %eax, 0x4(%rdi)
movslq (%r12), %rcx
movl %ecx, 0x8(%rdi)
leaq 0xe0(%rbp), %rdx
movq 0x30(%rdx), %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), %r14
movl (%r14), %eax
movl %eax, (%rdi)
leaq 0x20(%r14), %rsi
addq $0x20, %rdi
movl $0xc, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
callq 0x1100
movq %r13, %rdi
callq 0x1100
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq