// File: /workspace/github_c_makefile_star2_O1/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 $0x698, %rsp            # imm = 0x698
movq %r8, 0x70(%rsp)
movl %edx, %r12d
movq %rsi, 0x8(%rsp)
xorl %eax, %eax
testl %ecx, %ecx
movl $0x0, %r15d
cmovgl %ecx, %r15d
movq %rdi, %r14
cmpl %edx, %ecx
cmovgl %eax, %r15d
leaq 0x5f8c9(%rip), %r13     # 0xa740a
movl $0x8, %edi
movl $0x1, %esi
movl $0x7, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r13, %r8
movl $0x3, %r9d
callq 0x393b5
movq %rax, %rbp
leal 0x1(%r12), %eax
movq %rax, 0x68(%rsp)
movslq %eax, %rbx
movl $0x4, %esi
movq %rbx, %rdi
movq %r13, %rdx
movl $0x4, %ecx
callq 0x39210
movl $0x4, %esi
movq %rbx, %rdi
movq %r13, %rdx
movq %rax, %r13
movl $0x5, %ecx
callq 0x39210
movl $0x1, %ebx
movq %r13, 0x60(%rsp)
movl %ebx, (%r13,%r15,4)
movq %rax, 0x58(%rsp)
movl %ebx, (%rax,%r15,4)
movq 0x8(%r14), %rcx
leaq 0x5c64b(%rip), %rsi     # 0xa420e
leaq 0x2a0(%rsp), %rdi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x41b0
movq %r14, 0x50(%rsp)
movl 0x10(%r14), %r14d
cmpl %ebx, %r14d
adcl $0x0, %r14d
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x78(%rsp)
leal (%r14,%r14), %eax
cmpl %r12d, %eax
cmovgel %r12d, %eax
movl %eax, 0x2c(%rsp)
leaq 0x30(%rsp), %rcx
movq %rbp, 0x20(%rsp)
movq %r12, 0x10(%rsp)
movl $0x0, 0x1c(%rsp)
movq %rbp, %rdi
leaq 0x2a0(%rsp), %rbx
movq %rbx, %rsi
movl %r15d, %edx
leaq 0x1c(%rsp), %r13
movq %r13, %r8
callq 0x4772c
testl %r15d, %r15d
je 0x47cd2
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x8(%rsp)
movl %r12d, %edx
cmpl %r12d, %r15d
jge 0x47c8d
leal 0x1(%r15), %edx
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x30(%rsp), %rcx
movq %r13, %r8
callq 0x4772c
movsd 0x8(%rsp), %xmm0
mulsd 0x5b166(%rip), %xmm0    # 0xa2de0
movsd 0x78(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl %r12d, %edx
jb 0x47c8d
cvttsd2si %xmm0, %edx
movq %rbp, %rdi
movq %rbx, %rsi
movq %rbx, %r12
leaq 0x30(%rsp), %rbx
movq %rbx, %rcx
movq %r13, %r8
callq 0x4772c
leal -0x1(%r15), %edx
movq %rbp, %rdi
movq %r12, %rsi
movq %rbx, %rcx
movq %r13, %r8
callq 0x4772c
movsd 0x8(%rsp), %xmm0
mulsd 0x5b04f(%rip), %xmm0    # 0xa2d18
cvttsd2si %xmm0, %edx
jmp 0x47d67
movl %r12d, %edx
cmpl %r12d, %r14d
jg 0x47cf4
movq %rbp, %rdi
movq %rbx, %rsi
movl %r14d, %edx
leaq 0x30(%rsp), %rcx
movq %r13, %r8
callq 0x4772c
movl 0x2c(%rsp), %edx
movq %rbp, %rdi
movq %rbx, %rsi
movq %rbx, %r12
leaq 0x30(%rsp), %rbx
movq %rbx, %rcx
movq %r13, %r8
callq 0x4772c
movq 0x50(%rsp), %rax
movl 0x1c0(%rax), %ecx
leal (%rcx,%r14), %eax
addl $0x3, %eax
addl %r14d, %ecx
cmovnsl %ecx, %eax
sarl $0x2, %eax
movq 0x10(%rsp), %rcx
movl %ecx, %edx
cmpl %ecx, %eax
jg 0x47d67
movq %rbp, %rdi
movq %r12, %rsi
movl %eax, %edx
movq %rbx, %rcx
movq %r13, %r8
callq 0x4772c
movq 0x50(%rsp), %rax
movl 0x1c0(%rax), %eax
addl %r14d, %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
movq 0x10(%rsp), %rax
cmpl %eax, %edx
cmovgel %eax, %edx
movq %rbp, %rdi
movq %r12, %rsi
movq %rbx, %rcx
movq %r13, %r8
callq 0x4772c
movl 0x1c(%rsp), %eax
cmpq $0x1, %rax
movq 0x60(%rsp), %r13
movq 0x10(%rsp), %r12
je 0x47f24
movq %r15, 0x80(%rsp)
testl %eax, %eax
movq %rax, %r15
jle 0x47e5d
movq %r15, %rdx
leaq 0x30(%rsp), %rbx
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movq %r15, 0x88(%rsp)
leaq 0x1(%r13), %rax
movq %rax, 0x90(%rsp)
cmpq %r15, %rax
jae 0x47e37
movl $0x1, %ebp
movl 0x30(%rsp,%r13,4), %eax
movl (%rbx,%rbp,4), %ecx
cmpl %ecx, %eax
jle 0x47e2f
movl %ecx, 0x30(%rsp,%r13,4)
movl %eax, (%rbx,%rbp,4)
movq %r14, %r12
movq 0x20(%rsp), %r14
movq (%r14,%r13,8), %rsi
leaq 0x4a0(%rsp), %rdi
movq %rdx, %r15
callq 0x4270
movq (%r14,%r13,8), %rdi
movq %r12, %r14
movq 0x8(%rsp), %r12
movq (%r12,%rbp,8), %rsi
callq 0x4270
movq (%r12,%rbp,8), %rdi
leaq 0x4a0(%rsp), %rsi
callq 0x4270
movq %r15, %rdx
incq %rbp
cmpq %rbp, %rdx
jne 0x47dd6
addq $0x8, 0x8(%rsp)
addq $0x4, %rbx
decq %rdx
movq 0x88(%rsp), %r15
movq 0x90(%rsp), %r13
cmpq %r15, %r13
jne 0x47dc0
movw $0x2d, 0xa0(%rsp)
testl %r15d, %r15d
movq 0x58(%rsp), %rdx
jle 0x47e87
xorl %eax, %eax
movslq 0x30(%rsp,%rax,4), %rcx
movl $0x1, (%rdx,%rcx,4)
incq %rax
cmpq %rax, %r15
jne 0x47e73
leaq 0x5f573(%rip), %rdi     # 0xa7401
callq 0x535f7
movl %eax, %r12d
leaq 0x5aa9b(%rip), %rdi     # 0xa2938
callq 0x535f7
movl %eax, (%rsp)
movq %r15, %rsi
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
movl %r12d, %edx
leaq 0xa0(%rsp), %rcx
leaq 0x9c(%rsp), %r8
leaq 0x98(%rsp), %r9
callq 0x8c4bc
movslq (%rax), %rcx
movl 0x2c(%rsp,%rcx,4), %ebx
movq 0x80(%rsp), %r15
cmpl %r15d, %ebx
movq 0x60(%rsp), %r13
je 0x47f17
movslq %ebx, %rcx
cmpl $0x0, (%r13,%rcx,4)
movq 0x10(%rsp), %r12
jne 0x47f24
movl $0x1, (%r13,%rcx,4)
movq %rax, %rdi
callq 0x39194
movl %ebx, %r15d
leaq 0x30(%rsp), %rcx
jmp 0x47c10
movq %rax, %rdi
callq 0x39194
movq 0x10(%rsp), %r12
movq 0x70(%rsp), %rcx
movl $0x0, (%rcx)
testl %r12d, %r12d
movq 0x68(%rsp), %rdx
movq 0x58(%rsp), %rbx
js 0x47f50
xorl %eax, %eax
cmpl $0x0, (%rbx,%rax,4)
je 0x47f48
incl (%rcx)
incq %rax
cmpq %rax, %rdx
jne 0x47f40
movq %rbp, %rdi
movl $0x7, %esi
callq 0x3915f
movq %r13, %rdi
callq 0x39194
movq %rbx, %rdi
callq 0x39194
movl %r15d, %eax
addq $0x698, %rsp            # imm = 0x698
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq