// File: /workspace/github_cpp_makefile_star2_O2/BhanuPrakashN[P]sparse_chol/smatrix.cpp
// Function: sm_chol(smatrix*, etree*, std::map<int, std::vector<int, std::allocator<int>>*, std::less<int>, std::allocator<std::pair<int const, std::vector<int, std::allocator<int>>*>>>*)
sm *sm_chol(sm *A,et *e,map<int,vector<int>* > * cs){
    sm *L=smalloc (0, 0, 1, 1, 1);
    double l_jj,*l_b;
    int n,c;
    n=A->n;
    vector<int> *temp,*chl;
    Fm *F,*Um;
    map<int,Fm*> *U=new map<int,Fm*>;
    for(int j=0;j<n;j++){
        temp=cs->at(j);
        F=fmalloc(temp->size(),temp);
        fconstruct(F,A,j);
        //printf("\n Frontal[%d]\n",j);
        //for(int k=0;k<F->n;k++)printf("%d ",temp->at(k));
        
        chl=e->chl->at(j);
        for(int k=0;k<chl->size();k++){
            c=chl->at(k);
            Fupdate(F,U->at(c));
            U->erase(c);
        }
        //printFm(F);
        l_b=(double*)malloc(((F->n)-1)*sizeof(double));
        l_jj=sqrt(F->x[0][0]);
        sm_insert (L,  j,  j, l_jj);

        //printf("%g\n",*l_jj);
        for(int k=1;k<F->n;k++){
            l_b[k-1]=F->x[0][k]/(l_jj);
            sm_insert (L,  F->indices->at(k),  j, l_b[k-1]);
            //printf("%g\n",l_b[k-1]);
        }

        if(e->par[j] != -1){
            Um=UpdateF(F,l_b,cs->at(e->par[j]));
            // printf("\n Update[%d]\n",j);
            //printFm(Um);
           
            U->insert(pair<int,Fm*>(j,Um));
        }

    }
    L=TripletToCC(L);
    return L;



}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, -0x50(%rbp)
movq %rsi, %r12
movq %rdi, %rbx
xorl %r15d, %r15d
pushq $0x1
popq %rcx
xorl %edi, %edi
xorl %esi, %esi
movl %ecx, %edx
movl %ecx, %r8d
callq 0x174b
movq %rax, -0x38(%rbp)
movq %rbx, -0x58(%rbp)
movl 0x8(%rbx), %eax
movl %eax, -0x3c(%rbp)
pushq $0x30
popq %rdi
callq 0x1100
movq %rax, %r13
andl $0x0, 0x8(%rax)
andq $0x0, 0x10(%rax)
addq $0x8, %rax
movq %rax, 0x18(%r13)
movq %rax, 0x20(%r13)
andq $0x0, 0x28(%r13)
movq %r12, -0x60(%rbp)
movq %r13, -0x48(%rbp)
movl %r15d, -0x2c(%rbp)
cmpl -0x3c(%rbp), %r15d
jge 0x22d2
movq -0x50(%rbp), %rdi
leaq -0x2c(%rbp), %r14
movq %r14, %rsi
callq 0x1576
movq (%rax), %rsi
movq 0x8(%rsi), %rdi
subq (%rsi), %rdi
shrq $0x2, %rdi
callq 0x1d71
movq %rax, %rbx
movl -0x2c(%rbp), %edx
movq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x1def
movq 0x8(%r12), %rdi
movq %r14, %rsi
callq 0x1576
movq (%rax), %r14
xorl %r12d, %r12d
leaq -0x40(%rbp), %r15
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x2, %rax
cmpq %r12, %rax
jbe 0x21e9
movq %r14, %rdi
movq %r12, %rsi
callq 0x15ae
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x2310
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x1eed
movq %r13, %rdi
movq %r15, %rsi
callq 0x2adc
incq %r12
jmp 0x21a3
movslq (%rbx), %r15
leaq -0x8(,%r15,8), %rdi
callq 0x1150
movq %rax, %r14
movq 0x10(%rbx), %r13
movq (%r13), %rax
movsd (%rax), %xmm0
ucomisd 0xee0(%rip), %xmm0      # 0x30f0
jb 0x2218
sqrtsd %xmm0, %xmm0
jmp 0x221d
callq 0x10d0
movl -0x2c(%rbp), %edx
movq -0x38(%rbp), %rdi
movl %edx, %esi
movsd %xmm0, -0x68(%rbp)
callq 0x1630
pushq $0x1
popq %r12
cmpq %r15, %r12
jge 0x2278
movq (%r13), %rax
movsd (%rax,%r12,8), %xmm0
divsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd %xmm0, -0x8(%r14,%r12,8)
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x15ae
movl (%rax), %esi
movl -0x2c(%rbp), %edx
movq -0x38(%rbp), %rdi
movsd -0x70(%rbp), %xmm0
callq 0x1630
incq %r12
jmp 0x2234
movq -0x60(%rbp), %r12
movq (%r12), %rax
movslq -0x2c(%rbp), %r15
cmpl $-0x1, (%rax,%r15,4)
je 0x22c6
leaq (%rax,%r15,4), %rsi
movq -0x50(%rbp), %rdi
callq 0x1576
movq (%rax), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f76
movl -0x2c(%rbp), %ecx
movl %ecx, -0x80(%rbp)
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %r13
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
callq 0x2cbc
movl -0x2c(%rbp), %r15d
jmp 0x22ca
movq -0x48(%rbp), %r13
incl %r15d
jmp 0x2149
movq -0x38(%rbp), %rdi
callq 0x1953
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq