// File: /workspace/github_cpp_makefile_star2_O2/toxaart[P]hierarchical_block_sparse_lib/source/HierarchicalBlockSparseMatrix.h
// Function: hbsm::HierarchicalBlockSparseMatrix<double>::assign_from_buffer(char const*, unsigned long)
void HierarchicalBlockSparseMatrix<Treal>::assign_from_buffer(const char * dataBuffer, size_t const bufferSize) {

			const char *p = dataBuffer;

			int n_bytes_left_to_read = bufferSize;

			if (bufferSize < 5 * sizeof(int) + 4 * sizeof(size_t))
			  throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::assign_from_buffer(): buffer too small.");


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

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

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

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

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

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

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

			size_t child0_size, child1_size, child2_size, child3_size;

			memcpy(&child0_size, p, sizeof(size_t));
			p += sizeof(size_t);
			n_bytes_left_to_read -= sizeof(size_t);

			memcpy(&child1_size, p, sizeof(size_t));
			p += sizeof(size_t);
			n_bytes_left_to_read -= sizeof(size_t);

			memcpy(&child2_size, p, sizeof(size_t));
			p += sizeof(size_t);
			n_bytes_left_to_read -= sizeof(size_t);

			memcpy(&child3_size, p, sizeof(size_t));
			p += sizeof(size_t);
			n_bytes_left_to_read -= sizeof(size_t);

			this->resize(nRows_orig, nCols_orig);

			//check if buffer ended, if so, that was an empty matrix
			if(n_bytes_left_to_read == 0){
				return;
			}

			if(child0_size > 0){
				if(children[0] != NULL)
					throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::assign_from_buffer(): non-null child exist!");

				std::vector<char> child0_buf(child0_size);
				memcpy(&child0_buf[0], p, child0_size);
				p += child0_size;
				n_bytes_left_to_read -= child0_size;

				children[0] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				children[0]->assign_from_buffer(&child0_buf[0], child0_size);
				children[0]->parent = this;

			}


			if(child1_size > 0){
				if(children[1] != NULL)
					throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::assign_from_buffer(): non-null child exist!");

				std::vector<char> child1_buf(child1_size);
				memcpy(&child1_buf[0], p, child1_size);
				p += child1_size;
				n_bytes_left_to_read -= child1_size;

				children[1] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				children[1]->assign_from_buffer(&child1_buf[0], child1_size);
				children[1]->parent = this;

			}


			if(child2_size > 0){
				if(children[2] != NULL)
					throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::assign_from_buffer(): non-null child exist!");

				std::vector<char> child2_buf(child2_size);
				memcpy(&child2_buf[0], p, child2_size);
				p += child2_size;
				n_bytes_left_to_read -= child2_size;

				children[2] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				children[2]->assign_from_buffer(&child2_buf[0], child2_size);
				children[2]->parent = this;

			}


			if(child3_size > 0){
				if(children[3] != NULL)
					throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::assign_from_buffer(): non-null child exist!");

				std::vector<char> child3_buf(child3_size);
				memcpy(&child3_buf[0], p, child3_size);
				p += child3_size;
				n_bytes_left_to_read -= child3_size;

				children[3] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				children[3]->assign_from_buffer(&child3_buf[0], child3_size);
				children[3]->parent = this;

			}

			// at this point, if n_bytes_left_to_read is 0, then we are done, if not, then it was a leaf matrix!
			if(n_bytes_left_to_read == 0){
				return;
			}
			else{

				assert(n_bytes_left_to_read == nRows * nCols * sizeof(Treal));
				submatrix.resize(nRows * nCols);

				memcpy(&submatrix[0], p, nRows * nCols * sizeof(Treal));
				p += nRows * nCols * sizeof(Treal);
			}

		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpq $0x33, %rdx
jbe 0x4d2d
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movl (%rsi), %eax
movl %eax, (%rdi)
movl 0x4(%rsi), %eax
movl %eax, 0x4(%rdi)
movl 0x8(%rsi), %esi
movl %esi, 0x8(%rdi)
movl 0xc(%rbx), %edx
movl %edx, 0xc(%rdi)
movl 0x10(%rbx), %eax
movl %eax, 0x10(%rdi)
movq 0x14(%rbx), %rax
movq %rax, 0x18(%rdi)
movq 0x1c(%rbx), %rax
movq %rax, 0x20(%rdi)
movq 0x24(%rbx), %r12
movq 0x2c(%rbx), %rbp
movq 0x34(%rbx), %rax
movq %rax, 0x30(%rsp)
movq 0x3c(%rbx), %r13
xorl %ecx, %ecx
callq 0x39e4
addl $-0x44, %r15d
je 0x4d1e
addq $0x44, %rbx
testq %r12, %r12
je 0x4b63
cmpq $0x0, 0x28(%r14)
jne 0x4d49
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq %r12, %rsi
callq 0x46fc
movq %r13, 0x28(%rsp)
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2120
movq %rsp, %rdi
callq 0x68de
leaq 0x28(%r14), %r13
movq %rsp, %rsi
movq %r13, %rdi
callq 0x5a26
leaq 0x8(%rsp), %rdi
callq 0x5a54
movq (%r13), %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x4a68
addq %r12, %rbx
subl %r12d, %r15d
movq 0x28(%r14), %rax
movq %r14, 0x68(%rax)
leaq 0x10(%rsp), %rdi
callq 0x6f52
movq 0x28(%rsp), %r13
testq %rbp, %rbp
je 0x4bdd
cmpq $0x0, 0x38(%r14)
jne 0x4d65
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq %rbp, %rsi
callq 0x46fc
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2120
movq %rsp, %rdi
callq 0x68de
leaq 0x38(%r14), %r12
movq %rsp, %rsi
movq %r12, %rdi
callq 0x5a26
leaq 0x8(%rsp), %rdi
callq 0x5a54
movq (%r12), %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
callq 0x4a68
addq %rbp, %rbx
subl %ebp, %r15d
movq 0x38(%r14), %rax
movq %r14, 0x68(%rax)
leaq 0x10(%rsp), %rdi
callq 0x6f52
movq 0x30(%rsp), %rbp
testq %rbp, %rbp
je 0x4c5c
cmpq $0x0, 0x48(%r14)
jne 0x4d81
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq %rbp, %rsi
callq 0x46fc
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2120
movq %rsp, %rdi
callq 0x68de
leaq 0x48(%r14), %r12
movq %rsp, %rsi
movq %r12, %rdi
callq 0x5a26
leaq 0x8(%rsp), %rdi
callq 0x5a54
movq (%r12), %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
callq 0x4a68
addq %rbp, %rbx
subl %ebp, %r15d
movq 0x48(%r14), %rax
movq %r14, 0x68(%rax)
leaq 0x10(%rsp), %rdi
callq 0x6f52
testq %r13, %r13
je 0x4cd6
cmpq $0x0, 0x58(%r14)
jne 0x4d9d
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq %r13, %rsi
callq 0x46fc
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2120
movq %rsp, %rdi
callq 0x68de
leaq 0x58(%r14), %r12
movq %rsp, %rsi
movq %r12, %rdi
callq 0x5a26
leaq 0x8(%rsp), %rdi
callq 0x5a54
movq (%r12), %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0x4a68
addq %r13, %rbx
subl %r13d, %r15d
movq 0x58(%r14), %rax
movq %r14, 0x68(%rax)
leaq 0x10(%rsp), %rdi
callq 0x6f52
testl %r15d, %r15d
je 0x4d1e
movslq %r15d, %rax
movslq (%r14), %rcx
movslq 0x4(%r14), %rsi
imulq %rcx, %rsi
leaq (,%rsi,8), %rcx
cmpq %rax, %rcx
jne 0x4dcd
leaq 0x70(%r14), %rdi
callq 0x57fc
movq 0x70(%r14), %rdi
movslq (%r14), %rax
movslq 0x4(%r14), %rdx
imulq %rax, %rdx
shlq $0x3, %rdx
movq %rbx, %rsi
callq 0x2120
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %r14
leaq 0x418c(%rip), %rsi      # 0x8ecb
movq %rax, %rdi
callq 0x2050
jmp 0x4db7
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %r14
leaq 0x41c0(%rip), %rsi      # 0x8f1b
movq %rax, %rdi
callq 0x2050
jmp 0x4db7
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %r14
leaq 0x41a4(%rip), %rsi      # 0x8f1b
movq %rax, %rdi
callq 0x2050
jmp 0x4db7
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %r14
leaq 0x4188(%rip), %rsi      # 0x8f1b
movq %rax, %rdi
callq 0x2050
jmp 0x4db7
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %r14
leaq 0x416c(%rip), %rsi      # 0x8f1b
movq %rax, %rdi
callq 0x2050
movq 0x8232(%rip), %rsi      # 0xcff0
movq 0x81fb(%rip), %rdx      # 0xcfc0
movq %r14, %rdi
callq 0x21d0
leaq 0x419b(%rip), %rdi      # 0x8f6f
leaq 0x37b2(%rip), %rsi      # 0x858d
leaq 0x41c3(%rip), %rcx      # 0x8fa5
movl $0x5c8, %edx            # imm = 0x5C8
callq 0x20d0
jmp 0x4e1c
jmp 0x4e1c
jmp 0x4e1c
jmp 0x4e1c
jmp 0x4e08
jmp 0x4e08
jmp 0x4e17
jmp 0x4e08
jmp 0x4e08
jmp 0x4e17
jmp 0x4e08
jmp 0x4e08
jmp 0x4e17
jmp 0x4e08
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6f52
jmp 0x4e27
movq %rax, %rbx
jmp 0x4e27
movq %rax, %rbx
movq %r14, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x21f0