// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
movq %rdx, %r13
movq %rsi, 0x48(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x88(%rdi), %rbx
movsbq 0x8b9(%rbx), %rdi
movl $0x8, %esi
callq 0x4130
movq %rax, 0x10(%rsp)
movb 0x918(%rbx), %r14b
movl $0x60, %edi
callq 0x4210
movq %rax, %r15
movslq %ebp, %rax
testb %r14b, %r14b
je 0x1310f
movq 0x888(%rbx), %rcx
movq 0x898(%rbx), %rdx
movslq (%rdx,%rax,4), %rdx
leaq (%rcx,%rdx,4), %rcx
movq %rcx, 0x20(%rsp)
movl (%rcx), %ecx
movl %ecx, 0x4(%rsp)
movq 0x890(%rbx), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, (%rsp)
jmp 0x1312c
movq 0x880(%rbx), %rcx
movl (%rcx,%rax,4), %ecx
leaq 0x4(%rsp), %rdx
movq %rdx, 0x20(%rsp)
movl %ecx, (%rdx)
movl $0x1, (%rsp)
movq 0x878(%rbx), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x5c(%r15)
movl %eax, 0x8(%r15)
movsbq 0x8b9(%rbx), %rdx
testq %rdx, %rdx
movq 0x10(%rsp), %r14
jle 0x1315e
shlq $0x3, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x4120
cmpl $0x0, (%rsp)
movq 0x8(%rsp), %rsi
jle 0x132c0
movl (%rsp), %eax
movq %rax, 0x38(%rsp)
xorl %ebx, %ebx
movq %r13, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movq 0x48(%rsp), %rbp
movq 0x88(%rsi), %rax
movsbq 0x8b9(%rax), %rdx
testq %rdx, %rdx
jle 0x131ad
shlq $0x3, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x4120
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rax
movslq (%rax,%rbx,4), %r12
movl %r12d, 0x4(%rsp)
movl %r12d, 0x58(%r15)
movq 0x88(%rsi), %rax
movb 0x8b9(%rax), %al
testb %al, %al
jle 0x1328d
movq %rbx, 0x40(%rsp)
xorl %r13d, %r13d
movq 0x88(%rsi), %rax
cmpb $0x0, 0x8b8(%rax)
movq 0x10(%rsp), %r15
movq 0x28(%rsp), %rbx
jle 0x1325e
movsbl %r13b, %eax
movl %eax, 0x1c(%rsp)
xorl %r14d, %r14d
movslq 0x5c(%rbx), %rax
movq (%rbp,%rax,8), %rax
movq (%rax,%r12,8), %rax
movsd (%rax,%r14,8), %xmm0
movsd %xmm0, 0x50(%rsp)
movq (%rsi), %rax
movsbl %r14b, %edx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl 0x1c(%rsp), %ecx
callq *0x20(%rax)
movq 0x8(%rsp), %rsi
mulsd 0x50(%rsp), %xmm0
addsd (%r15,%r13,8), %xmm0
movsd %xmm0, (%r15,%r13,8)
incq %r14
movq 0x88(%rsi), %rax
movsbq 0x8b8(%rax), %rax
cmpq %rax, %r14
jl 0x13201
incq %r13
movq 0x88(%rsi), %rax
movsbq 0x8b9(%rax), %rax
cmpq %rax, %r13
jl 0x131dc
movq 0x30(%rsp), %r13
movq 0x10(%rsp), %r14
movq 0x28(%rsp), %r15
movq 0x40(%rsp), %rbx
testb %al, %al
jle 0x132b2
movzbl %al, %eax
xorl %ecx, %ecx
movsd (%r14,%rcx,8), %xmm0
addsd (%r13,%rcx,8), %xmm0
movsd %xmm0, (%r13,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x13296
incq %rbx
cmpq 0x38(%rsp), %rbx
jne 0x13186
cmpl $0x2, (%rsp)
jl 0x132fe
movq 0x88(%rsi), %rax
movsbq 0x8b9(%rax), %rax
testq %rax, %rax
jle 0x132fe
xorps %xmm0, %xmm0
cvtsi2sdl (%rsp), %xmm0
xorl %ecx, %ecx
movsd (%r13,%rcx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r13,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x132e4
movl $0x60, %esi
movq %r15, %rdi
callq 0x4220
movq %r14, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42a0
nop