// File: /workspace/github_cpp_makefile_star2_O2/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)
movzbl 0x8b8(%rsi), %ecx
movsbq %cl, %rax
movq %rax, -0x40(%rbp)
movq %rcx, -0x30(%rbp)
movsbl %cl, %r15d
movsbl 0x8b9(%rsi), %eax
movq %rax, -0x48(%rbp)
movslq %eax, %r14
movq %rsi, -0x90(%rbp)
movl 0x8c0(%rsi), %eax
movq %rax, -0x88(%rbp)
movb $0x1, 0x80(%rdi)
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x4120
movq %rax, 0x18(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rbx)
andq $0x0, 0x30(%rbx)
leaq -0x68(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0x50(%rbp), %rcx
movq %rbx, %rdi
movl %r15d, -0x34(%rbp)
movl %r15d, %r8d
movq %r14, -0x78(%rbp)
movl %r14d, %r9d
callq 0xde8c
movq 0x88(%rbx), %r14
movslq 0x8c0(%r14), %rdi
pushq $0x1
popq %rsi
callq 0x4120
movq %rax, 0x90(%rbx)
xorl %eax, %eax
movslq 0x8b0(%r14), %rcx
cmpq %rcx, %rax
jge 0x29f61
movq 0x890(%r14), %rcx
movl (%rcx,%rax,4), %ecx
cmpl $0x2, %ecx
jl 0x29f5c
xorl %edx, %edx
movq 0x88(%rbx), %r14
cmpl %edx, %ecx
je 0x29f5c
movq 0x888(%r14), %rsi
movq 0x898(%r14), %rdi
movslq (%rdi,%rax,4), %rdi
addq %rdx, %rdi
movslq (%rsi,%rdi,4), %rsi
movq 0x90(%rbx), %rdi
movb $0x1, (%rdi,%rsi)
incq %rdx
jmp 0x29f28
incq %rax
jmp 0x29f0b
movq %rsp, -0x98(%rbp)
movq -0x30(%rbp), %rax
leal 0xf(,%rax,8), %edx
andl $-0x10, %edx
movq %rsp, %rax
subq %rdx, %rax
movq %rax, %rsp
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, %rsp
xorl %edx, %edx
movq -0x40(%rbp), %rdi
testb %dil, %dil
movl $0x0, %esi
cmovgl %edi, %esi
movslq %esi, %r15
cmpq %rdx, %r15
je 0x29fb0
andq $0x0, (%rax,%rdx,8)
andq $0x0, (%rcx,%rdx,8)
incq %rdx
jmp 0x29f9c
movq -0x40(%rbp), %rdx
leal -0x1(%rdx), %edi
movq 0x88(%rbx), %rdx
xorpd %xmm1, %xmm1
movq -0x68(%rbp), %rsi
xorl %r8d, %r8d
cmpl %r8d, %edi
jle 0x29fe7
movq 0x8(%rdx), %r9
movsd (%r9,%r8,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
addsd %xmm0, %xmm1
incq %r8
jmp 0x29fc9
movsd 0x2901(%rip), %xmm0     # 0x2c8f0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movq -0x68(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rsi, -0x80(%rbp)
movsd %xmm2, -0x8(%rsi,%rdx,8)
movq -0x58(%rbp), %r8
movq 0x88(%rbx), %rdx
movq %rdx, -0x60(%rbp)
movq -0x30(%rbp), %rdx
decl %edx
movzbl %dl, %r10d
xorl %r11d, %r11d
movq %r10, %r14
movq %r8, %rdx
cmpq %r15, %r11
je 0x2a09a
movq 0x88(%rbx), %r12
movq -0x58(%rbp), %rdx
xorl %r13d, %r13d
cmpl %r13d, %edi
jle 0x2a071
leal (%r14,%r13), %r9d
movq 0x8(%r12), %rsi
movsbq %r9b, %r9
movsd (%rsi,%r9,8), %xmm1
movq (%rdx,%r11,8), %rsi
movsd %xmm1, (%rsi,%r13,8)
addsd (%rax,%r11,8), %xmm1
movsd %xmm1, (%rax,%r11,8)
incq %r13
jmp 0x2a03e
movapd %xmm0, %xmm1
subsd (%rax,%r11,8), %xmm1
movq (%r8,%r11,8), %rsi
movq -0x60(%rbp), %r9
movsbq 0x8b8(%r9), %r9
movsd %xmm1, -0x8(%rsi,%r9,8)
incq %r11
addq %r10, %r14
jmp 0x2a02b
movq -0x48(%rbp), %r9
leal -0x1(%r9), %edi
movq -0x50(%rbp), %r8
movq -0x40(%rbp), %rax
decl %eax
movq -0x30(%rbp), %rsi
incl %esi
movl %esi, -0x6c(%rbp)
mulb %sil
movzbl %al, %eax
leal -0x1(%r9), %esi
movzbl %sil, %r9d
xorl %r10d, %r10d
cmpq %r15, %r10
je 0x2a12d
movq 0x88(%rbx), %r11
movq -0x50(%rbp), %r14
xorl %r12d, %r12d
cmpl %r12d, %edi
jle 0x2a10c
leal (%rax,%r12), %esi
movq 0x8(%r11), %r13
movsbq %sil, %rsi
movsd (%r13,%rsi,8), %xmm1
movq (%r14,%r10,8), %rsi
movsd %xmm1, (%rsi,%r12,8)
addsd (%rcx,%r10,8), %xmm1
movsd %xmm1, (%rcx,%r10,8)
incq %r12
jmp 0x2a0d9
movapd %xmm0, %xmm1
subsd (%rcx,%r10,8), %xmm1
movq (%r8,%r10,8), %rsi
movq -0x78(%rbp), %r11
movsd %xmm1, -0x8(%rsi,%r11,8)
incq %r10
addq %r9, %rax
jmp 0x2a0c6
movq %r15, -0x60(%rbp)
movq 0x88(%rbx), %rax
cmpb $0x0, 0x32(%rax)
jne 0x2a156
movq -0x50(%rbp), %rcx
movq %rbx, %rdi
movq -0x80(%rbp), %rsi
callq 0xded0
testb %al, %al
je 0x2a3ca
movq -0x88(%rbp), %r15
movl %r15d, %edi
movl -0x34(%rbp), %r14d
movl %r14d, %esi
callq 0x9328
movq %rax, 0x38(%rbx)
movl %r15d, %edi
movl %r14d, %esi
movl %r14d, %edx
callq 0xa0be
movq %rax, 0x40(%rbx)
movl %r15d, %edi
movl %r14d, %esi
movq -0x48(%rbp), %rdx
callq 0xa0be
movq %rax, 0x48(%rbx)
movq -0x40(%rbp), %rax
leaq (,%rax,8), %r14
xorl %r12d, %r12d
testl %r15d, %r15d
cmovlel %r12d, %r15d
movl -0x34(%rbp), %r13d
movq -0x68(%rbp), %rsi
cmpq %r12, %r15
je 0x2a1fc
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rdi
movq %r14, %rdx
callq 0x41c0
movq -0x58(%rbp), %rdi
movq 0x40(%rbx), %rax
movq (%rax,%r12,8), %rsi
movl %r13d, %edx
movl %r13d, %ecx
callq 0x93ad
movq -0x50(%rbp), %rdi
movq 0x48(%rbx), %rax
movq (%rax,%r12,8), %rsi
movl %r13d, %edx
movq -0x48(%rbp), %rcx
callq 0x93ad
incq %r12
jmp 0x2a1af
movq %rsi, %rdi
callq 0x4290
movq -0x58(%rbp), %rdi
movl -0x34(%rbp), %r14d
movl %r14d, %esi
callq 0x7f2c
movq -0x50(%rbp), %rdi
movl %r14d, %esi
callq 0x7f2c
movq -0x90(%rbp), %rsi
cmpb $0x0, 0x6c(%rsi)
je 0x2a23b
addq $0x6c, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe026
leaq 0x50(%rbx), %rsi
leaq 0x58(%rbx), %rdx
leaq 0x60(%rbx), %rcx
movsbl -0x30(%rbp), %r8d
movq %rbx, %rdi
movq -0x48(%rbp), %r14
movl %r14d, %r9d
callq 0xde8c
leaq 0x68(%rbx), %rsi
leaq 0x70(%rbx), %rdx
leaq 0x78(%rbx), %rcx
movq %rbx, %rdi
movq -0x40(%rbp), %r8
movl %r14d, %r9d
callq 0xde8c
movq 0x88(%rbx), %rax
movq 0x50(%rbx), %rcx
movq 0x68(%rbx), %rdx
xorl %esi, %esi
movq -0x60(%rbp), %r15
cmpq %rsi, %r15
je 0x2a2b1
movq 0x18(%rax), %rdi
movsd (%rdi,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
movq 0x20(%rax), %rdi
movsd (%rdi,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
jmp 0x2a28b
movq -0x30(%rbp), %rcx
movq %rcx, %rax
negq %rax
xorl %edx, %edx
cmpq %r15, %rdx
je 0x2a31e
leaq 0x1(%rdx), %rsi
movq 0x88(%rbx), %rdi
movq 0x58(%rbx), %r8
movq 0x70(%rbx), %r9
xorl %r10d, %r10d
movq %rax, %r11
addq %r10, %r11
je 0x2a315
leal (%rcx,%r10), %r11d
movq 0x18(%rdi), %r14
movsbq %r11b, %r11
movsd (%r14,%r11,8), %xmm0
movq (%r8,%rdx,8), %r14
movsd %xmm0, (%r14,%r10,8)
movq 0x20(%rdi), %r14
movsd (%r14,%r11,8), %xmm0
movq (%r9,%rdx,8), %r11
movsd %xmm0, (%r11,%r10,8)
incq %r10
jmp 0x2a2d8
addq -0x30(%rbp), %rcx
movq %rsi, %rdx
jmp 0x2a2bd
xorl %ecx, %ecx
cmpb $0x0, -0x78(%rbp)
movq -0x48(%rbp), %rax
cmovlel %ecx, %eax
movzbl %al, %edx
movq -0x30(%rbp), %rsi
movl %esi, %eax
mulb -0x6c(%rbp)
movzbl %al, %eax
movzbl %sil, %esi
cmpq %r15, %rcx
je 0x2a397
movq 0x88(%rbx), %rdi
movq 0x60(%rbx), %r8
movq 0x78(%rbx), %r9
xorl %r10d, %r10d
cmpq %r10, %rdx
je 0x2a38f
leal (%rax,%r10), %r11d
movq 0x18(%rdi), %r14
movsbq %r11b, %r11
movsd (%r14,%r11,8), %xmm0
movq (%r8,%rcx,8), %r14
movsd %xmm0, (%r14,%r10,8)
movq 0x20(%rdi), %r14
movsd (%r14,%r11,8), %xmm0
movq (%r9,%rcx,8), %r11
movsd %xmm0, (%r11,%r10,8)
incq %r10
jmp 0x2a355
incq %rcx
addq %rsi, %rax
jmp 0x2a33e
pushq $0x8
popq %rdi
callq 0x4220
leaq 0xe152(%rip), %rcx      # 0x384f8
addq $0x10, %rcx
movq %rcx, (%rax)
movq %rax, 0x98(%rbx)
movq -0x98(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xec07(%rip), %rax      # 0x38fd8
movq (%rax), %rcx
leaq 0x3050(%rip), %rdi      # 0x2d42b
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x44b0
pushq $0x1
popq %rdi
callq 0x42a0