// File: /workspace/github_cpp_makefile_star2_O2/toxaart[P]hierarchical_block_sparse_lib/source/HierarchicalBlockSparseMatrix.h
// Function: hbsm::HierarchicalBlockSparseMatrix<double>::symm_square(hbsm::HierarchicalBlockSparseMatrix<double> const&, hbsm::HierarchicalBlockSparseMatrix<double>&)
void HierarchicalBlockSparseMatrix<Treal>::symm_square(HierarchicalBlockSparseMatrix<Treal> const & A, HierarchicalBlockSparseMatrix<Treal> & C){

			if(!C.empty()) throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::symm_square(): non-empty matrix to write result!");

			if(A.nCols_orig != A.nRows_orig) throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::symm_square(): matrix has bad sizes!");

			C.set_params(A.get_params());

			C.resize(A.nRows_orig,A.nCols_orig);


			if(A.lowest_level()){

				int blocksize = A.nRows;
				int M = A.nRows;
				if(A.on_bottom_boundary()) M = A.get_n_rows() % A.blocksize; // fill only necessary elements

				for (int row = 0; row < M; row++){
				  for (int col = row; col < M; col++){
					 // Here we rely on that resize has set the elements of C to zero.

					 for (int ind = 0; ind < row; ind++){
						C.submatrix[row + col * blocksize] += A.submatrix[ind + row * blocksize] * A.submatrix[ind + col * blocksize];
					 }

					 for (int ind = row; ind <= col; ind++){
						C.submatrix[row + col * blocksize] += A.submatrix[row + ind * blocksize] * A.submatrix[ind + col * blocksize];
					 }

					 for (int ind = col + 1; ind < M; ind++) {
						C.submatrix[row + col * blocksize] += A.submatrix[row + ind * blocksize] * A.submatrix[col + ind * blocksize];
					 }
				  }
				}

				return;
			}


			// same as regular multiplication, except that if A0*A0 and A3*A3 are done recursively,
			// multiplication invilving A0 XOR A3 is computed using symm_multiply
			// rest - standard routine

			// C0 = A0xA0 + A2xA2^T
			// C1 = A2^TxA0 + A3xA2^T  - NO NEED IN THIS
			// C2 = A0xA2 + A2xA3
			// C3 = A2^TxA2 + A3xA3

			if(A.children[2] != NULL){

				// C0 = A0xA0 + A2xA2^T
				std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> >  A0xA0;
				if(A.children[0] != NULL){
					A0xA0 = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
					symm_square(*A.children[0],  *A0xA0);
				}

				std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > A2xA2T;
				A2xA2T = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				multiply(*A.children[2], false, *A.children[2], true, *A2xA2T);

				std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > A2xA2T_U;
				A2xA2T_U = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				A2xA2T->get_upper_triangle(*A2xA2T_U);

				if(A0xA0 != NULL && A2xA2T_U == NULL){C.children[0] = A0xA0; C.children[0]->parent = &C;}
				if(A0xA0 == NULL && A2xA2T_U != NULL){C.children[0] = A2xA2T_U; C.children[0]->parent = &C;}
				if(A0xA0 != NULL && A2xA2T_U != NULL){
					add_to_first(*A0xA0, *A2xA2T_U);
					C.children[0] = A0xA0;
					C.children[0]->parent = &C;
				}

				// C2 = A0xA2 + A2xA3
				std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> >  A0xA2;
				if(A.children[0] != NULL){
					A0xA2 = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
					symm_multiply(*A.children[0], true, *A.children[2], false, *A0xA2);
				}

				std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> >  A2xA3;
				if(A.children[3] != NULL){
					A2xA3 = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
					symm_multiply(*A.children[2], false, *A.children[3], true, *A2xA3);
				}

				if(A0xA2 != NULL && A2xA3 == NULL){C.children[2] = A0xA2; C.children[2]->parent = &C;}
				if(A0xA2 == NULL && A2xA3 != NULL){C.children[2] = A2xA3; C.children[2]->parent = &C;}
				if(A0xA2 != NULL && A2xA3 != NULL){
					add_to_first(*A0xA2, *A2xA3);
					C.children[2] = A0xA2;
					C.children[2]->parent = &C;
				}

				// C3 = A2TxA2 + A3xA3
				std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > A2TxA2;
				A2TxA2 = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				multiply(*A.children[2], true, *A.children[2], false, *A2TxA2);

				std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > A2TxA2_U;
				A2TxA2_U = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				A2TxA2->get_upper_triangle(*A2TxA2_U);

				std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > A3xA3;
				if(A.children[3] != NULL){
					A3xA3 = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
					symm_square(*A.children[3], *A3xA3);
				}

				if(A2TxA2_U != NULL && A3xA3 == NULL){C.children[3] = A2TxA2_U; C.children[3]->parent = &C;}
				if(A2TxA2_U == NULL && A3xA3 != NULL){C.children[3] = A3xA3; C.children[3]->parent = &C;}
				if(A2TxA2_U != NULL && A3xA3 != NULL){
					add_to_first(*A2TxA2_U, *A3xA3);
					C.children[3] = A2TxA2_U;
					C.children[3]->parent = &C;
				}

			}
			else{ // so much less to compute

				// all summands which included A2 disappear now

				// C1 = A0 * A0
				if(A.children[0] != NULL){
					C.children[0] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
					C.children[0]->parent = &C;
					symm_square(*A.children[0],  *C.children[0]);
				}

				// C1 = NULL

				// C2 = NULL

				// C3 = A3*A3
				if(A.children[3] != NULL){
					C.children[3] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
					C.children[3]->parent = &C;
					symm_square(*A.children[3],  *C.children[3]);
				}

			}


			return;

		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %r14
movq %rsi, 0x8(%rsp)
movq %rsi, %rdi
callq 0x14e3a
testb %al, %al
je 0x18b46
movl 0xc(%r14), %eax
cmpl 0x8(%r14), %eax
jne 0x18b62
movl 0x10(%r14), %eax
leaq 0x10(%rsp), %rsi
movl %eax, (%rsi)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x7cc0
movl 0x8(%r14), %esi
movl 0xc(%r14), %edx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x7d24
movq %r14, %rdi
callq 0x14f94
testb %al, %al
je 0x18615
movl (%r14), %ebp
movslq %ebp, %rax
movq %rax, 0xb0(%rsp)
movq %r14, 0x78(%rsp)
movq %r14, %rdi
callq 0x15236
testb %al, %al
je 0x18453
movq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x15274
cltd
idivl 0x10(%rbx)
movl %edx, %ebp
pushq $0x1
popq %rsi
movslq %ebp, %rcx
xorl %edx, %edx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movq %rax, 0xc0(%rsp)
movl %ecx, %eax
movq %rax, 0xd0(%rsp)
movq 0xb0(%rsp), %rax
leaq (,%rax,8), %r14
leaq 0x8(,%rax,8), %rax
movq %rax, 0xb8(%rsp)
movl %esi, %eax
xorl %r11d, %r11d
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x78(%rsp), %r9
movq %rdx, %r13
movq %rbp, %r10
movq %r12, %r15
movl %eax, 0xa8(%rsp)
movl %eax, %edi
movq %r11, %rax
cmpq 0xc0(%rsp), %r12
movq %rbp, 0xc8(%rsp)
je 0x18b34
cmpq 0xd0(%rsp), %r15
je 0x185f5
movl %edi, 0xac(%rsp)
movslq %edi, %rbx
movq %r14, %r8
imulq %rbx, %r8
movq 0x70(%r9), %rdi
movq %r15, %rsi
imulq 0xb0(%rsp), %rsi
addq %r12, %rsi
movq 0x8(%rsp), %r9
movq 0x70(%r9), %r9
movq %r10, 0xd8(%rsp)
addq %rdi, %r10
addq %rbp, %rdi
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0x1853d
movsd (%rdi,%rbp,8), %xmm0
mulsd (%r10,%rbp,8), %xmm0
addsd (%r9,%rsi,8), %xmm0
movsd %xmm0, (%r9,%rsi,8)
incq %rbp
jmp 0x1851c
movq 0x78(%rsp), %rdi
movq 0x70(%rdi), %rdi
movq 0x8(%rsp), %r9
movq 0x70(%r9), %r10
movq %rax, 0xe0(%rsp)
leaq (%rdi,%rax), %r9
movq %r11, %rax
addq %r11, %rdi
xorl %ebp, %ebp
leaq (%r12,%rbp), %r11
cmpq %r15, %r11
ja 0x1858a
movsd (%rdi), %xmm0
mulsd (%r9,%rbp,8), %xmm0
addsd (%r10,%rsi,8), %xmm0
movsd %xmm0, (%r10,%rsi,8)
incq %rbp
addq %r14, %rdi
jmp 0x18563
movq 0x8(%rsp), %rdi
movq 0x70(%rdi), %rdi
movq 0x78(%rsp), %r9
addq 0x70(%r9), %r8
movq %rax, %r11
movq 0xc8(%rsp), %rbp
movq 0xe0(%rsp), %rax
movq 0xd8(%rsp), %r10
cmpq %rcx, %rbx
jge 0x185da
movsd (%r8,%rdx), %xmm0
mulsd (%r8,%r13), %xmm0
addsd (%rdi,%rsi,8), %xmm0
movsd %xmm0, (%rdi,%rsi,8)
incq %rbx
addq %r14, %r8
jmp 0x185b7
incq %r15
movl 0xac(%rsp), %edi
incl %edi
addq %r14, %r10
addq %r14, %rax
addq $0x8, %r13
jmp 0x184d1
incq %r12
movl 0xa8(%rsp), %eax
incl %eax
addq %r14, %rbp
addq 0xb8(%rsp), %r11
addq $0x8, %rdx
jmp 0x184a6
cmpq $0x0, 0x48(%r14)
je 0x1884d
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
cmpq $0x0, 0x28(%r14)
je 0x1866a
leaq 0x90(%rsp), %rdi
callq 0x152ec
leaq 0x10(%rsp), %r15
leaq 0x90(%rsp), %rsi
movq %r15, %rdi
callq 0x14fba
leaq 0x98(%rsp), %rdi
callq 0x14fe8
movq 0x28(%r14), %rdi
movq (%r15), %rsi
callq 0x183b0
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x152ec
leaq 0x90(%rsp), %r15
leaq 0x60(%rsp), %rsi
movq %r15, %rdi
callq 0x14fba
leaq 0x68(%rsp), %rdi
callq 0x14fe8
movq 0x48(%r14), %rdi
movq (%r15), %r8
andq $0x0, (%rsp)
pushq $0x1
popq %rcx
xorl %esi, %esi
movq %rdi, %rdx
xorl %r9d, %r9d
callq 0x8572
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x152ec
leaq 0x60(%rsp), %r15
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x14fba
leaq 0x38(%rsp), %rdi
callq 0x14fe8
movq 0x90(%rsp), %rdi
movq (%r15), %rsi
callq 0x18c36
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x18732
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
jne 0x18769
movq 0x8(%rsp), %rbx
leaq 0x28(%rbx), %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x162fc
movq 0x28(%rbx), %rax
movq %rbx, 0x68(%rax)
movq (%r15), %rdi
testq %rdi, %rdi
jne 0x1875f
cmpq $0x0, 0x60(%rsp)
je 0x1878b
movq 0x8(%rsp), %rbx
leaq 0x28(%rbx), %rdi
leaq 0x60(%rsp), %rsi
callq 0x162fc
movq 0x28(%rbx), %rax
movq %rbx, 0x68(%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1878b
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
je 0x1878b
xorl %edx, %edx
callq 0x163ac
movq 0x8(%rsp), %rbx
leaq 0x28(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x162fc
movq 0x28(%rbx), %rax
movq %rbx, 0x68(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
cmpq $0x0, 0x28(%r14)
je 0x187d5
leaq 0x50(%rsp), %rdi
callq 0x152ec
leaq 0x30(%rsp), %r15
leaq 0x50(%rsp), %rsi
movq %r15, %rdi
callq 0x14fba
leaq 0x58(%rsp), %rdi
callq 0x14fe8
movq 0x28(%r14), %rdi
movq 0x48(%r14), %rdx
movq (%r15), %r8
pushq $0x1
popq %rsi
xorl %ecx, %ecx
callq 0x17268
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
cmpq $0x0, 0x58(%r14)
je 0x188d6
leaq 0x80(%rsp), %rdi
callq 0x152ec
leaq 0x50(%rsp), %r15
leaq 0x80(%rsp), %rsi
movq %r15, %rdi
callq 0x14fba
leaq 0x88(%rsp), %rdi
callq 0x14fe8
movq 0x48(%r14), %rdi
movq 0x58(%r14), %rdx
movq (%r15), %r8
pushq $0x1
popq %rcx
xorl %esi, %esi
callq 0x17268
movq 0x50(%rsp), %rsi
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1890d
testq %rsi, %rsi
jne 0x18941
jmp 0x188e2
cmpq $0x0, 0x28(%r14)
je 0x1888d
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x152ec
movq 0x8(%rsp), %rbx
leaq 0x28(%rbx), %rdi
movq %r15, %rsi
callq 0x14fba
leaq 0x18(%rsp), %rdi
callq 0x14fe8
movq 0x28(%rbx), %rsi
movq %rbx, 0x68(%rsi)
movq 0x28(%r14), %rdi
callq 0x183b0
cmpq $0x0, 0x58(%r14)
je 0x18b34
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x152ec
movq 0x8(%rsp), %rbx
leaq 0x58(%rbx), %rdi
movq %r15, %rsi
callq 0x14fba
leaq 0x18(%rsp), %rdi
callq 0x14fe8
movq 0x58(%rbx), %rsi
movq %rbx, 0x68(%rsi)
movq 0x58(%r14), %rdi
callq 0x183b0
jmp 0x18b34
cmpq $0x0, 0x30(%rsp)
je 0x18963
movq 0x8(%rsp), %rbx
leaq 0x48(%rbx), %rdi
leaq 0x30(%rsp), %r15
movq %r15, %rsi
callq 0x162fc
movq 0x48(%rbx), %rax
movq %rbx, 0x68(%rax)
movq (%r15), %rdi
movq 0x50(%rsp), %rsi
testq %rdi, %rdi
jne 0x1893c
testq %rsi, %rsi
je 0x18963
movq 0x8(%rsp), %rbx
leaq 0x48(%rbx), %rdi
leaq 0x50(%rsp), %rsi
callq 0x162fc
movq 0x48(%rbx), %rax
movq %rbx, 0x68(%rax)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x18963
movq 0x50(%rsp), %rsi
testq %rsi, %rsi
je 0x18963
xorl %edx, %edx
callq 0x163ac
movq 0x8(%rsp), %rbx
leaq 0x48(%rbx), %rdi
leaq 0x30(%rsp), %rsi
callq 0x162fc
movq 0x48(%rbx), %rax
movq %rbx, 0x68(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x152ec
leaq 0x80(%rsp), %r15
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x14fba
leaq 0x28(%rsp), %rdi
callq 0x14fe8
movq 0x48(%r14), %rdi
movq (%r15), %r8
andq $0x0, (%rsp)
pushq $0x1
popq %rsi
movq %rdi, %rdx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x8572
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x152ec
leaq 0x20(%rsp), %r15
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x14fba
leaq 0x48(%rsp), %rdi
callq 0x14fe8
movq 0x80(%rsp), %rdi
movq (%r15), %rsi
callq 0x18c36
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
cmpq $0x0, 0x58(%r14)
je 0x18a51
leaq 0xe8(%rsp), %rdi
callq 0x152ec
leaq 0x40(%rsp), %r15
leaq 0xe8(%rsp), %rsi
movq %r15, %rdi
callq 0x14fba
leaq 0xf0(%rsp), %rdi
callq 0x14fe8
movq 0x58(%r14), %rdi
movq (%r15), %rsi
callq 0x183b0
movq 0x40(%rsp), %rsi
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x18a88
testq %rsi, %rsi
jne 0x18abc
jmp 0x18a5d
cmpq $0x0, 0x20(%rsp)
je 0x18ade
movq 0x8(%rsp), %rbx
leaq 0x58(%rbx), %rdi
leaq 0x20(%rsp), %r14
movq %r14, %rsi
callq 0x162fc
movq 0x58(%rbx), %rax
movq %rbx, 0x68(%rax)
movq (%r14), %rdi
movq 0x40(%rsp), %rsi
testq %rdi, %rdi
jne 0x18ab7
testq %rsi, %rsi
je 0x18ade
movq 0x8(%rsp), %rbx
leaq 0x58(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x162fc
movq 0x58(%rbx), %rax
movq %rbx, 0x68(%rax)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x18ade
movq 0x40(%rsp), %rsi
testq %rsi, %rsi
je 0x18ade
xorl %edx, %edx
callq 0x163ac
movq 0x8(%rsp), %rbx
leaq 0x58(%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0x162fc
movq 0x58(%rbx), %rax
movq %rbx, 0x68(%rax)
leaq 0x48(%rsp), %rdi
callq 0x14fe8
leaq 0x28(%rsp), %rdi
callq 0x14fe8
leaq 0x88(%rsp), %rdi
callq 0x14fe8
leaq 0x58(%rsp), %rdi
callq 0x14fe8
leaq 0x38(%rsp), %rdi
callq 0x14fe8
leaq 0x68(%rsp), %rdi
callq 0x14fe8
leaq 0x98(%rsp), %rdi
callq 0x14fe8
leaq 0x18(%rsp), %rdi
callq 0x14fe8
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20d0
movq %rax, %r14
leaq 0x4d47(%rip), %rsi      # 0x1d89f
movq %rax, %rdi
callq 0x2080
jmp 0x18b7c
pushq $0x10
popq %rdi
callq 0x20d0
movq %rax, %r14
leaq 0x4d84(%rip), %rsi      # 0x1d8f8
movq %rax, %rdi
callq 0x2080
movq 0xd46d(%rip), %rsi      # 0x25ff0
movq 0xd436(%rip), %rdx      # 0x25fc0
movq %r14, %rdi
callq 0x2270
jmp 0x18bbb
jmp 0x18be1
jmp 0x18b98
movq %rax, %rbx
jmp 0x18bee
jmp 0x18b9f
movq %rax, %rbx
jmp 0x18c14
jmp 0x18ba6
movq %rax, %rbx
jmp 0x18bc8
jmp 0x18bad
movq %rax, %rbx
jmp 0x18bd2
jmp 0x18bfa
jmp 0x18bb6
movq %rax, %rbx
jmp 0x18c07
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x14fe8
leaq 0x28(%rsp), %rdi
callq 0x14fe8
leaq 0x88(%rsp), %rdi
callq 0x14fe8
jmp 0x18be4
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x14fe8
leaq 0x38(%rsp), %rdi
callq 0x14fe8
jmp 0x18bfd
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x14fe8
leaq 0x98(%rsp), %rdi
callq 0x14fe8
leaq 0x18(%rsp), %rdi
callq 0x14fe8
movq %rbx, %rdi
callq 0x2290
jmp 0x18c28
movq %rax, %rbx
movq %r14, %rdi
callq 0x2130
jmp 0x18c1e
nop