// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rsi, %rbp
movq %rdi, 0xa8(%rsp)
leaq 0x120(%rsp), %rbx
movl (%rbx), %r12d
movl $0x1, %edi
movl %r12d, %esi
callq 0x3c6e5
movq %rax, 0xd0(%rsp)
movq %rax, 0xd8(%rsp)
movq %rdx, 0xc8(%rsp)
movq %rdx, 0xe0(%rsp)
movl $0x1, %edi
movl %r12d, %esi
callq 0x3c6e5
movq %rax, 0x98(%rsp)
movq %rax, 0xb0(%rsp)
movq %rdx, 0xc0(%rsp)
movq %rdx, 0xb8(%rsp)
movl $0x12, %ecx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x2, %edi
xorl %esi, %esi
callq 0x43f69
movq %rax, %r13
movslq 0x54(%rbx), %rax
movq %rax, 0xa0(%rsp)
testq %rax, %rax
jle 0x448e7
movq 0xa0(%rsp), %r12
shlq $0x4, %r12
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x448c6
leaq (%r15,%rbx), %rcx
movq -0x8(%r15,%rbx), %rax
movq (%rax), %rdi
movq (%rbp,%rbx), %rsi
movq 0x8(%rbp,%rbx), %rdx
jmp 0x448d9
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
movq 0xa8(%rsp), %rdi
movq %r15, %rcx
callq 0x43994
addq $0x10, %rbx
cmpq %rbx, %r12
jne 0x448a9
movq %rbp, %rax
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rcx
testl %ecx, %ecx
je 0x44910
movq %rcx, %rax
shlq $0x4, %rax
movq -0x8(%r15,%rax), %rcx
movq (%rcx), %rdi
addq %rbp, %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0xb0(%rsp), %rcx
callq 0x43e8f
leaq 0x120(%rsp), %rbx
movslq 0x4(%rbx), %rax
movq 0xa8(%rsp), %r12
movsd (%r12,%rax,8), %xmm0
leaq 0xd8(%rsp), %rdx
movq 0x98(%rsp), %rdi
movq 0xc0(%rsp), %rsi
callq 0x44342
movsd %xmm0, 0x98(%rsp)
movl $0x12, %ecx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0xc8(%rsp), %r12
movq %r12, %r9
callq 0x4448b
movl $0x12, %ecx
movq %rsp, %rdi
movq %rbx, %rsi
movq 0xa0(%rsp), %rbx
rep  movsq (%rsi), %es:(%rdi)
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x44713
testl %ebx, %ebx
js 0x449df
movl %ebx, %ebx
shlq $0x4, %rbx
addq $0x10, %rbx
xorl %r15d, %r15d
leaq (%r14,%r15), %rdi
movq (%r13,%r15), %rsi
movq 0x8(%r13,%r15), %rdx
callq 0x3f37d
addq $0x10, %r15
cmpq %r15, %rbx
jne 0x449c3
movq 0xd0(%rsp), %rdi
movq %r12, %rsi
callq 0x3dbad
movq 0xb0(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x3dbad
leaq 0x120(%rsp), %rax
movl 0x54(%rax), %esi
movq %r13, %rdi
callq 0x442c9
movsd 0x98(%rsp), %xmm0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq