// File: /workspace/github_cpp_makefile_star2_O1/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 $0x27b8, %rsp           # imm = 0x27B8
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 %ebp, %ebp
testl %edx, %edx
setg %bpl
addl %eax, %ebp
movl %r8d, 0x8(%rsp)
imull %r8d, %ebp
movslq %ebp, %r14
cmpq %r12, %r14
jb 0x10b14
xorpd %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %r14, %rsi
callq 0x1fea8
testl %ebp, %ebp
jle 0x10862
movq 0x50(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r14
jne 0x10857
leaq 0xa8(%rsp), %rdi
callq 0x1feda
leaq 0xa8(%rsp), %rdi
callq 0x2200
movl %eax, %eax
movq %rax, 0x1430(%rsp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, 0x1430(%rsp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x1088b
leaq 0x1430(%rsp), %rdx
movq $0x270, 0x1380(%rdx) # imm = 0x270
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x1ff54
xorpd %xmm0, %xmm0
leaq 0x70(%rsp), %rdi
movapd %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
movq %rax, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
movslq 0x10(%rbx), %rax
movq %rax, %rsi
imulq %r12, %rsi
imulq %rax, %rsi
callq 0x1fea8
movslq 0x10(%rbx), %rax
movq %rax, %rsi
imulq %r12, %rsi
imulq %rax, %rsi
leaq 0x30(%rsp), %rdi
callq 0x1fea8
movslq 0x10(%rbx), %rax
movq %rax, %rsi
imulq %r12, %rsi
imulq %rax, %rsi
leaq 0x10(%rsp), %rdi
callq 0x1aea2
movq $0x1, 0xa0(%rsp)
testq %r12, %r12
je 0x10a4f
xorl %edx, %edx
xorl %r15d, %r15d
movq %r12, 0x90(%rsp)
movl 0x10(%rbx), %ecx
movq 0x50(%rsp), %rax
movq %rdx, 0x98(%rsp)
movl (%rax,%rdx,4), %eax
cltd
idivl 0x8(%rsp)
testl %ecx, %ecx
je 0x10a31
movl %eax, %r13d
imull %ecx, %r13d
imull %ecx, %edx
movl %edx, 0xc(%rsp)
xorl %r14d, %r14d
movl %r14d, %eax
cltd
idivl %ecx
movl %eax, %ebp
movl %edx, %r12d
movq 0x68(%rbx), %rax
movq %rbx, %rcx
testq %rax, %rax
je 0x109ba
movq %rbx, %rdx
movq %rdx, %rcx
movq 0x68(%rdx), %rdx
testq %rdx, %rdx
jne 0x109ae
addl %r13d, %ebp
cmpl 0x8(%rcx), %ebp
jge 0x10a1d
movq %rbx, %rcx
testq %rax, %rax
je 0x109d9
movq %rbx, %rax
movq %rax, %rcx
movq 0x68(%rax), %rax
testq %rax, %rax
jne 0x109cd
addl 0xc(%rsp), %r12d
cmpl 0xc(%rcx), %r12d
jge 0x10a1d
leaq 0xa0(%rsp), %rdi
callq 0x20408
addsd %xmm0, %xmm0
addsd 0x12733(%rip), %xmm0    # 0x23130
movq 0x10(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
movq 0x70(%rsp), %rax
movl %ebp, (%rax,%r15,4)
movq 0x30(%rsp), %rax
movl %r12d, (%rax,%r15,4)
incq %r15
incl %r14d
movl 0x10(%rbx), %ecx
movl %ecx, %eax
imull %ecx, %eax
cmpl %eax, %r14d
jb 0x10994
movq 0x98(%rsp), %rdx
incq %rdx
movq 0x90(%rsp), %r12
cmpq %r12, %rdx
jne 0x10963
jmp 0x10a52
xorl %r15d, %r15d
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x1fea8
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x1fea8
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x1aea2
leaq 0x70(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1c848
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x10aad
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x10ac4
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x10ade
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq 0xa8(%rsp), %rdi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x10b02
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
addq $0x27b8, %rsp           # imm = 0x27B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x20c0
movq %rax, %r14
leaq 0x13ebc(%rip), %rsi     # 0x249e4
movq %rax, %rdi
callq 0x20a0
movq 0x1a4b9(%rip), %rsi     # 0x2aff0
movq 0x1a482(%rip), %rdx     # 0x2afc0
movq %r14, %rdi
callq 0x2290
movq %rax, %rbx
movq %r14, %rdi
callq 0x2140
jmp 0x10bda
jmp 0x10be2
jmp 0x10b5d
movq %rax, %rbx
jmp 0x10bc3
movq %rax, %rbx
jmp 0x10bb6
jmp 0x10b6b
jmp 0x10b6b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x10b85
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x10b9c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x10bb6
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq 0xa8(%rsp), %rdi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x10bda
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x1af02