// File: toxaart[P]hierarchical_block_sparse_lib/source/HierarchicalBlockSparseMatrix.h
// Function: hbsm::HierarchicalBlockSparseMatrix<double>::resize(int, int, unsigned long*)
void HierarchicalBlockSparseMatrix<Treal>::resize(int nRows_, int nCols_, size_t* no_of_resizes) {
		assert(blocksize > 0);

		if(!empty()) clear();

		nRows_orig = nRows_; // only top level contains true size, rest have duplicates of nRows and nCols
		nCols_orig = nCols_;

		// lowest level
		if(nRows_ <= blocksize && nCols_ <= blocksize){
			nRows = blocksize;
			nCols = blocksize;
			submatrix.resize(blocksize*blocksize);
			if(no_of_resizes != NULL) (*no_of_resizes)++;
			return;
		}

		// actually, matrix is always kept square, with padding with zeros where necessary
		// the "virtual dimension" can be computed as blocksize * 2^P,
		// where P is such that blocksize * 2^(P-1) <= max(nRows_, nCols_) <= blocksize * 2^P

		int maxdim = ((nRows_ > nCols_) ? nRows_ : nCols_);

		//how many times block covers maxdim
		int n_covers = maxdim / blocksize;
		if(maxdim % blocksize != 0) n_covers += 1;

		// now we need to find P such that 2^(P-1) <= n_covers <= 2^P
		int P = 1;
		int two_to_power_P = 2;
		while(n_covers >  two_to_power_P){
			two_to_power_P *= 2;
			P += 1;
		}

		int virtual_size = blocksize * two_to_power_P;


		nRows = virtual_size;
		nCols = virtual_size;

	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, 0x10(%rax)
jle 0x49f6
jmp 0x4a15
leaq 0xcb2a(%rip), %rdi      # 0x11527
leaq 0xcb31(%rip), %rsi      # 0x11535
movl $0x221, %edx            # imm = 0x221
leaq 0xcb9c(%rip), %rcx      # 0x115ac
callq 0x2100
movq -0x38(%rbp), %rdi
callq 0x4970
testb $0x1, %al
jne 0x4a2b
movq -0x38(%rbp), %rdi
callq 0x4be0
movq -0x38(%rbp), %rcx
movl -0xc(%rbp), %eax
movl %eax, 0x8(%rcx)
movl -0x10(%rbp), %eax
movl %eax, 0xc(%rcx)
movl -0xc(%rbp), %eax
cmpl 0x10(%rcx), %eax
jg 0x4a8e
movq -0x38(%rbp), %rcx
movl -0x10(%rbp), %eax
cmpl 0x10(%rcx), %eax
jg 0x4a8e
movq -0x38(%rbp), %rcx
movl 0x10(%rcx), %eax
movl %eax, (%rcx)
movl 0x10(%rcx), %eax
movl %eax, 0x4(%rcx)
movq %rcx, %rdi
addq $0x70, %rdi
movl 0x10(%rcx), %eax
imull 0x10(%rcx), %eax
movslq %eax, %rsi
callq 0x8c60
cmpq $0x0, -0x18(%rbp)
je 0x4a89
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x4b0f
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jle 0x4a9e
movl -0xc(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x4aa4
movl -0x10(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x3c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cltd
idivl 0x10(%rcx)
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cltd
idivl 0x10(%rcx)
cmpl $0x0, %edx
je 0x4acd
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x2, -0x28(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jle 0x4af6
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4adb
movq -0x38(%rbp), %rax
movl 0x10(%rax), %ecx
imull -0x28(%rbp), %ecx
movl %ecx, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
movl -0x2c(%rbp), %ecx
movl %ecx, 0x4(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop