// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1e8, %rsp            # imm = 0x1E8
movq %rdx, %r12
movq %rsi, 0x8(%rsp)
movq %rdi, %r13
movq (%rdi), %rax
movq 0x8(%rdi), %rbx
movq %rbx, %rcx
imulq %rax, %rcx
testq %rcx, %rcx
je 0x191c1
cmpq %rax, (%r12)
jne 0x19269
cmpq 0x8(%rsp), %rbx
jb 0x192ae
movq 0x8(%r12), %r15
movq 0x10(%r12), %r12
leaq (%rbx,%r15), %r14
movq (%r13), %rbp
movq %rbp, %rax
imulq %r14, %rax
movq %rax, %rcx
shrq $0x3e, %rcx
shlq $0x2, %rax
xorl %edi, %edi
negq %rcx
sbbq %rdi, %rdi
orq %rax, %rdi
callq 0x9030
testq %rbp, %rbp
je 0x19237
movq %r13, 0x30(%rsp)
movq 0x10(%r13), %rdx
movq %rbx, %rsi
movq 0x8(%rsp), %rcx
subq %rcx, %rsi
shlq $0x2, %rsi
movq %rsi, 0x48(%rsp)
leaq (,%rcx,4), %rsi
movq %rsi, 0x40(%rsp)
leaq (%rsi,%r15,4), %rcx
movq %rcx, 0x38(%rsp)
shlq $0x2, %r15
movq %r14, 0x28(%rsp)
leaq (,%r14,4), %rcx
movq %rcx, 0x58(%rsp)
movq %rbx, %r14
leaq (,%rbx,4), %rcx
movq %rcx, 0x50(%rsp)
movq %rbp, %r13
movq %rdx, 0x10(%rsp)
movq %rdx, %rbp
movq %r13, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, %rbx
cmpq $0x0, 0x8(%rsp)
je 0x19162
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x92b0
leaq (%rbx,%r15), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x92b0
cmpq 0x8(%rsp), %r14
je 0x19194
movq 0x38(%rsp), %rax
leaq (%rbx,%rax), %rdi
movq 0x40(%rsp), %rax
leaq (%rax,%rbp), %rsi
movq 0x48(%rsp), %rdx
callq 0x92b0
addq 0x58(%rsp), %rbx
addq 0x50(%rsp), %rbp
addq %r15, %r12
decq %r13
jne 0x1914c
movq 0x30(%rsp), %r13
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rdi
jmp 0x1923b
movq 0x10(%r12), %rbx
movq (%r12), %r15
movq 0x8(%r12), %r12
movq %r12, %r14
imulq %r15, %r14
movq 0x10(%r13), %rdi
testq %r14, %r14
je 0x1920f
testq %rdi, %rdi
je 0x191e9
callq 0x9420
movq %r14, %rax
shrq $0x3e, %rax
leaq (,%r14,4), %rcx
xorl %edi, %edi
negq %rax
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x9030
movq %rax, %rdi
movq %rax, 0x10(%r13)
movq %r15, (%r13)
movq %r12, 0x8(%r13)
shlq $0x2, %r14
movq %rbx, %rsi
movq %r14, %rdx
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x92b0
movq 0x10(%r13), %rdi
testq %rdi, %rdi
je 0x1924b
movq %rax, %rbx
callq 0x9420
movq %rbx, %rax
movq %rax, 0x10(%r13)
movq %rbp, (%r13)
movq %r14, 0x8(%r13)
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x232d0(%rip), %rsi     # 0x3c540
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movl $0xc2, %edx
movl $0x3, %ecx
callq 0x387b6
leaq 0x233bc(%rip), %rsi     # 0x3c64a
movl $0x21, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x60(%rsp), %rdi
callq 0x389de
movq 0x8(%r13), %rbx
jmp 0x19093
leaq 0x2328b(%rip), %rsi     # 0x3c540
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movl $0xc3, %edx
movl $0x3, %ecx
callq 0x387b6
leaq 0x233c4(%rip), %rsi     # 0x3c697
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x93b0
leaq 0x60(%rsp), %rdi
callq 0x389de
movq 0x8(%r13), %rbx
jmp 0x1909e
jmp 0x192f5
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x389de
movq %rbx, %rdi
callq 0x95d0