// File: btbujiangjun[P]abcdl/src/algebra/MatrixOperator.cpp
// Function: abcdl::algebra::Matrix<int>::operator+(abcdl::algebra::Matrix<int> const&) const
Matrix<T> Matrix<T>::operator + (const Matrix<T>& mat) const{
    
	if(get_size() == 0){
        return mat.clone();
    }

    CHECK(equal_shape(mat) 
          || (_cols == mat.cols() && mat.rows() == 1)
          || (_rows == mat.rows() && mat.cols() == 1));

    Matrix<T> new_mat = clone();

    if(equal_shape(mat) || (_cols == mat.cols() && mat.rows() == 1)){
        auto lambda = [](T* a, const T& b){*a += b;};
        _po.parallel_mul2mul_repeat(new_mat.data(), new_mat.get_size(), mat.data(), mat.get_size(), lambda);
    }else{
        for(size_t i = 0; i < _rows; i++){
            T value = mat.get_data(i, 0);
            for(size_t j = 0; j < _cols; j++){
                new_mat.set_data(get_data(i, j) + value, i, j);
            }
        }
    }
    return new_mat;
}

// Assembly:
subq $0x288, %rsp            # imm = 0x288
movq %rdi, 0x80(%rsp)
movq %rdi, %rax
movq %rax, 0x88(%rsp)
movq %rdi, 0x280(%rsp)
movq %rsi, 0x278(%rsp)
movq %rdx, 0x270(%rsp)
movq 0x278(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x317f0
cmpq $0x0, %rax
jne 0x3f3c7
movq 0x80(%rsp), %rdi
movq 0x270(%rsp), %rsi
callq 0x331e0
jmp 0x3f7ab
movq 0x90(%rsp), %rdi
movq 0x270(%rsp), %rsi
callq 0x339c0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, 0x7f(%rsp)
jne 0x3f484
movq 0x90(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x270(%rsp), %rdi
callq 0x31a20
movq %rax, %rcx
movq 0x70(%rsp), %rax
cmpq %rcx, %rax
jne 0x3f434
movq 0x270(%rsp), %rdi
callq 0x31a10
movq %rax, %rcx
movb $0x1, %al
cmpq $0x1, %rcx
movb %al, 0x7f(%rsp)
je 0x3f484
movq 0x90(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x270(%rsp), %rdi
callq 0x31a10
movq 0x60(%rsp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x6f(%rsp)
jne 0x3f47c
movq 0x270(%rsp), %rdi
callq 0x31a20
cmpq $0x1, %rax
sete %al
movb %al, 0x6f(%rsp)
movb 0x6f(%rsp), %al
movb %al, 0x7f(%rsp)
movb 0x7f(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3f490
jmp 0x3f4fb
leaq 0x51ab9(%rip), %rsi     # 0x90f50
leaq 0xe8(%rsp), %rdi
movq %rdi, 0x58(%rsp)
movl $0x51, %edx
movl $0x3, %ecx
callq 0x89860
movq 0x58(%rsp), %rdi
leaq 0x51ab0(%rip), %rsi     # 0x90f6f
callq 0x3f7d0
jmp 0x3f4c6
leaq 0xe8(%rsp), %rdi
callq 0x89c20
jmp 0x3f4fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x89c20
jmp 0x3f7bb
movq 0x90(%rsp), %rsi
movq 0x80(%rsp), %rdi
movb $0x0, 0xdb(%rsp)
callq 0x331e0
movq 0x90(%rsp), %rdi
movq 0x270(%rsp), %rsi
callq 0x339c0
movb %al, 0x57(%rsp)
jmp 0x3f533
movb 0x57(%rsp), %al
testb $0x1, %al
jne 0x3f583
jmp 0x3f53d
movq 0x90(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x270(%rsp), %rdi
callq 0x31a20
movq %rax, %rcx
movq 0x48(%rsp), %rax
cmpq %rcx, %rax
jne 0x3f66c
movq 0x270(%rsp), %rdi
callq 0x31a10
cmpq $0x1, %rax
jne 0x3f66c
movq 0x80(%rsp), %rdi
movq 0x90(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x18(%rsp)
callq 0x31a30
movq 0x80(%rsp), %rdi
movq %rax, 0x20(%rsp)
callq 0x317f0
movq %rax, 0x28(%rsp)
movq 0x270(%rsp), %rdi
callq 0x31a30
movq %rax, 0x30(%rsp)
movq 0x270(%rsp), %rdi
callq 0x317f0
movq %rax, 0x38(%rsp)
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x40(%rsp)
leaq 0xda(%rsp), %rsi
callq 0x3f800
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
movq 0x40(%rsp), %r9
callq 0xbb40
jmp 0x3f61b
leaq 0xb8(%rsp), %rdi
callq 0x318a0
jmp 0x3f77b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
jmp 0x3f79c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x318a0
jmp 0x3f79c
movq $0x0, 0xb0(%rsp)
movq 0x90(%rsp), %rcx
movq 0xb0(%rsp), %rax
cmpq (%rcx), %rax
jae 0x3f779
movq 0x270(%rsp), %rdi
movq 0xb0(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x31bc0
movq %rax, 0x10(%rsp)
jmp 0x3f6b1
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xac(%rsp)
movq $0x0, 0xa0(%rsp)
movq 0x90(%rsp), %rcx
movq 0xa0(%rsp), %rax
cmpq 0x8(%rcx), %rax
jae 0x3f75e
movq 0x90(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movq 0xa0(%rsp), %rdx
callq 0x31bc0
movq %rax, 0x8(%rsp)
jmp 0x3f705
movq 0x80(%rsp), %rdi
movq 0x8(%rsp), %rax
movl (%rax), %eax
movl 0xac(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x9c(%rsp)
movq 0xb0(%rsp), %rdx
movq 0xa0(%rsp), %rcx
leaq 0x9c(%rsp), %rsi
callq 0x31da0
jmp 0x3f743
jmp 0x3f745
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0x3f6cb
jmp 0x3f760
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0x3f678
jmp 0x3f77b
movb $0x1, 0xdb(%rsp)
testb $0x1, 0xdb(%rsp)
jne 0x3f79a
movq 0x80(%rsp), %rdi
callq 0x31a40
jmp 0x3f7ab
movq 0x80(%rsp), %rdi
callq 0x31a40
jmp 0x3f7bb
movq 0x88(%rsp), %rax
addq $0x288, %rsp            # imm = 0x288
retq
movq 0xe0(%rsp), %rdi
callq 0x9700
nopl (%rax,%rax)