// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblemSt.cpp
// Function: HMMProblemSt::updateValuesLocal(double***, int*, signed char, double*, context*)
void HMMProblemSt::updateValuesLocal(NUMBER*** group_skill_map, NCAT* skills, NPAR n_skills, NUMBER* local_pred, struct context *ctx) {
    NPAR i, j, nS = this->task->nS;//, o = this->task->dat_obs[ctx->t];
    NCAT k, g = ctx->g;
    NUMBER pLe_denom = 0.0;
    NUMBER *pLe = init1D<NUMBER>(nS);
    NUMBER* group_skill_map_gk; // TODO, try to see time change
    
    // update pL
    for(NPAR l=0; l<n_skills; l++) {
        k = skills[l];
        ctx->k = k;
        group_skill_map_gk = group_skill_map[g][k]; // TODO, try to see time change
//        NUMBER* pLbit = gsm(g,k); //BOOST
        
        if(ctx->o>-1) { // known observations //
            // update p(L)
            pLe_denom = 0.0;
            // 1. pLe =  (L .* B(:,o)) ./ ( L'*B(:,o)+1e-8 );
            for(i=0; i<nS; i++)
                pLe_denom += /*group_skill_map[g][k]*/group_skill_map_gk[i] * getB(ctx,i,ctx->o);  // TODO: this is local_pred[o]!!!//UNBOOST
//                  pLe_denom += pLbit[i] * getB(ctx,i,o); //BOOST
            for(i=0; i<nS; i++)
                pLe[i] = /*group_skill_map[g][k]*/group_skill_map_gk[i] * getB(ctx,i,ctx->o) / safe0num(pLe_denom); //UNBOOST
//                  pLe[i] = pLbit[i] * getB(ctx,i,o) / safe0num(pLe_denom); //BOOST
            // 2. L = (pLe'*A)';
            for(i=0; i<nS; i++)
            /*group_skill_map[g][k]*/group_skill_map_gk[i]= 0.0; //UNBOOST
//                  pLbit[i]= 0.0; //BOOST
            for(j=0; j<nS; j++)
                for(i=0; i<nS; i++)
            /*group_skill_map[g][k]*/group_skill_map_gk[j] += pLe[i] * getA(ctx,i,j);//A[i][j]; //UNBOOST
//                    pLbit[j] += pLe[i] * getA(ctx,i,j);//A[i][j]; //BOOST
        } else { // unknown observation
            // 2. L = (pL'*A)';
            for(i=0; i<nS; i++)
                pLe[i] = /*group_skill_map[g][k]*/group_skill_map_gk[i]; // copy first; //UNBOOST
//                  pLe[i] = pLbit[i]; // copy first; //BOOST
            for(i=0; i<nS; i++)
            /*group_skill_map[g][k]*/group_skill_map_gk[i] = 0.0; // erase old value //UNBOOST
//                  pLbit[i] = 0.0; // erase old value //BOOST
            for(j=0; j<nS; j++)
                for(i=0; i<nS; i++)
                    /*group_skill_map[g][k]*/group_skill_map_gk[j] += pLe[i] * getA(ctx,i,j);//UNBOOST
//               pLbit[j] += pLe[i] * getA(ctx,i,j);//BOOST
        }// observations
        projectsimplex(/*group_skill_map[g][k]*/group_skill_map_gk, nS); // addition to make sure there's no side effects //UNBOOST
//            projectsimplex(pLbit, nS); // addition to make sure there's no side effects //BOOST
    }
    free(pLe);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, %r14d
movq %rdx, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, %r12
movq 0x68(%rdi), %rax
movzbl 0x900(%rax), %ebx
movq %r9, 0x18(%rsp)
movslq 0x4(%r9), %rax
movq %rax, 0x28(%rsp)
movsbl %bl, %edi
movl %edi, 0x24(%rsp)
callq 0x6a57
movq %rax, 0x10(%rsp)
xorl %edi, %edi
testb %bl, %bl
movl $0x0, %eax
movq %rbx, %r13
cmovgl %ebx, %eax
movq %rax, %rbx
testb %r14b, %r14b
cmovlel %edi, %r14d
movslq %r14d, %rax
movq %rax, 0x40(%rsp)
movq %rbx, 0x50(%rsp)
cmpq 0x40(%rsp), %rdi
je 0xc73f
movq 0x38(%rsp), %rax
movslq (%rax,%rdi,4), %rax
movq 0x18(%rsp), %rdx
movl %eax, (%rdx)
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rsi
movq (%rcx,%rsi,8), %rcx
movq (%rcx,%rax,8), %r14
cmpb $0x0, 0x10(%rdx)
movq %rdi, 0x48(%rsp)
js 0xc6a9
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0xc5e3
movsd (%r14,%r15,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rsi
movsbl 0x10(%rsi), %ecx
movq (%r12), %rax
movsbl %r15b, %edx
movq %r12, %rdi
callq *0x38(%rax)
mulsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
incq %r15
jmp 0xc5a2
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0xc63e
movsd (%r14,%r15,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rsi
movsbl 0x10(%rsi), %ecx
movq (%r12), %rax
movsbl %r15b, %edx
movq %r12, %rdi
callq *0x38(%rax)
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
callq 0x55a1
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0x10(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
incq %r15
jmp 0xc5e6
xorl %eax, %eax
cmpq %rax, %rbx
je 0xc64f
andq $0x0, (%r14,%rax,8)
incq %rax
jmp 0xc640
xorl %ebp, %ebp
cmpq %rbx, %rbp
je 0xc726
movsbl %bpl, %r15d
xorl %ebx, %ebx
cmpq %rbx, %r13
je 0xc69f
movq 0x10(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rsp)
movq (%r12), %rax
movsbl %bl, %edx
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movl %r15d, %ecx
callq *0x30(%rax)
mulsd (%rsp), %xmm0
addsd (%r14,%rbp,8), %xmm0
movsd %xmm0, (%r14,%rbp,8)
incq %rbx
jmp 0xc660
incq %rbp
movq 0x50(%rsp), %rbx
jmp 0xc651
xorl %eax, %eax
cmpq %rax, %rbx
je 0xc6c5
movsd (%r14,%rax,8), %xmm0
movq 0x10(%rsp), %rcx
movsd %xmm0, (%rcx,%rax,8)
incq %rax
jmp 0xc6ab
xorl %eax, %eax
cmpq %rax, %rbx
je 0xc6d6
andq $0x0, (%r14,%rax,8)
incq %rax
jmp 0xc6c7
xorl %r15d, %r15d
cmpq %rbx, %r15
je 0xc726
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0xc721
movq 0x10(%rsp), %rax
movsd (%rax,%rbp,8), %xmm0
movsd %xmm0, (%rsp)
movq (%r12), %rax
movsbl %r15b, %ecx
movsbl %bpl, %edx
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq *0x30(%rax)
mulsd (%rsp), %xmm0
addsd (%r14,%r15,8), %xmm0
movsd %xmm0, (%r14,%r15,8)
incq %rbp
jmp 0xc6e0
incq %r15
jmp 0xc6d9
movq %r14, %rdi
movl 0x24(%rsp), %esi
callq 0x43e4
movq 0x48(%rsp), %rdi
incq %rdi
jmp 0xc55a
movq 0x10(%rsp), %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3230
nop