// File: dcarrey[P]hgt-detection/./fonctions.cpp
// Function: DeleteUseLessHGT(int, HGT*, InputTree, InputTree)
int DeleteUseLessHGT(int nbHGT,struct HGT *bestHGT, struct InputTree SpeciesTree, struct InputTree SaveTree){

	int i,j,source,destination,p,q;
	struct InputTree tmpTree;
	struct CRITERIA aCrit;
	int cpt=0,retour=0;

	InitCriteria(&aCrit,SpeciesTree.size);
	initInputTree(&tmpTree);
	printf("\nHGT_INT : Procedure de suppression des transferts inutiles, il y a %d transferts",nbHGT);
	for(i=1;i<=nbHGT;i++){
		printf("\nHGT_INT : bestHGT[%d].valide=%d",i,bestHGT[i].valide);
	}
	for(i=1;i<=nbHGT;i++){
		if((bestHGT[i].valide == 1) || (bestHGT[i].valide == 6) || (bestHGT[i].valide == 4))
		{
			copyInputTree(&tmpTree,SaveTree,0,0);
			for(j=1;j<=nbHGT;j++){
				if((bestHGT[j].valide == 1) || (bestHGT[j].valide == 6) || (bestHGT[j].valide == 4))
				{
					if (i!=j){
						findBranch(tmpTree,&source,bestHGT[j].listSource);
						findBranch(tmpTree,&destination,bestHGT[j].listDestination);
						if(source != 0 && destination !=0){
							if(isAValidHGT(tmpTree,source,destination)==1){
								applyHGT(SpeciesTree.ADD,&tmpTree,source,destination);
							}
						}
					}
				}
			}
			if(AdjustBranchLength2(&tmpTree,SpeciesTree,0,1) == 0){
				//printf("\nHGT-DETECTION : on calcule les criteres");
				computeCriteria(SpeciesTree.ADD,tmpTree.ADD,SpeciesTree.size,&aCrit,SpeciesTree.LONGUEUR,SpeciesTree.ARETE,tmpTree.LONGUEUR,tmpTree.ARETE);
				printf("\nHGT-DETECTION : on a termine le calcul RF=%d",aCrit.RF);
				if(aCrit.RF == 0){
					printf("\nHGT_INT : Le transfert %d est inutile",i);
					bestHGT[i].valide = 0;
					retour++;
				}
			}
		}
	}
	FreeMemory_InputTree(&tmpTree,tmpTree.size);
	FreeCriteria(&aCrit,SpeciesTree.size);
	return retour;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
leaq 0x68(%rbp), %rax
movq %rax, -0x2b0(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0xe4(%rbp)
movl $0x0, -0xe8(%rbp)
movl (%rax), %esi
leaq -0xe0(%rbp), %rdi
callq 0x14520
leaq -0x80(%rbp), %rdi
callq 0xd040
movl -0x4(%rbp), %esi
leaq 0xcdd6(%rip), %rdi      # 0x25a43
movb $0x0, %al
callq 0x1030
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x18cb3
movl -0x14(%rbp), %esi
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
leaq 0xcdf4(%rip), %rdi      # 0x25a95
movb $0x0, %al
callq 0x1030
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x18c7b
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x19095
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
je 0x18d0f
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x6, (%rax)
je 0x18d0f
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x4, (%rax)
jne 0x19085
movq -0x2b0(%rbp), %rsi
leaq -0x140(%rbp), %rdi
movl $0x58, %edx
callq 0x1070
xorl %eax, %eax
movq -0xf0(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x50(%rax)
movups -0x100(%rbp), %xmm0
movups %xmm0, 0x40(%rax)
movups -0x140(%rbp), %xmm0
movups -0x130(%rbp), %xmm1
movups -0x120(%rbp), %xmm2
movups -0x110(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x12530
movl $0x1, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x18f7f
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
je 0x18dd6
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x6, (%rax)
je 0x18dd6
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x4, (%rax)
jne 0x18f6f
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0x18f6d
leaq -0x198(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x58, %edx
callq 0x1070
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
movq -0x148(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x50(%rax)
movups -0x158(%rbp), %xmm0
movups %xmm0, 0x40(%rax)
movups -0x198(%rbp), %xmm0
movups -0x188(%rbp), %xmm1
movups -0x178(%rbp), %xmm2
movups -0x168(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x1c(%rbp), %rdi
callq 0x17630
leaq -0x1f0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x58, %edx
callq 0x1070
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rsi
movq -0x1a0(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x50(%rax)
movups -0x1b0(%rbp), %xmm0
movups %xmm0, 0x40(%rax)
movups -0x1f0(%rbp), %xmm0
movups -0x1e0(%rbp), %xmm1
movups -0x1d0(%rbp), %xmm2
movups -0x1c0(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x20(%rbp), %rdi
callq 0x17630
cmpl $0x0, -0x1c(%rbp)
je 0x18f6b
cmpl $0x0, -0x20(%rbp)
je 0x18f6b
leaq -0x248(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x58, %edx
callq 0x1070
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
movq -0x1f8(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x50(%rax)
movups -0x208(%rbp), %xmm0
movups %xmm0, 0x40(%rax)
movups -0x248(%rbp), %xmm0
movups -0x238(%rbp), %xmm1
movups -0x228(%rbp), %xmm2
movups -0x218(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x12050
cmpl $0x1, %eax
jne 0x18f69
movq -0x2a8(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
leaq -0x80(%rbp), %rsi
callq 0xec00
jmp 0x18f6b
jmp 0x18f6d
jmp 0x18f6f
jmp 0x18f71
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x18d81
movq -0x2a8(%rbp), %rsi
leaq -0x2a0(%rbp), %rdi
movl $0x58, %edx
callq 0x1070
xorl %eax, %eax
movq -0x250(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x50(%rax)
movups -0x260(%rbp), %xmm0
movups %xmm0, 0x40(%rax)
movups -0x2a0(%rbp), %xmm0
movups -0x290(%rbp), %xmm1
movups -0x280(%rbp), %xmm2
movups -0x270(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x14420
cmpl $0x0, %eax
jne 0x19083
movq -0x2a8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x78(%rbp), %rsi
movl (%rax), %edx
movq 0x38(%rax), %r8
movq 0x30(%rax), %r9
movq -0x48(%rbp), %r10
movq -0x50(%rbp), %rax
leaq -0xe0(%rbp), %rcx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xea10
movl -0xb0(%rbp), %esi
leaq 0xca7d(%rip), %rdi      # 0x25ab6
movb $0x0, %al
callq 0x1030
cmpl $0x0, -0xb0(%rbp)
jne 0x19081
movl -0x14(%rbp), %esi
leaq 0xca91(%rip), %rdi      # 0x25ae4
movb $0x0, %al
callq 0x1030
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x19083
jmp 0x19085
jmp 0x19087
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x18cba
movl -0x80(%rbp), %esi
leaq -0x80(%rbp), %rdi
callq 0x13810
movq -0x2a8(%rbp), %rax
movl (%rax), %esi
leaq -0xe0(%rbp), %rdi
callq 0x14650
movl -0xe8(%rbp), %eax
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
nopw %cs:(%rax,%rax)