// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/HMMProblemSt.cpp
// Function: HMMProblemSt::init(task*)
void HMMProblemSt::init(struct task *task) {
//    printf("HMMProblemSt::init\n");
   // init
    this->task = task;
    this->non01constraints = true;
    this->null_obs_ratios = Calloc(NUMBER, (size_t)this->task->nO);
//    this->neg_log_lik = 0;
    this->null_skill_obs = 0;
    this->null_skill_obs_prob = 0;
    if( this->task->solver == METHOD_CGD && this->task->solver_setting == -1)
        this->task->solver_setting = 1; // default Fletcher-Reeves
    
    NPAR nS = this->task->nS, nO = this->task->nO;
    NCAT nK = this->task->nK, nG = this->task->nG;
    
    //
    // setup params
    //
    this->skill1_n = nS * (1 + nS + nO); // number of params per 1 skill slot
    this->param_skill = init1D<NUMBER>( (NDAT)(this->skill1_n*nK) );
    this->gradient_skill = init1D<NUMBER>( (NDAT)(this->skill1_n*nK) );
    this->active_set_block = initToValue1D<NPAR>((NDAT)nK, 1);
    this->unblocked_simplex = initToValue1D<NPAR>((NDAT)(nK * (1 + 2 * nS)), 1);
    
    NPAR i, j, m;
    int offset, idx;

    // write default parameters first
    NUMBER sum = 0;
    
    // vv populate skill parameters
    for(NCAT k=0; k<nK; k++) {
        // vv populate PI
        for(i=0; i<((nS)-1); i++) {
            this->param_skill[ k*this->skill1_n + i ] = this->task->init_param_values[i];
            sum  += this->task->init_param_values[i];
        } // ^^ populate PI
        this->param_skill[ k*this->skill1_n + nS - 1 ] = 1 - sum;
        // vv populate A
        offset = (int)(nS-1);
        for(i=0; i<nS; i++) {
            sum = 0;
            for(j=0; j<((nS)-1); j++) {
                idx = (int)(offset + i*((nS)-1) + j);
                this->param_skill[ k*this->skill1_n + nS + i*nS + j ] = this->task->init_param_values[idx];
                sum  += this->task->init_param_values[idx];
            }
            this->param_skill[ k*this->skill1_n + nS + i*nS + nS-1 ] = 1 - sum;
        } // ^^ populate A
        // vv populate B
        offset = (int)((nS-1) + nS*(nS-1));
        for(i=0; i<nS; i++) {
            sum = 0;
            for(m=0; m<((nO)-1); m++) {
                idx = (int)(offset + i*((nO)-1) + m);
                this->param_skill[ k*this->skill1_n + nS + nS*nS + i*nO + m ] = this->task->init_param_values[idx];
                sum += this->task->init_param_values[idx];
            }
            this->param_skill[ k*this->skill1_n + nS + nS*nS + i*nO + nO - 1 ] = 1 - sum;
        } // ^^ populate B
    } // ^^ populate skill parameters
    
    // check only first mass-produced skill
    if( this->task->do_not_check_constraints==0 && !checkSkillConstraints(this->param_skill)) {
        fprintf(stderr,"params do not meet constraints.\n");
        exit(1);
    }

    if(task->initfile[0]!=0) { // from setup file
        // if needs be -- read in init params from a file
        this->readModel(task->initfile, false /* read and upload but not overwrite*/);
    }
    
    // init and populate boundaries
    this->lb_param_skill = init1D<NUMBER>(this->skill1_n);
    cpy1D(this->task->param_values_lb, this->lb_param_skill, this->skill1_n);
    this->ub_param_skill = init1D<NUMBER>(this->skill1_n);
    cpy1D(this->task->param_values_ub, this->ub_param_skill, this->skill1_n);
    
    // init supportive data structures
    NDAT Nst = this->task->Nst;
    this->alpha = init2D<NUMBER>(Nst, nS); // forward variables, 2D array of Nst rows nS values in each ((1..nS)){Nst}
    this->po_param_gk = init2D<NUMBER>(nG, nK); //
    this->loglik_k = init1D<NUMBER>(nK); //
    this->ndat_k = init1D<NDAT>(nK);
    this->beta = init2D<NUMBER>(Nst, nS); // backward variables, 2D array of Nst rows nS values in each ((1..nS)){Nst}
    this->scale = (this->task->is_scaled==1) ? initToValue1D<NUMBER>(Nst, 0) : NULL;
    this->gamma = NULL;
    this->xi = NULL;
    if(this->task->solver == METHOD_BW) {
        this->gamma = init2D<NUMBER>(Nst, nS);
        this->xi = init3D<NUMBER>(Nst, nS, nS);
    }
    this->backward_ix = init1D<NDAT>(Nst); // Nst sized array of pointing to previous student-skill repetition, -1 means none before
    this->forward_ix = init1D<NDAT>(Nst); // Nst sized array of pointing to next student-skill repetition, -1 means no more
    this->is_fwd_bwd_built=false; // flag for noting whether backward_ix & forward_ix are already built
    
    this->group_skill_map = init3D<NUMBER>(nG, nK, nS);//UNBOOST

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r12
movq %rdi, %r14
movq %rsi, 0x68(%rdi)
movb $0x1, 0x50(%rdi)
movsbl 0x901(%rsi), %ebx
movslq %ebx, %r13
movl $0x8, %esi
movq %r13, %rdi
callq 0x2110
movq %rax, 0x10(%r14)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x18(%r14)
cmpb $0x3, 0x4f(%r12)
jne 0xacef
cmpb $-0x1, 0x50(%r12)
jne 0xacef
movb $0x1, 0x50(%r12)
movsbl 0x900(%r12), %ecx
movslq 0x908(%r12), %r15
movl 0x904(%r12), %eax
movl %eax, 0x14(%rsp)
leal (%rcx,%rbx), %edx
incl %edx
movq %rcx, (%rsp)
imull %ecx, %edx
movl %edx, 0x38(%r14)
movl %edx, 0x18(%rsp)
movl %edx, %eax
imull %r15d, %eax
movslq %eax, %rdi
movq %rdi, 0x28(%rsp)
movl $0x8, %esi
callq 0x2110
movq %rax, %rbp
movq %rax, 0x28(%r14)
movl $0x8, %esi
movq 0x28(%rsp), %rdi
callq 0x2110
movq %r14, 0x8(%rsp)
movq %rax, 0x30(%r14)
movl $0x1, %esi
movq %r15, %rdi
callq 0x2110
movq %rax, %r14
testq %r15, %r15
jle 0xad7c
movq %r14, %rdi
movl $0x1, %esi
movq %r15, %rdx
callq 0x2100
movq 0x8(%rsp), %rax
movq %r14, 0x58(%rax)
movq (%rsp), %rax
leal 0x1(,%rax,2), %r14d
movq %r15, 0x20(%rsp)
imull %r15d, %r14d
movslq %r14d, %r15
movl $0x1, %esi
movq %r15, %rdi
callq 0x2110
movq %rax, %rcx
testl %r15d, %r15d
jle 0xadc8
movl %r14d, %edx
movq %rcx, %r14
movq %rcx, %rdi
movl $0x1, %esi
callq 0x2100
movq %r14, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x60(%rax)
cmpl $0x0, 0x20(%rsp)
jle 0xafbf
movq (%rsp), %rdi
movslq %edi, %rax
leal 0x1(%rax), %esi
leaq -0x1(%rax), %rcx
imull %ecx, %esi
leaq -0x1(%r13), %rdx
imull %edi, %edi
leal (%rdi,%rbx), %r8d
movq %r8, 0x38(%rsp)
movslq %esi, %rsi
movq %rsi, 0x40(%rsp)
movslq 0x18(%rsp), %rsi
movq %rsi, 0x18(%rsp)
leaq (,%rdi,8), %rsi
addq %rbp, %rsi
movq %rsi, 0x30(%rsp)
xorpd %xmm1, %xmm1
xorl %r11d, %r11d
movsd 0x6b22(%rip), %xmm0     # 0x11950
cmpb $0x2, %al
jl 0xae75
movq (%r12), %rsi
movq %r11, %rdi
imulq 0x18(%rsp), %rdi
leaq (,%rdi,8), %r8
addq %rbp, %r8
xorl %r10d, %r10d
xorl %r9d, %r9d
movsbq %r9b, %r9
movsd (%rsi,%r9,8), %xmm2
movslq %r10d, %rdi
movsd %xmm2, (%r8,%rdi,8)
addsd (%rsi,%r9,8), %xmm1
incb %r9b
movsbl %r9b, %r10d
cmpl %r10d, %ecx
jg 0xae50
movq %r11, 0x28(%rsp)
imulq 0x18(%rsp), %r11
addq %rax, %r11
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, -0x8(%rbp,%r11,8)
testb %al, %al
jle 0xaf1b
movq (%rsp), %rsi
leal (%r11,%rsi), %r15d
leaq (,%r11,8), %rsi
addq %rbp, %rsi
xorl %r9d, %r9d
xorpd %xmm1, %xmm1
cmpb $0x2, %al
jl 0xaef8
leaq 0x1(%r9), %r8
imulq %rcx, %r8
movq %r9, %rdi
imulq %rax, %rdi
shlq $0x3, %r8
addq (%r12), %r8
leaq (%rsi,%rdi,8), %r10
xorl %edi, %edi
movb $0x1, %r14b
movslq %edi, %rdi
movsd (%r8,%rdi,8), %xmm2
movsd %xmm2, (%r10,%rdi,8)
addsd (%r8,%rdi,8), %xmm1
movsbl %r14b, %edi
incb %r14b
cmpl %edi, %ecx
jg 0xaed8
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movl %r9d, %edi
imull (%rsp), %edi
addl %r15d, %edi
movslq %edi, %rdi
movsd %xmm2, -0x8(%rbp,%rdi,8)
incq %r9
cmpq %rax, %r9
jne 0xaeb0
testb %al, %al
movq 0x40(%rsp), %r14
jle 0xafac
movq 0x38(%rsp), %rsi
leal (%rsi,%r11), %r15d
movq 0x30(%rsp), %rsi
leaq (%rsi,%r11,8), %rsi
xorl %r9d, %r9d
xorpd %xmm1, %xmm1
cmpb $0x2, %r13b
jl 0xaf8a
movq %r9, %rdi
imulq %rdx, %rdi
movq %r9, %r10
imulq %r13, %r10
shlq $0x3, %rdi
addq (%r12), %rdi
leaq (%rdi,%r14,8), %r8
leaq (%rsi,%r10,8), %r10
xorl %edi, %edi
movb $0x1, %r11b
movslq %edi, %rdi
movsd (%r8,%rdi,8), %xmm2
movsd %xmm2, (%r10,%rdi,8)
addsd (%r8,%rdi,8), %xmm1
movsbl %r11b, %edi
incb %r11b
cmpl %edi, %edx
jg 0xaf6a
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movl %r9d, %edi
imull %ebx, %edi
addl %r15d, %edi
movslq %edi, %rdi
movsd %xmm2, -0x8(%rbp,%rdi,8)
incq %r9
cmpq %rax, %r9
jne 0xaf3d
movq 0x28(%rsp), %r11
incq %r11
cmpq 0x20(%rsp), %r11
jne 0xae2e
cmpb $0x0, 0x42(%r12)
jne 0xafdc
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0xb18c
testb %al, %al
je 0xb186
cmpb $0x0, 0x7c(%r12)
movq 0x8(%rsp), %rbp
je 0xaffa
addq $0x7c, %r12
movq %rbp, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xb20c
movslq 0x38(%rbp), %rbx
movl $0x8, %esi
movq %rbx, %rdi
callq 0x2110
movq %rax, 0x40(%rbp)
movq 0x68(%rbp), %r14
movq 0x10(%r14), %rsi
leaq (,%rbx,8), %r15
movq %rax, %rdi
movq %r15, %rdx
callq 0x2180
movl $0x8, %esi
movq %rbx, %rdi
callq 0x2110
movq %rax, 0x48(%rbp)
movq 0x18(%r14), %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0x2180
movl 0x8fc(%r14), %r13d
movslq %r13d, %r12
movl %r12d, %edi
movq (%rsp), %rbx
movl %ebx, %esi
callq 0x10493
movq %rax, 0x70(%rbp)
movl 0x14(%rsp), %edi
movq 0x20(%rsp), %r15
movl %r15d, %esi
callq 0x10493
movq %rax, 0x78(%rbp)
movl $0x8, %esi
movq %r15, %rdi
callq 0x2110
movq %rax, 0x80(%rbp)
movl $0x4, %esi
movq %r15, %rdi
callq 0x2110
movq %rax, 0x88(%rbp)
movl %r12d, %edi
movl %ebx, %esi
callq 0x10493
movq %rax, 0x90(%rbp)
movq 0x68(%rbp), %rbx
cmpb $0x1, 0x41(%rbx)
jne 0xb0e7
movl $0x8, %esi
movq %r12, %rdi
callq 0x2110
movq %rax, %rbp
testl %r13d, %r13d
jle 0xb0e9
leaq (,%r13,8), %rdx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2100
jmp 0xb0e9
xorl %ebp, %ebp
movq 0x8(%rsp), %r14
movq %rbp, 0xa8(%r14)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x98(%r14)
cmpb $0x1, 0x4f(%rbx)
jne 0xb130
movl %r13d, %edi
movq (%rsp), %rbx
movl %ebx, %esi
callq 0x10493
movq %rax, 0x98(%r14)
movl %r13d, %edi
movl %ebx, %esi
movl %ebx, %edx
callq 0x104e6
movq %rax, 0xa0(%r14)
movl $0x4, %esi
movq %r12, %rdi
callq 0x2110
movq %rax, 0xb0(%r14)
movl $0x4, %esi
movq %r12, %rdi
callq 0x2110
movq %rax, 0xb8(%r14)
movb $0x0, 0xc0(%r14)
movl 0x14(%rsp), %edi
movl %r15d, %esi
movq (%rsp), %rdx
callq 0x104e6
movq %rax, 0xc8(%r14)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2983
nop