// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/mlp.c
// Function: mlpn_general
Mlpnetwork mlpn_general(matrix Train, matrix Validation, Mlpparametersptr P, SUPERVISED_ALGORITHM_TYPE algorithm_type)
{
	int iindex, tr, k;
	double sqrdError = 0, minError, cvError, loglikelihood;
	int *I;
	Mlpnetwork nN, minN;
	matrixptr prevWeights;
	matrixptr H;
	nN = allocate_mlpnnetwork(*P);
	prevWeights = allocate_weights(*P, INITIAL_VALUE, 0);
	H = allocate_hiddens(*P);
	P->eta = P->initialeta;
	for (tr = 0; tr < P->epochs; tr++)
  {
   sqrdError = 0;
   I = random_array(P->inputnum);
   for (k = 0; k < P->inputnum; k++)
    {
     iindex = I[k];
     switch (algorithm_type)
      {
       case CLASSIFICATION:
       default            :sqrdError = sqrdError + backPropMlpn_cls(Train.values[iindex], nN.weights, H, prevWeights, *P);
                           break;
       case REGRESSION    :sqrdError = sqrdError + backPropMlpn_reg(Train.values[iindex], nN.weights, H, prevWeights, *P);
                           break;
       case AUTOENCODER   :sqrdError = sqrdError + backPropMlpn_autoencoder(Train.values[iindex], nN.weights, H, prevWeights, *P);
                           break;
      }
    }
   safe_free(I);
   sqrdError = sqrdError / P->inputnum;
   P->sqrderror = sqrdError;
   P->eta = P->eta * P->etadecrease;
   /*check validation data and update the best network if necessary*/
   nN.P = *P;
   switch (algorithm_type)
    {
     case CLASSIFICATION:
     default            :cvError = Validation.row - testMlpnNetwork_cls(Validation, nN, &loglikelihood);
                         break;
     case REGRESSION    :cvError = testMlpnNetwork_reg(Validation, nN);
                         break;
     case AUTOENCODER   :cvError = testMlpnNetwork_autoencoder(Validation, nN);
                         break;
    }
   if (tr > 0)
    {
     if (cvError < minError)
      {
       P->bestepoch = tr;
       minError = cvError;
       free_mlpnnetwork(&minN);
       minN = copy_of_Mlpnetwork(nN);
      }
    }
   else
    {
     P->bestepoch = tr;
     minError = cvError;
     minN = copy_of_Mlpnetwork(nN);
    }
  }
	free_weights(prevWeights, P->layernum);
	free_hiddens(H, P->layernum);
	free_mlpnnetwork(&nN);
 return minN;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %r9, %r14
movq %r8, 0xd0(%rsp)
movq %rcx, 0xc8(%rsp)
movq %rdx, 0xa8(%rsp)
movq %rdi, %rbp
leaq 0x228(%rsp), %r15
movl $0x90, %edx
movq %r15, %rdi
movq %r9, %rsi
callq 0x4310
movl $0x12, %ecx
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
callq 0x452e5
leaq 0x198(%rsp), %rdi
movq %rax, 0xc0(%rsp)
movq %rax, -0x8(%rdi)
movl $0x90, %edx
movq %r15, %rsi
callq 0x4310
movl $0x12, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %edi
xorl %esi, %esi
callq 0x452e5
movq %rax, 0xb8(%rsp)
leaq 0xf8(%rsp), %r12
movl $0x90, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x4310
movslq 0x54(%r12), %r12
testq %r12, %r12
jle 0x43f3b
movq %r12, %rdi
shlq $0x4, %rdi
leaq 0x664a2(%rip), %rsi     # 0xaa3a5
movl $0x4, %edx
callq 0x3a0e1
movq %rax, %rbx
shlq $0x2, %r12
xorl %r13d, %r13d
movl 0x140(%rsp,%r13), %esi
movl $0x1, %edi
callq 0x3d79d
movq %rax, (%rbx,%r13,4)
movq %rdx, 0x8(%rbx,%r13,4)
addq $0x4, %r13
cmpq %r13, %r12
jne 0x43f17
movq 0xa8(%rsp), %r15
movsd 0x20(%r14), %xmm0
movsd %xmm0, 0x38(%r14)
movq (%rbp), %rax
movq %rax, 0xa0(%rsp)
cmpl $0x0, 0x14(%r14)
movq %rbp, 0xd8(%rsp)
jle 0x442fb
movq %rbp, %rax
movl 0x2f0(%rsp), %ebp
addq $0x8, %rax
movq %rax, 0xe0(%rsp)
movq $0x0, 0xb0(%rsp)
movl 0x8(%r14), %edi
callq 0x3afe4
movq %rax, %r13
cmpl $0x0, 0x8(%r14)
jle 0x4405b
xorpd %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
xorl %r12d, %r12d
movslq (%r13,%r12,4), %rax
movq (%r15,%rax,8), %rax
movl $0x12, %ecx
movq %rsp, %rdi
movq %r14, %rsi
cmpl $0x1, %ebp
je 0x43ff5
cmpl $0x2, %ebp
jne 0x44015
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
movq 0xc0(%rsp), %rsi
movq %rbx, %rdx
movq 0xb8(%rsp), %rcx
callq 0x46115
jmp 0x44033
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
movq 0xc0(%rsp), %rsi
movq %rbx, %rdx
movq 0xb8(%rsp), %rcx
callq 0x45dea
jmp 0x44033
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
movq 0xc0(%rsp), %rsi
movq %rbx, %rdx
movq 0xb8(%rsp), %rcx
callq 0x45ba8
movsd 0x98(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x98(%rsp)
incq %r12
movslq 0x8(%r14), %rax
cmpq %rax, %r12
jl 0x43fb7
jmp 0x44068
xorpd %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
movq %r13, %rdi
callq 0x3a180
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%r14), %xmm0
movsd 0x98(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x88(%r14)
movsd 0x38(%r14), %xmm0
mulsd 0x40(%r14), %xmm0
movsd %xmm0, 0x38(%r14)
movl $0x90, %edx
leaq 0x198(%rsp), %rdi
movq %r14, %rsi
callq 0x4310
movl $0x13, %ecx
movq %rsp, %rdi
leaq 0x190(%rsp), %rsi
cmpl $0x1, %ebp
je 0x440ea
cmpl $0x2, %ebp
jne 0x44108
rep  movsq (%rsi), %es:(%rdi)
movq 0xc8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x46a32
jmp 0x44102
rep  movsq (%rsi), %es:(%rdi)
movq 0xc8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x444e9
movapd %xmm0, %xmm1
jmp 0x4413f
rep  movsq (%rsi), %es:(%rdi)
movq 0xc8(%rsp), %r15
movq %r15, %rdi
movq 0xd0(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
callq 0x44398
movl %r15d, %ecx
movq 0xa8(%rsp), %r15
subl %eax, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
cmpl $0x0, 0xb0(%rsp)
je 0x44218
movsd 0xe8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x442df
movsd %xmm1, 0x98(%rsp)
movq 0xb0(%rsp), %rax
movl %eax, 0x18(%r14)
movq 0xd8(%rsp), %rax
movl 0x5c(%rax), %esi
movq 0xa0(%rsp), %rdi
callq 0x45654
movl $0x98, %edx
leaq 0xf8(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x4310
movl $0x12, %ecx
movq %rsp, %rdi
leaq 0x100(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %edi, %edi
xorl %esi, %esi
callq 0x452e5
movl 0x154(%rsp), %r12d
testl %r12d, %r12d
movq %rax, 0xa0(%rsp)
js 0x442ab
movq 0xf8(%rsp), %r13
shlq $0x4, %r12
addq $0x10, %r12
xorl %r15d, %r15d
leaq (%rax,%r15), %rdi
movq (%r13,%r15), %rsi
movq 0x8(%r13,%r15), %rdx
callq 0x406d5
movq 0xa0(%rsp), %rax
addq $0x10, %r15
cmpq %r15, %r12
jne 0x441ef
jmp 0x442ab
movsd %xmm1, 0x98(%rsp)
movl $0x0, 0x18(%r14)
movl $0x98, %edx
leaq 0xf8(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x4310
movl $0x12, %ecx
movq %rsp, %rdi
leaq 0x100(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %edi, %edi
xorl %esi, %esi
callq 0x452e5
movl 0x154(%rsp), %r12d
testl %r12d, %r12d
movq %rax, 0xa0(%rsp)
js 0x442ab
movq 0xf8(%rsp), %r13
shlq $0x4, %r12
addq $0x10, %r12
xorl %r15d, %r15d
leaq (%rax,%r15), %rdi
movq (%r13,%r15), %rsi
movq 0x8(%r13,%r15), %rdx
callq 0x406d5
movq 0xa0(%rsp), %rax
addq $0x10, %r15
cmpq %r15, %r12
jne 0x44287
movl $0x90, %edx
movq 0xe0(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x4310
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movq 0xa8(%rsp), %r15
movq 0xb0(%rsp), %rax
incl %eax
movq %rax, 0xb0(%rsp)
cmpl 0x14(%r14), %eax
jl 0x43f90
movq 0xd8(%rsp), %r15
movq 0xa0(%rsp), %rax
movq %rax, (%r15)
movl 0x54(%r14), %esi
movq 0xb8(%rsp), %rdi
callq 0x45654
movl 0x54(%r14), %esi
movq %rbx, %rdi
callq 0x45692
movl 0x1ec(%rsp), %esi
movq 0xc0(%rsp), %rdi
callq 0x45654
movq %r15, %rax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq