// File: /workspace/github_c_makefile_star2_O1/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, -0x20(%rsp)
movq %rcx, -0x38(%rsp)
movq %rdx, -0x30(%rsp)
movq %rsi, -0x40(%rsp)
movslq 0x8c(%rsp), %rdx
testq %rdx, %rdx
js 0x44708
leaq 0x38(%rsp), %rax
movq -0x30(%rsp), %rcx
addq $-0x8, %rcx
movq %rcx, -0x28(%rsp)
leaq -0x8(%rdi), %r10
movsd 0x38(%rax), %xmm0
movsd 0x5e042(%rip), %xmm1    # 0xa2520
movq %rdx, %r11
movq %rdx, -0x18(%rsp)
testl %edx, %edx
je 0x4457f
movq %r11, %rbx
shlq $0x4, %rbx
movq -0x40(%rsp), %rax
leaq (%rax,%rbx), %rcx
movl (%rax,%rbx), %r14d
cmpq %rdx, %r11
jne 0x445fd
testl %r14d, %r14d
jle 0x446f3
movq -0x20(%rsp), %rax
movq (%rax), %rax
movq -0x38(%rsp), %rdx
movq 0x8(%rdx,%rbx), %rdx
movl 0x4(%rcx), %r8d
addq -0x28(%rsp), %rbx
movq %r8, %rcx
decq %rcx
xorl %r9d, %r9d
movsd (%rax,%r9,8), %xmm2
mulsd %xmm0, %xmm2
movq (%rdx,%r9,8), %rsi
movsd %xmm2, (%rsi)
cmpl $0x2, %r8d
jl 0x44572
movq (%rbx), %r15
movq (%r15), %r15
xorl %r12d, %r12d
movsd (%r15,%r12,8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, 0x8(%rsi,%r12,8)
incq %r12
cmpq %r12, %rcx
jne 0x44559
incq %r9
cmpq %r14, %r9
jne 0x44538
jmp 0x446f3
movq %r11, %rcx
shlq $0x4, %rcx
movq -0x40(%rsp), %rax
movslq (%rax,%rcx), %rax
testq %rax, %rax
jle 0x446f3
movq -0x40(%rsp), %rdx
leaq (%rdx,%rcx), %rsi
movq -0x20(%rsp), %rdx
movq (%rdx), %rdx
movq -0x38(%rsp), %r8
movq 0x8(%r8,%rcx), %r8
movl 0x4(%rsi), %ecx
movq %rcx, %r9
decq %r9
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm2
mulsd %xmm0, %xmm2
movq (%r8,%rsi,8), %rbx
movsd %xmm2, (%rbx)
cmpl $0x2, %ecx
jl 0x445f0
xorl %r14d, %r14d
movsd (%rdi,%r14,8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, 0x8(%rbx,%r14,8)
incq %r14
cmpq %r14, %r9
jne 0x445d7
incq %rsi
cmpq %rax, %rsi
jne 0x445be
jmp 0x446f3
testl %r14d, %r14d
jle 0x446f3
movq -0x40(%rsp), %rax
addq %rbx, %rax
addq $0x10, %rax
movq %rax, -0x8(%rsp)
movl (%rax), %r12d
movq -0x38(%rsp), %rax
leaq 0x18(%rax,%rbx), %rdx
movq -0x30(%rsp), %rax
movq 0x8(%rax,%rbx), %rax
movq (%rax), %rbp
movq %rdx, -0x10(%rsp)
movq -0x10(%rdx), %r8
movl 0x4(%rcx), %edx
addq -0x28(%rsp), %rbx
leaq -0x8(,%rdx,8), %rax
xorl %r9d, %r9d
testl %r12d, %r12d
jle 0x4468e
movq -0x10(%rsp), %rcx
movq (%rcx), %rcx
movq -0x8(%rsp), %rsi
movq 0x8(%rsi), %rsi
xorpd %xmm3, %xmm3
xorl %r15d, %r15d
movq (%rcx,%r15,8), %r13
movsd 0x8(%r13,%r9,8), %xmm2
movq (%rsi,%r15,8), %r13
mulsd 0x8(%r13,%r9,8), %xmm2
addsd %xmm2, %xmm3
incq %r15
cmpq %r15, %r12
jne 0x4466a
jmp 0x44692
xorpd %xmm3, %xmm3
movapd %xmm1, %xmm2
subsd (%rbp,%r9,8), %xmm2
mulsd %xmm3, %xmm2
movq (%r8,%r9,8), %rcx
movsd %xmm2, (%rcx)
cmpl $0x2, %edx
jl 0x446e7
movl $0x1, %r15d
xorl %esi, %esi
testq %r11, %r11
je 0x446c7
movq (%rbx), %r13
movq (%r13), %r13
addq %rsi, %r13
jmp 0x446cb
leaq (%r10,%r15,8), %r13
movsd (%r13), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, 0x8(%rcx,%rsi)
incq %r15
addq $0x8, %rsi
cmpq %rsi, %rax
jne 0x446b6
incq %r9
cmpq %r14, %r9
jne 0x4464d
leaq -0x1(%r11), %rax
testq %r11, %r11
movq %rax, %r11
movq -0x18(%rsp), %rdx
jg 0x444e6
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq