// File: dcarrey[P]hgt-detection/./fonctions.cpp
// Function: TestCriterionAndUpdate(int*, char const*, CRITERIA, HGT*, int, int, int, int)
int TestCriterionAndUpdate(int *first,const char *CRITERION, struct CRITERIA aCrit, struct HGT * aHGT,int i,int j,int flag,int flag_bootstrap){

	int best = 0;

	if (strcmp(CRITERION,"rf")==0){
		if (aHGT->crit.RF > aCrit.RF) {
			best = 1;			
			(*first)=0;
		}
		if (aHGT->crit.RF == aCrit.RF && aHGT->crit.LS > aCrit.LS && (*first) == 0)
			best = 1; 
	}
	else if (strcmp(CRITERION,"ls")==0){
		if (aHGT->crit.LS > aCrit.LS) best = 1;
	}
	else if (strcmp(CRITERION,"bd")==0){
		if (aHGT->crit.BD > aCrit.BD) best = 1;
		if (flag == 2){
			printf("LALA");
			best=1;
		}
		
	}
	else if (strcmp(CRITERION,"qd")==0){
		if (aHGT->crit.QD > aCrit.QD) best = 1;
	}
	else{
		printf("\nunknown criterion %s, try again...\n",CRITERION);
		exit(-1);
	}

	if (flag_bootstrap == 1){
		
		if(rand_bootstrap == 0){
			best = 0;
		}
		else{
			best = 1;
		}
		
		//printf("\n==> rand_bootstrap = %d, best = %d",rand_bootstrap,best);
	}
	
	if(best == 1){
  	//printf("FIN TCAU");
		aHGT->destination = j;
		aHGT->source = i;
		aHGT->crit.BD = aCrit.BD;
		aHGT->crit.LS = aCrit.LS;
		aHGT->crit.RF = aCrit.RF;
		aHGT->crit.QD = aCrit.QD;
	}
	
	//printf("\n>>>> DANS testCRiterionAndUpdate : RF = %d, BD =%lf",aCrit.RF,aCrit.BD);
	
	return best;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl 0x70(%rbp), %eax
leaq 0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x13a85(%rip), %rsi     # 0x258b1
callq 0x1130
cmpl $0x0, %eax
jne 0x11e8f
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
cmpl 0x30(%rcx), %eax
jle 0x11e57
movl $0x1, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
cmpl 0x30(%rcx), %eax
jne 0x11e8a
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movsd 0x20(%rcx), %xmm0
ucomisd (%rax), %xmm0
jbe 0x11e8a
movq -0x8(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x11e8a
movl $0x1, -0x28(%rbp)
jmp 0x11f60
movq -0x10(%rbp), %rdi
leaq 0x146c8(%rip), %rsi     # 0x26562
callq 0x1130
cmpl $0x0, %eax
jne 0x11ec3
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movsd 0x20(%rcx), %xmm0
ucomisd (%rax), %xmm0
jbe 0x11ebe
movl $0x1, -0x28(%rbp)
jmp 0x11f5e
movq -0x10(%rbp), %rdi
leaq 0x13a11(%rip), %rsi     # 0x258df
callq 0x1130
cmpl $0x0, %eax
jne 0x11f10
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movsd 0x30(%rcx), %xmm0
ucomisd 0x10(%rax), %xmm0
jbe 0x11ef3
movl $0x1, -0x28(%rbp)
cmpl $0x2, -0x24(%rbp)
jne 0x11f0e
leaq 0x13a9d(%rip), %rdi     # 0x2599d
movb $0x0, %al
callq 0x1030
movl $0x1, -0x28(%rbp)
jmp 0x11f5c
movq -0x10(%rbp), %rdi
leaq 0x139e1(%rip), %rsi     # 0x258fc
callq 0x1130
cmpl $0x0, %eax
jne 0x11f3e
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x54(%rax), %eax
cmpl 0x34(%rcx), %eax
jle 0x11f3c
movl $0x1, -0x28(%rbp)
jmp 0x11f5a
movq -0x10(%rbp), %rsi
leaq 0x13a59(%rip), %rdi     # 0x259a2
movb $0x0, %al
callq 0x1030
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x10f0
jmp 0x11f5c
jmp 0x11f5e
jmp 0x11f60
cmpl $0x1, 0x70(%rbp)
jne 0x11f81
cmpl $0x0, 0x181b7(%rip)     # 0x2a124
jne 0x11f78
movl $0x0, -0x28(%rbp)
jmp 0x11f7f
movl $0x1, -0x28(%rbp)
jmp 0x11f81
cmpl $0x1, -0x28(%rbp)
jne 0x11fce
movq -0x30(%rbp), %rax
movl -0x20(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x8(%rcx)
movl -0x1c(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x4(%rcx)
movsd 0x10(%rax), %xmm0
movq -0x18(%rbp), %rcx
movsd %xmm0, 0x30(%rcx)
movsd (%rax), %xmm0
movq -0x18(%rbp), %rcx
movsd %xmm0, 0x20(%rcx)
movl 0x30(%rax), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x50(%rcx)
movl 0x34(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x54(%rax)
movl -0x28(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)