// File: toxaart[P]hierarchical_block_sparse_lib/source/HierarchicalBlockSparseMatrix.h
// Function: hbsm::HierarchicalBlockSparseMatrix<double>::remove_dummy_levels(hbsm::HierarchicalBlockSparseMatrix<double>&, int)
void HierarchicalBlockSparseMatrix<Treal>::remove_dummy_levels(HierarchicalBlockSparseMatrix<Treal> & C, int n_dummy_levels){

			if(n_dummy_levels == 0) throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::remove_dummy_levels(): n_dummy_levels = 0!");

			HierarchicalBlockSparseMatrix<Treal> *ptr = &C;
			if(!C.children_exist() && !C.lowest_level()){
				int nRows = C.nRows;
				for(int i = 0; i < n_dummy_levels; ++i){
					nRows = nRows / 2;
				}
				C.nRows = nRows;
				C.nCols = nRows;
				return;
			}


			for(int i = 0; i < n_dummy_levels; ++i){
				if(ptr->children[0] != NULL) ptr = ptr->children[0].get();
				else throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::remove_dummy_levels(): error when squeezing matrix!");
			}

			// ok, we have found a child which is the "correct matrix", ptr is pointing to it

			// "replace" C with this "correct" matrix

			C.nRows = ptr->nRows;
			C.nCols = ptr->nCols;

			if(ptr->lowest_level()){
				C.submatrix.clear();
				C.submatrix.resize(C.blocksize*C.blocksize);
				std::memcpy(&C.submatrix[0], &ptr->submatrix[0], C.submatrix.size() * sizeof(Treal));
				for(int i = 0; i < 4; ++i) C.children[0] = nullptr;
			}
			else{
				for(int i = 0; i < 4; ++i) C.children[i] = ptr->children[i];
			}

			ptr->parent = &C;

	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x27a38
movl $0x10, %edi
callq 0x20d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x58(%rbp)
leaq 0xf527(%rip), %rsi      # 0x36f27
callq 0x20a0
jmp 0x27a07
movq -0x58(%rbp), %rdi
movq 0x195de(%rip), %rsi     # 0x40ff0
movq 0x195a7(%rip), %rdx     # 0x40fc0
callq 0x2320
movq -0x58(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x2150
jmp 0x27c7e
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x23140
testb $0x1, %al
jne 0x27aa3
movq -0x8(%rbp), %rdi
callq 0x23500
testb $0x1, %al
jne 0x27aa3
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x27a8b
movl -0x2c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x27a6a
movl -0x2c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movl -0x2c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x27c78
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x27b43
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x232b0
testb $0x1, %al
jne 0x27acd
jmp 0x27ae0
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
callq 0x23730
movq %rax, -0x28(%rbp)
jmp 0x27b33
movl $0x10, %edi
callq 0x20d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
leaq 0xf47f(%rip), %rsi      # 0x36f7a
callq 0x20a0
jmp 0x27b02
movq -0x60(%rbp), %rdi
movq 0x194e3(%rip), %rsi     # 0x40ff0
movq 0x194ac(%rip), %rdx     # 0x40fc0
callq 0x2320
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x2150
jmp 0x27c7e
jmp 0x27b35
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x27aaa
movq -0x28(%rbp), %rax
movl (%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rdi
callq 0x23500
testb $0x1, %al
jne 0x27b6f
jmp 0x27c27
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
callq 0x23550
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x8(%rbp), %rcx
imull 0x10(%rcx), %eax
movslq %eax, %rsi
callq 0x23470
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x22b60
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rdi
addq $0x70, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x22b60
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
callq 0x22b40
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq %rax, %rdx
shlq $0x3, %rdx
callq 0x21a0
movl $0x0, -0x38(%rbp)
cmpl $0x4, -0x38(%rbp)
jge 0x27c25
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x23590
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
leaq -0x48(%rbp), %rsi
callq 0x235b0
leaq -0x48(%rbp), %rdi
callq 0x235e0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x27bed
jmp 0x27c6c
movl $0x0, -0x4c(%rbp)
cmpl $0x4, -0x4c(%rbp)
jge 0x27c6a
movq -0x28(%rbp), %rsi
addq $0x28, %rsi
movslq -0x4c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
movslq -0x4c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
callq 0x273b0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x27c2e
jmp 0x27c6c
movq -0x8(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x68(%rax)
addq $0x70, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x2340
nopw (%rax,%rax)