// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %r13d
movl %r8d, -0x2c(%rbp)
movl %ecx, -0x30(%rbp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r14
leaq 0x10(%rbp), %r15
leaq 0xb508(%rip), %rsi      # 0x15865
movq %r12, %rdi
callq 0x1170
testl %eax, %eax
je 0xa3b4
leaq 0xc14d(%rip), %rsi      # 0x164bd
movq %r12, %rdi
callq 0x1170
testl %eax, %eax
je 0xa3ea
leaq 0xb510(%rip), %rsi      # 0x15893
movq %r12, %rdi
callq 0x1170
testl %eax, %eax
je 0xa3fa
leaq 0xb51a(%rip), %rsi      # 0x158b0
movq %r12, %rdi
callq 0x1170
testl %eax, %eax
jne 0xa47d
movl 0x54(%rbx), %eax
xorl %ecx, %ecx
cmpl 0x34(%r15), %eax
setg %cl
jmp 0xa427
movl 0x30(%r15), %eax
xorl %ecx, %ecx
cmpl %eax, 0x50(%rbx)
jle 0xa3cb
movl $0x0, (%r14)
movl $0x1, %ecx
cmpl %eax, 0x50(%rbx)
jne 0xa427
movsd 0x20(%rbx), %xmm0
ucomisd (%r15), %xmm0
jbe 0xa427
cmpl $0x0, (%r14)
movl $0x1, %eax
cmovel %eax, %ecx
jmp 0xa427
movsd 0x20(%rbx), %xmm0
xorl %ecx, %ecx
ucomisd (%r15), %xmm0
ja 0xa41e
jmp 0xa427
movsd 0x30(%rbx), %xmm0
xorl %ecx, %ecx
ucomisd 0x10(%r15), %xmm0
seta %al
cmpl $0x2, %r13d
jne 0xa425
leaq 0xb53a(%rip), %rdi      # 0x15951
xorl %eax, %eax
callq 0x1030
movl $0x1, %ecx
jmp 0xa427
movb %al, %cl
xorl %eax, %eax
cmpl $0x0, 0xfd24(%rip)      # 0x1a154
setne %al
cmpl $0x1, 0x70(%rbp)
cmovnel %ecx, %eax
cmpl $0x1, %eax
jne 0xa46e
movl -0x2c(%rbp), %ecx
movl %ecx, 0x8(%rbx)
movl -0x30(%rbp), %ecx
movl %ecx, 0x4(%rbx)
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x30(%rbx)
movsd (%r15), %xmm0
movsd %xmm0, 0x20(%rbx)
movl 0x30(%r15), %ecx
movl %ecx, 0x50(%rbx)
movl 0x34(%r15), %ecx
movl %ecx, 0x54(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb4d2(%rip), %rdi      # 0x15956
movq %r12, %rsi
xorl %eax, %eax
callq 0x1030
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110