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


			if(!Z.empty()) throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::inv_chol(): non-empty matrix to write result!");
			if(A.nRows_orig != A.nCols_orig) throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::inv_chol(): call for non-square matrix!");

			Z.set_params(A.get_params());

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

			if(Z.lowest_level()){

				if(Z.get_first_row_position() > Z.get_n_rows()-1 || Z.get_first_col_position() > Z.get_n_cols()-1) return;

				int blocksize = Z.nRows;

				int n = Z.nRows;

				if(Z.on_bottom_boundary()) n = Z.get_n_rows() % Z.blocksize; // fill only necessary elements

				for(int i = 0; i < n; ++i) Z.submatrix[i*blocksize + i] = 1.0;

				Z.submatrix[0] = std::sqrt(1/A.submatrix[0]);
				for (int i = 1; i < n; i++) {
					Treal R;
					for (int j = 0; j < i; j++) {
						R = 0;

						for (int k = 0; k < n; k++)
							R += A.submatrix[k*blocksize+j] * Z.submatrix[i*blocksize+k];

						R *= Z.submatrix[j*blocksize+j];

						for (int k = 0; k < n; k++)
							Z.submatrix[i*blocksize+k] -= Z.submatrix[j*blocksize+k] * R;
					}
					R = 0;
					for (int k = 0; k < n; k++)
						R += A.submatrix[k*blocksize+i] * Z.submatrix[i*blocksize+k];

					R = std::sqrt(1/R);
					for (int k = 0; k < n; k++)
						Z.submatrix[i*blocksize+k] *= R;
				}

			   return;


			}

			// Z_00 = invChol(A_00)
			if(A.children[0] != NULL){
				Z.children[0] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				Z.children[0]->parent = &Z;
				inv_chol(*A.children[0], *Z.children[0]);
			}


			if(Z.children[0] == NULL) throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::inv_chol(): smth went wrong since Z_00 is NULL!");

			// R = Z_00^T * A_01
			std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > R;

			if(A.children[2] != NULL){
				R = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				multiply(*Z.children[0], true, *A.children[2], false, *R);
			}

			// T = Z_00 * R
			std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > T;
			if(R != NULL){
				T = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				multiply(*Z.children[0], false, *R, false, *T);
			}


			// X = -T
			std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > X;
			if(T != NULL){
				X = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				X->rescale(*T,-1.0);
			}

			// Y = A_10 * X
			std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > Y;

			if(A.children[1] != NULL && X != NULL){
				Y = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
				multiply(*A.children[1], false, *X, false, *Y);
			}


			// Q = Y + A_11
			std::shared_ptr<HierarchicalBlockSparseMatrix<Treal> > Q;
			if(A.children[3] != NULL){
				if(Y != NULL){
					Q = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
					add(*Y, *A.children[3], *Q);
				}
				else{
					Q = A.children[3];
				}
			}
			else{
				Q = Y;
			}

			// Z_11 = invChol(Q)
			if(Z.children[3] == NULL){
				if(Q != NULL){
					Z.children[3] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
					Z.children[3]->parent = &Z;
					inv_chol(*Q, *Z.children[3]);
				}
			}
			else throw std::runtime_error("Error in HierarchicalBlockSparseMatrix::inv_chol(): smth went wrong since Z_11 was not NULL!");

			// Z_01 = X * Z_11
			if(Z.children[2] == NULL){
				if(X != NULL){
					Z.children[2] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
					multiply(*X, false, *Z.children[3], false, *Z.children[2]);
				}
			}
			else std::runtime_error("Error in HierarchicalBlockSparseMatrix::inv_chol(): smth went wrong since Z_01 was not NULL!");

			// Z_10 = 0
			assert(Z.children[1] == NULL);

			return;

		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %r12
movq %rsi, %rdi
callq 0x1b2de
testb %al, %al
je 0x1014d
movl 0x8(%r12), %eax
cmpl 0xc(%r12), %eax
jne 0x1016b
movl 0x10(%r12), %eax
leaq 0x10(%rsp), %rsi
movl %eax, (%rsi)
movq %r14, %rdi
callq 0x9920
movl 0x8(%r12), %esi
movl 0xc(%r12), %edx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x9986
movq %r14, %rdi
callq 0x1b448
testb %al, %al
je 0xfa85
movq %r12, 0x28(%rsp)
movq %r14, %rdi
callq 0x1b70e
cmpq $0x0, 0x68(%r14)
movq %r14, %rcx
je 0xf9ba
movq %r14, %rdx
movq %rdx, %rcx
movq 0x68(%rdx), %rdx
testq %rdx, %rdx
jne 0xf9ae
movq %r14, 0x40(%rsp)
cmpl 0x8(%rcx), %eax
jge 0x10005
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x1b9dc
cmpq $0x0, 0x68(%rbx)
movq %rbx, %rcx
je 0xf9eb
movq %rbx, %rcx
movq 0x68(%rbx), %rbx
testq %rbx, %rbx
jne 0xf9df
cmpl 0xc(%rcx), %eax
jge 0x10005
movq 0x40(%rsp), %rbx
movl (%rbx), %r15d
movq %rbx, %rdi
callq 0x1b660
movl %r15d, %ebp
testb %al, %al
je 0xfa2d
cmpq $0x0, 0x68(%rbx)
movq %rbx, %rax
je 0xfa24
movq %rbx, %rcx
movq %rcx, %rax
movq 0x68(%rcx), %rcx
testq %rcx, %rcx
jne 0xfa18
movl 0x8(%rax), %eax
cltd
idivl 0x10(%rbx)
movl %edx, %ebp
movl %ebp, %r12d
testl %ebp, %ebp
jle 0xfa59
leal 0x1(%r15), %eax
movq 0x70(%rbx), %rcx
xorl %edx, %edx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %r12, %rdi
movslq %edx, %rdx
movq %rsi, (%rcx,%rdx,8)
addl %eax, %edx
decq %rdi
jne 0xfa4b
movq 0x28(%rsp), %rax
movq 0x70(%rax), %rax
movsd 0x145b6(%rip), %xmm0    # 0x24020
divsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x10014
sqrtsd %xmm0, %xmm0
jmp 0x10019
cmpq $0x0, 0x28(%r12)
je 0xfb15
movl $0x98, %edi
callq 0x21c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x1c268(%rip), %rcx     # 0x2bd18
movq %rcx, (%rax)
leaq 0x10(%rax), %rsi
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rax)
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movupd %xmm0, 0x28(%rax)
movupd %xmm0, 0x38(%rax)
movupd %xmm0, 0x48(%rax)
movupd %xmm0, 0x58(%rax)
movupd %xmm0, 0x68(%rax)
movupd %xmm0, 0x78(%rax)
movupd %xmm0, 0x88(%rax)
movq %rsi, 0x28(%r14)
movq 0x30(%r14), %rdi
movq %rax, 0x30(%r14)
testq %rdi, %rdi
je 0xfb07
callq 0x1b482
movq 0x28(%r14), %rsi
movq %r14, 0x68(%rsi)
movq 0x28(%r12), %rdi
callq 0xf928
cmpq $0x0, 0x28(%r14)
je 0x10189
cmpq $0x0, 0x48(%r12)
je 0xfd64
movl $0x98, %edi
callq 0x21c0
movq %rax, %r15
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r15)
leaq 0x1c1ca(%rip), %rbx     # 0x2bd18
movq %rbx, (%r15)
leaq 0x10(%r15), %r13
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%r15)
movl $0xffffffff, 0x20(%r15) # imm = 0xFFFFFFFF
movupd %xmm0, 0x28(%r15)
movupd %xmm0, 0x38(%r15)
movupd %xmm0, 0x48(%r15)
movupd %xmm0, 0x58(%r15)
movupd %xmm0, 0x68(%r15)
movupd %xmm0, 0x78(%r15)
movupd %xmm0, 0x88(%r15)
movq 0x28(%r14), %rdi
movq 0x48(%r12), %rdx
movq $0x0, (%rsp)
movl $0x1, %esi
xorl %ecx, %ecx
movq %r13, %r8
xorl %r9d, %r9d
callq 0xa4b0
movq %r12, 0x28(%rsp)
movl $0x98, %edi
callq 0x21c0
movq %rax, %rbp
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%rbp)
movq %rbx, (%rbp)
movq %rbp, %r12
addq $0x10, %r12
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rbp)
movl $0xffffffff, 0x20(%rbp) # imm = 0xFFFFFFFF
movupd %xmm0, 0x28(%rbp)
movupd %xmm0, 0x38(%rbp)
movupd %xmm0, 0x48(%rbp)
movupd %xmm0, 0x58(%rbp)
movupd %xmm0, 0x68(%rbp)
movupd %xmm0, 0x78(%rbp)
movupd %xmm0, 0x88(%rbp)
movq 0x28(%r14), %rdi
movq $0x0, (%rsp)
xorl %esi, %esi
movq %r13, %rdx
xorl %ecx, %ecx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xa4b0
movl $0x98, %edi
callq 0x21c0
movq %rax, %r13
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r13)
movq %rbx, (%r13)
movq %r13, %rdi
addq $0x10, %rdi
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%r13)
movl $0xffffffff, 0x20(%r13) # imm = 0xFFFFFFFF
movupd %xmm0, 0x28(%r13)
movupd %xmm0, 0x38(%r13)
movupd %xmm0, 0x48(%r13)
movupd %xmm0, 0x58(%r13)
movupd %xmm0, 0x68(%r13)
movupd %xmm0, 0x78(%r13)
movupd %xmm0, 0x88(%r13)
movsd 0x1448d(%rip), %xmm0    # 0x24130
movq %rdi, %rbx
movq %r12, %rsi
callq 0xf748
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %r12
cmpq $0x0, 0x38(%r12)
je 0xfd78
movl $0x98, %edi
callq 0x21c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x1c030(%rip), %rcx     # 0x2bd18
movq %rcx, (%rax)
movq %rax, %r8
addq $0x10, %r8
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rax)
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movupd %xmm0, 0x28(%rax)
movupd %xmm0, 0x38(%rax)
movupd %xmm0, 0x48(%rax)
movupd %xmm0, 0x58(%rax)
movupd %xmm0, 0x68(%rax)
movupd %xmm0, 0x78(%rax)
movupd %xmm0, 0x88(%rax)
movq %r8, 0x10(%rsp)
movq 0x18(%rsp), %rdi
movq %rax, 0x18(%rsp)
testq %rdi, %rdi
je 0xfd46
callq 0x1b482
movq 0x10(%rsp), %r8
movq 0x38(%r12), %rdi
movq $0x0, (%rsp)
xorl %esi, %esi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0xa4b0
jmp 0xfd78
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %ebp, %ebp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq 0x58(%r12), %rax
movq 0x10(%rsp), %rcx
testq %rax, %rax
je 0xfe2e
testq %rcx, %rcx
je 0xfe3e
movl $0x98, %edi
callq 0x21c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x1bf5b(%rip), %rcx     # 0x2bd18
movq %rcx, (%rax)
movq %rax, %rdx
addq $0x10, %rdx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rax)
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movupd %xmm0, 0x28(%rax)
movupd %xmm0, 0x38(%rax)
movupd %xmm0, 0x48(%rax)
movupd %xmm0, 0x58(%rax)
movupd %xmm0, 0x68(%rax)
movupd %xmm0, 0x78(%rax)
movupd %xmm0, 0x88(%rax)
movq %rdx, 0x30(%rsp)
movq 0x38(%rsp), %rdi
movq %rax, 0x38(%rsp)
testq %rdi, %rdi
je 0xfe1b
callq 0x1b482
movq 0x30(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq 0x58(%r12), %rsi
xorl %ecx, %ecx
callq 0xa182
jmp 0xfe53
leaq 0x38(%rsp), %rdi
movq %rcx, -0x8(%rdi)
leaq 0x18(%rsp), %rsi
jmp 0xfe4e
leaq 0x38(%rsp), %rdi
movq %rax, -0x8(%rdi)
addq $0x60, %r12
movq %r12, %rsi
callq 0x1c8e8
cmpq $0x0, 0x58(%r14)
jne 0x101bb
cmpq $0x0, 0x30(%rsp)
je 0xfef1
movl $0x98, %edi
callq 0x21c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x1be8f(%rip), %rcx     # 0x2bd18
movq %rcx, (%rax)
movq %rax, %rsi
addq $0x10, %rsi
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rax)
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movupd %xmm0, 0x28(%rax)
movupd %xmm0, 0x38(%rax)
movupd %xmm0, 0x48(%rax)
movupd %xmm0, 0x58(%rax)
movupd %xmm0, 0x68(%rax)
movupd %xmm0, 0x78(%rax)
movupd %xmm0, 0x88(%rax)
movq %rsi, 0x58(%r14)
movq 0x60(%r14), %rdi
movq %rax, 0x60(%r14)
testq %rdi, %rdi
je 0xfee3
callq 0x1b482
movq 0x58(%r14), %rsi
movq %r14, 0x68(%rsi)
movq 0x30(%rsp), %rdi
callq 0xf928
cmpq $0x0, 0x48(%r14)
je 0xff18
leaq 0x15652(%rip), %rsi     # 0x25551
leaq 0x48(%rsp), %rdi
callq 0x20a0
leaq 0x48(%rsp), %rdi
callq 0x22d8
jmp 0xffb5
testq %rbx, %rbx
je 0xffb5
movl $0x98, %edi
callq 0x21c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x1bdd8(%rip), %rcx     # 0x2bd18
movq %rcx, (%rax)
movq %rax, %r8
addq $0x10, %r8
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rax)
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movupd %xmm0, 0x28(%rax)
movupd %xmm0, 0x38(%rax)
movupd %xmm0, 0x48(%rax)
movupd %xmm0, 0x58(%rax)
movupd %xmm0, 0x68(%rax)
movupd %xmm0, 0x78(%rax)
movupd %xmm0, 0x88(%rax)
movq %r8, 0x48(%r14)
movq 0x50(%r14), %rdi
movq %rax, 0x50(%r14)
testq %rdi, %rdi
je 0xff9a
callq 0x1b482
movq 0x48(%r14), %r8
movq 0x58(%r14), %rdx
movq $0x0, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0xa4b0
cmpq $0x0, 0x38(%r14)
jne 0x101ed
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xffcf
callq 0x1b482
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xffde
callq 0x1b482
testq %r13, %r13
je 0xffeb
movq %r13, %rdi
callq 0x1b482
testq %rbp, %rbp
je 0xfff8
movq %rbp, %rdi
callq 0x1b482
testq %r15, %r15
je 0x10005
movq %r15, %rdi
callq 0x1b482
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2170
movq 0x70(%rbx), %rax
movsd %xmm0, (%rax)
cmpl $0x2, %ebp
jl 0x10005
movslq %r15d, %r13
shlq $0x3, %r13
movl $0x1, %ebp
movl $0x8, %r14d
xorpd %xmm3, %xmm3
movq %r13, %rbx
movq 0x40(%rsp), %rax
movq 0x70(%rax), %rcx
movq 0x28(%rsp), %rax
movq 0x70(%rax), %rdx
leaq (%rcx,%rbx), %rax
movq %rcx, %rsi
xorl %edi, %edi
xorpd %xmm0, %xmm0
movq %rdx, %r8
xorl %r9d, %r9d
movsd (%r8), %xmm1
mulsd (%rax,%r9,8), %xmm1
addsd %xmm1, %xmm0
incq %r9
addq %r13, %r8
cmpq %r9, %r12
jne 0x10064
movl %r15d, %r8d
imull %edi, %r8d
movslq %r8d, %r8
leaq (%rcx,%rdi,8), %r9
mulsd (%r9,%r8,8), %xmm0
xorl %r8d, %r8d
movsd (%rax,%r8,8), %xmm1
movsd (%rsi,%r8,8), %xmm2
mulsd %xmm0, %xmm2
subsd %xmm2, %xmm1
movsd %xmm1, (%rax,%r8,8)
incq %r8
cmpq %r8, %r12
jne 0x10095
incq %rdi
addq $0x8, %rdx
addq %r13, %rsi
cmpq %rbp, %rdi
jne 0x1005a
movq 0x28(%rsp), %rcx
movq 0x70(%rcx), %rcx
addq %r14, %rcx
xorpd %xmm1, %xmm1
xorl %edx, %edx
movsd (%rcx), %xmm0
mulsd (%rax,%rdx,8), %xmm0
addsd %xmm0, %xmm1
incq %rdx
addq %r13, %rcx
cmpq %rdx, %r12
jne 0x100d8
movsd 0x13f28(%rip), %xmm0    # 0x24020
divsd %xmm1, %xmm0
ucomisd %xmm3, %xmm0
jb 0x10108
sqrtsd %xmm0, %xmm0
jmp 0x10111
callq 0x2170
xorpd %xmm3, %xmm3
movq 0x40(%rsp), %rax
movq 0x70(%rax), %rax
addq %rbx, %rax
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r12
jne 0x1011f
incq %rbp
addq %r13, %rbx
addq $0x8, %r14
cmpq %r12, %rbp
jne 0x1003f
jmp 0x10005
movl $0x10, %edi
callq 0x20c0
movq %rax, %r14
leaq 0x15295(%rip), %rsi     # 0x253f6
movq %rax, %rdi
callq 0x20a0
jmp 0x101a5
movl $0x10, %edi
callq 0x20c0
movq %rax, %r14
leaq 0x152cd(%rip), %rsi     # 0x2544c
movq %rax, %rdi
callq 0x20a0
jmp 0x101a5
movl $0x10, %edi
callq 0x20c0
movq %rax, %r14
leaq 0x152ff(%rip), %rsi     # 0x2549c
movq %rax, %rdi
callq 0x20a0
movq 0x1be44(%rip), %rsi     # 0x2bff0
movq 0x1be0d(%rip), %rdx     # 0x2bfc0
movq %r14, %rdi
callq 0x2290
movl $0x10, %edi
callq 0x20c0
movq %rax, %r14
leaq 0x15325(%rip), %rsi     # 0x254f4
movq %rax, %rdi
callq 0x20a0
movq 0x1be12(%rip), %rsi     # 0x2bff0
movq 0x1bddb(%rip), %rdx     # 0x2bfc0
movq %r14, %rdi
callq 0x2290
leaq 0x153ba(%rip), %rdi     # 0x255ae
leaq 0x145a4(%rip), %rsi     # 0x2479f
leaq 0x153c2(%rip), %rcx     # 0x255c4
movl $0xca5, %edx            # imm = 0xCA5
callq 0x2100
jmp 0x1024a
jmp 0x10210
movq %rax, %rbx
jmp 0x1025c
jmp 0x1024a
movq %rax, %rbx
movq %r14, %rdi
callq 0x2140
jmp 0x1024d
jmp 0x1023d
jmp 0x1024a
movq %rax, %rbx
jmp 0x10270
jmp 0x1022f
movq %rax, %rbx
jmp 0x1027d
jmp 0x10236
movq %rax, %rbx
jmp 0x1028a
jmp 0x1023d
movq %rax, %rbx
movq %r14, %rdi
callq 0x2140
jmp 0x10292
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x1025c
callq 0x1b482
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1026b
callq 0x1b482
testq %r13, %r13
je 0x10278
movq %r13, %rdi
callq 0x1b482
testq %rbp, %rbp
je 0x10285
movq %rbp, %rdi
callq 0x1b482
testq %r15, %r15
je 0x10292
movq %r15, %rdi
callq 0x1b482
movq %rbx, %rdi
callq 0x22b0