// File: /workspace/github_c_makefile_star2_O2/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 $0x688, %rsp            # imm = 0x688
movq %r8, 0x68(%rsp)
movl %edx, %r12d
movq %rsi, 0x10(%rsp)
xorl %eax, %eax
testl %ecx, %ecx
movl $0x0, %ebx
cmovgl %ecx, %ebx
movq %rdi, %r14
cmpl %edx, %ecx
cmovgl %eax, %ebx
leaq 0x582ae(%rip), %r13     # 0x9a3da
pushq $0x8
popq %rdi
pushq $0x1
popq %rsi
pushq $0x7
popq %rdx
pushq $0x3
popq %r9
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r13, %r8
callq 0x351c3
movq %rax, %r15
leal 0x1(%r12), %eax
movslq %eax, %rbp
pushq $0x4
popq %rsi
pushq $0x4
popq %rcx
movq %rbp, %rdi
movq %r13, %rdx
callq 0x35067
movq %rax, %r13
pushq $0x5
popq %rcx
movq %rbp, %rdi
movq %rbx, %rbp
pushq $0x4
popq %rsi
leaq 0x58262(%rip), %rdx     # 0x9a3da
callq 0x35067
pushq $0x1
popq %rbx
movq %r13, 0x20(%rsp)
movl %ebx, (%r13,%rbp,4)
movq %rax, 0x58(%rsp)
movl %ebx, (%rax,%rbp,4)
movq 0x8(%r14), %rcx
leaq 0x55053(%rip), %rsi     # 0x971f0
leaq 0x290(%rsp), %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x41b0
movq %r14, 0x50(%rsp)
movl 0x10(%r14), %eax
cmpl %ebx, %eax
movq %r12, %rcx
movq %rax, %r12
adcl $0x0, %r12d
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x70(%rsp)
leal (%r12,%r12), %eax
cmpl %ecx, %eax
movq %rcx, 0x8(%rsp)
cmovgel %ecx, %eax
movl %eax, 0x2c(%rsp)
leaq 0x490(%rsp), %r13
movq %r12, 0x78(%rsp)
andl $0x0, 0x1c(%rsp)
movq %r15, %rdi
leaq 0x290(%rsp), %rsi
movq %rsi, %rbx
movl %ebp, %edx
leaq 0x30(%rsp), %rcx
leaq 0x1c(%rsp), %r14
movq %r14, %r8
callq 0x41d0e
testl %ebp, %ebp
movq %rbp, 0x60(%rsp)
je 0x42277
movq 0x8(%rsp), %rdx
cmpl %edx, %ebp
jge 0x4230e
leal 0x1(%rbp), %edx
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x30(%rsp), %r12
movq %r12, %rcx
movq %r14, %r8
callq 0x41d0e
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x10(%rsp)
mulsd 0x53b91(%rip), %xmm0    # 0x95de8
movsd 0x70(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x42325
movq %r15, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
jmp 0x4232f
movq 0x8(%rsp), %rax
movl %eax, %edx
cmpl %eax, %r12d
jg 0x4229d
movq %r15, %rdi
movq %rbx, %rsi
movl %r12d, %edx
leaq 0x30(%rsp), %rcx
movq %r14, %r8
callq 0x41d0e
movl 0x2c(%rsp), %edx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rbp
leaq 0x30(%rsp), %r14
movq %r14, %rcx
movq %rbp, %r8
callq 0x41d0e
movq 0x50(%rsp), %rax
movl 0x1c0(%rax), %eax
addl %r12d, %eax
cltd
pushq $0x4
popq %rcx
idivl %ecx
movq 0x8(%rsp), %rcx
movl %ecx, %edx
cmpl %ecx, %eax
jg 0x42366
movq %r15, %rdi
movq %rbx, %rsi
movl %eax, %edx
movq %r14, %rcx
movq %rbp, %r8
callq 0x41d0e
movq 0x50(%rsp), %rax
movl 0x1c0(%rax), %eax
addl %r12d, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movq 0x8(%rsp), %rcx
movl %eax, %edx
cmpl %ecx, %eax
cmovgel %ecx, %edx
jmp 0x42366
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x30(%rsp), %r12
jmp 0x4232f
cvttsd2si %xmm0, %edx
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rcx
movq %r14, %r8
callq 0x41d0e
leal -0x1(%rbp), %edx
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rcx
movq %r14, %r8
callq 0x41d0e
movsd 0x10(%rsp), %xmm0
mulsd 0x539c4(%rip), %xmm0    # 0x95d20
cvttsd2si %xmm0, %edx
movq %r14, %rbp
movq %r12, %r14
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rcx
movq %rbp, %r8
callq 0x41d0e
movl 0x1c(%rsp), %r14d
cmpl $0x1, %r14d
movq 0x60(%rsp), %rbp
je 0x424b6
movl $0x0, %esi
cmovgel %r14d, %esi
xorl %ebp, %ebp
pushq $0x1
popq %rbx
movq %rsi, 0x80(%rsp)
cmpq %rsi, %rbp
je 0x42405
movq %rbx, 0x10(%rsp)
cmpl %ebx, %r14d
jle 0x423f0
movl 0x30(%rsp,%rbp,4), %eax
movl 0x30(%rsp,%rbx,4), %ecx
cmpl %ecx, %eax
jle 0x423eb
movl %ecx, 0x30(%rsp,%rbp,4)
movl %eax, 0x30(%rsp,%rbx,4)
movq (%r15,%rbp,8), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x4270
movq (%r15,%rbx,8), %rsi
movq %r12, %rdi
callq 0x4270
movq (%r15,%rbx,8), %rdi
movq %r13, %rsi
callq 0x4270
incq %rbx
jmp 0x423ab
incq %rbp
movq 0x10(%rsp), %rbx
incq %rbx
movq 0x80(%rsp), %rsi
jmp 0x423a1
movw $0x2d, 0x90(%rsp)
xorl %eax, %eax
movq 0x60(%rsp), %rbp
movq 0x58(%rsp), %rdx
cmpq %rax, %rsi
je 0x42431
movslq 0x30(%rsp,%rax,4), %rcx
movl $0x1, (%rdx,%rcx,4)
incq %rax
jmp 0x4241b
leaq 0x57f99(%rip), %rdi     # 0x9a3d1
callq 0x4cf11
movl %eax, %r12d
leaq 0x534f1(%rip), %rdi     # 0x95938
callq 0x4cf11
movl %eax, (%rsp)
movq %r15, %rdi
movl %r14d, %esi
movl %r12d, %edx
leaq 0x90(%rsp), %rcx
leaq 0x8c(%rsp), %r8
leaq 0x88(%rsp), %r9
callq 0x81133
movslq (%rax), %rcx
movl 0x2c(%rsp,%rcx,4), %ebx
cmpl %ebp, %ebx
je 0x424ae
movslq %ebx, %rcx
movq 0x20(%rsp), %rdx
cmpl $0x0, (%rdx,%rcx,4)
movq 0x78(%rsp), %r12
jne 0x424b6
movq 0x20(%rsp), %rdx
movl $0x1, (%rdx,%rcx,4)
movq %rax, %rdi
callq 0x34ff7
movl %ebx, %ebp
jmp 0x421ef
movq %rax, %rdi
callq 0x34ff7
movq 0x68(%rsp), %rsi
andl $0x0, (%rsi)
movslq 0x8(%rsp), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x58(%rsp), %rbx
cmpq %rax, %rdx
jg 0x424e0
cmpl $0x0, (%rbx,%rdx,4)
je 0x424db
incl %ecx
movl %ecx, (%rsi)
incq %rdx
jmp 0x424cc
pushq $0x7
popq %rsi
movq %r15, %rdi
callq 0x34fc3
movq 0x20(%rsp), %rdi
callq 0x34ff7
movq %rbx, %rdi
callq 0x34ff7
movl %ebp, %eax
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq