// File: /workspace/github_c_makefile_star2_O2/xtanitfy[P]Murphy/src/net.c
// Function: NETUpdate
static int NETUpdate(void *usr,int idCurr,int *idPrev,int nIdPrev)
{
	NET_s *pNet = (void *)usr;
	CHECK_EXPR_RET(pNet == NULL,-1);

	LAYER_s *pLayer = pNet->layers[idCurr];
	CHECK_EXPR_RET(pLayer == NULL,-1);
	if (pLayer->k == NULL || pLayer->b == NULL \
				|| pLayer->pDK == NULL || pLayer->pDB == NULL) {
		//DBG_PRT;
		return 0;
	}

	double alpha = pNet->para.alpha;
	BLOB_DATA_PTR(pLayer->k,ptrK);
	BLOB_DATA_PTR(pLayer->b,ptrB);
	BLOB_DATA_PTR(pLayer->pDK,ptrDK);
	BLOB_DATA_PTR(pLayer->pDB,ptrDB);

	unsigned long numOut = pLayer->k->numSize;
	unsigned long numIn = pLayer->k->channelSize;
	unsigned long width = pLayer->k->widthSize;
	unsigned long height = pLayer->k->heightSize;
	
	for (int i_out = 0;i_out < numOut;i_out++) {
		for (int i_in = 0;i_in < numIn;i_in++) {
			for (int i_h = 0;i_h < height;i_h++) {
				for (int i_w = 0;i_w < width;i_w++) {
					ptrK[i_out][i_in][i_h][i_w] -=  alpha * \
						ptrDK[i_out][i_in][i_h][i_w];		
				}
			}
		}
	}


	unsigned long b_out = pLayer->b->channelSize;	
	for (int i_out = 0;i_out < b_out;i_out++) {
		ptrB[0][i_out][0][0] = alpha * \
			ptrDB[0][i_out][0][0];	
	}


#if defined(DEBUG)
	char filename[128];
	snprintf(filename,128,"%s_newk.txt",pLayer->para->name);
	pLayer->k->type = BLOB_TYPE_WEIGHT;
	LOG_writeBlobToTxtFile(filename,pLayer->k);

	snprintf(filename,128,"%s_newb.txt",pLayer->para->name);
	pLayer->b->type = BLOB_TYPE_BIAS;
	LOG_writeBlobToTxtFile(filename,pLayer->b);
#endif
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
testq %rdi, %rdi
je 0x2ee8
movslq %esi, %rax
movq 0x240(%rdi,%rax,8), %rsi
testq %rsi, %rsi
je 0x2f01
movq 0x18(%rsi), %rcx
xorl %ebx, %ebx
testq %rcx, %rcx
je 0x2f23
movq 0x20(%rsi), %r10
testq %r10, %r10
je 0x2f23
movq 0x30(%rsi), %rax
testq %rax, %rax
je 0x2f23
movq 0x38(%rsi), %rdx
testq %rdx, %rdx
je 0x2f23
movq %rsi, 0x40(%rsp)
movsd 0x208(%rdi), %xmm0
movq 0x18(%rcx), %rdi
movq 0x20(%rcx), %r8
movq 0x28(%rcx), %r9
movq 0x8(%rcx), %rbx
movq 0x10(%rcx), %rcx
movq %rcx, 0x58(%rsp)
movq 0x8(%r10), %rcx
movq %rcx, 0x38(%rsp)
movq 0x8(%rax), %r14
movq 0x28(%rax), %r13
movq 0x8(%rdx), %rcx
movq %rcx, 0x30(%rsp)
movq 0x20(%rdx), %rcx
movq %rcx, 0x10(%rsp)
movq 0x28(%rdx), %rcx
movq %rcx, 0x28(%rsp)
movq 0x20(%rax), %rbp
imulq %r13, %rbp
movapd 0x44dd(%rip), %xmm1     # 0x72f0
xorpd %xmm0, %xmm1
movq 0x18(%rax), %rax
imulq %rbp, %rax
shlq $0x3, %rax
movq %rax, 0x50(%rsp)
shlq $0x3, %rbp
shlq $0x3, %r13
movq %r9, %rsi
imulq %r8, %rsi
movq %rsi, %rax
imulq %rdi, %rax
shlq $0x3, %rax
movq %rax, 0x48(%rsp)
shlq $0x3, %rsi
movq 0x20(%r10), %rax
movq %rax, 0x8(%rsp)
movq %r10, 0x20(%rsp)
movq 0x28(%r10), %rax
movq %rax, 0x18(%rsp)
leaq (,%r9,8), %rdx
xorl %r11d, %r11d
cmpq 0x58(%rsp), %r11
je 0x2f37
movq %rbx, 0x68(%rsp)
movq %r14, 0x60(%rsp)
xorl %r15d, %r15d
cmpq %rdi, %r15
je 0x2ecf
movq %rbx, %r10
movq %r14, %r12
xorl %eax, %eax
cmpq %r8, %rax
je 0x2ec4
xorl %ecx, %ecx
cmpq %rcx, %r9
je 0x2eb9
movsd (%r12,%rcx,8), %xmm2
mulsd %xmm1, %xmm2
addsd (%r10,%rcx,8), %xmm2
movsd %xmm2, (%r10,%rcx,8)
incq %rcx
jmp 0x2e99
incq %rax
addq %r13, %r12
addq %rdx, %r10
jmp 0x2e92
incq %r15
addq %rbp, %r14
addq %rsi, %rbx
jmp 0x2e85
incq %r11
movq 0x60(%rsp), %r14
addq 0x50(%rsp), %r14
movq 0x68(%rsp), %rbx
addq 0x48(%rsp), %rbx
jmp 0x2e6d
leaq 0x4156(%rip), %rdi      # 0x7045
leaq 0x4537(%rip), %rsi      # 0x742d
leaq 0x45b7(%rip), %rdx      # 0x74b4
pushq $0x48
jmp 0x2f18
leaq 0x413d(%rip), %rdi      # 0x7045
leaq 0x451e(%rip), %rsi      # 0x742d
leaq 0x459e(%rip), %rdx      # 0x74b4
pushq $0x4b
popq %rcx
xorl %eax, %eax
callq 0x1030
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rsp), %rsi
imulq 0x10(%rsp), %rsi
shlq $0x3, %rsi
movq 0x18(%rsp), %rdi
imulq 0x8(%rsp), %rdi
shlq $0x3, %rdi
movq 0x40(%rsp), %r15
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %rdx
subq $0x1, %rax
jb 0x2f87
movsd (%rdx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rcx)
addq %rsi, %rdx
addq %rdi, %rcx
jmp 0x2f6d
movq 0x8(%r15), %rcx
addq $0x44, %rcx
leaq 0x4528(%rip), %rdx      # 0x74be
xorl %ebx, %ebx
leaq 0x70(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x1150
movq 0x18(%r15), %rsi
movl $0x1, (%rsi)
movq %r14, %rdi
callq 0x39ff
movq 0x8(%r15), %rcx
addq $0x44, %rcx
leaq 0x44fd(%rip), %rdx      # 0x74ca
movl $0x80, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x1150
movq 0x20(%r15), %rsi
movl $0x2, (%rsi)
movq %r14, %rdi
callq 0x39ff
jmp 0x2f23