// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl $0x1, -0x4c(%rbp)
movl $0x1, -0x5c(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x4, %esi
leaq 0x7de26(%rip), %rdx     # 0xe7017
movl $0x3, %ecx
callq 0x52f40
movq %rax, -0x68(%rbp)
cmpl $0x0, -0x18(%rbp)
jl 0x6920d
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0x69224
cmpl $0x0, -0x24(%rbp)
jne 0x6921c
movl $0x0, -0x34(%rbp)
jmp 0x69222
movl -0x14(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x6922a
movl -0x18(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x68(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0x7dde4(%rip), %rsi     # 0xe7031
movl $0x9, %edx
callq 0x52d70
movq %rax, -0x58(%rbp)
movl -0x34(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, (%rax)
movl $0x8, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
leaq 0x7ddb2(%rip), %r8      # 0xe7031
movl $0x9, %r9d
callq 0x53120
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x69400
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x34(%rbp), %edx
movl -0x24(%rbp), %r8d
leaq -0x44(%rbp), %rcx
callq 0x68990
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x692d4
movq -0x40(%rbp), %rdi
movslq -0x44(%rbp), %rsi
movl $0x4, %edx
leaq -0x15e8d(%rip), %rcx    # 0x53440
callq 0x41f0
jmp 0x692ed
movq -0x40(%rbp), %rdi
movslq -0x44(%rbp), %rsi
movl $0x4, %edx
leaq -0x15e58(%rip), %rcx    # 0x53490
callq 0x41f0
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x693a6
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x34(%rbp), %eax
je 0x69396
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq -0x48(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl $0x1, (%rax,%rcx,4)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rdx
movl -0x34(%rbp), %ecx
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %r8
movl (%rax,%r8,4), %r8d
callq 0x69470
movl %eax, -0x50(%rbp)
movl -0x34(%rbp), %eax
movq -0x40(%rbp), %rcx
movslq -0x48(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x69367
cmpl $0x1, -0x50(%rbp)
je 0x6937d
movl -0x34(%rbp), %eax
movq -0x40(%rbp), %rcx
movslq -0x48(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x69394
cmpl $0x0, -0x50(%rbp)
jne 0x69394
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x693a6
jmp 0x69396
jmp 0x69398
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x692fb
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x693db
movq -0x58(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x34(%rbp), %eax
jne 0x693ce
movl $0x0, -0x4c(%rbp)
jmp 0x693db
jmp 0x693d0
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x693ad
movl -0x34(%rbp), %edx
movq -0x58(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x40(%rbp), %rdi
callq 0x52e80
jmp 0x6928e
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x6943f
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x69432
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x69434
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x69411
movq -0x58(%rbp), %rdi
callq 0x52e80
movq -0x68(%rbp), %rdi
callq 0x52e80
movq -0x30(%rbp), %rdi
movl $0x2, %esi
callq 0x52e20
movl -0x34(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)