// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/model.c
// Function: mlp_model_simulation_multitest
int mlp_model_simulation_multitest(Datasetptr d, char* simulationdirectory, int maxhidden, int starthidden, int* tries)
{
 /*!Last Changed 26.05.2006 added starthidden*/
	/*!Last Changed 29.10.2005*/
	/*!Last Changed 02.06.2004*/
	char **filenames, filename[500], directory[500], tmpst[500];
	int numberofclasses, bestmodel, filecount, models[MAX_MODEL_SEARCH], i, j, tmp, m, c, *model, *modelselected, *modelstried;
 if (starthidden < 0 || starthidden > maxhidden)
   bestmodel = 0;
 else
   bestmodel = starthidden;
	filenames = (char **) safemalloc_2d(sizeof(char *), sizeof(char), MAX_MODEL_SEARCH, 500, "mlp_model_simulation", 3);
	modelselected = (int *) safecalloc(maxhidden + 1, sizeof(int), "mlp_model_simulation", 4);
	modelstried = (int *) safecalloc(maxhidden + 1, sizeof(int), "mlp_model_simulation", 5);
	modelselected[bestmodel] = 1;
	modelstried[bestmodel] = 1;
	sprintf(directory,"%s/%s", simulationdirectory, d->name);
	if (d->classno == 0)
		 numberofclasses = 1;
	else
		 numberofclasses = d->classno;
	while (1)
	 {
		 filecount = 0;
		 search_and_add_candidate_model(filenames, directory, bestmodel, models, &filecount);
		 if (bestmodel == 0)
			 {
				 if (numberofclasses <= maxhidden)
					 {
						 search_and_add_candidate_model(filenames, directory, numberofclasses, models, &filecount);
							if (2 * numberofclasses <= maxhidden)
								 search_and_add_candidate_model(filenames, directory, 2 * numberofclasses, models, &filecount);
							else
						   search_and_add_candidate_model(filenames, directory, maxhidden, models, &filecount);
					 }
					else
						 search_and_add_candidate_model(filenames, directory, maxhidden, models, &filecount);
					if ((numberofclasses + d->multifeaturecount) / 4 <= maxhidden)
					 {
						 search_and_add_candidate_model(filenames, directory, (numberofclasses + d->multifeaturecount) / 4, models, &filecount);
							if ((numberofclasses + d->multifeaturecount) / 2 <= maxhidden)
								 search_and_add_candidate_model(filenames, directory, (numberofclasses + d->multifeaturecount) / 2, models, &filecount);
							else
						   search_and_add_candidate_model(filenames, directory, maxhidden, models, &filecount);
					 }
					else
						 search_and_add_candidate_model(filenames, directory, maxhidden, models, &filecount);
			 }
			else
			 {
				 if (bestmodel + 1 <= maxhidden)
					 {
  				 search_and_add_candidate_model(filenames, directory, bestmodel + 1, models, &filecount);
							if (1.5 * bestmodel <= maxhidden)
								 search_and_add_candidate_model(filenames, directory, (int) (1.5 * bestmodel), models, &filecount);
							else
         search_and_add_candidate_model(filenames, directory, maxhidden, models, &filecount);
					 }
					else
						 search_and_add_candidate_model(filenames, directory, maxhidden, models, &filecount);
					search_and_add_candidate_model(filenames, directory, bestmodel - 1, models, &filecount);
     search_and_add_candidate_model(filenames, directory, (int) (0.5 * bestmodel), models, &filecount);
			 }
			if (filecount == 1)
				 break;
			for (i = 0; i < filecount; i++)
				 for (j = i + 1; j < filecount; j++)
						 if (models[i] > models[j])
							 {
								 tmp = models[i];
									models[i] = models[j];
									models[j] = tmp;
									strcpy(filename, filenames[i]);
									strcpy(filenames[i], filenames[j]);
									strcpy(filenames[j], filename);
							 }
			sprintf(tmpst,"-");
			for (i = 0; i < filecount; i++)
				 modelstried[models[i]] = 1;
			model = multiple_comparison(filenames, filecount, get_parameter_l("testtype"), tmpst, &m, &c, get_parameter_l("correctiontype"));
			if (models[model[0] - 1] == bestmodel)
			 {
				 safe_free(model);
				 break;
			 }
			else
			 {
				 if (modelselected[models[model[0] - 1]])
						 break;
				 bestmodel = models[model[0] - 1];
					modelselected[bestmodel] = 1;
			 }
			safe_free(model);
	 }
	*tries = 0;
	for (i = 0; i <= maxhidden; i++)
		 if (modelstried[i])
				 (*tries)++;
	free_2d((void**)filenames, MAX_MODEL_SEARCH);
	safe_free(modelselected);
	safe_free(modelstried);
 return bestmodel;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6a8, %rsp            # imm = 0x6A8
movq %r8, 0x78(%rsp)
movl %edx, %ebx
movq %rsi, 0x18(%rsp)
xorl %eax, %eax
testl %ecx, %ecx
movl $0x0, %r15d
cmovgl %ecx, %r15d
movq %rdi, %r13
cmpl %edx, %ecx
cmovgl %eax, %r15d
leaq 0x615be(%rip), %r12     # 0xaa4aa
movl $0x8, %edi
movl $0x1, %esi
movl $0x7, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r12, %r8
movl $0x3, %r9d
callq 0x3a3ac
movq %rax, %r14
leal 0x1(%rbx), %eax
movl %eax, 0x28(%rsp)
movslq %eax, %rbp
movl $0x4, %esi
movq %rbp, %rdi
movq %r12, %rdx
movl $0x4, %ecx
callq 0x3a1fc
movl $0x4, %esi
movq %rbp, %rdi
movq %rbx, %rbp
movq %r12, %rdx
movq %rax, %r12
movl $0x5, %ecx
callq 0x3a1fc
movl $0x1, %ebx
movl %ebx, (%r12,%r15,4)
movq %rax, 0x60(%rsp)
movl %ebx, (%rax,%r15,4)
movq 0x8(%r13), %rcx
leaq 0x5e2e8(%rip), %rsi     # 0xa7250
leaq 0x2b0(%rsp), %rdi
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x41b0
movq %r13, 0x58(%rsp)
movl 0x10(%r13), %r13d
cmpl %ebx, %r13d
adcl $0x0, %r13d
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x80(%rsp)
leal (,%r13,2), %eax
cmpl %ebp, %eax
cmovgel %ebp, %eax
movl %eax, 0x2c(%rsp)
leaq 0x30(%rsp), %rcx
movq %r13, 0x88(%rsp)
movq %r14, 0x70(%rsp)
movq %r12, 0x68(%rsp)
movq %rbp, 0x20(%rsp)
movl $0x0, 0x14(%rsp)
movq %r14, %rdi
leaq 0x2b0(%rsp), %rbx
movq %rbx, %rsi
movl %r15d, %edx
leaq 0x14(%rsp), %r8
callq 0x48ad3
testl %r15d, %r15d
je 0x4904c
cmpl %ebp, %r15d
jge 0x490ea
leal 0x1(%r15), %edx
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x30(%rsp), %r12
movq %r12, %rcx
leaq 0x14(%rsp), %r13
movq %r13, %r8
callq 0x48ad3
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x18(%rsp)
mulsd 0x5cdb4(%rip), %xmm0    # 0xa5de0
movsd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x49117
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %edx
jmp 0x49121
movl %ebp, %edx
cmpl %ebp, %r13d
jg 0x4906f
movq %r14, %rdi
movq %rbx, %rsi
movl %r13d, %edx
leaq 0x30(%rsp), %rcx
leaq 0x14(%rsp), %r8
callq 0x48ad3
movl 0x2c(%rsp), %edx
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x30(%rsp), %r12
movq %r12, %rcx
leaq 0x14(%rsp), %rbp
movq %rbp, %r8
callq 0x48ad3
movq 0x58(%rsp), %rax
movl 0x1c0(%rax), %ecx
leal (%rcx,%r13), %eax
addl $0x3, %eax
addl %r13d, %ecx
cmovnsl %ecx, %eax
sarl $0x2, %eax
movq 0x20(%rsp), %rcx
movl %ecx, %edx
cmpl %ecx, %eax
jg 0x49156
movq %r14, %rdi
movq %rbx, %rsi
movl %eax, %edx
movq %r12, %rcx
movq %rbp, %r8
callq 0x48ad3
movq 0x58(%rsp), %rax
movl 0x1c0(%rax), %eax
addl %r13d, %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
movq 0x20(%rsp), %rax
cmpl %eax, %edx
cmovgel %eax, %edx
jmp 0x49156
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %edx
leaq 0x30(%rsp), %r12
movq %r12, %rcx
leaq 0x14(%rsp), %r13
movq %r13, %r8
callq 0x48ad3
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x18(%rsp)
jmp 0x4912c
cvttsd2si %xmm0, %edx
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rcx
movq %r13, %r8
callq 0x48ad3
leal -0x1(%r15), %edx
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rcx
movq %r13, %r8
callq 0x48ad3
movsd 0x18(%rsp), %xmm0
mulsd 0x5cbc9(%rip), %xmm0    # 0xa5d18
cvttsd2si %xmm0, %edx
movq %r13, %rbp
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rcx
movq %rbp, %r8
callq 0x48ad3
movl 0x14(%rsp), %eax
cmpq $0x1, %rax
movq 0x68(%rsp), %r12
movq 0x20(%rsp), %rbp
je 0x49314
testl %eax, %eax
jle 0x49281
movq %r15, 0x90(%rsp)
movq %rax, %r15
leaq 0x30(%rsp), %rbp
movq %r14, 0x18(%rsp)
xorl %ebx, %ebx
movq %rax, 0x98(%rsp)
leaq 0x1(%rbx), %rcx
movq %rcx, 0xa0(%rsp)
cmpq %rax, %rcx
jae 0x49216
movl $0x1, %r14d
movl 0x30(%rsp,%rbx,4), %eax
movl (%rbp,%r14,4), %ecx
cmpl %ecx, %eax
jle 0x4920e
movl %ecx, 0x30(%rsp,%rbx,4)
movl %eax, (%rbp,%r14,4)
movq 0x70(%rsp), %rax
movq (%rax,%rbx,8), %r13
leaq 0x4b0(%rsp), %rdi
movq %r13, %rsi
callq 0x4270
movq 0x18(%rsp), %r12
movq (%r12,%r14,8), %rsi
movq %r13, %rdi
callq 0x4270
movq (%r12,%r14,8), %rdi
leaq 0x4b0(%rsp), %rsi
callq 0x4270
incq %r14
cmpq %r14, %r15
jne 0x491bd
addq $0x8, 0x18(%rsp)
addq $0x4, %rbp
decq %r15
movq 0x98(%rsp), %rax
movq 0xa0(%rsp), %rbx
cmpq %rax, %rbx
jne 0x491a6
movw $0x2d, 0xb0(%rsp)
testl %eax, %eax
movq 0x90(%rsp), %r15
movq 0x70(%rsp), %r14
movq 0x68(%rsp), %r12
movq 0x20(%rsp), %rbp
movq 0x60(%rsp), %rdx
movq %rax, %rbx
jle 0x4928e
xorl %eax, %eax
movslq 0x30(%rsp,%rax,4), %rcx
movl $0x1, (%rdx,%rcx,4)
incq %rax
cmpq %rax, %rbx
jne 0x4926b
jmp 0x4928e
movw $0x2d, 0xb0(%rsp)
movq %rax, %rbx
leaq 0x6120c(%rip), %rdi     # 0xaa4a1
callq 0x54afc
movl %eax, %r13d
leaq 0x5c694(%rip), %rdi     # 0xa5938
callq 0x54afc
movl %eax, (%rsp)
movq %r14, %rdi
movl %ebx, %esi
movl %r13d, %edx
leaq 0xb0(%rsp), %rcx
leaq 0xac(%rsp), %r8
leaq 0xa8(%rsp), %r9
callq 0x8ec4a
movslq (%rax), %rcx
movl 0x2c(%rsp,%rcx,4), %ebx
cmpl %r15d, %ebx
je 0x4930c
movslq %ebx, %rcx
cmpl $0x0, (%r12,%rcx,4)
movq 0x88(%rsp), %r13
jne 0x49314
movl $0x1, (%r12,%rcx,4)
movq %rax, %rdi
callq 0x3a180
movl %ebx, %r15d
leaq 0x30(%rsp), %rcx
jmp 0x48fc6
movq %rax, %rdi
callq 0x3a180
movq 0x78(%rsp), %rsi
movl $0x0, (%rsi)
testl %ebp, %ebp
movq 0x60(%rsp), %rbx
js 0x49342
movl 0x28(%rsp), %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpl $0x0, (%rbx,%rdx,4)
je 0x4933a
incl %ecx
movl %ecx, (%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x49330
movq %r14, %rdi
movl $0x7, %esi
callq 0x3a14b
movq %r12, %rdi
callq 0x3a180
movq %rbx, %rdi
callq 0x3a180
movl %r15d, %eax
addq $0x6a8, %rsp            # imm = 0x6A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq