// File: /workspace/github_c_makefile_star2_O3/xtanitfy[P]Murphy/src/layers/samp_layer.c
// Function: SampLayerForward
int SampLayerForward(NET_PARA_s *pNetPara,LAYER_s *pLayer)
{
	SAMP_LAYER_PARA_s *pPara = &pLayer->para->select.sampLayer;

	BLOB_s *pPrevBlob = pLayer->pPrev[0]->pData;
	int nx =  pPrevBlob->widthSize/ pPara->stride;
	int ny =  pPrevBlob->heightSize/ pPara->stride;

	BLOB_s *pData = pLayer->pData;
	BLOB_DATA_PTR(pData,ptrCurr);
	BLOB_DATA_PTR(pPrevBlob,ptrPrev);
	double scale = (double)1 / (pPara->stride * pPara->stride);
	int xStart = 0,yStart = 0;
	
	
	for (int i_batch = 0;i_batch < pData->numSize;i_batch++) {
		for (int i_out = 0;i_out < pData->channelSize;i_out++) {
			for (int y =0;y < ny;y++) {
				for (int x = 0;x < nx;x++) {
					yStart = y * pPara->stride;
					xStart = x * pPara->stride;
					ptrCurr[i_batch][i_out][y][x] = 0;
					for (int by = yStart; by < yStart + pPara->stride;by++) {
						for (int bx = xStart; bx < xStart + pPara->stride;bx++) {
							ptrCurr[i_batch][i_out][y][x] += \
									ptrPrev[i_batch][i_out][by][bx] * scale;
						}
					}
				}
			}
		}
	}
	
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq 0x10(%rsi), %rdi
movq 0x10(%rdi), %rax
movq %rax, -0x30(%rsp)
testq %rax, %rax
je 0x6b5b
movq 0xa8(%rsi), %rax
movq 0x10(%rax), %rax
movq 0x28(%rax), %rcx
movq 0x8(%rsi), %rdx
movslq 0x28c(%rdx), %r9
movq 0x20(%rax), %rsi
movq 0x18(%rdi), %r8
movq 0x28(%rdi), %r10
movq 0x8(%rdi), %rdx
movq %rdx, -0x40(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, -0x58(%rsp)
movl %r9d, %edx
imull %r9d, %edx
cvtsi2sd %edx, %xmm1
movq 0x18(%rax), %r11
movsd 0x9cb(%rip), %xmm0      # 0x7320
divsd %xmm1, %xmm0
movabsq $0x100000000, %r12      # imm = 0x100000000
movq $0x0, -0x80(%rsp)
movq %rsi, %rax
xorl %edx, %edx
divq %r9
movq %rax, %rbx
movq %rcx, %rax
xorl %edx, %edx
divq %r9
movq 0x20(%rdi), %rdx
movq %r10, -0x8(%rsp)
imulq %r10, %rdx
movq %rdx, -0x28(%rsp)
movq %r8, -0x50(%rsp)
imulq %r8, %rdx
movq %rdx, -0x48(%rsp)
movq %rax, 0x10(%rsp)
cltq
movq %rax, 0x18(%rsp)
imulq %rcx, %rsi
imulq %rsi, %r11
shlq $0x3, %r11
movq %r11, -0x38(%rsp)
shlq $0x3, %rsi
movq %rsi, -0x10(%rsp)
shlq $0x3, %rcx
movq %rbx, -0x18(%rsp)
movslq %ebx, %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, -0x50(%rsp)
je 0x6b39
movq -0x48(%rsp), %rax
imulq -0x80(%rsp), %rax
movq -0x40(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
movq %rax, -0x20(%rsp)
movq -0x58(%rsp), %rax
movq %rax, -0x70(%rsp)
movq $0x0, -0x78(%rsp)
cmpl $0x0, -0x18(%rsp)
jle 0x6b12
movq -0x28(%rsp), %rax
imulq -0x78(%rsp), %rax
movq -0x20(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
movq %rax, (%rsp)
movq $0x0, -0x68(%rsp)
xorl %eax, %eax
movl %eax, %eax
movq %rax, -0x60(%rsp)
cmpl $0x0, 0x10(%rsp)
jle 0x6af2
movq %rcx, %rsi
imulq -0x60(%rsp), %rsi
movq -0x8(%rsp), %rax
movq -0x68(%rsp), %rdi
imulq %rdi, %rax
movq (%rsp), %rdx
leaq (%rdx,%rax,8), %r10
incq %rdi
imulq %r9, %rdi
addq -0x70(%rsp), %rsi
xorl %r15d, %r15d
xorl %r11d, %r11d
movq $0x0, (%r10,%r15,8)
testl %r9d, %r9d
jle 0x6ae5
movl %r11d, %edx
leaq (%rsi,%rdx,8), %rbx
shlq $0x20, %rdx
addq %r12, %rdx
leaq 0x1(%r15), %rax
imulq %r9, %rax
xorpd %xmm1, %xmm1
movq -0x60(%rsp), %r8
movq %rdx, %r13
movq %rbx, %rbp
movsd (%rbp), %xmm2
mulsd %xmm0, %xmm2
addsd %xmm2, %xmm1
movsd %xmm1, (%r10,%r15,8)
movq %r13, %r14
sarq $0x20, %r14
addq $0x8, %rbp
addq %r12, %r13
cmpq %rax, %r14
jl 0x6ab1
incq %r8
movslq %r8d, %r13
addq %rcx, %rbx
cmpq %rdi, %r13
jl 0x6aab
incq %r15
addl %r9d, %r11d
cmpq 0x18(%rsp), %r15
jl 0x6a7f
movq -0x68(%rsp), %rsi
incq %rsi
movq -0x60(%rsp), %rax
addl %r9d, %eax
movq %rsi, -0x68(%rsp)
cmpq 0x8(%rsp), %rsi
jl 0x6a3c
movq -0x78(%rsp), %rdx
incq %rdx
movq -0x70(%rsp), %rax
addq -0x10(%rsp), %rax
movq %rax, -0x70(%rsp)
movq %rdx, -0x78(%rsp)
cmpq -0x50(%rsp), %rdx
jne 0x6a0e
movq -0x80(%rsp), %rdx
incq %rdx
movq -0x38(%rsp), %rax
addq %rax, -0x58(%rsp)
movq %rdx, -0x80(%rsp)
cmpq -0x30(%rsp), %rdx
jne 0x69d6
xorl %eax, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq