// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/HMMProblemComp.cpp
// Function: HMMProblemComp::init(param*)
void HMMProblemComp::init(struct param *param) {
	this->p = param;
    NPAR nS = this->p->nS, nO = this->p->nO; NCAT nK = this->p->nK;//, nG = this->p->nG;
	this->non01constraints = true;
    this->null_obs_ratio = Calloc(NUMBER, (size_t)this->p->nO);
    this->neg_log_lik = 0;
    this->null_skill_obs = 0;
    this->null_skill_obs_prob = 0;
    
    NUMBER *a_PI, ** a_A, ** a_B;
    init3Params(a_PI, a_A, a_B, nS, nO);
    
	// is_multi
	this->is_multi = Calloc(NPAR, (size_t)this->p->nK);
	// assign is_multi labels
	NCAT k, n;
	for(NDAT t=0; t<this->p->N; t++) {
		n = this->p->dat_skill_rcount[t];
		if(n>1) {
			for(NCAT l=0; l<n; l++) {
				k = this->p->dat_skill_stacked[ this->p->dat_skill_rix[t] + l ];
				is_multi[k] = 1;
			}
		}
	}

	//
    // setup params
    //
	NPAR i, j, idx, offset;
	NUMBER sumPI = 0;
	NUMBER sumA[nS];
	NUMBER sumB[nS];
	for(i=0; i<nS; i++) {
		sumA[i] = 0;
		sumB[i] = 0;
	}
    
    // write default parameters first
	// populate PI
	for(i=0; i<((nS)-1); i++) {
		a_PI[i] = this->p->init_params[i];
		sumPI  += this->p->init_params[i];
	}
	a_PI[nS-1] = 1 - sumPI;
	// populate A
	offset = (NPAR)(nS-1);
	for(i=0; i<nS; i++) {
		for(j=0; j<((nS)-1); j++) {
			idx = (NPAR)(offset + i*((nS)-1) + j);
			a_A[i][j] = this->p->init_params[idx];
			sumA[i]  += this->p->init_params[idx];
		}
		a_A[i][((this->p->nS)-1)]  = 1 - sumA[i];
	}
	// polupale B
	offset = (NPAR)((nS-1) + nS*(nS-1));
	for(i=0; i<nS; i++) {
		for(j=0; j<((nO)-1); j++) {
			idx = (NPAR)(offset + i*((nO)-1) + j);
			a_B[i][j] = this->p->init_params[idx];
			sumB[i] += this->p->init_params[idx];
		}
		a_B[i][((nO)-1)]  = 1 - sumB[i];
	}
    
    // mass produce PI's/PIg's, A's, B's
    if( this->p->do_not_check_constraints==0 && !checkPIABConstraints(a_PI, a_A, a_B)) {
        fprintf(stderr,"params do not meet constraints.\n");
        exit(1);
    }
    this->pi  = init2D<NUMBER>(nK, nS);
    this->A   = init3D<NUMBER>(nK, nS, nS);
    this->B   = init3D<NUMBER>(nK, nS, nO);
    NCAT x;
    for(x=0; x<nK; x++) {
//		if(this->is_multi[x]==0) {
			cpy1D<NUMBER>(a_PI, this->pi[x], nS);
			cpy2D<NUMBER>(a_A,  this->A[x],  nS, nS);
			cpy2D<NUMBER>(a_B,  this->B[x],  nS, nO);
//		} else {
//			for(i=0; i<nS; i++) {
//				this->pi[x][i] = 0.5;
//				for(j=0; j<nS; j++)
//					this->A[x][i][j] = 0.5;
//				for(m=0; m<nO; m++)
//					this->B[x][i][m] = 0.5;
//			}
//		}
    }
    // PIg start with same params
    // destroy setup params
	free(a_PI);
	free2D<NUMBER>(a_A, nS);
	free2D<NUMBER>(a_B, nS);
	
    // if needs be -- read in init params from a file
    if(param->initfile[0]!=0)
        this->readModel(param->initfile, false /* read and upload but not overwrite*/);
    
    // populate boundaries
	// populate lb*/ub*
	// *PI
    init3Params(this->lbPI, this->lbA, this->lbB, nS, nO);
    init3Params(this->ubPI, this->ubA, this->ubB, nS, nO);
	for(i=0; i<nS; i++) {
		lbPI[i] = this->p->param_lo[i];
		ubPI[i] = this->p->param_hi[i];
	}
	// *A
	offset = nS;
	for(i=0; i<nS; i++)
		for(j=0; j<nS; j++) {
			idx = (NPAR)(offset + i*nS + j);
			lbA[i][j] = this->p->param_lo[idx];
			ubA[i][j] = this->p->param_hi[idx];
		}
	// *B
	offset = (NPAR)(nS + nS*nS);
	for(i=0; i<nS; i++)
		for(j=0; j<nO; j++) {
			idx = (NPAR)(offset + i*nS + j);
			lbB[i][j] = this->p->param_lo[idx];
			ubB[i][j] = this->p->param_hi[idx];
		}
	// set up parameter union
//	this->pu = new PUCorbettianAdditive();
	this->pu = new PULogistic();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movq %rsi, 0x88(%rdi)
movsbl 0x8b8(%rsi), %eax
movzbl %al, %r13d
movl %eax, -0x2c(%rbp)
movslq %eax, %r15
movsbl 0x8b9(%rsi), %eax
movl %eax, -0x30(%rbp)
movslq %eax, %r14
movq %rsi, -0x80(%rbp)
movl 0x8c0(%rsi), %eax
movq %rax, -0x78(%rbp)
movb $0x1, 0x80(%rdi)
movl $0x8, %esi
movq %r14, %rdi
callq 0x4130
movq %rax, 0x18(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movq $0x0, 0x30(%rbx)
leaq -0x60(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0x50(%rbp), %rcx
movq %rbx, %rdi
movq %r15, -0x40(%rbp)
movl %r15d, %r8d
movq %r14, -0x48(%rbp)
movl %r14d, %r9d
callq 0x1112e
movq 0x88(%rbx), %rax
movslq 0x8c0(%rax), %rdi
movl $0x1, %esi
callq 0x4130
movq %rax, 0x90(%rbx)
movq 0x88(%rbx), %rcx
cmpl $0x0, 0x8b0(%rcx)
jle 0x31156
xorl %eax, %eax
movq 0x890(%rcx), %rcx
movl (%rcx,%rax,4), %ecx
cmpl $0x2, %ecx
jl 0x31140
xorl %edx, %edx
movq 0x88(%rbx), %rsi
movq 0x90(%rbx), %rdi
movq 0x888(%rsi), %r8
movq 0x898(%rsi), %rsi
movslq (%rsi,%rax,4), %rsi
addq %rdx, %rsi
movslq (%r8,%rsi,4), %rsi
movb $0x1, (%rdi,%rsi)
incq %rdx
cmpl %edx, %ecx
jne 0x3110e
incq %rax
movq 0x88(%rbx), %rcx
movslq 0x8b0(%rcx), %rdx
cmpq %rdx, %rax
jl 0x310fd
movq %rbx, -0x38(%rbp)
movq %rsp, -0x88(%rbp)
leal 0xf(,%r13,8), %eax
andl $-0x10, %eax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
cmpb $0x0, -0x40(%rbp)
jle 0x311a8
leal (,%r13,8), %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x4120
leal (,%r13,8), %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x4120
movq -0x40(%rbp), %rax
decl %eax
xorpd %xmm1, %xmm1
cmpb $0x2, %r13b
jl 0x311eb
movq -0x38(%rbp), %rcx
movq 0x88(%rcx), %rcx
movq 0x8(%rcx), %rcx
movq -0x60(%rbp), %rdx
xorl %esi, %esi
movsbq %sil, %rsi
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
addsd (%rcx,%rsi,8), %xmm1
incb %sil
movsbl %sil, %edi
cmpl %edi, %eax
jg 0x311cd
movsd 0x36fd(%rip), %xmm0     # 0x348f0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movq -0x60(%rbp), %rsi
movq -0x40(%rbp), %rcx
movsd %xmm2, -0x8(%rsi,%rcx,8)
testb %cl, %cl
movq %r13, -0x68(%rbp)
jle 0x312a1
movq -0x38(%rbp), %rcx
movq 0x88(%rcx), %rcx
movq -0x58(%rbp), %rdx
movsbq 0x8b8(%rcx), %rdi
leal -0x1(%r13), %r8d
xorl %r9d, %r9d
movl %r8d, %r10d
cmpl $0x1, %r13d
je 0x31281
movq 0x8(%rcx), %r11
movq (%rdx,%r9,8), %rbx
movsd (%r12,%r9,8), %xmm1
xorl %r14d, %r14d
leal (%r10,%r14), %r13d
movsbq %r13b, %r13
movsd (%r11,%r13,8), %xmm2
movsbq %r14b, %r14
movsd %xmm2, (%rbx,%r14,8)
addsd (%r11,%r13,8), %xmm1
incb %r14b
movsbl %r14b, %r13d
cmpl %r13d, %eax
jg 0x3124d
movsd %xmm1, (%r12,%r9,8)
movq -0x68(%rbp), %r13
movapd %xmm0, %xmm1
subsd (%r12,%r9,8), %xmm1
movq (%rdx,%r9,8), %r11
movsd %xmm1, -0x8(%r11,%rdi,8)
incq %r9
addb %r8b, %r10b
cmpq %r13, %r9
jne 0x31236
testb %r13b, %r13b
movq -0x38(%rbp), %r12
movq -0x48(%rbp), %r11
jle 0x3133d
leal -0x1(%r11), %ecx
movq 0x88(%r12), %rdx
movq -0x50(%rbp), %rdi
leal -0x1(%r13), %eax
leal 0x1(%r13), %r8d
mulb %r8b
leal -0x1(%r11), %r8d
xorl %r9d, %r9d
cmpb $0x2, %r11b
jl 0x3131d
movq 0x8(%rdx), %r10
movq (%rdi,%r9,8), %r11
movsd (%r15,%r9,8), %xmm1
xorl %ebx, %ebx
leal (%rax,%rbx), %r14d
movsbq %r14b, %r14
movsd (%r10,%r14,8), %xmm2
movsbq %bl, %rbx
movsd %xmm2, (%r11,%rbx,8)
addsd (%r10,%r14,8), %xmm1
incb %bl
movsbl %bl, %r14d
cmpl %r14d, %ecx
jg 0x312ea
movsd %xmm1, (%r15,%r9,8)
movq -0x48(%rbp), %r11
movapd %xmm0, %xmm1
subsd (%r15,%r9,8), %xmm1
movq (%rdi,%r9,8), %r10
movsd %xmm1, -0x8(%r10,%r11,8)
incq %r9
addb %r8b, %al
cmpq %r13, %r9
jne 0x312d4
movq 0x88(%r12), %rax
cmpb $0x0, 0x32(%rax)
jne 0x31363
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq %r12, %rdi
callq 0x1117c
testb %al, %al
je 0x31643
movq -0x78(%rbp), %r14
movl %r14d, %edi
movl -0x2c(%rbp), %ebx
movl %ebx, %esi
callq 0xbb5c
movq %rax, 0x38(%r12)
movl %r14d, %edi
movl %ebx, %esi
movl %ebx, %edx
callq 0xcaae
movq %rax, 0x40(%r12)
movl %r14d, %edi
movl %ebx, %esi
movl -0x30(%rbp), %edx
callq 0xcaae
movq %rax, 0x48(%r12)
testl %r14d, %r14d
jle 0x3147c
movq -0x40(%rbp), %rax
leaq (,%rax,8), %r15
movl -0x2c(%rbp), %r14d
movq -0x48(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x98(%rbp)
xorl %ecx, %ecx
movq %r15, -0x90(%rbp)
movq -0x60(%rbp), %rsi
movq 0x38(%r12), %rax
movq %rcx, -0x70(%rbp)
movq (%rax,%rcx,8), %rdi
movq %r15, %rdx
callq 0x41c0
testb %r13b, %r13b
jle 0x3141f
movq -0x58(%rbp), %r13
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rbx
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rdi
movq (%r13,%r12,8), %rsi
movq %r15, %rdx
callq 0x41c0
incq %r12
cmpq %r12, %r14
jne 0x31406
cmpb $0x0, -0x68(%rbp)
movq -0x98(%rbp), %r15
jle 0x3145c
movq -0x50(%rbp), %r13
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rbx
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rdi
movq (%r13,%r12,8), %rsi
movq %r15, %rdx
callq 0x41c0
incq %r12
cmpq %r12, %r14
jne 0x31443
movq -0x70(%rbp), %rcx
incq %rcx
cmpq -0x78(%rbp), %rcx
movq -0x38(%rbp), %r12
movq -0x68(%rbp), %r13
movq -0x90(%rbp), %r15
jne 0x313d1
movq -0x60(%rbp), %rdi
callq 0x42a0
movq -0x58(%rbp), %rdi
movl -0x2c(%rbp), %ebx
movl %ebx, %esi
callq 0xa5e0
movq -0x50(%rbp), %rdi
movl %ebx, %esi
callq 0xa5e0
movq -0x80(%rbp), %rsi
cmpb $0x0, 0x6c(%rsi)
je 0x314b6
addq $0x6c, %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x112f0
leaq 0x50(%r12), %rsi
leaq 0x58(%r12), %rdx
leaq 0x60(%r12), %rcx
movsbl %r13b, %r8d
movq %r12, %rdi
movl -0x30(%rbp), %ebx
movl %ebx, %r9d
callq 0x1112e
leaq 0x68(%r12), %rsi
leaq 0x70(%r12), %rdx
leaq 0x78(%r12), %rcx
movsbl %r13b, %r8d
movq %r12, %rdi
movl %ebx, %r9d
callq 0x1112e
testb %r13b, %r13b
movq -0x40(%rbp), %r14
jle 0x31536
movq 0x88(%r12), %rcx
movq 0x18(%rcx), %rax
movq 0x20(%rcx), %rcx
movq 0x50(%r12), %rdx
movq 0x68(%r12), %rsi
xorl %edi, %edi
movsd (%rax,%rdi,8), %xmm0
movsd %xmm0, (%rdx,%rdi,8)
movsd (%rcx,%rdi,8), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %r13
jne 0x3151a
testb %r14b, %r14b
jle 0x31596
movq 0x88(%r12), %rsi
movq 0x58(%r12), %rax
movq 0x70(%r12), %rcx
movq 0x18(%rsi), %rdx
movq 0x20(%rsi), %rsi
xorl %edi, %edi
movq %r13, %r8
movq (%rax,%rdi,8), %r9
movq (%rcx,%rdi,8), %r10
xorl %r11d, %r11d
leal (%r8,%r11), %ebx
movsbq %bl, %rbx
movsd (%rdx,%rbx,8), %xmm0
movsd %xmm0, (%r9,%r11,8)
movsd (%rsi,%rbx,8), %xmm0
movsd %xmm0, (%r10,%r11,8)
incq %r11
cmpq %r11, %r13
jne 0x31565
incq %rdi
addq %r13, %r8
cmpq %r14, %rdi
jne 0x3155a
testb %r13b, %r13b
jle 0x3160d
movq 0x88(%r12), %rcx
movq 0x60(%r12), %rdx
movq 0x78(%r12), %rsi
movzbl -0x30(%rbp), %edi
leal 0x1(%r14), %r8d
movl -0x2c(%rbp), %eax
mulb %r8b
movzbl %al, %eax
xorl %r8d, %r8d
cmpb $0x0, -0x48(%rbp)
jle 0x31602
movq 0x18(%rcx), %r9
movq 0x20(%rcx), %r10
movq (%rdx,%r8,8), %r11
movq (%rsi,%r8,8), %rbx
xorl %r14d, %r14d
leal (%rax,%r14), %r15d
movsbq %r15b, %r15
movsd (%r9,%r15,8), %xmm0
movsd %xmm0, (%r11,%r14,8)
movsd (%r10,%r15,8), %xmm0
movsd %xmm0, (%rbx,%r14,8)
incq %r14
cmpq %r14, %rdi
jne 0x315da
incq %r8
addq %r13, %rax
cmpq %r13, %r8
jne 0x315c1
movl $0x8, %edi
callq 0x4210
leaq 0xdeca(%rip), %rcx      # 0x3f4e8
addq $0x10, %rcx
movq %rcx, (%rax)
movq %rax, 0x98(%r12)
movq -0x88(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x55a4