// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq 0x68(%rax), %rax
movb 0x900(%rax), %al
movb %al, -0x33(%rbp)
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x3c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movsbl -0x33(%rbp), %edi
callq 0x9da0
movq %rax, -0x50(%rbp)
movb $0x0, -0x59(%rbp)
movsbl -0x59(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x153e5
movq -0x18(%rbp), %rax
movsbq -0x59(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $-0x1, %eax
jle 0x152d9
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movb $0x0, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movsbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1519a
movq -0x68(%rbp), %rdi
movq -0x58(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x30(%rbp), %rsi
movb -0x31(%rbp), %dl
movq -0x30(%rbp), %rax
movb 0x10(%rax), %cl
movq (%rdi), %rax
movsbl %dl, %edx
movsbl %cl, %ecx
callq *0x38(%rax)
movaps %xmm0, %xmm2
movsd -0x70(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x15139
movb $0x0, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movsbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1521a
movq -0x68(%rbp), %rdi
movq -0x58(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x30(%rbp), %rsi
movb -0x31(%rbp), %dl
movq -0x30(%rbp), %rax
movb 0x10(%rax), %cl
movq (%rdi), %rax
movsbl %dl, %edx
movsbl %cl, %ecx
callq *0x38(%rax)
movaps %xmm0, %xmm1
movsd -0x80(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x48(%rbp), %xmm0
callq 0x75f0
movaps %xmm0, %xmm1
movsd -0x78(%rbp), %xmm0
divsd %xmm1, %xmm0
movq -0x50(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x1519e
movb $0x0, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movsbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0x15245
movq -0x58(%rbp), %rax
movsbq -0x31(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x1521e
movb $0x0, -0x32(%rbp)
movsbl -0x32(%rbp), %eax
movsbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0x152d4
movb $0x0, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movsbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0x152c5
movq -0x68(%rbp), %rdi
movq -0x50(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x30(%rbp), %rsi
movb -0x31(%rbp), %dl
movb -0x32(%rbp), %cl
movq (%rdi), %rax
movsbl %dl, %edx
movsbl %cl, %ecx
callq *0x30(%rax)
movaps %xmm0, %xmm2
movsd -0x88(%rbp), %xmm0
movq -0x58(%rbp), %rax
movsbq -0x32(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x15259
jmp 0x152c7
movb -0x32(%rbp), %al
addb $0x1, %al
movb %al, -0x32(%rbp)
jmp 0x15249
jmp 0x153cb
movb $0x0, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movsbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1530f
movq -0x58(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x50(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x152dd
movb $0x0, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movsbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1533a
movq -0x58(%rbp), %rax
movsbq -0x31(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x15313
movb $0x0, -0x32(%rbp)
movsbl -0x32(%rbp), %eax
movsbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0x153c9
movb $0x0, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movsbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0x153ba
movq -0x68(%rbp), %rdi
movq -0x50(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x30(%rbp), %rsi
movb -0x31(%rbp), %dl
movb -0x32(%rbp), %cl
movq (%rdi), %rax
movsbl %dl, %edx
movsbl %cl, %ecx
callq *0x30(%rax)
movaps %xmm0, %xmm2
movsd -0x90(%rbp), %xmm0
movq -0x58(%rbp), %rax
movsbq -0x32(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x1534e
jmp 0x153bc
movb -0x32(%rbp), %al
addb $0x1, %al
movb %al, -0x32(%rbp)
jmp 0x1533e
jmp 0x153cb
movq -0x58(%rbp), %rdi
movsbl -0x33(%rbp), %esi
callq 0x5560
movb -0x59(%rbp), %al
addb $0x1, %al
movb %al, -0x59(%rbp)
jmp 0x150dc
movq -0x50(%rbp), %rdi
callq 0x3320
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)