// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/model.c
// Function: mlp_model_simulation_most
int mlp_model_simulation_most(Datasetptr d, char* simulationdirectory, int maxhidden, int starthidden, int* tries, MODEL_SEARCH_DIRECTION_TYPE searchdirection)
{
 /*!Last Changed 26.05.2006 added starthidden*/
	/*!Last Changed 17.07.2005*/
	char **two_file;
	int bestmodel, *list, modelcount, i, improved = 1, bestoftwo, *bestmodels, bestmodelcount = 1, *modelstried;
	modelstried = (int *) safecalloc(maxhidden + 1, sizeof(int), "mlp_model_simulation_most", 3);
 if (starthidden < 0 || starthidden > maxhidden)
  {
  	if (searchdirection == FORWARD)
		   bestmodel = 0;
	  else
  		 bestmodel = maxhidden;
  }
 else
   bestmodel = starthidden;
	modelstried[bestmodel] = 1;
	bestmodels = safemalloc((maxhidden + 2) * sizeof(int), "mlp_model_simulation_forw1", 9);
	bestmodels[0] = bestmodel;
 two_file = (char**) safemalloc_2d(sizeof(char *), sizeof(char), 2, 500, "mlp_model_simulation_forw1", 9);
	while (improved)
	 {
		 list = generate_candidate_mlp_models(d, maxhidden, bestmodel, &modelcount, searchdirection); 
			if (searchdirection == FORWARD)
  			qsort(list, modelcount, sizeof(int), sort_function_int_ascending);
			else
				 qsort(list, modelcount, sizeof(int), sort_function_int_descending);
			improved = 0;
			for (i = 0; i < modelcount; i++)
				 if (list[i] != bestmodel)
					 {
						 modelstried[list[i]] = 1;
			  	 bestoftwo = compare_two_mlp_models(two_file, simulationdirectory, d, bestmodel, list[i]);
			  	 if ((bestmodel < list[i] && bestoftwo == 1) || (bestmodel > list[i] && bestoftwo == 0))
							 {
				  		 bestmodel = list[i];
				  			improved = 1;
				  			break;
							 }
					 }
   for (i = 0; i < bestmodelcount; i++)
				 if (bestmodels[i] == bestmodel)
					 {
						 improved = 0;
							break;
					 }
			bestmodels[bestmodelcount] = bestmodel;
			bestmodelcount++;
			safe_free(list);
	 }
	*tries = 0;
	for (i = 0; i <= maxhidden; i++)
		 if (modelstried[i])
				 (*tries)++;
	safe_free(bestmodels);
	safe_free(modelstried);
	free_2d((void**)two_file, 2);
	return bestmodel;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, %ebp
movq %r8, 0x38(%rsp)
movl %ecx, %ebx
movl %edx, %r14d
movq %rsi, 0x50(%rsp)
movq %rdi, 0x28(%rsp)
leal 0x1(%r14), %eax
movq %rax, 0x30(%rsp)
movslq %eax, %rdi
leaq 0x5ef09(%rip), %rdx     # 0xa7457
movl $0x4, %esi
movl $0x3, %ecx
callq 0x39210
testl %ebp, %ebp
movl %r14d, %ecx
movl %ebp, 0x14(%rsp)
cmovel %ebp, %ecx
leaq -0xefa1(%rip), %rdx     # 0x395cf
cmoveq 0x88a60(%rip), %rdx     # 0xd0fd8
movq %rdx, 0x40(%rsp)
cmpl %r14d, %ebx
movl %ebx, %ebp
cmovgl %ecx, %ebp
testl %ebx, %ebx
cmovsl %ecx, %ebp
movslq %ebp, %rbx
movq %rax, 0x8(%rsp)
movl $0x1, (%rax,%rbx,4)
movq %r14, 0x18(%rsp)
movslq %r14d, %rax
leaq 0x8(,%rax,4), %rdi
leaq 0x5eec1(%rip), %r15     # 0xa7471
movq %r15, %rsi
movl $0x9, %edx
callq 0x390f5
movl %ebx, (%rax)
movq %rax, %rbx
movl $0x1, %r14d
movl $0x8, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r15, %r8
movl $0x9, %r9d
callq 0x393b5
movq %rax, 0x20(%rsp)
movq %rbx, 0x48(%rsp)
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl %ebp, %edx
leaq 0x4(%rsp), %rcx
movl 0x14(%rsp), %r8d
callq 0x47f82
movq %rax, %r12
movslq 0x4(%rsp), %rsi
movl $0x4, %edx
movq %rax, %rdi
movq 0x40(%rsp), %rcx
callq 0x4240
cmpl $0x0, 0x4(%rsp)
jle 0x48696
xorl %ebx, %ebx
movslq (%r12,%rbx,4), %rax
cmpl %ebp, %eax
je 0x48689
movq 0x8(%rsp), %rcx
movl $0x1, (%rcx,%rax,4)
movl (%r12,%rbx,4), %r8d
movq 0x20(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl %ebp, %ecx
callq 0x48732
movl (%r12,%rbx,4), %r15d
cmpl %r15d, %ebp
setl %cl
cmpl $0x1, %eax
sete %dl
movl $0x1, %r13d
testb %dl, %cl
jne 0x4869c
cmpl %r15d, %ebp
setg %cl
testl %eax, %eax
sete %al
testb %al, %cl
jne 0x4869c
incq %rbx
movslq 0x4(%rsp), %rax
cmpq %rax, %rbx
jl 0x48632
xorl %r13d, %r13d
movl %ebp, %r15d
xorl %eax, %eax
movq 0x48(%rsp), %rbx
cmpl %r15d, (%rbx,%rax,4)
je 0x486b3
incq %rax
cmpq %rax, %r14
jne 0x486a3
jmp 0x486b6
xorl %r13d, %r13d
movl %r15d, (%rbx,%r14,4)
incq %r14
movq %r12, %rdi
callq 0x39194
movl %r15d, %ebp
testl %r13d, %r13d
jne 0x485f4
movq 0x38(%rsp), %rcx
movl $0x0, (%rcx)
cmpl $0x0, 0x18(%rsp)
movq 0x30(%rsp), %rdx
js 0x486ff
xorl %eax, %eax
movq 0x8(%rsp), %rsi
cmpl $0x0, (%rsi,%rax,4)
je 0x486f7
incl (%rcx)
incq %rax
cmpq %rax, %rdx
jne 0x486ef
movq %rbx, %rdi
callq 0x39194
movq 0x8(%rsp), %rdi
callq 0x39194
movq 0x20(%rsp), %rdi
movl $0x2, %esi
callq 0x3915f
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq