// File: btbujiangjun[P]abcdl/src/algebra/MatrixBase.cpp
// Function: abcdl::algebra::Matrix<int>::insert_col(unsigned long, abcdl::algebra::Matrix<int> const&)
void Matrix<T>::insert_col(const size_t col_id, const Matrix<T>& mat){
    
    if(get_size() == 0){
        set_data(mat.data(), mat.rows(), mat.cols());
        return;
    }

    CHECK(mat.rows() == _rows);
    CHECK(col_id <= _cols);

    size_t sub_cols = mat.cols();
    size_t new_cols = _cols + sub_cols;
    T* sub_data   = mat.data();

    T* data = new T[_rows * new_cols];
    for(size_t i = 0; i != _rows; i++){
        if(col_id > 0){
            memcpy(&data[i * new_cols], &_data[i * _cols], sizeof(T) * sub_cols);
        }
        memcpy(&data[i * new_cols + sub_cols], &sub_data[i * sub_cols], sizeof(T) * sub_cols);
        if(col_id != _cols){
            memcpy(&data[i * new_cols + col_id + sub_cols], &_data[i * _cols + col_id], sizeof(T) * (_cols - col_id));
        }
    }

    set_shallow_data(data, _rows, new_cols);
}

// Assembly:
subq $0x388, %rsp            # imm = 0x388
movq %rdi, 0x380(%rsp)
movq %rsi, 0x378(%rsp)
movq %rdx, 0x370(%rsp)
movq 0x380(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x317f0
cmpq $0x0, %rax
jne 0x32eb4
movq 0x370(%rsp), %rdi
callq 0x31a30
movq %rax, 0x10(%rsp)
movq 0x370(%rsp), %rdi
callq 0x31a10
movq %rax, 0x18(%rsp)
movq 0x370(%rsp), %rdi
callq 0x31a20
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x31ea0
jmp 0x3316d
movq 0x370(%rsp), %rdi
callq 0x31a10
movq 0x20(%rsp), %rcx
cmpq (%rcx), %rax
sete %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x32ed4
jmp 0x32f3f
leaq 0x5d65d(%rip), %rsi     # 0x90538
leaq 0x1e8(%rsp), %rdi
movq %rdi, 0x8(%rsp)
movl $0xc2, %edx
movl $0x3, %ecx
callq 0x89860
movq 0x8(%rsp), %rdi
leaq 0x5d73f(%rip), %rsi     # 0x90642
callq 0x310b0
jmp 0x32f0a
leaq 0x1e8(%rsp), %rdi
callq 0x89c20
jmp 0x32f3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x89c20
jmp 0x33175
movq 0x20(%rsp), %rcx
movq 0x378(%rsp), %rax
cmpq 0x8(%rcx), %rax
setbe %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x32f5b
jmp 0x32fbb
leaq 0x5d5d6(%rip), %rsi     # 0x90538
leaq 0x50(%rsp), %rdi
movq %rdi, (%rsp)
movl $0xc3, %edx
movl $0x3, %ecx
callq 0x89860
movq (%rsp), %rdi
leaq 0x5d70a(%rip), %rsi     # 0x9068f
callq 0x2cfb0
jmp 0x32f8c
leaq 0x50(%rsp), %rdi
callq 0x89c20
jmp 0x32fbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x89c20
jmp 0x33175
movq 0x370(%rsp), %rdi
callq 0x31a20
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x48(%rsp)
movq 0x8(%rax), %rax
addq 0x48(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x370(%rsp), %rdi
callq 0x31a30
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x38(%rsp)
movq (%rax), %rax
imulq 0x40(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x9030
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
cmpq (%rcx), %rax
je 0x33156
cmpq $0x0, 0x378(%rsp)
jbe 0x33092
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
imulq 0x40(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq 0x10(%rcx), %rsi
movq 0x28(%rsp), %rax
imulq 0x8(%rcx), %rax
shlq $0x2, %rax
addq %rax, %rsi
movq 0x48(%rsp), %rdx
shlq $0x2, %rdx
callq 0x9370
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
imulq 0x40(%rsp), %rax
addq 0x48(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq 0x38(%rsp), %rsi
movq 0x28(%rsp), %rax
imulq 0x48(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movq 0x48(%rsp), %rdx
shlq $0x2, %rdx
callq 0x9370
movq 0x20(%rsp), %rcx
movq 0x378(%rsp), %rax
cmpq 0x8(%rcx), %rax
je 0x33141
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rcx
imulq 0x40(%rsp), %rcx
addq 0x378(%rsp), %rcx
addq 0x48(%rsp), %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq 0x10(%rax), %rsi
movq 0x28(%rsp), %rcx
imulq 0x8(%rax), %rcx
addq 0x378(%rsp), %rcx
shlq $0x2, %rcx
addq %rcx, %rsi
movq 0x8(%rax), %rdx
subq 0x378(%rsp), %rdx
shlq $0x2, %rdx
callq 0x9370
jmp 0x33143
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x33035
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq (%rdi), %rdx
movq 0x40(%rsp), %rcx
callq 0x31fe0
addq $0x388, %rsp            # imm = 0x388
retq
movq 0x1e0(%rsp), %rdi
callq 0x9700
nopw %cs:(%rax,%rax)
nopl (%rax)