// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdx, %r14
movq %rdi, %r15
movq (%rdi), %rax
movq 0x8(%rdi), %rbx
movq %rbx, %rcx
imulq %rax, %rcx
testq %rcx, %rcx
je 0x17918
cmpq %rax, (%r14)
movq %rsi, (%rsp)
jne 0x1793c
cmpq %rsi, %rbx
jb 0x1797e
movq 0x8(%r14), %r13
movq 0x10(%r14), %rbp
leaq (%rbx,%r13), %r12
movq (%r15), %rax
movq %rax, 0x8(%rsp)
imulq %r12, %rax
movq %rax, %rcx
shrq $0x3e, %rcx
shlq $0x2, %rax
xorl %edi, %edi
negq %rcx
sbbq %rdi, %rdi
orq %rax, %rdi
movq %rsi, %r14
callq 0x9030
movq %r15, 0x20(%rsp)
movq 0x10(%r15), %r15
movq %rbx, %rcx
subq %r14, %rcx
shlq $0x2, %rcx
movq %rcx, 0x38(%rsp)
leaq (,%r14,4), %rdx
movq %r14, %rsi
movq %rdx, 0x30(%rsp)
leaq (%rdx,%r13,4), %rcx
movq %rcx, 0x28(%rsp)
shlq $0x2, %r13
movq %r12, 0x18(%rsp)
leaq (,%r12,4), %rcx
movq %rcx, 0x48(%rsp)
movq %rbx, %r14
leaq (,%rbx,4), %rcx
movq %rcx, 0x40(%rsp)
movq 0x8(%rsp), %r12
movq %rax, 0x10(%rsp)
movq %rax, %rbx
movq %rsi, %rax
subq $0x1, %r12
jb 0x178ed
testq %rax, %rax
je 0x178a6
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x92c0
leaq (%rbx,%r13), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x92c0
movq (%rsp), %rax
cmpq %rax, %r14
je 0x178de
movq 0x28(%rsp), %rax
leaq (%rbx,%rax), %rdi
movq 0x30(%rsp), %rax
leaq (%r15,%rax), %rsi
movq 0x38(%rsp), %rdx
callq 0x92c0
movq (%rsp), %rax
addq 0x48(%rsp), %rbx
addq 0x40(%rsp), %r15
addq %r13, %rbp
jmp 0x1788d
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x17012
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r14), %rsi
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movq %r15, %rdi
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x16f7e
leaq 0x1aba5(%rip), %rsi     # 0x324e8
leaq 0x50(%rsp), %rbx
pushq $0x3
popq %rcx
movq %rbx, %rdi
movl $0xc2, %edx
callq 0x2ee18
leaq 0x1ac93(%rip), %rsi     # 0x325f2
movq %rbx, %rdi
callq 0x9370
leaq 0x50(%rsp), %rdi
callq 0x2f054
movq 0x8(%r15), %rbx
movq (%rsp), %rsi
jmp 0x177e7
leaq 0x1ab63(%rip), %rsi     # 0x324e8
leaq 0x50(%rsp), %rbx
pushq $0x3
popq %rcx
movq %rbx, %rdi
movl $0xc3, %edx
callq 0x2ee18
leaq 0x1ac9e(%rip), %rsi     # 0x3263f
movq %rbx, %rdi
callq 0x9370
leaq 0x50(%rsp), %rdi
callq 0x2f054
movq 0x8(%r15), %rbx
movq (%rsp), %rsi
jmp 0x177f0
jmp 0x179c2
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x2f054
movq %rbx, %rdi
callq 0x95e0
nop