// File: /workspace/github_cpp_makefile_star2_O3/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 %r15d, %r15d
testl %edx, %edx
setg %r15b
addl %eax, %r15d
movl %r8d, 0x8(%rsp)
imull %r8d, %r15d
movslq %r15d, %r14
cmpq %r12, %r14
jb 0x10d0b
pxor %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movdqa %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %r14, %rsi
callq 0x2045a
testl %r15d, %r15d
jle 0x10a54
movq 0x50(%rsp), %rax
incl %r15d
andl $-0x2, %r15d
decq %r14
movq %r14, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x1391c(%rip), %xmm1    # 0x24300
xorl %ecx, %ecx
movdqa 0x13922(%rip), %xmm2    # 0x24310
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x13922(%rip), %xmm4    # 0x24320
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0x10a32
movl %ecx, (%rax,%rcx,4)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x10a47
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rax,%rcx,4)
addq $0x2, %rcx
paddq %xmm4, %xmm1
cmpq %rcx, %r15
jne 0x109fe
leaq 0xa8(%rsp), %rdi
callq 0x2048c
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 0x10a7d
leaq 0x1430(%rsp), %rdx
movq $0x270, 0x1380(%rdx) # imm = 0x270
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x20506
pxor %xmm0, %xmm0
leaq 0x70(%rsp), %rdi
movdqa %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
movq %rax, 0x40(%rsp)
movdqa %xmm0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movdqa %xmm0, 0x10(%rsp)
movslq 0x10(%rbx), %rax
movq %rax, %rsi
imulq %r12, %rsi
imulq %rax, %rsi
callq 0x2045a
movslq 0x10(%rbx), %rax
movq %rax, %rsi
imulq %r12, %rsi
imulq %rax, %rsi
leaq 0x30(%rsp), %rdi
callq 0x2045a
movslq 0x10(%rbx), %rax
movq %rax, %rsi
imulq %r12, %rsi
imulq %rax, %rsi
leaq 0x10(%rsp), %rdi
callq 0x1b416
movq $0x1, 0xa0(%rsp)
testq %r12, %r12
je 0x10c46
movl 0x10(%rbx), %ecx
xorl %edx, %edx
movl %ecx, %esi
xorl %r15d, %r15d
movq %r12, 0x90(%rsp)
movq 0x50(%rsp), %rax
movq %rdx, 0x98(%rsp)
movl (%rax,%rdx,4), %eax
cltd
idivl 0x8(%rsp)
testl %esi, %esi
je 0x10c26
movl %eax, %r13d
imull %esi, %r13d
imull %esi, %edx
movl %edx, 0xc(%rsp)
xorl %r14d, %r14d
movl %r14d, %eax
cltd
idivl %esi
movl %edx, %r12d
movl %eax, %ebp
addl %r13d, %ebp
cmpq $0x0, 0x68(%rbx)
je 0x10bc2
movq %rbx, %rdx
movq %rdx, %rax
movq 0x68(%rdx), %rdx
testq %rdx, %rdx
jne 0x10ba0
movq %rbx, %rdx
cmpl 0x8(%rax), %ebp
jge 0x10c11
movq %rdx, %rax
movq 0x68(%rdx), %rdx
testq %rdx, %rdx
jne 0x10bb4
jmp 0x10bca
movq %rbx, %rax
cmpl 0x8(%rbx), %ebp
jge 0x10c11
addl 0xc(%rsp), %r12d
cmpl 0xc(%rax), %r12d
jge 0x10c11
leaq 0xa0(%rsp), %rdi
callq 0x209e6
addsd %xmm0, %xmm0
addsd 0x13542(%rip), %xmm0    # 0x24130
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
movl 0x10(%rbx), %ecx
incl %r14d
movl %ecx, %eax
imull %ecx, %eax
movl %ecx, %esi
cmpl %eax, %r14d
jb 0x10b88
jmp 0x10c28
xorl %esi, %esi
movq 0x98(%rsp), %rdx
incq %rdx
movq 0x90(%rsp), %r12
cmpq %r12, %rdx
jne 0x10b5a
jmp 0x10c49
xorl %r15d, %r15d
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x2045a
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x2045a
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x1b416
leaq 0x70(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1cda0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x10ca4
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x10cbb
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x10cd5
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq 0xa8(%rsp), %rdi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x10cf9
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 0x14d25(%rip), %rsi     # 0x25a44
movq %rax, %rdi
callq 0x20a0
movq 0x1b2c2(%rip), %rsi     # 0x2bff0
movq 0x1b28b(%rip), %rdx     # 0x2bfc0
movq %r14, %rdi
callq 0x2290
movq %rax, %rbx
movq %r14, %rdi
callq 0x2140
jmp 0x10dd1
jmp 0x10dd9
jmp 0x10d54
movq %rax, %rbx
jmp 0x10dba
movq %rax, %rbx
jmp 0x10dad
jmp 0x10d62
jmp 0x10d62
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x10d7c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x10d93
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x10dad
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq 0xa8(%rsp), %rdi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x10dd1
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x1b476
nop