// File: /workspace/github_c_makefile_star2_O1/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 0x6625
movq 0xa8(%rsi), %rax
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x662c
movq 0x10(%rsi), %r14
testq %r14, %r14
je 0x6633
movl $0x4d, %ecx
cmpq $0x1, 0x20(%r14)
jne 0x6638
movl $0x4e, %ecx
cmpq $0x1, 0x28(%r14)
jne 0x6638
movq 0x18(%rsi), %rax
testq %rax, %rax
je 0x6668
movq 0x20(%rsi), %rdx
testq %rdx, %rdx
je 0x666f
movq 0x20(%rax), %rdi
movl $0x53, %ecx
cmpl $0x1, %edi
jne 0x6638
movq 0x28(%rax), %r15
movl $0x54, %ecx
cmpl $0x1, %r15d
jne 0x6638
cmpq $0x0, 0x10(%r14)
je 0x6676
movq 0x8(%rsi), %rcx
movq %rcx, 0x50(%rsp)
movq 0x8(%r14), %rcx
movq %rcx, 0x28(%rsp)
movq 0x18(%r14), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rsi
movq %rsi, 0x8(%rsp)
movq 0x20(%rcx), %rbp
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq 0x8(%rdx), %rsi
movq %rsi, 0x48(%rsp)
movq 0x28(%rdx), %rsi
imulq 0x20(%rdx), %rsi
movq %rsi, 0x40(%rsp)
imulq %rdi, %r15
movq 0x18(%rax), %rax
imulq %r15, %rax
shlq $0x3, %rax
movq %rax, 0x38(%rsp)
shlq $0x3, %r15
imulq 0x28(%rcx), %rbp
movq 0x18(%rcx), %rax
imulq %rbp, %rax
shlq $0x3, %rax
movq %rax, 0x30(%rsp)
shlq $0x3, %rbp
movq $0x0, (%rsp)
cmpq $0x0, 0x18(%r14)
je 0x6602
movq (%rsp), %rax
imulq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movq 0x18(%rsp), %r13
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x65ce
movq 0x8(%rsp), %rcx
movq %r13, %rdx
movsd (%rcx), %xmm1
mulsd (%rdx), %xmm1
addsd %xmm1, %xmm0
addq %r15, %rdx
addq %rbp, %rcx
decq %rax
jne 0x65b7
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
addq 0x38(%rsp), %r13
cmpq %rbx, 0x18(%r14)
ja 0x659d
movq (%rsp), %rdx
incq %rdx
movq 0x30(%rsp), %rax
addq %rax, 0x8(%rsp)
xorl %eax, %eax
movq %rdx, (%rsp)
cmpq %rdx, 0x10(%r14)
ja 0x657c
jmp 0x6659
movl $0x44, %ecx
jmp 0x6638
movl $0x46, %ecx
jmp 0x6638
movl $0x4c, %ecx
leaq 0x1a06(%rip), %rdi      # 0x8045
leaq 0x21fd(%rip), %rsi      # 0x8843
leaq 0x221c(%rip), %rdx      # 0x8869
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 0x6638
movl $0x50, %ecx
jmp 0x6638
xorl %eax, %eax
jmp 0x6659