// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rdi, 0x38(%rsp)
movq %rsi, 0x48(%rsp)
movq %rsi, %rdi
callq 0x1abb8
movq %rax, %r14
movq %rdx, %r13
movq (%rbx), %rcx
movq %rbx, 0x50(%rsp)
movq 0x8(%rbx), %rax
subq %rcx, %rax
je 0xb13f
movq 0x10(%rcx), %rdx
movl 0x18(%rcx), %esi
subq (%rcx), %rdx
leaq (%rsi,%rdx,8), %rcx
jmp 0xb141
xorl %ecx, %ecx
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x1a5e0
testb %al, %al
je 0xb2aa
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %r14, %r14
je 0xb282
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
xorl %ebp, %ebp
leaq 0x3f(%rax), %rbx
movq %r14, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %r13, %r13
je 0xb276
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 0xb23b
movq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x1adb2
movq (%rax), %rdx
addq %r12, %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0xb233
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0xb23b
movq %rsp, %rdi
callq 0x17694
incq %r14
addq $0x8, %r12
cmpq %r14, %r13
jne 0xb1bf
movq (%rsp), %rdi
cmpq %rdi, 0x8(%rsp)
movq 0x40(%rsp), %r14
je 0xb26c
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x1454c
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xb276
callq 0x4230
incq %rbp
cmpq %r14, %rbp
jne 0xb195
leaq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x1a9c6
leaq 0x20(%rsp), %rdi
callq 0x14578
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e32d(%rip), %rdi     # 0x295de
leaq 0x1c492(%rip), %rsi     # 0x2774a
leaq 0x1e32c(%rip), %rcx     # 0x295eb
movl $0x622, %edx            # imm = 0x622
callq 0x4160
movq %rax, %rbx
jmp 0xb2e1
jmp 0xb2d0
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xb2e1
callq 0x4230
leaq 0x20(%rsp), %rdi
callq 0x14578
movq %rbx, %rdi
callq 0x43e0
nop