// File: /workspace/github_cpp_makefile_star2_O3/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 0x519e
cmpq %r15, %rax
ja 0x557f
movq %r14, %rdi
callq 0x42c4
testb %al, %al
je 0x5310
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 0x5570
movq %r14, %rdi
callq 0x6b0e
testb %al, %al
je 0x537a
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 0x2100
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
xorl %r15d, %r15d
movq %r15, 0x70(%rsp)
movq %r15, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq %r15, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq %r15, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq 0x28(%r14), %rdi
testq %rdi, %rdi
je 0x53d6
callq 0x519e
movq %rax, %r15
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x82e8
movq 0x28(%r14), %rdi
movq 0x60(%rsp), %rsi
movq %r15, %rdx
callq 0x529e
movq 0x38(%r14), %rdi
testq %rdi, %rdi
je 0x5407
callq 0x519e
movq %rax, %r12
leaq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x82e8
movq 0x38(%r14), %rdi
movq 0x40(%rsp), %rsi
movq %r12, %rdx
callq 0x529e
jmp 0x540a
xorl %r12d, %r12d
movq 0x48(%r14), %rdi
testq %rdi, %rdi
je 0x543b
callq 0x519e
movq %rax, %r13
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x82e8
movq 0x48(%r14), %rdi
movq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x529e
jmp 0x543e
xorl %r13d, %r13d
movq 0x58(%r14), %rdi
testq %rdi, %rdi
je 0x546c
callq 0x519e
movq %rax, %rbp
movq %rsp, %rdi
movq %rax, %rsi
callq 0x82e8
movq 0x58(%r14), %rdi
movq (%rsp), %rsi
movq %rbp, %rdx
callq 0x529e
jmp 0x546e
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 0x54cb
movq 0x60(%rsp), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x2100
addq %r15, %rbx
testq %r12, %r12
je 0x54e3
movq 0x40(%rsp), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x2100
addq %r12, %rbx
testq %r13, %r13
je 0x54fb
movq 0x20(%rsp), %rsi
movq %rbx, %rdi
movq %r13, %rdx
callq 0x2100
addq %r13, %rbx
movq (%rsp), %rax
testq %rbp, %rbp
je 0x5516
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x2100
movq (%rsp), %rax
testq %rax, %rax
je 0x552b
movq 0x10(%rsp), %rsi
subq %rax, %rsi
movq %rax, %rdi
callq 0x2140
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5542
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x5559
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x5570
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x2070
movq %rax, %r14
leaq 0x58e4(%rip), %rsi      # 0xae77
movq %rax, %rdi
callq 0x2060
movq 0x8a4e(%rip), %rsi      # 0xdff0
movq 0x8a17(%rip), %rdx      # 0xdfc0
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movq %r14, %rdi
callq 0x20e0
jmp 0x55ee
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x55d7
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x60(%rsp), %rcx
callq 0x21f0
movq %rbx, %rdi
callq 0x21c0