// File: xbai0624[P]dnn/src/Matrix.cpp
// Function: Matrix::GetSection(unsigned long, unsigned long, unsigned long, unsigned long, bool, double)
Matrix Matrix::GetSection(size_t r_s, size_t r_e, size_t c_s, size_t c_e, 
        bool padding, double padding_value)
{
    // get a section of this matrix
    auto dim = Dimension();

    if( c_e <= c_s || r_e <= r_s || (int)c_s<0 || (int)r_s<0 || r_s>=dim.first || c_s>=dim.second ) 
    {
        std::cout<<"Error: wrong index provided in fetching matrix section."<<std::endl;
        std::cout<<"       front close, back open."<<std::endl;
        exit(0);
    }

    if(!padding) {
        if(r_e > dim.first || c_e > dim.second) {
            std::cout<<"Error: matrix fetching section exceeded range."<<std::endl;
            exit(0);
        }
    }

    Matrix _m(r_e - r_s, c_e - c_s);
    for(size_t i=0;i<(r_e-r_s);i++)
    {
        for(size_t j=0;j<(c_e-c_s);j++){
            if( (r_s + i) < dim.first && (c_s + j) < dim.second ){
                _m[i][j] = __M[r_s+i][c_s+j];
            } else {
                _m[i][j] = padding_value;
            }
        }
    }
    return _m;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x18(%rsp)
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movb 0xa0(%rsp), %al
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdx, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movq %r8, 0x70(%rsp)
movq %r9, 0x68(%rsp)
andb $0x1, %al
movb %al, 0x67(%rsp)
movsd %xmm0, 0x58(%rsp)
movq 0x88(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x3bae0
movq %rax, 0x48(%rsp)
movq %rdx, 0x50(%rsp)
movq 0x68(%rsp), %rax
cmpq 0x70(%rsp), %rax
jbe 0x3eef7
movq 0x78(%rsp), %rax
cmpq 0x80(%rsp), %rax
jbe 0x3eef7
movq 0x70(%rsp), %rax
cmpl $0x0, %eax
jl 0x3eef7
movq 0x80(%rsp), %rax
cmpl $0x0, %eax
jl 0x3eef7
movq 0x80(%rsp), %rax
cmpq 0x48(%rsp), %rax
jae 0x3eef7
movq 0x70(%rsp), %rax
cmpq 0x50(%rsp), %rax
jb 0x3ef42
movq 0x2c0da(%rip), %rdi     # 0x6afd8
leaq 0x16194(%rip), %rsi     # 0x55099
callq 0x4230
movq %rax, %rdi
movq 0x2c09c(%rip), %rsi     # 0x6afb0
callq 0x4260
movq 0x2c0b8(%rip), %rdi     # 0x6afd8
leaq 0x161aa(%rip), %rsi     # 0x550d1
callq 0x4230
movq %rax, %rdi
movq 0x2c07a(%rip), %rsi     # 0x6afb0
callq 0x4260
xorl %edi, %edi
callq 0x4290
testb $0x1, 0x67(%rsp)
jne 0x3ef8c
movq 0x78(%rsp), %rax
cmpq 0x48(%rsp), %rax
ja 0x3ef61
movq 0x68(%rsp), %rax
cmpq 0x50(%rsp), %rax
jbe 0x3ef8a
movq 0x2c070(%rip), %rdi     # 0x6afd8
leaq 0x16181(%rip), %rsi     # 0x550f0
callq 0x4230
movq %rax, %rdi
movq 0x2c032(%rip), %rsi     # 0x6afb0
callq 0x4260
xorl %edi, %edi
callq 0x4290
jmp 0x3ef8c
movq 0x18(%rsp), %rdi
movb $0x0, 0x47(%rsp)
movq 0x78(%rsp), %rsi
subq 0x80(%rsp), %rsi
movq 0x68(%rsp), %rdx
subq 0x70(%rsp), %rdx
callq 0x3b3b0
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq 0x78(%rsp), %rcx
subq 0x80(%rsp), %rcx
cmpq %rcx, %rax
jae 0x3f0d3
movq $0x0, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq 0x68(%rsp), %rcx
subq 0x70(%rsp), %rcx
cmpq %rcx, %rax
jae 0x3f0be
movq 0x80(%rsp), %rax
addq 0x38(%rsp), %rax
cmpq 0x48(%rsp), %rax
jae 0x3f077
movq 0x70(%rsp), %rax
addq 0x30(%rsp), %rax
cmpq 0x50(%rsp), %rax
jae 0x3f077
movq 0x28(%rsp), %rdi
movq 0x80(%rsp), %rsi
addq 0x38(%rsp), %rsi
callq 0x42670
movq %rax, %rdi
movq 0x70(%rsp), %rsi
addq 0x30(%rsp), %rsi
callq 0x1fd60
movq 0x18(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x3f0a9
movq 0x18(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x3f0ab
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x3efdf
jmp 0x3f0c0
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x3efbb
movb $0x1, 0x47(%rsp)
testb $0x1, 0x47(%rsp)
jne 0x3f0e9
movq 0x18(%rsp), %rdi
callq 0x3bb80
movq 0x20(%rsp), %rax
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)