// File: /workspace/github_cpp_makefile_star2_O1/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: filterMatrix(Matrix&, Filter2D&)
static Matrix filterMatrix(Matrix &A, Filter2D &F)
{
    // this function takes out all active elements from A according to F
    //       and return them in another matrix
    //       the filter info is given in matrix F
    auto dimA = A.Dimension();
    auto dimF = F.Dimension();
    assert(dimA == dimF);

    std::vector<std::vector<double>> R;
    for(size_t i=0;i<dimA.first;i++)
    {
        std::vector<double> _tmp_row;
        for(size_t j=0;j<dimA.second;j++)
        {
            if(F[i][j]==1)
            {
                _tmp_row.push_back(A[i][j]);
            }
            else if(F[i][j] != 0)
            {
                std::cout<<"Error: filter matrix element value must be 0 or 1"<<std::endl;
                exit(0);
            }
        }
        if(_tmp_row.size() > 0)
            R.push_back(_tmp_row);
    }
    Matrix Ret(R);
    return Ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r14
movq %rdi, %rbx
movq %rsi, 0x48(%rsp)
movq %rsi, %rdi
callq 0x1ac7c
movq %rax, %r15
movq %rdx, %r13
movq (%r14), %rax
movq %r14, 0x50(%rsp)
movq 0x8(%r14), %rcx
subq %rax, %rcx
je 0xb1af
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
movq 0x10(%rax), %rcx
movl 0x18(%rax), %esi
subq (%rax), %rcx
leaq (%rsi,%rcx,8), %rcx
jmp 0xb1b3
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, 0x38(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x1a680
testb %al, %al
je 0xb315
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %r15, %r15
je 0xb2e7
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
xorl %ebp, %ebp
leaq 0x3f(%rax), %rbx
movq %r15, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %r13, %r13
je 0xb2b0
leaq (,%rbp,4), %r15
addq %rbp, %r15
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x50(%rsp), %rax
movq (%rax), %rax
leaq 0x3f(%r14), %rcx
testq %r14, %r14
cmovnsq %r14, %rcx
sarq $0x6, %rcx
shlq $0x3, %rcx
addq (%rax,%r15,8), %rcx
movq %r14, %rax
andq %rbx, %rax
xorl %edx, %edx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
cmpq %rsi, %rax
setbe %dl
movq -0x8(%rcx,%rdx,8), %rax
btq %r14, %rax
jae 0xb2a0
movq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x1ae76
movq (%rax), %rdx
addq %r12, %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0xb298
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0xb2a0
movq %rsp, %rdi
callq 0x17770
incq %r14
addq $0x8, %r12
cmpq %r14, %r13
jne 0xb224
movq 0x8(%rsp), %rax
cmpq (%rsp), %rax
je 0xb2c8
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x1468c
movq (%rsp), %rdi
testq %rdi, %rdi
movq 0x40(%rsp), %r15
je 0xb2db
callq 0x4230
incq %rbp
cmpq %r15, %rbp
jne 0xb1fa
leaq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x1aa86
leaq 0x20(%rsp), %rdi
callq 0x146b8
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e301(%rip), %rdi     # 0x2961d
leaq 0x1c427(%rip), %rsi     # 0x2774a
leaq 0x1e300(%rip), %rcx     # 0x2962a
movl $0x622, %edx            # imm = 0x622
callq 0x4160
movq %rax, %rbx
jmp 0xb34c
jmp 0xb33b
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xb34c
callq 0x4230
leaq 0x20(%rsp), %rdi
callq 0x146b8
movq %rbx, %rdi
callq 0x43e0