// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/mlp.c
// Function: backPropMlpn_autoencoder
double backPropMlpn_autoencoder(double *Train, matrixptr weights, matrixptr hidden, matrixptr prevWeights, Mlpparameters P)
{
	matrix output_error, Y;
	matrixptr dweights;
	double sqrderror;
 int li;
	output_error = matrix_alloc(1, P.classnum);
	Y = matrix_alloc(1, P.classnum);
	dweights = allocate_weights(P, NO_INITIALIZATION, 0);/*dweights has the same dimensions as weights*/
	/*calculate hidden layers*/
	for (li = 0; li < P.layernum; li++)
  {
   if (li == 0)
     calculate_hidden_values(Train, weights[0], &hidden[0]);
   else
     calculate_hidden_values(hidden[li-1].values[0], weights[li], &hidden[li]);
  }
 calculate_output_values_reg(hidden[P.layernum-1].values[0], weights[P.layernum], &Y);
	sqrderror = calculate_error_values_autoencoder(Train, Y, &output_error); 	/*calculate error*/
	calculate_change_in_weights(Train, weights, hidden, dweights, output_error, P); 	/*calculate the change in weights*/
	update_weights(weights, dweights, prevWeights, P); 	/*add the change and momentum value to weights*/
	/*update prevWeights*/
	for (li = 0; li < (P.layernum + 1); li++)
   matrix_identical(&(prevWeights[li]), dweights[li]);
	matrix_free(output_error);
	matrix_free(Y);
	free_weights(dweights, P.layernum);
	return sqrderror;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rcx, 0xc0(%rsp)
movq %rdx, %rbp
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x100(%rsp), %r14
movl (%r14), %r15d
movl $0x1, %edi
movl %r15d, %esi
callq 0x3d79d
movq %rax, 0xb8(%rsp)
movq %rdx, 0xa8(%rsp)
movl $0x1, %edi
movl %r15d, %esi
callq 0x3d79d
movq %rax, 0xb0(%rsp)
movq %rdx, 0x90(%rsp)
movl $0x12, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x2, %edi
xorl %esi, %esi
callq 0x452e5
movq %rax, %r15
movslq 0x54(%r14), %rax
movq %rax, 0x98(%rsp)
testq %rax, %rax
jle 0x461f2
movq 0x98(%rsp), %r12
shlq $0x4, %r12
xorl %r14d, %r14d
testq %r14, %r14
je 0x461d6
leaq (%r14,%rbp), %rcx
movq -0x8(%rbp,%r14), %rax
movq (%rax), %rdi
movq (%r13,%r14), %rsi
movq 0x8(%r13,%r14), %rdx
jmp 0x461e4
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rbx, %rdi
movq %rbp, %rcx
callq 0x44d21
addq $0x10, %r14
cmpq %r14, %r12
jne 0x461b9
movq 0x98(%rsp), %rsi
shlq $0x4, %rsi
movq (%r13,%rsi), %rax
testl %eax, %eax
jle 0x4626c
movq 0x8(%r13,%rsi), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movq -0x8(%rbp,%rsi), %rsi
movq (%rsi), %rsi
movq 0x90(%rsp), %rdi
movq (%rdi), %rdi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rdx, %r8
decq %r8
xorl %r9d, %r9d
movq (%rcx,%r9,8), %r10
movsd (%r10), %xmm0
cmpl $0x2, %edx
jl 0x4625e
xorl %r11d, %r11d
movsd 0x8(%r10,%r11,8), %xmm1
mulsd (%rsi,%r11,8), %xmm1
addsd %xmm1, %xmm0
incq %r11
cmpq %r11, %r8
jne 0x46245
movsd %xmm0, (%rdi,%r9,8)
incq %r9
cmpq %rax, %r9
jne 0x46234
movq 0xb0(%rsp), %r12
shrq $0x20, %r12
testl %r12d, %r12d
jle 0x462ba
movq 0x90(%rsp), %rax
movq (%rax), %rax
movq 0xa8(%rsp), %rcx
movq (%rcx), %rcx
xorpd %xmm1, %xmm1
xorl %edx, %edx
movsd (%rbx,%rdx,8), %xmm0
subsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
mulsd %xmm0, %xmm0
addsd %xmm0, %xmm1
incq %rdx
cmpq %rdx, %r12
jne 0x46299
jmp 0x462be
xorpd %xmm1, %xmm1
movsd %xmm1, 0xa0(%rsp)
movl $0x12, %ecx
movq %rsp, %rdi
leaq 0x100(%rsp), %r14
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq 0xa8(%rsp), %rbp
movq %rbp, %r9
callq 0x45816
movl $0x12, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r13, %rdi
movq %r15, %rsi
movq 0xc0(%rsp), %r13
movq %r13, %rdx
callq 0x45ad5
movq 0x98(%rsp), %rax
testl %eax, %eax
js 0x46351
movl %eax, %ebx
shlq $0x4, %rbx
addq $0x10, %rbx
xorl %r14d, %r14d
leaq (%r14,%r13), %rdi
movq (%r15,%r14), %rsi
movq 0x8(%r15,%r14), %rdx
callq 0x406d5
addq $0x10, %r14
cmpq %r14, %rbx
jne 0x46336
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd 0xa0(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0xa0(%rsp)
movq 0xb8(%rsp), %rdi
movq %rbp, %rsi
callq 0x3ed51
movq 0xb0(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x3ed51
leaq 0x100(%rsp), %rax
movl 0x54(%rax), %esi
movq %r15, %rdi
callq 0x45654
movsd 0xa0(%rsp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq