// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblem.cpp
// Function: HMMProblem::producePCorrect(double***, double*, int)
void HMMProblem::producePCorrect(NUMBER*** group_skill_map, NUMBER* local_pred, NDAT t) {
    NPAR m, i;
    NCAT k;
    NUMBER *local_pred_inner = init1D<NUMBER>(this->p->nO);
    char f_multiskill = this->p->multiskill;
    
    struct data* dt = new struct data;
    NCAT *ks;
    int nks;
    if(f_multiskill==0) {
        k = this->p->dat_skill[t];
        ks = &k;
        nks = 1;
    } else {
        NDAT rix = this->p->dat_skill_rix[t];
        k = this->p->dat_skill_stacked[ rix ];
        ks = &this->p->dat_skill_stacked[ rix ];
        nks = this->p->dat_skill_rcount[t];
    }
    
    dt->g = this->p->dat_group[t];
    dt->t = t; // statefulness
    for(m=0; m<this->p->nO; m++) local_pred[m] = 0.0;
    for(int l=0; l<nks; l++) {
        for(m=0; m<this->p->nO; m++) local_pred_inner[m] = 0.0;
        k = ks[l];
        dt->k = k;
        for(m=0; m<this->p->nO; m++)
            for(i=0; i<this->p->nS; i++)
                local_pred_inner[m] += group_skill_map[dt->g][k][i] * getB(dt,i,m);
        for(m=0; m<this->p->nO; m++)
            local_pred[m] += local_pred_inner[m];
    }
    if(nks>1) {
        for(m=0; m<this->p->nO; m++)
            local_pred[m] /= nks;
    }
    
    delete(dt);
//    NUMBER sum=0;
//    for(m=0; m<this->p->nO; m++)
//        sum+=local_pred[m];
//    if( fabs(sum-1)>SAFETY ) {
//        int a = 0;
//    }
    
    free(local_pred_inner);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, 0x38(%rsp)
movq %rdi, %r13
movq 0x88(%rdi), %rax
movsbl 0x8b9(%rax), %edi
callq 0x7dde
movq %rax, 0x10(%rsp)
movq 0x88(%r13), %rbx
movb 0x918(%rbx), %r14b
pushq $0x60
popq %rdi
callq 0x4220
movq %rax, 0x8(%rsp)
movslq %ebp, %rax
testb %r14b, %r14b
je 0xfafa
movq 0x890(%rbx), %rdx
movq 0x898(%rbx), %rcx
movslq (%rcx,%rax,4), %rcx
shlq $0x2, %rcx
addq 0x888(%rbx), %rcx
movl (%rdx,%rax,4), %edx
movl %edx, (%rsp)
movq %rcx, 0x18(%rsp)
jmp 0xfb19
leaq (,%rax,4), %rcx
addq 0x880(%rbx), %rcx
pushq $0x1
popq %rdx
movl %edx, (%rsp)
leaq 0x4(%rsp), %rdx
movq %rdx, 0x18(%rsp)
movl (%rcx), %ecx
movl %ecx, 0x4(%rsp)
movq 0x878(%rbx), %rcx
movl (%rcx,%rax,4), %ecx
movq 0x8(%rsp), %rdx
movl %ecx, 0x5c(%rdx)
movl %eax, 0x8(%rdx)
movzbl 0x8b9(%rbx), %eax
xorl %ecx, %ecx
testb %al, %al
movl %eax, %edx
cmovlel %ecx, %edx
movzbl %dl, %edx
cmpq %rcx, %rdx
je 0xfb56
andq $0x0, (%r15,%rcx,8)
incq %rcx
jmp 0xfb47
xorl %edi, %edi
movl (%rsp), %ecx
testl %ecx, %ecx
movl $0x0, %edx
cmovgl %ecx, %edx
movq %rdx, 0x28(%rsp)
xorl %r8d, %r8d
movq %r15, 0x20(%rsp)
movzbl %al, %ecx
cmpq 0x28(%rsp), %r8
je 0xfc7e
testb %cl, %cl
cmovlel %edi, %ecx
movzbl %cl, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0xfb9e
movq 0x10(%rsp), %rsi
andq $0x0, (%rsi,%rdx,8)
incq %rdx
jmp 0xfb8a
movq 0x18(%rsp), %rcx
movq %r8, 0x30(%rsp)
movslq (%rcx,%r8,4), %r12
movl %r12d, 0x4(%rsp)
movq 0x8(%rsp), %rcx
movl %r12d, 0x58(%rcx)
xorl %r14d, %r14d
movsbq %al, %rcx
cmpq %rcx, %r14
jge 0xfc3a
movsbl %r14b, %ebp
xorl %r15d, %r15d
movsbq 0x8b8(%rbx), %rax
cmpq %rax, %r15
jge 0xfc2f
movq 0x8(%rsp), %rsi
movslq 0x5c(%rsi), %rax
movq 0x38(%rsp), %rcx
movq (%rcx,%rax,8), %rax
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq (%r13), %rax
movsbl %r15b, %edx
movq %r13, %rdi
movl %ebp, %ecx
callq *0x20(%rax)
mulsd 0x40(%rsp), %xmm0
movq 0x10(%rsp), %rax
addsd (%rax,%r14,8), %xmm0
movsd %xmm0, (%rax,%r14,8)
incq %r15
movq 0x88(%r13), %rbx
jmp 0xfbcd
incq %r14
movb 0x8b9(%rbx), %al
jmp 0xfbbd
movzbl %al, %ecx
testb %al, %al
movl $0x0, %edi
cmovlel %edi, %ecx
movzbl %cl, %ecx
xorl %edx, %edx
movq 0x20(%rsp), %r15
movq 0x30(%rsp), %r8
cmpq %rdx, %rcx
je 0xfc76
movq 0x10(%rsp), %rsi
movsd (%rsi,%rdx,8), %xmm0
addsd (%r15,%rdx,8), %xmm0
movsd %xmm0, (%r15,%rdx,8)
incq %rdx
jmp 0xfc56
incq %r8
jmp 0xfb72
movl (%rsp), %eax
cmpl $0x2, %eax
jl 0xfcae
cvtsi2sd %eax, %xmm0
xorl %eax, %eax
testb %cl, %cl
cmovlel %eax, %ecx
movzbl %cl, %ecx
cmpq %rax, %rcx
je 0xfcae
movsd (%r15,%rax,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r15,%rax,8)
incq %rax
jmp 0xfc94
pushq $0x60
popq %rsi
movq 0x8(%rsp), %rdi
callq 0x4230
movq 0x10(%rsp), %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4290
nop