// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %r9, %rbx
movl %ecx, %r15d
movq %rdx, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdi, 0x38(%rsp)
movq 0x68(%rdi), %rax
movsbq 0x900(%rax), %r14
movslq 0x4(%r9), %rax
movq %rax, 0x58(%rsp)
movl $0x8, %esi
movq %r14, %rdi
callq 0x2110
movq %rax, 0x28(%rsp)
testb %r15b, %r15b
jle 0xddf9
movzbl %r14b, %esi
leal (,%rsi,8), %eax
movq %rax, 0x48(%rsp)
movzbl %r15b, %eax
movq %rax, 0x50(%rsp)
xorl %edi, %edi
movsbl %sil, %eax
movl %eax, 0x44(%rsp)
movq %rsi, 0x18(%rsp)
movq %rbx, 0x30(%rsp)
movq 0x68(%rsp), %rax
movslq (%rax,%rdi,4), %rax
movl %eax, (%rbx)
movq 0x60(%rsp), %rcx
movq 0x58(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, 0x10(%rsp)
cmpb $0x0, 0x10(%rbx)
movq %rdi, 0x70(%rsp)
js 0xdd3c
testb %sil, %sil
jle 0xddce
xorps %xmm0, %xmm0
xorl %r15d, %r15d
movq 0x18(%rsp), %r13
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r12
movq 0x10(%rsp), %r14
movsd %xmm0, 0x8(%rsp)
movsd (%r14,%r15,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsbl 0x10(%rbx), %ecx
movq (%r12), %rax
movsbl %r15b, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq *0x38(%rax)
mulsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
incq %r15
cmpq %r15, %r13
jne 0xdbfe
testb %r13b, %r13b
jle 0xddce
xorl %r15d, %r15d
movq 0x18(%rsp), %r13
movq 0x28(%rsp), %rbp
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r12
movq 0x10(%rsp), %r14
movsd (%r14,%r15,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsbl 0x10(%rbx), %ecx
movq (%r12), %rax
movsbl %r15b, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq *0x38(%rax)
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x6158
movsd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rbp,%r15,8)
incq %r15
cmpq %r15, %r13
jne 0xdc6e
testb %r13b, %r13b
jle 0xddce
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x48(%rsp), %rdx
callq 0x2100
xorl %r13d, %r13d
movsbl %r13b, %r15d
xorl %ebx, %ebx
movq 0x18(%rsp), %rbp
movq 0x38(%rsp), %r14
movq 0x10(%rsp), %r12
movq 0x28(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%r14), %rax
movsbl %bl, %edx
movq %r14, %rdi
movq 0x30(%rsp), %rsi
movl %r15d, %ecx
callq *0x30(%rax)
mulsd 0x8(%rsp), %xmm0
addsd (%r12,%r13,8), %xmm0
movsd %xmm0, (%r12,%r13,8)
incq %rbx
cmpq %rbx, %rbp
jne 0xdcf1
incq %r13
cmpq %rbp, %r13
jne 0xdcdc
jmp 0xddce
testb %sil, %sil
jle 0xddce
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq 0x48(%rsp), %r15
movq %r15, %rdx
callq 0x2180
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x2100
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %r12
movq 0x38(%rsp), %r14
movq 0x10(%rsp), %rbp
movsd (%rbx,%r13,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%r14), %rax
movsbl %r15b, %ecx
movsbl %r13b, %edx
movq %r14, %rdi
movq %r12, %rsi
callq *0x30(%rax)
mulsd 0x8(%rsp), %xmm0
addsd (%rbp,%r15,8), %xmm0
movsd %xmm0, (%rbp,%r15,8)
incq %r13
cmpq %r13, 0x18(%rsp)
jne 0xdd86
incq %r15
cmpq 0x18(%rsp), %r15
jne 0xdd6f
movq 0x10(%rsp), %rdi
movl 0x44(%rsp), %esi
callq 0x3d7e
movq 0x70(%rsp), %rdi
incq %rdi
cmpq 0x50(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rbx
jne 0xdbaa
movq 0x28(%rsp), %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2240
nop