// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/mlp.c
// Function: calculate_change_in_weights
void calculate_change_in_weights(double *inputdata, matrixptr weights, matrixptr hiddens, matrixptr dweights, matrix output_error, Mlpparameters P)
{
	/*!Last Changed 09.02.2004 Oya*/
	int li, i, j, pi;
	/*
	li layer index
	i, j row and column index for the current matrix
	pi row index of the weight matrix of above layer
	*/
	double sum = 0, tmp;
	for (li = P.layernum; li >= 0; li--)
	 {
 		if (P.layernum == 0)
			 {
	  		for (i=0; i<weights[li].row; i++)
					 {
						 tmp = P.eta * output_error.values[0][i];
		   		dweights[li].values[i][0] = tmp;
   				for (j=1; j<weights[li].col; j++)
		    			dweights[li].values[i][j] = tmp * inputdata[j-1]; 
					 }
			 }
		 else 
				 if (li==P.layernum)
					 {
    			for (i=0; i<weights[li].row; i++)
							 {
								 tmp = P.eta * output_error.values[0][i];
				     dweights[li].values[i][0] = tmp;
				     for (j=1; j<weights[li].col; j++)
					      dweights[li].values[i][j] = tmp * hiddens[li-1].values[0][j-1]; 
							 }
					 }
		   else
					 {
			    for (i=0; i<weights[li].row; i++)
							 {
				     sum = 0;
				     for (pi=0; pi<weights[li+1].row; pi++)
      					sum = sum + dweights[li+1].values[pi][i+1] * weights[li+1].values[pi][i+1];
									tmp = sum * (1 - hiddens[li].values[0][i]);
				     dweights[li].values[i][0] = tmp;
				     for (j=1; j<weights[li].col; j++)
									 {
      					if (li == 0)
				       		dweights[li].values[i][j] = tmp * inputdata[j-1];
      					else
       						dweights[li].values[i][j] = tmp * hiddens[li-1].values[0][j-1];
								  }
							 }
					 }
		} 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r9, -0x40(%rsp)
movq %rcx, -0x50(%rsp)
movq %rdx, -0x48(%rsp)
movq %rsi, -0x58(%rsp)
movslq 0x8c(%rsp), %rdx
testq %rdx, %rdx
js 0x45aca
leaq 0x38(%rsp), %rax
movq -0x48(%rsp), %rcx
addq $-0x8, %rcx
leaq -0x8(%rdi), %r10
movsd 0x38(%rax), %xmm0
movq %rdx, %rsi
shlq $0x4, %rsi
movq -0x58(%rsp), %rax
addq %rsi, %rax
movq %rax, -0x38(%rsp)
movq -0x50(%rsp), %rax
addq %rsi, %rax
addq $0x8, %rax
movq %rax, -0x30(%rsp)
movq %rcx, -0x28(%rsp)
addq %rcx, %rsi
movq %rsi, -0x18(%rsp)
movsd 0x5fc8a(%rip), %xmm1    # 0xa5520
movq %rdx, %r15
movq %rdx, -0x20(%rsp)
testl %edx, %edx
je 0x4592f
cmpq %rdx, %r15
jne 0x459ae
movq -0x38(%rsp), %rax
movslq (%rax), %rax
testq %rax, %rax
jle 0x45ab5
movq -0x40(%rsp), %rcx
movq (%rcx), %rcx
movq -0x30(%rsp), %rdx
movq (%rdx), %rdx
movq -0x38(%rsp), %rsi
movl 0x4(%rsi), %r8d
movq %r8, %rsi
decq %rsi
xorl %r9d, %r9d
movsd (%rcx,%r9,8), %xmm2
mulsd %xmm0, %xmm2
movq (%rdx,%r9,8), %r11
movsd %xmm2, (%r11)
cmpl $0x2, %r8d
jl 0x45922
movq -0x18(%rsp), %rbx
movq (%rbx), %rbx
movq (%rbx), %rbx
xorl %r14d, %r14d
movsd (%rbx,%r14,8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, 0x8(%r11,%r14,8)
incq %r14
cmpq %r14, %rsi
jne 0x45909
incq %r9
cmpq %rax, %r9
jne 0x458e2
jmp 0x45ab5
movq %r15, %rdx
shlq $0x4, %rdx
movq -0x58(%rsp), %rax
movslq (%rax,%rdx), %rax
testq %rax, %rax
jle 0x45ab5
movq -0x58(%rsp), %rcx
leaq (%rcx,%rdx), %rsi
movq -0x40(%rsp), %rcx
movq (%rcx), %rcx
movq -0x50(%rsp), %r8
movq 0x8(%r8,%rdx), %rdx
movl 0x4(%rsi), %esi
movq %rsi, %r8
decq %r8
xorl %r9d, %r9d
movsd (%rcx,%r9,8), %xmm2
mulsd %xmm0, %xmm2
movq (%rdx,%r9,8), %r11
movsd %xmm2, (%r11)
cmpl $0x2, %esi
jl 0x459a1
xorl %ebx, %ebx
movsd (%rdi,%rbx,8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, 0x8(%r11,%rbx,8)
incq %rbx
cmpq %rbx, %r8
jne 0x45989
incq %r9
cmpq %rax, %r9
jne 0x4596f
jmp 0x45ab5
movq %r15, %r12
shlq $0x4, %r12
movq -0x58(%rsp), %rax
movslq (%rax,%r12), %r13
testq %r13, %r13
jle 0x45ab5
movq -0x58(%rsp), %rcx
leaq (%rcx,%r12), %rax
addq %r12, %rcx
addq $0x10, %rcx
movq %rcx, -0x8(%rsp)
movl (%rcx), %r14d
movq -0x50(%rsp), %rcx
leaq 0x18(%rcx,%r12), %rdx
movq -0x48(%rsp), %rcx
movq 0x8(%rcx,%r12), %rcx
movq (%rcx), %rbx
movq %rdx, -0x10(%rsp)
movq -0x10(%rdx), %rdx
movl 0x4(%rax), %r9d
addq -0x28(%rsp), %r12
leaq -0x8(,%r9,8), %rcx
xorl %eax, %eax
testl %r14d, %r14d
jle 0x45a52
movq -0x10(%rsp), %rsi
movq (%rsi), %rsi
movq -0x8(%rsp), %r8
movq 0x8(%r8), %r11
xorpd %xmm3, %xmm3
xorl %ebp, %ebp
movq (%rsi,%rbp,8), %r8
movsd 0x8(%r8,%rax,8), %xmm2
movq (%r11,%rbp,8), %r8
mulsd 0x8(%r8,%rax,8), %xmm2
addsd %xmm2, %xmm3
incq %rbp
cmpq %rbp, %r14
jne 0x45a2e
jmp 0x45a56
xorpd %xmm3, %xmm3
movapd %xmm1, %xmm2
subsd (%rbx,%rax,8), %xmm2
mulsd %xmm3, %xmm2
movq (%rdx,%rax,8), %rsi
movsd %xmm2, (%rsi)
cmpl $0x2, %r9d
jl 0x45aa9
movl $0x1, %r11d
xorl %ebp, %ebp
testq %r15, %r15
je 0x45a8a
movq (%r12), %r8
movq (%r8), %r8
addq %rbp, %r8
jmp 0x45a8e
leaq (%r10,%r11,8), %r8
movsd (%r8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, 0x8(%rsi,%rbp)
incq %r11
addq $0x8, %rbp
cmpq %rbp, %rcx
jne 0x45a79
incq %rax
cmpq %r13, %rax
jne 0x45a12
leaq -0x1(%r15), %rax
testq %r15, %r15
movq %rax, %r15
movq -0x20(%rsp), %rdx
jg 0x4589e
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq