// File: /workspace/github_c_makefile_star2_O2/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 %rdi, %r13
movl 0x8c(%rsp), %edi
leaq -0x8(%rdx), %rax
movq %rax, -0x30(%rsp)
movsd 0x70(%rsp), %xmm0
movq %rdi, %rax
shlq $0x4, %rax
movq %rsi, -0x48(%rsp)
addq %rax, %rsi
movq %rsi, -0x38(%rsp)
movq %rcx, -0x40(%rsp)
leaq 0x8(%rcx,%rax), %rcx
movq %rcx, -0x18(%rsp)
movq %rdx, -0x28(%rsp)
leaq -0x8(%rdx,%rax), %rbx
movabsq $0x1, %r15
movsd 0x5642f(%rip), %xmm1    # 0x95520
movl %edi, %ebp
movq %rdi, -0x20(%rsp)
testl %ebp, %ebp
js 0x3f2fc
movl %ebp, %r12d
testl %edi, %edi
je 0x3f178
cmpl %edi, %ebp
jne 0x3f1e8
movq -0x38(%rsp), %rax
movl (%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0x3f2f0
movq (%r9), %rdx
movsd (%rdx,%rcx,8), %xmm2
mulsd %xmm0, %xmm2
movq -0x18(%rsp), %rdx
movq (%rdx), %rdx
movq (%rdx,%rcx,8), %rdx
movsd %xmm2, (%rdx)
movq -0x38(%rsp), %rsi
movslq 0x4(%rsi), %rsi
movq %r15, %rdi
cmpq %rsi, %rdi
jge 0x3f173
movq (%rbx), %r8
movq (%r8), %r8
movsd -0x8(%r8,%rdi,8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, (%rdx,%rdi,8)
incq %rdi
jmp 0x3f153
incq %rcx
jmp 0x3f122
shlq $0x4, %r12
movq -0x48(%rsp), %rcx
leaq (%rcx,%r12), %rax
movl (%rcx,%r12), %ecx
movq -0x40(%rsp), %rdx
addq %r12, %rdx
addq $0x8, %rdx
testl %ecx, %ecx
movl $0x0, %esi
cmovlel %esi, %ecx
xorl %esi, %esi
cmpq %rcx, %rsi
je 0x3f2f0
movq (%r9), %rdi
movsd (%rdi,%rsi,8), %xmm2
mulsd %xmm0, %xmm2
movq (%rdx), %rdi
movq (%rdi,%rsi,8), %rdi
movsd %xmm2, (%rdi)
movslq 0x4(%rax), %r8
movq %r15, %r11
cmpq %r8, %r11
jge 0x3f1e3
movsd -0x8(%r13,%r11,8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, (%rdi,%r11,8)
incq %r11
jmp 0x3f1c8
incq %rsi
jmp 0x3f1a1
shlq $0x4, %r12
movq -0x48(%rsp), %rax
leaq (%rax,%r12), %rcx
movq %rcx, -0x8(%rsp)
leaq (%rax,%r12), %r8
addq $0x10, %r8
movl -0x10(%r8), %eax
movq -0x40(%rsp), %rcx
leaq 0x18(%rcx,%r12), %rdx
movq -0x28(%rsp), %rcx
addq %r12, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rsp)
addq -0x30(%rsp), %r12
testl %eax, %eax
movl $0x0, %esi
cmovlel %esi, %eax
xorl %r14d, %r14d
cmpq %rax, %r14
je 0x3f2f0
movl (%r8), %r11d
leaq 0x1(%r14), %rsi
testl %r11d, %r11d
movl $0x0, %edi
cmovlel %edi, %r11d
xorpd %xmm2, %xmm2
xorl %edi, %edi
cmpq %rdi, %r11
je 0x3f27e
movq (%rdx), %r10
movq (%r10,%rdi,8), %r10
movsd (%r10,%rsi,8), %xmm3
movq 0x8(%r8), %r10
movq (%r10,%rdi,8), %r10
mulsd (%r10,%rsi,8), %xmm3
addsd %xmm3, %xmm2
incq %rdi
jmp 0x3f255
movq -0x10(%rsp), %rcx
movq (%rcx), %rdi
movq (%rdi), %rdi
movapd %xmm1, %xmm3
subsd (%rdi,%r14,8), %xmm3
mulsd %xmm3, %xmm2
movq -0x10(%rdx), %rdi
movq (%rdi,%r14,8), %r14
movsd %xmm2, (%r14)
movq -0x8(%rsp), %rcx
movslq 0x4(%rcx), %r11
movq %r13, %r10
movq %r15, %rcx
cmpq %r11, %r15
jge 0x3f2e5
movq %r10, %rdi
testl %ebp, %ebp
je 0x3f2ce
movq (%r12), %rdi
movq (%rdi), %rdi
leaq (%rdi,%r15,8), %rdi
addq $-0x8, %rdi
movsd (%rdi), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, (%r14,%r15,8)
incq %r15
addq $0x8, %r10
jmp 0x3f2b3
movq %rsi, %r14
movq %rcx, %r15
jmp 0x3f233
decl %ebp
movq -0x20(%rsp), %rdi
jmp 0x3f0f8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq