// File: xbai0624[P]dnn/src/Matrix.cpp
// Function: Matrix::Padding(unsigned long, unsigned long, bool, double)
Matrix Matrix::Padding(size_t ROW, size_t COL, bool pad_front, double padding_value)
{
    // matrix padding, only two modes supported: 1) only pad back, 2) pad back and front
    // only pad front not supported, b/c it's not useful reallistically
    auto dim = Dimension();
    if(ROW < dim.first || COL < dim.second) {
        std::cout<<"Error: trying pad matrix to a smaller size, no padding needed."<<std::endl;
        exit(0);
    }

    Matrix _m(ROW, COL, padding_value);
    if( ! pad_front){ // only pad back
        for(size_t i=0;i<dim.first;i++){
            for(size_t j=0;j<dim.second;j++){
                _m[i][j] = __M[i][j];
            }
        }
    } else { // pad back and front
        size_t extra_row = ROW - dim.first, extra_col = COL - dim.second;
        size_t extra_front_row = extra_row/2, extra_front_col = extra_col/2;
        for(size_t i=0;i<dim.first;i++){
            for(size_t j=0;j<dim.second;j++){
                _m[extra_front_row+i][extra_front_col+j] = __M[i][j];
            }
        }
    }

    return _m;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0x18(%rsp)
movb %r8b, %al
movq %rdi, %r8
movq %r8, 0x20(%rsp)
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rcx, 0x98(%rsp)
andb $0x1, %al
movb %al, 0x97(%rsp)
movsd %xmm0, 0x88(%rsp)
movq 0xa8(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x3bae0
movq %rax, 0x78(%rsp)
movq %rdx, 0x80(%rsp)
movq 0xa0(%rsp), %rax
cmpq 0x78(%rsp), %rax
jb 0x3f189
movq 0x98(%rsp), %rax
cmpq 0x80(%rsp), %rax
jae 0x3f1b2
movq 0x2be48(%rip), %rdi     # 0x6afd8
leaq 0x15f88(%rip), %rsi     # 0x5511f
callq 0x4230
movq %rax, %rdi
movq 0x2be0a(%rip), %rsi     # 0x6afb0
callq 0x4260
xorl %edi, %edi
callq 0x4290
movq 0x18(%rsp), %rdi
movb $0x0, 0x77(%rsp)
movq 0xa0(%rsp), %rsi
movq 0x98(%rsp), %rdx
movsd 0x88(%rsp), %xmm0
callq 0x3b590
testb $0x1, 0x97(%rsp)
jne 0x3f28f
movq $0x0, 0x68(%rsp)
movq 0x68(%rsp), %rax
cmpq 0x78(%rsp), %rax
jae 0x3f28a
movq $0x0, 0x60(%rsp)
movq 0x60(%rsp), %rax
cmpq 0x80(%rsp), %rax
jae 0x3f275
movq 0x28(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x42670
movq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0x1fd60
movq 0x18(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x68(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0x1fd60
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x3f20a
jmp 0x3f277
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x3f1f1
jmp 0x3f37e
movq 0xa0(%rsp), %rax
subq 0x78(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x98(%rsp), %rax
subq 0x80(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rax
shrq %rax
movq %rax, 0x48(%rsp)
movq 0x50(%rsp), %rax
shrq %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x78(%rsp), %rax
jae 0x3f37c
movq $0x0, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x80(%rsp), %rax
jae 0x3f367
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x42670
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movq 0x18(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x48(%rsp), %rsi
addq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x40(%rsp), %rsi
addq 0x30(%rsp), %rsi
callq 0x1fd60
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x3f2f2
jmp 0x3f369
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x3f2d9
jmp 0x3f37e
movb $0x1, 0x77(%rsp)
testb $0x1, 0x77(%rsp)
jne 0x3f394
movq 0x18(%rsp), %rdi
callq 0x3bb80
movq 0x20(%rsp), %rax
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)