// File: /workspace/github_c_makefile_star2_O1/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, 0xc8(%rsp)
movq %rcx, 0xc0(%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 0x43f69
leaq 0x100(%rsp), %rdi
movq %rax, 0xb8(%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 0x43f69
movq %rax, 0xb0(%rsp)
leaq 0x190(%rsp), %r12
movl $0x90, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x4310
movslq 0x54(%r12), %r12
testq %r12, %r12
jle 0x42bcf
movq %r12, %rdi
shlq $0x4, %rdi
leaq 0x6476e(%rip), %rsi     # 0xa7305
movl $0x4, %edx
callq 0x390f5
movq %rax, %rbx
shlq $0x2, %r12
xorl %r13d, %r13d
movl 0x1d8(%rsp,%r13), %esi
movl $0x1, %edi
callq 0x3c6e5
movq %rax, (%rbx,%r13,4)
movq %rdx, 0x8(%rbx,%r13,4)
addq $0x4, %r13
cmpq %r13, %r12
jne 0x42bab
movq 0xa8(%rsp), %r15
movsd 0x20(%r14), %xmm0
movsd %xmm0, 0x38(%r14)
movq (%rbp), %rdi
cmpl $0x0, 0x14(%r14)
movq %rbp, 0xd8(%rsp)
jle 0x42f7d
leaq 0x8(%rbp), %rax
movq %rax, 0xe0(%rsp)
xorl %eax, %eax
movq %rdi, %rbp
movq %rax, 0xd0(%rsp)
movl 0x8(%r14), %edi
callq 0x39fdc
movq %rax, %r13
cmpl $0x0, 0x8(%r14)
jle 0x42d02
xorpd %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
xorl %r12d, %r12d
movl 0x2f0(%rsp), %ecx
movslq (%r13,%r12,4), %rax
movq (%r15,%rax,8), %rax
cmpl $0x1, %ecx
je 0x42c7f
cmpl $0x2, %ecx
jne 0x42caa
movl $0x12, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
movq 0xb8(%rsp), %rsi
movq %rbx, %rdx
movq 0xb0(%rsp), %rcx
callq 0x44d5d
jmp 0x42cd3
movl $0x12, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
movq 0xb8(%rsp), %rsi
movq %rbx, %rdx
movq 0xb0(%rsp), %rcx
callq 0x44a32
jmp 0x42cd3
movl $0x12, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
movq 0xb8(%rsp), %rsi
movq %rbx, %rdx
movq 0xb0(%rsp), %rcx
callq 0x447e6
movsd 0xa0(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0xa0(%rsp)
incq %r12
movslq 0x8(%r14), %rax
cmpq %rax, %r12
movl 0x2f0(%rsp), %ecx
jl 0x42c41
jmp 0x42d0f
xorpd %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
movq %r13, %rdi
callq 0x39194
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%r14), %xmm0
movsd 0xa0(%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 0x100(%rsp), %rdi
movq %r14, %rsi
callq 0x4310
movl 0x2f0(%rsp), %eax
movl $0x13, %ecx
movq %rsp, %rdi
leaq 0xf8(%rsp), %rsi
cmpl $0x1, %eax
je 0x42d98
cmpl $0x2, %eax
jne 0x42db2
rep  movsq (%rsi), %es:(%rdi)
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0x45686
jmp 0x42de9
rep  movsq (%rsi), %es:(%rdi)
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0x43163
jmp 0x42de9
rep  movsq (%rsi), %es:(%rdi)
movq 0xc0(%rsp), %r15
movq %r15, %rdi
movq 0xc8(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
callq 0x43012
movl %r15d, %ecx
movq 0xa8(%rsp), %r15
subl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movq 0xd0(%rsp), %rax
testl %eax, %eax
movsd 0xe8(%rsp), %xmm1
je 0x42eaa
movq %rbp, %rdi
ucomisd %xmm0, %xmm1
jbe 0x42f64
movsd %xmm0, 0xa0(%rsp)
movl %eax, 0x18(%r14)
movq 0xd8(%rsp), %rax
movl 0x5c(%rax), %esi
callq 0x442c9
movl $0x98, %edx
leaq 0x190(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x4310
movl $0x12, %ecx
movq %rsp, %rdi
leaq 0x198(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %edi, %edi
xorl %esi, %esi
callq 0x43f69
movq %rax, %rbp
movl 0x1ec(%rsp), %r12d
testl %r12d, %r12d
js 0x42f2c
movq 0x190(%rsp), %r13
shlq $0x4, %r12
addq $0x10, %r12
xorl %r15d, %r15d
leaq (%r15,%rbp), %rdi
movq (%r13,%r15), %rsi
movq 0x8(%r13,%r15), %rdx
callq 0x3f37d
addq $0x10, %r15
cmpq %r15, %r12
jne 0x42e89
jmp 0x42f2c
movsd %xmm0, 0xa0(%rsp)
movl %eax, 0x18(%r14)
movl $0x98, %edx
leaq 0x190(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x4310
movl $0x12, %ecx
movq %rsp, %rdi
leaq 0x198(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %edi, %edi
xorl %esi, %esi
callq 0x43f69
movq %rax, %rbp
movl 0x1ec(%rsp), %r12d
testl %r12d, %r12d
js 0x42f2c
movq 0x190(%rsp), %r13
shlq $0x4, %r12
addq $0x10, %r12
xorl %r15d, %r15d
leaq (%r15,%rbp), %rdi
movq (%r13,%r15), %rsi
movq 0x8(%r13,%r15), %rdx
callq 0x3f37d
addq $0x10, %r15
cmpq %r15, %r12
jne 0x42f10
movl $0x90, %edx
movq 0xe0(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x4310
movq 0xa8(%rsp), %r15
movq 0xd0(%rsp), %rax
movq %rbp, %rdi
movsd 0xa0(%rsp), %xmm0
jmp 0x42f68
movapd %xmm1, %xmm0
incl %eax
movsd %xmm0, 0xe8(%rsp)
cmpl 0x14(%r14), %eax
jl 0x42c08
movq 0xd8(%rsp), %r15
movq %rdi, (%r15)
movl 0x54(%r14), %esi
movq 0xb0(%rsp), %rdi
callq 0x442c9
movl 0x54(%r14), %esi
movq %rbx, %rdi
callq 0x44307
movl 0x154(%rsp), %esi
movq 0xb8(%rsp), %rdi
callq 0x442c9
movq %r15, %rax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq