// File: toxaart[P]hierarchical_block_sparse_lib/source/HierarchicalBlockSparseMatrix.h
// Function: hbsm::HierarchicalBlockSparseMatrix<double>::set_to_identity(hbsm::HierarchicalBlockSparseMatrix<double>&, int)
void HierarchicalBlockSparseMatrix<Treal>::set_to_identity(HierarchicalBlockSparseMatrix<Treal> & A, int nRows) {

            // assume params are set

            A.clear();

            A.resize(nRows, nRows);

            if(A.lowest_level()){

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

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

                return;
            }

            int blocksize = A.blocksize;

            A.children[0] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
            A.children[0]->parent = &A;
            A.children[0]->set_params(A.get_params());
            set_to_identity(*A.children[0], A.nRows/2);

            if(A.children[0]->get_first_row_position() + A.children[0]->nRows >= A.get_n_rows() ) return;

            A.children[3] = std::make_shared<HierarchicalBlockSparseMatrix<Treal> >();
            A.children[3]->parent = &A;
            A.children[3]->set_params(A.get_params());
            set_to_identity(*A.children[3], A.nRows/2);

            return;
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
callq 0x23300
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0xc(%rbp), %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x8600
movq -0x8(%rbp), %rdi
callq 0x23500
testb $0x1, %al
jne 0x13ced
jmp 0x13d64
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rdi
callq 0x24400
testb $0x1, %al
jne 0x13d0f
jmp 0x13d1f
movq -0x8(%rbp), %rdi
callq 0x24470
cltd
idivl -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x13d5f
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
movl -0x18(%rbp), %eax
imull -0x10(%rbp), %eax
addl -0x18(%rbp), %eax
movslq %eax, %rsi
callq 0x22b60
movsd 0x222d0(%rip), %xmm0    # 0x36020
movsd %xmm0, (%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x13d26
jmp 0x13ee3
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x1c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x245c0
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
leaq -0x30(%rbp), %rsi
callq 0x235b0
leaq -0x30(%rbp), %rdi
callq 0x235e0
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0x23570
movq -0x68(%rbp), %rcx
movq %rcx, 0x68(%rax)
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0x23570
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x243e0
movq -0x60(%rbp), %rdi
movl %eax, -0x34(%rbp)
leaq -0x34(%rbp), %rsi
callq 0x8570
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0x24630
movq %rax, %rdi
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %esi
callq 0x13cb0
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0x23570
movq %rax, %rdi
callq 0x24660
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0x23570
movq %rax, %rcx
movl -0x54(%rbp), %eax
addl (%rcx), %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
callq 0x24470
movl %eax, %ecx
movl -0x50(%rbp), %eax
cmpl %ecx, %eax
jl 0x13e44
jmp 0x13ee3
leaq -0x48(%rbp), %rdi
callq 0x245c0
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
addq $0x30, %rdi
leaq -0x48(%rbp), %rsi
callq 0x235b0
leaq -0x48(%rbp), %rdi
callq 0x235e0
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
addq $0x30, %rdi
callq 0x23570
movq -0x78(%rbp), %rcx
movq %rcx, 0x68(%rax)
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
addq $0x30, %rdi
callq 0x23570
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
callq 0x243e0
movq -0x70(%rbp), %rdi
movl %eax, -0x4c(%rbp)
leaq -0x4c(%rbp), %rsi
callq 0x8570
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
addq $0x30, %rdi
callq 0x24630
movq %rax, %rdi
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %esi
callq 0x13cb0
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)