// File: /workspace/github_c_makefile_star2_O3/xtanitfy[P]Murphy/src/layers/output_layer.c
// Function: OutputLayerForward
int OutputLayerForward(NET_PARA_s *pNetPara,LAYER_s *pLayer)
{
	CHECK_EXPR_RET(pLayer == NULL,-1);
	BLOB_s *pPrevBlob = pLayer->pPrev[0]->pData;
	CHECK_EXPR_RET(pPrevBlob == NULL,-1);

	OUTPUT_LAYER_PARA_s *pPara = &pLayer->para->select.outputLayer;
	BLOB_s *pPrevData = pPrevBlob;
	BLOB_s *pCurrData = pLayer->pData;
	
	CHECK_EXPR_RET(pCurrData == NULL,-1);
	CHECK_EXPR_RET(pCurrData->heightSize!= 1,-1);
	CHECK_EXPR_RET(pCurrData->widthSize!= 1,-1);
	CHECK_EXPR_RET(pLayer->k == NULL,-1);
	CHECK_EXPR_RET(pLayer->b == NULL,-1);
	int kh = pLayer->k->heightSize;
	int kw = pLayer->k->widthSize;
	CHECK_EXPR_RET(kh != 1,-1);
	CHECK_EXPR_RET(kw != 1,-1);

	BLOB_DATA_PTR(pCurrData,ptrCurr);
	BLOB_DATA_PTR(pPrevData,ptrPrev);
	BLOB_DATA_PTR(pLayer->k,ptrK);
	BLOB_DATA_PTR(pLayer->b,ptrB);

	double tmp = 0;
	
	for (int i_batch = 0;i_batch < pCurrData->numSize;i_batch++) {
		for (int i_out = 0;i_out < pCurrData->channelSize;i_out++) {
			tmp = 0;
			for (int i_in = 0;i_in < pPrevBlob->channelSize;i_in++) {
				tmp += ptrPrev[i_batch][i_in][0][0] * \
					ptrK[i_out][i_in][0][0];
			}	
			ptrCurr[i_batch][i_out][0][0]  = pPara->function(tmp + \
						ptrB[0][i_out][0][0],FUNC_VALUE);
		}
	}
	
	//pCurrData->type = BLOB_TYPE_DATA;
	//LOG_writeBlobToTxtFile("output.txt",pCurrData);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
testq %rsi, %rsi
je 0x6472
movq 0xa8(%rsi), %rax
movq 0x10(%rax), %rax
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x6479
movq 0x10(%rsi), %r14
testq %r14, %r14
je 0x6480
movl $0x4d, %ecx
cmpq $0x1, 0x20(%r14)
jne 0x6485
movl $0x4e, %ecx
cmpq $0x1, 0x28(%r14)
jne 0x6485
movq 0x18(%rsi), %rax
testq %rax, %rax
je 0x64b5
movq 0x20(%rsi), %rdx
testq %rdx, %rdx
je 0x64bc
movq 0x20(%rax), %rdi
movl $0x53, %ecx
cmpl $0x1, %edi
jne 0x6485
movq 0x28(%rax), %r15
movl $0x54, %ecx
cmpl $0x1, %r15d
jne 0x6485
movq 0x10(%r14), %rcx
testq %rcx, %rcx
je 0x64c3
movq 0x8(%rsi), %rsi
movq %rsi, 0x50(%rsp)
movq 0x18(%r14), %r8
movq 0x8(%r14), %rsi
movq %rsi, 0x18(%rsp)
movq 0x8(%rsp), %rsi
movq 0x8(%rsi), %r9
movq %r9, (%rsp)
movq 0x20(%rsi), %r13
movq 0x8(%rax), %r9
movq %r9, 0x10(%rsp)
movq 0x8(%rdx), %r9
movq %r9, 0x48(%rsp)
movq 0x28(%rdx), %r9
imulq 0x20(%rdx), %r9
movq %r9, 0x40(%rsp)
imulq %rdi, %r15
movq 0x18(%rax), %rax
imulq %r15, %rax
shlq $0x3, %rax
movq %rax, 0x38(%rsp)
shlq $0x3, %r15
imulq 0x28(%rsi), %r13
movq 0x18(%rsi), %rax
imulq %r13, %rax
shlq $0x3, %rax
movq %rax, 0x28(%rsp)
shlq $0x3, %r13
xorl %esi, %esi
movq %r8, 0x20(%rsp)
movq %r8, %rdx
testq %rdx, %rdx
je 0x6457
movq %rsi, 0x30(%rsp)
movq %rsi, %rax
imulq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movq 0x10(%rsp), %rbp
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x6415
movq (%rsp), %rcx
movq %rbp, %rdx
movsd (%rcx), %xmm1
mulsd (%rdx), %xmm1
addsd %xmm1, %xmm0
addq %r15, %rdx
addq %r13, %rcx
decq %rax
jne 0x63fe
movq 0x40(%rsp), %rax
imulq %rbx, %rax
movq 0x48(%rsp), %rcx
addsd (%rcx,%rax,8), %xmm0
xorl %edi, %edi
movq 0x50(%rsp), %rax
callq *0x290(%rax)
movsd %xmm0, (%r12,%rbx,8)
incq %rbx
movq 0x18(%r14), %rdx
addq 0x38(%rsp), %rbp
cmpq %rbx, %rdx
ja 0x63e5
movq 0x10(%r14), %rcx
movq 0x30(%rsp), %rsi
jmp 0x6459
xorl %edx, %edx
incq %rsi
movq 0x28(%rsp), %rax
addq %rax, (%rsp)
xorl %eax, %eax
cmpq %rsi, %rcx
ja 0x63be
jmp 0x64a6
movl $0x44, %ecx
jmp 0x6485
movl $0x46, %ecx
jmp 0x6485
movl $0x4c, %ecx
leaq 0xbb9(%rip), %rdi       # 0x7045
leaq 0x139d(%rip), %rsi      # 0x7830
leaq 0x13bc(%rip), %rdx      # 0x7856
xorl %eax, %eax
callq 0x1030
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4f, %ecx
jmp 0x6485
movl $0x50, %ecx
jmp 0x6485
xorl %eax, %eax
jmp 0x64a6