// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movl %ecx, 0x20(%rsp)
movq %rdx, %r15
movq %rsi, 0x50(%rsp)
movq %rdi, %r13
movq 0x88(%rdi), %rbx
movsbq 0x8b9(%rbx), %rbp
movl $0x8, %esi
movq %rbp, %rdi
callq 0x4130
movq %rax, %r12
movb 0x918(%rbx), %r14b
movl $0x60, %edi
callq 0x4210
movq %rax, %r8
movslq 0x20(%rsp), %rax
testb %r14b, %r14b
je 0x12f28
movq 0x890(%rbx), %rdx
movq 0x898(%rbx), %rcx
movslq (%rcx,%rax,4), %rcx
shlq $0x2, %rcx
addq 0x888(%rbx), %rcx
movl (%rdx,%rax,4), %r14d
movq %rcx, 0x8(%rsp)
jmp 0x12f45
leaq (,%rax,4), %rcx
addq 0x880(%rbx), %rcx
movl $0x1, %r14d
movq %rsp, %rdx
movq %rdx, 0x8(%rsp)
movl (%rcx), %ecx
movl %ecx, (%rsp)
movq 0x878(%rbx), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x5c(%r8)
movl %eax, 0x8(%r8)
testb %bpl, %bpl
movq %r8, 0x18(%rsp)
jle 0x12f7c
shlq $0x3, %rbp
movq %r15, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x4120
movq 0x18(%rsp), %r8
testl %r14d, %r14d
jle 0x13112
movl %r14d, %eax
movq %rax, 0x40(%rsp)
xorl %ebp, %ebp
movq %r15, 0x30(%rsp)
movq %r12, 0x10(%rsp)
movq %r13, 0x48(%rsp)
movl %r14d, 0x4(%rsp)
movq 0x48(%rsp), %r13
movsbq 0x8b9(%rbx), %rdx
testq %rdx, %rdx
jle 0x130ae
shlq $0x3, %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x4120
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %rax
movq %rbp, 0x38(%rsp)
movslq (%rax,%rbp,4), %rcx
movl %ecx, (%rsp)
movl %ecx, 0x58(%r8)
xorl %r14d, %r14d
cmpb $0x0, 0x8b8(%rbx)
movq 0x10(%rsp), %r12
movq 0x50(%rsp), %rbp
jle 0x13064
movsbl %r14b, %eax
movl %eax, 0x2c(%rsp)
xorl %r15d, %r15d
movslq 0x5c(%r8), %rax
movq (%rbp,%rax,8), %rax
movq (%rax,%rcx,8), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq (%r13), %rax
movsbl %r15b, %edx
movq %r13, %rdi
movq %r8, %rsi
movq %rcx, %rbx
movl 0x2c(%rsp), %ecx
callq *0x20(%rax)
movq %rbx, %rcx
movq 0x18(%rsp), %r8
mulsd 0x20(%rsp), %xmm0
addsd (%r12,%r14,8), %xmm0
movsd %xmm0, (%r12,%r14,8)
incq %r15
movq 0x88(%r13), %rbx
movsbq 0x8b8(%rbx), %rax
cmpq %rax, %r15
jl 0x13002
incq %r14
movsbq 0x8b9(%rbx), %rax
cmpq %rax, %r14
jl 0x12fe4
testb %al, %al
jle 0x130bb
xorl %ecx, %ecx
movq 0x30(%rsp), %r15
movq 0x10(%rsp), %r12
movl 0x4(%rsp), %r14d
movq 0x38(%rsp), %rbp
movsd (%r12,%rcx,8), %xmm0
addsd (%r15,%rcx,8), %xmm0
movsd %xmm0, (%r15,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x13092
jmp 0x130cf
movq 0x8(%rsp), %rax
movl (%rax,%rbp,4), %eax
movl %eax, (%rsp)
jmp 0x130cf
movq 0x30(%rsp), %r15
movq 0x10(%rsp), %r12
movl 0x4(%rsp), %r14d
movq 0x38(%rsp), %rbp
incq %rbp
cmpq 0x40(%rsp), %rbp
jne 0x12fa8
cmpl $0x1, %r14d
je 0x13112
movsbq 0x8b9(%rbx), %rax
testq %rax, %rax
jle 0x13112
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
xorl %ecx, %ecx
movsd (%r15,%rcx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r15,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x130fa
movl $0x60, %esi
movq %r8, %rdi
callq 0x4220
movq %r12, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42a0
nop