// File: /workspace/github_c_makefile_star2_O0/xtanitfy[P]Murphy/src/layers/linear_layer.c
// Function: LinearLayerBackward
int LinearLayerBackward(NET_PARA_s *pNetPara,LAYER_s *pLayer)
{
	/*���Բ�����һ����չ������Ϊ�������к���������*/
	CHECK_EXPR_RET(pLayer == NULL,-1);
	CHECK_EXPR_RET(pLayer->nNext <= 0,-1);
	BLOB_s *pNextK = pLayer->pNext[0]->k;
	CHECK_EXPR_RET(pNextK == NULL,-1);
	
	BLOB_s *pNextDelta = pLayer->pNext[0]->pDelta;
	CHECK_EXPR_RET(pNextDelta == NULL,-1);
	
	BLOB_s *pDelta = pLayer->pDelta;
	CHECK_EXPR_RET(pDelta == NULL,-1);
	
	BLOB_DATA_PTR(pNextK,ptrNextK);
	BLOB_DATA_PTR(pNextDelta,ptrNextDelta);
	BLOB_DATA_PTR(pDelta,ptrCurrDelta);

	double tmp = 0;
	
	for (int i_batch = 0;i_batch < pDelta->numSize;i_batch++) {
		for (int i_in = 0;i_in < pDelta->channelSize;i_in++) {
			tmp = 0;
			for (int i_out = 0;i_out < pNextDelta->channelSize;i_out++) {
				tmp += ptrNextK[i_out][i_in][0][0] * \
							ptrNextDelta[i_batch][i_out][0][0];
			}
			ptrCurrDelta[i_batch][i_in][0][0] = tmp;
		}
	}
	
	//LOG_writeBlobToTxtFile("linearDelta.txt",pDelta);
	
	/*���Ի�ԭ,������ʱ�����Ƕ����ĺϲ���������ҪLAYER_TYPE_MERGEȥ��*/
	BLOB_s *pPrevDelta = pLayer->pPrev[0]->pDelta;
	BLOB_s *pPrevData = pLayer->pPrev[0]->pData;
	CHECK_EXPR_RET(pPrevDelta == NULL,-1);
	CHECK_EXPR_RET(pPrevData == NULL,-1);
	BLOB_DATA_PTR(pPrevDelta,ptrPrevDelta);
//	BLOB_DATA_PTR(pPrevData,ptrPrevData);

	int cnt = 0;
	
	for (int i_batch = 0;i_batch < pPrevData->numSize;i_batch++) {
		cnt = 0;
		for (int i_in = 0;i_in < pPrevData->channelSize;i_in++) {
			for (int i_w = 0; i_w < pPrevData->widthSize;i_w++) {
				for (int i_h = 0; i_h < pPrevData->heightSize;i_h++) {
					ptrPrevDelta[i_batch][i_in][i_h][i_w] = \
						ptrCurrDelta[i_batch][cnt++][0][0]; 
				}
			}
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x8a37
leaq 0x2604(%rip), %rdi      # 0xb015
leaq 0x2db2(%rip), %rsi      # 0xb7ca
leaq 0x2ddd(%rip), %rdx      # 0xb7fc
movl $0x5a, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8fc6
movq -0x18(%rbp), %rax
cmpl $0x0, 0xa0(%rax)
jg 0x8a71
leaq 0x25ca(%rip), %rdi      # 0xb015
leaq 0x2d78(%rip), %rsi      # 0xb7ca
leaq 0x2da3(%rip), %rdx      # 0xb7fc
movl $0x5b, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8fc6
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x8ab5
leaq 0x2586(%rip), %rdi      # 0xb015
leaq 0x2d34(%rip), %rsi      # 0xb7ca
leaq 0x2d5f(%rip), %rdx      # 0xb7fc
movl $0x5d, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8fc6
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x8af9
leaq 0x2542(%rip), %rdi      # 0xb015
leaq 0x2cf0(%rip), %rsi      # 0xb7ca
leaq 0x2d1b(%rip), %rdx      # 0xb7fc
movl $0x60, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8fc6
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8b39
leaq 0x2502(%rip), %rdi      # 0xb015
leaq 0x2cb0(%rip), %rsi      # 0xb7ca
leaq 0x2cdb(%rip), %rdx      # 0xb7fc
movl $0x63, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8fc6
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x8d66
movl $0x0, -0x58(%rbp)
movslq -0x58(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x8d56
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movl $0x0, -0x5c(%rbp)
movslq -0x5c(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x8cf7
movq -0xb0(%rbp), %rcx
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rdx
movq -0xd0(%rbp), %r9
movq -0xd8(%rbp), %r10
movq -0x38(%rbp), %rax
movslq -0x5c(%rbp), %r8
imulq %r9, %r10
imulq %rdx, %r10
imulq %r10, %r8
shlq $0x3, %r8
addq %r8, %rax
movslq -0x58(%rbp), %r8
imulq %rdx, %r9
imulq %r9, %r8
shlq $0x3, %r8
addq %r8, %rax
imulq $0x0, %rdx, %rdx
movsd (%rax,%rdx,8), %xmm0
movq -0x40(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq %rsi, %rdi
imulq %rcx, %rdi
imulq %rdi, %rdx
shlq $0x3, %rdx
addq %rdx, %rax
movslq -0x5c(%rbp), %rdx
imulq %rcx, %rsi
imulq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rax
imulq $0x0, %rcx, %rcx
movsd (%rax,%rcx,8), %xmm2
movsd -0x50(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x8c2d
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %rsi
movq -0xa8(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq %rsi, %rdi
imulq %rcx, %rdi
imulq %rdi, %rdx
shlq $0x3, %rdx
addq %rdx, %rax
movslq -0x58(%rbp), %rdx
imulq %rcx, %rsi
imulq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rax
imulq $0x0, %rcx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x8c0c
jmp 0x8d58
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x8bf3
movq -0x18(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x28(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x8dc0
leaq 0x227b(%rip), %rdi      # 0xb015
leaq 0x2a29(%rip), %rsi      # 0xb7ca
leaq 0x2a54(%rip), %rdx      # 0xb7fc
movl $0x7b, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8fc6
cmpq $0x0, -0x70(%rbp)
jne 0x8df4
leaq 0x2247(%rip), %rdi      # 0xb015
leaq 0x29f5(%rip), %rsi      # 0xb7ca
leaq 0x2a20(%rip), %rdx      # 0xb7fc
movl $0x7c, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8fc6
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xf0(%rbp)
movq -0x68(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xe8(%rbp)
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movslq -0x80(%rbp), %rax
movq -0x70(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x8fbf
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x84(%rbp)
movslq -0x84(%rbp), %rax
movq -0x70(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x8faf
movl $0x0, -0x88(%rbp)
movslq -0x88(%rbp), %rax
movq -0x70(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jae 0x8f99
movl $0x0, -0x8c(%rbp)
movslq -0x8c(%rbp), %rax
movq -0x70(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x8f83
movq -0xe0(%rbp), %rdx
movq -0xe8(%rbp), %rsi
movq -0xf0(%rbp), %rdi
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %r9
movq -0xa8(%rbp), %r10
movq -0x48(%rbp), %rax
movslq -0x80(%rbp), %r8
imulq %r9, %r10
imulq %rcx, %r10
imulq %r10, %r8
shlq $0x3, %r8
addq %r8, %rax
movl -0x7c(%rbp), %r8d
movl %r8d, %r10d
addl $0x1, %r10d
movl %r10d, -0x7c(%rbp)
movslq %r8d, %r8
imulq %rcx, %r9
imulq %r9, %r8
shlq $0x3, %r8
addq %r8, %rax
imulq $0x0, %rcx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x78(%rbp), %rax
movslq -0x80(%rbp), %rcx
imulq %rsi, %rdi
imulq %rdx, %rdi
imulq %rdi, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x84(%rbp), %rcx
imulq %rdx, %rsi
imulq %rsi, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x8c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x88(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x8e9c
jmp 0x8f85
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x8e7d
jmp 0x8f9b
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x8e5e
jmp 0x8fb1
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x8e3b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)