// File: /workspace/github_c_makefile_star2_O2/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 0x5de2
movq 0xa8(%rsi), %rax
movq 0x10(%rax), %rax
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x5de6
movq 0x10(%rsi), %r15
testq %r15, %r15
je 0x5dea
cmpq $0x1, 0x20(%r15)
jne 0x5dee
cmpq $0x1, 0x28(%r15)
jne 0x5df2
movq 0x18(%rsi), %rax
testq %rax, %rax
je 0x5df6
movq 0x20(%rsi), %rdx
testq %rdx, %rdx
je 0x5dfa
movq 0x20(%rax), %rcx
cmpl $0x1, %ecx
jne 0x5dfe
movq 0x28(%rax), %r12
cmpl $0x1, %r12d
jne 0x5e02
movq 0x8(%rsi), %rsi
movq %rsi, 0x50(%rsp)
movq 0x8(%r15), %rsi
movq %rsi, 0x28(%rsp)
movq 0x18(%r15), %r8
movq 0x8(%rsp), %rsi
movq 0x8(%rsi), %r9
movq %r9, (%rsp)
movq 0x28(%rsi), %rbx
movq 0x8(%rax), %r9
movq %r9, 0x18(%rsp)
movq 0x8(%rdx), %r9
movq %r9, 0x48(%rsp)
movq 0x28(%rdx), %r9
imulq 0x20(%rsi), %rbx
movq 0x18(%rsi), %rsi
imulq %rbx, %rsi
imulq 0x20(%rdx), %r9
movq %r9, 0x40(%rsp)
shlq $0x3, %rsi
movq %rsi, 0x10(%rsp)
shlq $0x3, %rbx
imulq %rcx, %r12
movq 0x18(%rax), %rax
imulq %r12, %rax
shlq $0x3, %rax
movq %rax, 0x38(%rsp)
shlq $0x3, %r12
movq %r8, 0x20(%rsp)
movq %r8, %rax
xorl %edx, %edx
cmpq %rdx, 0x10(%r15)
jbe 0x5e33
movq 0x20(%rsp), %rcx
movq %rdx, 0x30(%rsp)
imulq %rdx, %rcx
movq 0x28(%rsp), %rdx
leaq (%rdx,%rcx,8), %r14
movq 0x18(%rsp), %r13
xorl %ebp, %ebp
cmpq %rbp, %rax
jbe 0x5dcc
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
xorpd %xmm0, %xmm0
movq %r13, %rcx
movq (%rsp), %rdx
subq $0x1, %rax
jb 0x5d98
movsd (%rdx), %xmm1
mulsd (%rcx), %xmm1
addsd %xmm1, %xmm0
addq %rbx, %rdx
addq %r12, %rcx
jmp 0x5d7e
movq 0x40(%rsp), %rax
imulq %rbp, %rax
movq 0x48(%rsp), %rcx
addsd (%rcx,%rax,8), %xmm0
xorl %edi, %edi
movq 0x50(%rsp), %rax
callq *0x290(%rax)
movsd %xmm0, (%r14,%rbp,8)
incq %rbp
movq 0x18(%r15), %rax
addq 0x38(%rsp), %r13
jmp 0x5d65
movq 0x30(%rsp), %rdx
incq %rdx
movq 0x10(%rsp), %rcx
addq %rcx, (%rsp)
jmp 0x5d3d
pushq $0x44
jmp 0x5e04
pushq $0x46
jmp 0x5e04
pushq $0x4c
jmp 0x5e04
pushq $0x4d
jmp 0x5e04
pushq $0x4e
jmp 0x5e04
pushq $0x4f
jmp 0x5e04
pushq $0x50
jmp 0x5e04
pushq $0x53
jmp 0x5e04
pushq $0x54
popq %rcx
leaq 0x1239(%rip), %rdi      # 0x7045
leaq 0x1a1d(%rip), %rsi      # 0x7830
leaq 0x1a3c(%rip), %rdx      # 0x7856
xorl %eax, %eax
callq 0x1030
pushq $-0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x5e24