// File: 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
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
xorl %esi, %esi
movl $0x1, %r8d
movl %esi, %edi
movl %r8d, %edx
movl %r8d, %ecx
callq 0x1de0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x30, %edi
callq 0x1100
movq %rax, %rdi
movq %rdi, -0x98(%rbp)
callq 0x30a0
movq -0x98(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x2ec6
movq -0x18(%rbp), %rdi
leaq -0x64(%rbp), %rsi
callq 0x15e0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1680
movl %eax, %edi
movq -0x40(%rbp), %rsi
callq 0x2750
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x64(%rbp), %edx
callq 0x27e0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x64(%rbp), %rsi
callq 0x15e0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x68(%rbp)
movslq -0x68(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1680
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jae 0x2d50
movq -0x48(%rbp), %rdi
movslq -0x68(%rbp), %rsi
callq 0x16a0
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x60(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x30c0
movq -0xa8(%rbp), %rdi
movq (%rax), %rsi
callq 0x2930
movq -0x60(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3160
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x2cdc
movq -0x50(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x1150
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
callq 0x10d0
movsd %xmm0, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movl -0x64(%rbp), %esi
movl -0x64(%rbp), %edx
movsd -0x28(%rbp), %xmm0
callq 0x1b90
movl $0x1, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x2e1d
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movslq -0x6c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd -0x28(%rbp), %xmm0
movq -0x30(%rbp), %rax
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0x6c(%rbp), %rsi
callq 0x16a0
movq -0xb0(%rbp), %rdi
movl (%rax), %esi
movl -0x64(%rbp), %edx
movq -0x30(%rbp), %rax
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x1b90
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x2d9d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x64(%rbp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
je 0x2eb6
movq -0x50(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movslq -0x64(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x15e0
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq (%rax), %rdx
callq 0x29f0
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x64(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x31d0
movq -0xb8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3190
movq %rax, -0x90(%rbp)
movb %dl, -0x88(%rbp)
jmp 0x2eb8
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x2c75
movq -0x20(%rbp), %rdi
callq 0x20b0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq