// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/mlp.c
// Function: backPropMlpn_reg
double backPropMlpn_reg(double *Train, matrixptr weights, matrixptr hidden, matrixptr prevWeights, Mlpparameters P)
{	
	/*!Last Changed 16.03.2004 Oya*/
	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]);
	 }
	if (P.layernum == 0) 	/*calculate outputs*/
		 calculate_output_values_reg(Train, weights[P.layernum], &Y);
	else
		 calculate_output_values_reg(hidden[P.layernum-1].values[0], weights[P.layernum], &Y);	
	sqrderror = calculate_error_values_reg(Train[P.dimnum], 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 $0xe8, %rsp
movq %rcx, 0xc0(%rsp)
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, 0x98(%rsp)
leaq 0x120(%rsp), %r14
movl (%r14), %ebp
pushq $0x1
popq %r15
movl %r15d, %edi
movl %ebp, %esi
callq 0x380d3
movq %rax, 0xb8(%rsp)
movq %rax, 0xd8(%rsp)
movq %rdx, 0xb0(%rsp)
movq %rdx, 0xe0(%rsp)
movl %r15d, %edi
movl %ebp, %esi
callq 0x380d3
movq %rax, 0xa8(%rsp)
movq %rax, 0xc8(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rdx, 0xd0(%rsp)
pushq $0x12
popq %rcx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
pushq $0x2
popq %rdi
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x3eb62
movq %rax, %r15
movslq 0x54(%r14), %rbp
testl %ebp, %ebp
movl $0x0, %r14d
cmovgl %ebp, %r14d
shlq $0x4, %r14
cmpq %r13, %r14
je 0x3f72c
testq %r13, %r13
je 0x3f70f
leaq (%r12,%r13), %rcx
movq -0x8(%r12,%r13), %rax
movq (%rax), %rdi
movq (%rbx,%r13), %rsi
movq 0x8(%rbx,%r13), %rdx
jmp 0x3f721
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x98(%rsp), %rdi
movq %r12, %rcx
callq 0x3e5db
addq $0x10, %r13
jmp 0x3f6ee
testl %ebp, %ebp
je 0x3f767
movq %rbp, %rax
shlq $0x4, %rax
movq -0x8(%r12,%rax), %rcx
movq (%rcx), %rdi
movq (%rbx,%rax), %rsi
movq 0x8(%rbx,%rax), %rdx
leaq 0xc8(%rsp), %rcx
callq 0x3ea4a
leaq 0x120(%rsp), %r13
movq 0x98(%rsp), %r14
jmp 0x3f790
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
leaq 0xc8(%rsp), %rcx
movq 0x98(%rsp), %r14
movq %r14, %rdi
callq 0x3ea4a
xorl %ebp, %ebp
leaq 0x120(%rsp), %r13
movslq 0x4(%r13), %rax
movsd (%r14,%rax,8), %xmm0
leaq 0xd8(%rsp), %rdx
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x3eff6
movsd %xmm0, 0x98(%rsp)
pushq $0x12
popq %rcx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq 0xb0(%rsp), %r9
callq 0x3f08f
pushq $0x12
popq %rcx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r15, %rsi
movq 0xc0(%rsp), %r12
movq %r12, %rdx
callq 0x3f307
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpq %rbp, %r14
jg 0x3f82c
leaq (%r12,%rbx), %rdi
movq (%r15,%rbx), %rsi
movq 0x8(%r15,%rbx), %rdx
callq 0x3a763
incq %r14
addq $0x10, %rbx
jmp 0x3f80c
movq 0xb8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x3929f
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x3929f
movl 0x54(%r13), %esi
movq %r15, %rdi
callq 0x3eec0
movsd 0x98(%rsp), %xmm0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq