// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblemPiABGK.cpp
// Function: HMMProblemPiABGK::init(param*)
void HMMProblemPiABGK::init(struct param *param) {
	this->p = param;
	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;
    NPAR nS = this->p->nS, nO = this->p->nO; NCAT nK = this->p->nK, nG = this->p->nG;
    
    NUMBER *a_PI, ** a_A, ** a_B;
    init3Params(a_PI, a_A, a_B, nS, nO);
    
    //
    // setup params
    //
	NPAR i, j, m, 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][((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);
    this->PIg = init2D<NUMBER>(nG, nS);
    this->Ag  = init3D<NUMBER>(nG, nS, nS);
    this->Bg  = init3D<NUMBER>(nG, nS, nO);
    NCAT x;
    for(x=0; x<nK; x++) {
        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);
    }
    // PIg start with "no-effect" params,PI[i] = 1/nS
    for(x=0; x<nG; x++) {
        for(i=0; i<nS; i++) {
            this->PIg[x][i] = (NUMBER)1/nS;
            for(j=0; j<nS; j++)
                this->Ag[x][i][j] = (NUMBER)1/nS;
            for(m=0; m<nS; m++)
                this->Bg[x][i][m] = (NUMBER)1/nO;
        }
    }
    // 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];
		}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, 0x88(%rdi)
movb $0x1, 0x80(%rdi)
movsbl 0x8b9(%rsi), %eax
movq %rax, -0x30(%rbp)
movslq %eax, %r14
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x4120
movq %rax, 0x18(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rbx)
andq $0x0, 0x30(%rbx)
movzbl 0x8b8(%r15), %r12d
movsbq %r12b, %rax
movq %rax, -0x38(%rbp)
movsbl %r12b, %r13d
movl 0x8bc(%r15), %eax
movq %rax, -0x78(%rbp)
movq %r15, -0x90(%rbp)
movl 0x8c0(%r15), %eax
movq %rax, -0x58(%rbp)
leaq -0x68(%rbp), %rsi
leaq -0x60(%rbp), %rdx
leaq -0x50(%rbp), %rcx
movq %rbx, %rdi
movl %r13d, %r8d
movq %r14, -0x80(%rbp)
movl %r14d, %r9d
callq 0xde8c
movq %rsp, -0x98(%rbp)
leal 0xf(,%r12,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
movl %r13d, -0x3c(%rbp)
testb %r13b, %r13b
movl %r12d, %r13d
cmovlel %edx, %r13d
cmpq %rdx, %r13
je 0x1d067
andq $0x0, (%rax,%rdx,8)
andq $0x0, (%rcx,%rdx,8)
incq %rdx
jmp 0x1d053
movq -0x38(%rbp), %rdx
leal -0x1(%rdx), %edi
movq 0x88(%rbx), %rdx
xorpd %xmm0, %xmm0
movq -0x68(%rbp), %rsi
xorl %r8d, %r8d
cmpl %r8d, %edi
jle 0x1d09e
movq 0x8(%rdx), %r9
movsd (%r9,%r8,8), %xmm1
movsd %xmm1, (%rsi,%r8,8)
addsd %xmm1, %xmm0
incq %r8
jmp 0x1d080
movsd 0xf84a(%rip), %xmm2     # 0x2c8f0
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
movq -0x68(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq %rsi, -0x88(%rbp)
movsd %xmm1, -0x8(%rsi,%rdx,8)
movq -0x60(%rbp), %rsi
leal -0x1(%r12), %edx
movzbl %dl, %r11d
xorl %r10d, %r10d
movq %r11, -0x48(%rbp)
movq %rsi, %r9
movq %rsi, %rdx
cmpq %r13, %r10
je 0x1d144
movq 0x88(%rbx), %r14
movq -0x60(%rbp), %rdx
xorl %r15d, %r15d
cmpl %r15d, %edi
jle 0x1d122
leal (%r11,%r15), %r8d
movq 0x8(%r14), %rsi
movsbq %r8b, %r8
movsd (%rsi,%r8,8), %xmm0
movq (%rdx,%r10,8), %rsi
movsd %xmm0, (%rsi,%r15,8)
addsd (%rax,%r10,8), %xmm0
movsd %xmm0, (%rax,%r10,8)
incq %r15
jmp 0x1d0f0
movapd %xmm2, %xmm0
subsd (%rax,%r10,8), %xmm0
movq (%r9,%r10,8), %rsi
movq -0x38(%rbp), %r8
movsd %xmm0, -0x8(%rsi,%r8,8)
incq %r10
addq -0x48(%rbp), %r11
jmp 0x1d0dd
movq -0x30(%rbp), %rsi
leal -0x1(%rsi), %edi
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
decl %eax
leal 0x1(%r12), %r8d
movl %r8d, -0x6c(%rbp)
mulb %r8b
movzbl %al, %eax
decl %esi
movzbl %sil, %r9d
xorl %r10d, %r10d
cmpq %r13, %r10
je 0x1d1db
movq 0x88(%rbx), %r11
movq -0x50(%rbp), %r14
xorl %r15d, %r15d
cmpl %r15d, %edi
jle 0x1d1b6
leal (%rax,%r15), %esi
movq 0x8(%r11), %r8
movsbq %sil, %rsi
movsd (%r8,%rsi,8), %xmm0
movq (%r14,%r10,8), %rsi
movsd %xmm0, (%rsi,%r15,8)
addsd (%rcx,%r10,8), %xmm0
movsd %xmm0, (%rcx,%r10,8)
incq %r15
jmp 0x1d184
movapd %xmm2, %xmm0
subsd (%rcx,%r10,8), %xmm0
movq -0x48(%rbp), %rsi
movq (%rsi,%r10,8), %rsi
movq -0x80(%rbp), %r8
movsd %xmm0, -0x8(%rsi,%r8,8)
incq %r10
addq %r9, %rax
jmp 0x1d171
movq 0x88(%rbx), %rax
cmpb $0x0, 0x32(%rax)
jne 0x1d203
movq -0x50(%rbp), %rcx
movq %rbx, %rdi
movq -0x88(%rbp), %rsi
callq 0xded0
testb %al, %al
je 0x1d52f
movq -0x58(%rbp), %r14
movl %r14d, %edi
movl -0x3c(%rbp), %r15d
movl %r15d, %esi
callq 0x9328
movq %rax, 0x38(%rbx)
movl %r14d, %edi
movl %r15d, %esi
movl %r15d, %edx
callq 0xa0be
movq %rax, 0x40(%rbx)
movl %r14d, %edi
movl %r15d, %esi
movq -0x30(%rbp), %rdx
callq 0xa0be
movq %rax, 0x48(%rbx)
movq -0x78(%rbp), %r14
movl %r14d, %edi
movl %r15d, %esi
callq 0x9328
movq %rax, 0x90(%rbx)
movl %r14d, %edi
movl %r15d, %esi
movl %r15d, %edx
callq 0xa0be
movq %rax, 0x98(%rbx)
movl %r14d, %edi
movl %r15d, %esi
movq -0x30(%rbp), %rdx
callq 0xa0be
movq %rax, 0xa0(%rbx)
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x48(%rbp)
xorl %r15d, %r15d
movq -0x58(%rbp), %rax
testl %eax, %eax
cmovlel %r15d, %eax
movq %rax, -0x58(%rbp)
movl -0x3c(%rbp), %r14d
cmpq %r15, -0x58(%rbp)
je 0x1d2f4
movq -0x68(%rbp), %rsi
movq 0x38(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq -0x48(%rbp), %rdx
callq 0x41c0
movq -0x60(%rbp), %rdi
movq 0x40(%rbx), %rax
movq (%rax,%r15,8), %rsi
movl %r14d, %edx
movl %r14d, %ecx
callq 0x93ad
movq -0x50(%rbp), %rdi
movq 0x48(%rbx), %rax
movq (%rax,%r15,8), %rsi
movl %r14d, %edx
movq -0x30(%rbp), %rcx
callq 0x93ad
incq %r15
jmp 0x1d2a5
cvtsi2sdl -0x38(%rbp), %xmm1
movsd 0xf5ef(%rip), %xmm2     # 0x2c8f0
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
divsd %xmm1, %xmm2
xorl %eax, %eax
movq -0x78(%rbp), %r9
testl %r9d, %r9d
cmovlel %eax, %r9d
cmpq %r9, %rax
je 0x1d387
movq 0x90(%rbx), %rcx
xorl %edx, %edx
cmpq %r13, %rdx
je 0x1d382
movq (%rcx,%rax,8), %rsi
movsd %xmm0, (%rsi,%rdx,8)
movq 0x98(%rbx), %rsi
xorl %edi, %edi
cmpq %rdi, %r12
je 0x1d35c
movq (%rsi,%rax,8), %r8
movq (%r8,%rdx,8), %r8
movsd %xmm0, (%r8,%rdi,8)
incq %rdi
jmp 0x1d344
movq 0xa0(%rbx), %rsi
xorl %edi, %edi
cmpq %rdi, %r12
je 0x1d37d
movq (%rsi,%rax,8), %r8
movq (%r8,%rdx,8), %r8
movsd %xmm2, (%r8,%rdi,8)
incq %rdi
jmp 0x1d365
incq %rdx
jmp 0x1d32d
incq %rax
jmp 0x1d31f
movq -0x68(%rbp), %rdi
callq 0x4290
movq -0x60(%rbp), %rdi
movl -0x3c(%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 0x1d3c7
addq $0x6c, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe026
leaq 0x50(%rbx), %rsi
leaq 0x58(%rbx), %rdx
leaq 0x60(%rbx), %rcx
movsbl %r12b, %r8d
movq %rbx, %rdi
movq -0x30(%rbp), %r14
movl %r14d, %r9d
callq 0xde8c
leaq 0x68(%rbx), %rsi
leaq 0x70(%rbx), %rdx
leaq 0x78(%rbx), %rcx
movq %rbx, %rdi
movq -0x38(%rbp), %r8
movl %r14d, %r9d
callq 0xde8c
movq 0x88(%rbx), %rax
movq 0x50(%rbx), %rcx
movq 0x68(%rbx), %rdx
xorl %esi, %esi
cmpq %rsi, %r13
je 0x1d438
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 0x1d412
movq %r12, %rax
negq %rax
xorl %edx, %edx
movq %r12, %rcx
cmpq %r13, %rdx
je 0x1d4a3
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 0x1d49b
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 0x1d45e
addq %r12, %rcx
movq %rsi, %rdx
jmp 0x1d443
xorl %ecx, %ecx
cmpb $0x0, -0x80(%rbp)
movq -0x30(%rbp), %rax
cmovlel %ecx, %eax
movzbl %al, %edx
movl %r12d, %eax
mulb -0x6c(%rbp)
movzbl %al, %eax
movzbl %r12b, %esi
cmpq %r13, %rcx
je 0x1d519
movq 0x88(%rbx), %rdi
movq 0x60(%rbx), %r8
movq 0x78(%rbx), %r9
xorl %r10d, %r10d
cmpq %r10, %rdx
je 0x1d511
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 0x1d4d7
incq %rcx
addq %rsi, %rax
jmp 0x1d4c0
movq -0x98(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1baa2(%rip), %rax     # 0x38fd8
movq (%rax), %rcx
leaq 0xfeeb(%rip), %rdi      # 0x2d42b
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x44b0
pushq $0x1
popq %rdi
callq 0x42a0
nop