// File: /workspace/github_cpp_makefile_star2_O1/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::InitNeuronsCNN()
void ConstructLayer::InitNeuronsCNN()
{
    // clear
    __neurons.clear();

    // get output image size of previous layer (input image size for this layer)
    assert(__prevLayer != nullptr);
    auto size_prev_layer = __prevLayer->GetOutputImageSize();
    //std::cout<<__func__<<" prev layer output image size: "<<size_prev_layer<<std::endl;

    int n_row = size_prev_layer.first;
    int n_col = size_prev_layer.second;

    assert(__cnnStride >= 1);
    // deduct output image dimension
    int x_size = (int)n_row - (int)__kernelDim.first + 1;
    int y_size = (int)n_col - (int)__kernelDim.second + 1;
    if(x_size <= 0) x_size = 1; // small images will be complemented by padding
    if(y_size <= 0) y_size = 1; // so it is safe to set size >= 1
    __outputImageSizeCNN.first = x_size;
    __outputImageSizeCNN.second = y_size;

    if(__cnnStride > 1)
    {
        __outputImageSizeCNN.first = (int)__outputImageSizeCNN.first / (int) __cnnStride + 1;
        __outputImageSizeCNN.second = (int)__outputImageSizeCNN.second / (int) __cnnStride + 1;
    }
    assert(__outputImageSizeCNN.first >=1);
    assert(__outputImageSizeCNN.second >=1);

    for(size_t k=0;k<__n_kernels_cnn;k++)
    {
        Pixel2D<Neuron*> image(__outputImageSizeCNN.first, __outputImageSizeCNN.second);
        for(size_t i=0;i<__outputImageSizeCNN.first;i++)
        {
            for(size_t j=0;j<__outputImageSizeCNN.second;j++)
            {
                Neuron *n = new Neuron();
                n->SetCoord(i, j, k); // set neuron coord
                n->SetActuationFuncType(__neuron_actuation_func_type);
                image[i][j] = n;
            }
        }
        __neurons.push_back(image);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %r15
movq 0x48(%rdi), %r12
cmpq %r15, %r12
je 0x64bc
movq %r15, %r14
movq %r14, %rdi
callq 0x146fc
addq $0x18, %r14
cmpq %r12, %r14
jne 0x64a7
movq %r15, 0x48(%rbx)
movq 0x3f0(%rbx), %rdi
testq %rdi, %rdi
je 0x6605
movq (%rdi), %rax
callq *0x270(%rax)
movl 0x3e0(%rbx), %esi
testl %esi, %esi
jle 0x6624
movq %rdx, %rcx
subl 0x20(%rbx), %eax
subl 0x28(%rbx), %ecx
xorl %edx, %edx
testl %eax, %eax
cmovlel %edx, %eax
incl %eax
testl %ecx, %ecx
cmovlel %edx, %ecx
incl %ecx
movq %rax, 0x30(%rbx)
movq %rcx, 0x38(%rbx)
cmpl $0x1, %esi
je 0x651f
xorl %edx, %edx
divl %esi
incl %eax
movq %rax, 0x30(%rbx)
movl %ecx, %eax
xorl %edx, %edx
divl %esi
incl %eax
movq %rax, 0x38(%rbx)
cmpq $0x0, 0x30(%rbx)
je 0x6643
cmpq $0x0, 0x38(%rbx)
je 0x6662
cmpq $0x0, 0x18(%rbx)
je 0x65f6
leaq 0x40(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
leaq 0x10(%rsp), %r14
movq 0x30(%rbx), %rsi
movq 0x38(%rbx), %rdx
movq %r14, %rdi
callq 0x1387a
cmpq $0x0, 0x30(%rbx)
je 0x65cf
xorl %r13d, %r13d
cmpq $0x0, 0x38(%rbx)
je 0x65c6
leaq (,%r13,2), %r12
addq %r13, %r12
xorl %ebp, %ebp
movl $0xa0, %edi
callq 0x4270
movq %rax, %r14
movq %rax, %rdi
callq 0x201f4
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x21e58
movl 0x58(%rbx), %esi
movq %r14, %rdi
callq 0x20a3a
movq 0x10(%rsp), %rax
movq (%rax,%r12,8), %rax
movq %r14, (%rax,%rbp,8)
incq %rbp
cmpq 0x38(%rbx), %rbp
jb 0x657f
incq %r13
cmpq 0x30(%rbx), %r13
jb 0x656b
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
callq 0x1390c
movq %r14, %rdi
callq 0x146fc
incq %r15
cmpq 0x18(%rbx), %r15
jb 0x6551
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21127(%rip), %rdi     # 0x27733
leaq 0x21137(%rip), %rsi     # 0x2774a
leaq 0x21147(%rip), %rcx     # 0x27761
movl $0x159, %edx            # imm = 0x159
callq 0x4160
leaq 0x2115c(%rip), %rdi     # 0x27787
leaq 0x21118(%rip), %rsi     # 0x2774a
leaq 0x21128(%rip), %rcx     # 0x27761
movl $0x160, %edx            # imm = 0x160
callq 0x4160
leaq 0x2114e(%rip), %rdi     # 0x27798
leaq 0x210f9(%rip), %rsi     # 0x2774a
leaq 0x21109(%rip), %rcx     # 0x27761
movl $0x16e, %edx            # imm = 0x16E
callq 0x4160
leaq 0x2114e(%rip), %rdi     # 0x277b7
leaq 0x210da(%rip), %rsi     # 0x2774a
leaq 0x210ea(%rip), %rcx     # 0x27761
movl $0x16f, %edx            # imm = 0x16F
callq 0x4160
jmp 0x6690
movq %rax, %rbx
movq %r14, %rdi
callq 0x4230
jmp 0x6693
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x146fc
movq %rbx, %rdi
callq 0x43e0
nop