// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/mlp.c
// Function: backPropMlpn_cls
double backPropMlpn_cls(double *Train, matrixptr weights, matrixptr hidden, matrixptr prevWeights, Mlpparameters P)
{
	/*!Last Changed 09.02.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_cls(Train, weights[P.layernum], &Y);
	else
		 calculate_output_values_cls(hidden[P.layernum-1].values[0], weights[P.layernum], &Y);	
	sqrderror = calculate_error_values_cls(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, %r14
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, 0x98(%rsp)
leaq 0x120(%rsp), %r13
movl (%r13), %ebp
movl $0x1, %edi
movl %ebp, %esi
callq 0x3d79d
movq %rax, 0xc0(%rsp)
movq %rax, 0xd8(%rsp)
movq %rdx, 0xb8(%rsp)
movq %rdx, 0xe0(%rsp)
movl $0x1, %edi
movl %ebp, %esi
callq 0x3d79d
movq %rax, 0xa8(%rsp)
movq %rax, 0xc8(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rdx, 0xd0(%rsp)
movl $0x12, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x2, %edi
xorl %esi, %esi
callq 0x452e5
movq %rax, %r15
movslq 0x54(%r13), %rax
movq %rax, 0x90(%rsp)
testq %rax, %rax
jle 0x45ca7
movq 0x90(%rsp), %rbp
shlq $0x4, %rbp
xorl %r13d, %r13d
testq %r13, %r13
je 0x45c87
leaq (%r12,%r13), %rcx
movq -0x8(%r12,%r13), %rax
movq (%rax), %rdi
movq (%rbx,%r13), %rsi
movq 0x8(%rbx,%r13), %rdx
jmp 0x45c99
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x98(%rsp), %rdi
movq %r12, %rcx
callq 0x44d21
addq $0x10, %r13
cmpq %r13, %rbp
jne 0x45c6b
movq %rbx, %rax
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rdx
testl %edx, %edx
je 0x45cd0
movq %rdx, %rax
shlq $0x4, %rax
movq -0x8(%r12,%rax), %rcx
movq (%rcx), %rdi
addq %rbx, %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0xc8(%rsp), %rcx
callq 0x4521e
leaq 0x120(%rsp), %r13
movslq 0x4(%r13), %rax
movq 0x98(%rsp), %rbp
movsd (%rbp,%rax,8), %xmm0
leaq 0xd8(%rsp), %rdx
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x456cd
movsd %xmm0, 0xb0(%rsp)
movl $0x12, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq 0xb8(%rsp), %rbp
movq %rbp, %r9
callq 0x45816
movl $0x12, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x45ad5
movq 0x90(%rsp), %rax
testl %eax, %eax
js 0x45d9e
movl %eax, %ebx
shlq $0x4, %rbx
addq $0x10, %rbx
xorl %r12d, %r12d
leaq (%r14,%r12), %rdi
movq (%r15,%r12), %rsi
movq 0x8(%r15,%r12), %rdx
callq 0x406d5
addq $0x10, %r12
cmpq %r12, %rbx
jne 0x45d83
movq 0xc0(%rsp), %rdi
movq %rbp, %rsi
callq 0x3ed51
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x3ed51
movl 0x54(%r13), %esi
movq %r15, %rdi
callq 0x45654
movsd 0xb0(%rsp), %xmm0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq