// File: /workspace/github_cpp_makefile_star2_O2/toxaart[P]hierarchical_block_sparse_lib/source/HierarchicalBlockSparseMatrix.h
// Function: hbsm::HierarchicalBlockSparseMatrix<double>::random_blocks(unsigned long)
void HierarchicalBlockSparseMatrix<Treal>::random_blocks(size_t nnz_blocks){

            // assume matrix is resized and we are at the top level;

            int M = nRows_orig;
            int N = nCols_orig;

            int n_block_dim1 = M / blocksize;
            if(M % blocksize > 0) n_block_dim1 += 1;

            int n_block_dim2 = N / blocksize;
            if(N % blocksize > 0) n_block_dim2 += 1;

            int total_number_of_blocks = n_block_dim1 * n_block_dim2;

            if(nnz_blocks > total_number_of_blocks) throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::random_blocks():too many blocks!");

            std::vector<int> v;
            v.resize(total_number_of_blocks);
            for(int i = 0; i < total_number_of_blocks; ++i) v[i] = i;

            std::random_device rd;
            std::mt19937 g(rd());
            std::shuffle(v.begin(), v.end(), g);

            std::vector<int> row_indices, col_indices;
            std::vector<Treal> values;

            row_indices.resize(nnz_blocks * blocksize * blocksize);
            col_indices.resize(nnz_blocks * blocksize * blocksize);
            values.resize(nnz_blocks * blocksize * blocksize);

            size_t element_counter = 0;

            double lower_bound = -1.0;
            double upper_bound = 1.0;
            std::uniform_real_distribution<double> unif(lower_bound,upper_bound);
            std::default_random_engine re;

            for(int k = 0; k < nnz_blocks; ++k){

                int block_row_pos = blocksize * (v[k] / n_block_dim1);
                int block_col_pos = blocksize * (v[k] % n_block_dim1);

                for(int i = 0; i < blocksize*blocksize; ++i){

                    int element_row_pos = block_row_pos + i / blocksize;
                    int element_col_pos = block_col_pos + i % blocksize;

                    if(element_row_pos > get_n_rows()-1 || element_col_pos > get_n_cols()-1) continue;

                    values[element_counter] = unif(re);
                    row_indices[element_counter] = element_row_pos;
                    col_indices[element_counter] = element_col_pos;

                    element_counter++;
                }

            }

            row_indices.resize(element_counter);
            col_indices.resize(element_counter);
            values.resize(element_counter);



            assign_from_vectors(row_indices, col_indices, values);



        }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x27c8, %rsp           # imm = 0x27C8
movq %rsi, %r12
movq %rdi, %rbx
movl 0x8(%rdi), %eax
movl 0xc(%rdi), %ecx
movl 0x10(%rdi), %edi
cltd
idivl %edi
movl %eax, %esi
xorl %r8d, %r8d
testl %edx, %edx
setg %r8b
movl %ecx, %eax
cltd
idivl %edi
addl %esi, %r8d
xorl %r14d, %r14d
testl %edx, %edx
setg %r14b
addl %eax, %r14d
movl %r8d, 0x8(%rsp)
imull %r8d, %r14d
movslq %r14d, %rsi
cmpq %r12, %rsi
jb 0xd87b
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
callq 0x18f3e
movq 0x50(%rsp), %rax
xorl %ecx, %ecx
testl %r14d, %r14d
cmovlel %ecx, %r14d
cmpq %rcx, %r14
je 0xd65f
movl %ecx, (%rax,%rcx,4)
incq %rcx
jmp 0xd652
leaq 0xb8(%rsp), %rdi
callq 0x18f70
leaq 0xb8(%rsp), %rdi
callq 0x21f0
movl %eax, %esi
leaq 0x1440(%rsp), %rdi
callq 0x19242
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
leaq 0x1440(%rsp), %rdx
callq 0x18fc5
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movslq 0x10(%rbx), %rax
movq %rax, %rsi
imulq %r12, %rsi
imulq %rax, %rsi
callq 0x18f3e
movslq 0x10(%rbx), %rax
movq %rax, %rsi
imulq %r12, %rsi
imulq %rax, %rsi
leaq 0x30(%rsp), %rdi
callq 0x18f3e
movslq 0x10(%rbx), %rax
movq %rax, %rsi
imulq %r12, %rsi
imulq %rax, %rsi
leaq 0x10(%rsp), %rdi
callq 0x14f62
movaps 0xebee(%rip), %xmm0     # 0x1c300
leaq 0xa0(%rsp), %rax
movaps %xmm0, (%rax)
leaq 0x98(%rsp), %rax
movq $0x1, (%rax)
xorl %edx, %edx
xorl %r15d, %r15d
movq %r12, 0x88(%rsp)
cmpq %r12, %rdx
je 0xd7f6
movl 0x10(%rbx), %ecx
movq 0x50(%rsp), %rax
movq %rdx, 0x90(%rsp)
movl (%rax,%rdx,4), %eax
cltd
idivl 0x8(%rsp)
movl %eax, %r14d
imull %ecx, %r14d
imull %ecx, %edx
movl %edx, 0xc(%rsp)
xorl %r12d, %r12d
movl %ecx, %eax
imull %ecx, %eax
cmpl %eax, %r12d
jae 0xd7de
movl %r12d, %eax
cltd
idivl %ecx
movl %edx, %r13d
movl %eax, %ebp
addl %r14d, %ebp
movq %rbx, %rdi
callq 0x15274
cmpl %eax, %ebp
jge 0xd7d6
addl 0xc(%rsp), %r13d
movq %rbx, %rdi
callq 0x152d0
cmpl %eax, %r13d
jge 0xd7d6
leaq 0xa0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x190f2
movq 0x10(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
movq 0x70(%rsp), %rax
movl %ebp, (%rax,%r15,4)
movq 0x30(%rsp), %rax
movl %r13d, (%rax,%r15,4)
incq %r15
incl %r12d
movl 0x10(%rbx), %ecx
jmp 0xd76b
movq 0x90(%rsp), %rdx
incq %rdx
movq 0x88(%rsp), %r12
jmp 0xd739
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x18f3e
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x18f3e
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x14f62
leaq 0x70(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
callq 0xbd96
leaq 0x10(%rsp), %rdi
callq 0x1722c
leaq 0x30(%rsp), %rdi
callq 0x1724a
leaq 0x70(%rsp), %rdi
callq 0x1724a
leaq 0xb8(%rsp), %rdi
callq 0x190fa
leaq 0x50(%rsp), %rdi
callq 0x1724a
addq $0x27c8, %rsp           # imm = 0x27C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20d0
movq %rax, %r14
leaq 0x10167(%rip), %rsi     # 0x1d9f4
movq %rax, %rdi
callq 0x2080
movq 0x18754(%rip), %rsi     # 0x25ff0
movq 0x1871d(%rip), %rdx     # 0x25fc0
movq %r14, %rdi
callq 0x2270
movq %rax, %rbx
movq %r14, %rdi
callq 0x2130
jmp 0xd900
jmp 0xd8ba
movq %rax, %rbx
jmp 0xd8f6
jmp 0xd8c8
movq %rax, %rbx
jmp 0xd8e9
jmp 0xd8c8
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1722c
leaq 0x30(%rsp), %rdi
callq 0x1724a
leaq 0x70(%rsp), %rdi
callq 0x1724a
leaq 0xb8(%rsp), %rdi
callq 0x190fa
leaq 0x50(%rsp), %rdi
callq 0x1724a
movq %rbx, %rdi
callq 0x2290