// File: /workspace/github_cpp_makefile_star2_O2/toxaart[P]hierarchical_block_sparse_lib/source/HierarchicalBlockSparseMatrix.h
// Function: hbsm::HierarchicalBlockSparseMatrix<double>::write_to_buffer(char*, unsigned long) const
void HierarchicalBlockSparseMatrix<Treal>::write_to_buffer(char * dataBuffer, size_t const bufferSize) const  {
			if(bufferSize < get_size())
				throw std::runtime_error("Error in HierarchicalBlockSparseMatrix<Treal>::write_to_buffer(): buffer too small.");

			char* p = dataBuffer;

			if(empty()){

				int n_bytes_written = 0;

				memcpy(p, &nRows, sizeof(int));
				p += sizeof(int);
				n_bytes_written += sizeof(int);

				memcpy(p, &nCols, sizeof(int));
				p += sizeof(int);
				n_bytes_written += sizeof(int);

				memcpy(p, &nRows_orig, sizeof(int));
				p += sizeof(int);
				n_bytes_written += sizeof(int);

				memcpy(p, &nCols_orig, sizeof(int));
				p += sizeof(int);
				n_bytes_written += sizeof(int);

				memcpy(p, &blocksize, sizeof(int));
				p += sizeof(int);
				n_bytes_written += sizeof(int);

				memcpy(p, &frob_norm_squared_internal, sizeof(Treal));
				p += sizeof(Treal);
				n_bytes_written += sizeof(Treal);

				memcpy(p, &n_block_multiplies, sizeof(size_t));
				p += sizeof(size_t);
				n_bytes_written += sizeof(size_t);

				//no children - write 4 zeros!
				size_t zero_size = 0;
				memcpy(p, &zero_size, sizeof(size_t));
				p += sizeof(size_t);
				n_bytes_written += sizeof(size_t);

				memcpy(p, &zero_size, sizeof(size_t));
				p += sizeof(size_t);
				n_bytes_written += sizeof(size_t);

				memcpy(p, &zero_size, sizeof(size_t));
				p += sizeof(size_t);
				n_bytes_written += sizeof(size_t);

				memcpy(p, &zero_size, sizeof(size_t));
				p += sizeof(size_t);
				n_bytes_written += sizeof(size_t);

				return;
			}


			if(lowest_level()){

				memcpy(p, &nRows, sizeof(int));
				p += sizeof(int);

				memcpy(p, &nCols, sizeof(int));
				p += sizeof(int);

				memcpy(p, &nRows_orig, sizeof(int));
				p += sizeof(int);

				memcpy(p, &nCols_orig, sizeof(int));
				p += sizeof(int);

				memcpy(p, &blocksize, sizeof(int));
				p += sizeof(int);

				memcpy(p, &frob_norm_squared_internal, sizeof(Treal));
				p += sizeof(Treal);

				memcpy(p, &n_block_multiplies, sizeof(size_t));
				p += sizeof(size_t);

				//no children - write 4 zeros!
				size_t zero_size = 0;
				memcpy(p, &zero_size, sizeof(size_t));
				p += sizeof(size_t);

				memcpy(p, &zero_size, sizeof(size_t));
				p += sizeof(size_t);

				memcpy(p, &zero_size, sizeof(size_t));
				p += sizeof(size_t);

				memcpy(p, &zero_size, sizeof(size_t));
				p += sizeof(size_t);

				memcpy(p, &submatrix[0], submatrix.size() * sizeof(Treal));
				p += submatrix.size() * sizeof(Treal);

				return;
			}

			size_t size_child0 = 0, size_child1 = 0, size_child2 = 0, size_child3 = 0;
			std::vector<char> buf_child0, buf_child1, buf_child2, buf_child3;

			if(children[0] != NULL){ // if child do not exist, its size will be zero!
				size_child0 = children[0]->get_size();
				buf_child0.resize(size_child0);
				children[0]->write_to_buffer(&buf_child0[0],size_child0);
			}

			if(children[1] != NULL){
				size_child1 = children[1]->get_size();
				buf_child1.resize(size_child1);
				children[1]->write_to_buffer(&buf_child1[0],size_child1);
			}

			if(children[2] != NULL){
				size_child2 = children[2]->get_size();
				buf_child2.resize(size_child2);
				children[2]->write_to_buffer(&buf_child2[0],size_child2);
			}

			if(children[3] != NULL){
				size_child3 = children[3]->get_size();
				buf_child3.resize(size_child3);
				children[3]->write_to_buffer(&buf_child3[0],size_child3);
			}


			memcpy(p, &nRows, sizeof(int));
			p += sizeof(int);

			memcpy(p, &nCols, sizeof(int));
			p += sizeof(int);

			memcpy(p, &nRows_orig, sizeof(int));
			p += sizeof(int);

			memcpy(p, &nCols_orig, sizeof(int));
			p += sizeof(int);

			memcpy(p, &blocksize, sizeof(int));
			p += sizeof(int);

			memcpy(p, &frob_norm_squared_internal, sizeof(Treal));
			p += sizeof(Treal);

			memcpy(p, &n_block_multiplies, sizeof(size_t));
			p += sizeof(size_t);

			// write sizes of children even if they are zeros!
			memcpy(p, &size_child0, sizeof(size_t));
			p += sizeof(size_t);

			memcpy(p, &size_child1, sizeof(size_t));
			p += sizeof(size_t);

			memcpy(p, &size_child2, sizeof(size_t));
			p += sizeof(size_t);

			memcpy(p, &size_child3, sizeof(size_t));
			p += sizeof(size_t);


	    if(size_child0 > 0){ // if child size is > 0, write size and the child itself
				memcpy(p, &buf_child0[0],  size_child0);
				p += size_child0;
			}

			if(size_child1 > 0){
				memcpy(p, &buf_child1[0],  size_child1);
				p += size_child1;
			}

			if(size_child2 > 0){
				memcpy(p, &buf_child2[0],  size_child2);
				p += size_child2;
			}

			if(size_child3 > 0){
				memcpy(p, &buf_child3[0],  size_child3);
				p += size_child3;
			}

		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
callq 0x4668
cmpq %r15, %rax
ja 0x49fa
movq %r14, %rdi
callq 0x39bc
testb %al, %al
je 0x47c0
movl (%r14), %eax
movl %eax, (%rbx)
movl 0x4(%r14), %eax
movl %eax, 0x4(%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%r14), %eax
movl %eax, 0xc(%rbx)
movl 0x10(%r14), %eax
movl %eax, 0x10(%rbx)
movq 0x18(%r14), %rax
movq %rax, 0x14(%rbx)
movq 0x20(%r14), %rax
movq %rax, 0x1c(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x24(%rbx)
movups %xmm0, 0x34(%rbx)
jmp 0x49eb
movq %r14, %rdi
callq 0x5a0a
testb %al, %al
je 0x482a
movl (%r14), %eax
movl %eax, (%rbx)
movl 0x4(%r14), %eax
movl %eax, 0x4(%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%r14), %eax
movl %eax, 0xc(%rbx)
movl 0x10(%r14), %eax
movl %eax, 0x10(%rbx)
movq 0x18(%r14), %rax
movq %rax, 0x14(%rbx)
movq 0x20(%r14), %rax
movq %rax, 0x1c(%rbx)
leaq 0x44(%rbx), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x24(%rbx)
movups %xmm0, 0x34(%rbx)
movq 0x70(%r14), %rsi
movq 0x78(%r14), %rdx
subq %rsi, %rdx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2120
andq $0x0, 0x70(%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
andq $0x0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, (%rsp)
movq 0x28(%r14), %rdi
testq %rdi, %rdi
je 0x4889
callq 0x4668
movq %rax, %r15
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x6fcc
movq 0x28(%r14), %rdi
movq 0x60(%rsp), %rsi
movq %r15, %rdx
callq 0x474e
jmp 0x488c
xorl %r15d, %r15d
movq 0x38(%r14), %rdi
testq %rdi, %rdi
je 0x48bd
callq 0x4668
movq %rax, %r12
leaq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x6fcc
movq 0x38(%r14), %rdi
movq 0x40(%rsp), %rsi
movq %r12, %rdx
callq 0x474e
jmp 0x48c0
xorl %r12d, %r12d
movq 0x48(%r14), %rdi
testq %rdi, %rdi
je 0x48f1
callq 0x4668
movq %rax, %r13
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x6fcc
movq 0x48(%r14), %rdi
movq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x474e
jmp 0x48f4
xorl %r13d, %r13d
movq 0x58(%r14), %rdi
testq %rdi, %rdi
je 0x4922
callq 0x4668
movq %rax, %rbp
movq %rsp, %rdi
movq %rax, %rsi
callq 0x6fcc
movq 0x58(%r14), %rdi
movq (%rsp), %rsi
movq %rbp, %rdx
callq 0x474e
jmp 0x4924
xorl %ebp, %ebp
movl (%r14), %eax
movl %eax, (%rbx)
movl 0x4(%r14), %eax
movl %eax, 0x4(%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%r14), %eax
movl %eax, 0xc(%rbx)
movl 0x10(%r14), %eax
movl %eax, 0x10(%rbx)
movq 0x18(%r14), %rax
movq %rax, 0x14(%rbx)
movq 0x20(%r14), %rax
movq %rax, 0x1c(%rbx)
movq %r15, 0x24(%rbx)
movq %r12, 0x2c(%rbx)
movq %r13, 0x34(%rbx)
movq %rbp, 0x3c(%rbx)
addq $0x44, %rbx
testq %r15, %r15
je 0x4981
movq 0x60(%rsp), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x2120
addq %r15, %rbx
testq %r12, %r12
je 0x4999
movq 0x40(%rsp), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x2120
addq %r12, %rbx
testq %r13, %r13
je 0x49b1
movq 0x20(%rsp), %rsi
movq %rbx, %rdi
movq %r13, %rdx
callq 0x2120
addq %r13, %rbx
testq %rbp, %rbp
je 0x49c5
movq (%rsp), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x2120
movq %rsp, %rdi
callq 0x6f52
leaq 0x20(%rsp), %rdi
callq 0x6f52
leaq 0x40(%rsp), %rdi
callq 0x6f52
leaq 0x60(%rsp), %rdi
callq 0x6f52
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %r14
leaq 0x446b(%rip), %rsi      # 0x8e77
movq %rax, %rdi
callq 0x2050
movq 0x85d5(%rip), %rsi      # 0xcff0
movq 0x859e(%rip), %rdx      # 0xcfc0
movq %r14, %rdi
callq 0x21d0
movq %rax, %rbx
movq %r14, %rdi
callq 0x2100
jmp 0x4a60
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6f52
leaq 0x20(%rsp), %rdi
callq 0x6f52
leaq 0x40(%rsp), %rdi
callq 0x6f52
leaq 0x60(%rsp), %rdi
callq 0x6f52
movq %rbx, %rdi
callq 0x21f0