// File: /workspace/github_cpp_makefile_star2_O3/myudelson[P]hmm-scalable/HMMProblem.cpp
// Function: HMMProblem::init(param*)
void HMMProblem::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;
    if( this->p->solver == METHOD_CGD && this->p->solver_setting == -1)
        this->p->solver_setting = 1; // default Fletcher-Reeves
    
    NPAR nS = this->p->nS, nO = this->p->nO;
    NUMBER *a_PI, ** a_A, ** a_B;
    init3Params(a_PI, a_A, a_B, nS, nO);
    
    //
    // setup params
    //
    this->pi = init2D<NUMBER>((NDAT)this->sizes[0], (NDAT)nS);
    this->A =  init3D<NUMBER>((NDAT)this->sizes[1], (NDAT)nS, (NDAT)nS);
    this->B =  init3D<NUMBER>((NDAT)this->sizes[2], (NDAT)nS, (NDAT)nO);
    NPAR i, j;
    int offset, idx;

    // write default parameters first
    NUMBER sumPI = 0;
    NUMBER sumA[this->p->nS];
    NUMBER sumB[this->p->nS];
    for(i=0; i<this->p->nS; i++) {
        sumA[i] = 0;
        sumB[i] = 0;
    }
    // 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 = (int)(nS-1);
    for(i=0; i<nS; i++) {
        for(j=0; j<((nS)-1); j++) {
            idx = (int)(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];
    }
    // populate B
    offset = (int)((nS-1) + nS*(nS-1));
    for(i=0; i<nS; i++) {
        for(j=0; j<((nO)-1); j++) {
            idx = (int)(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, 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);
    }

    NCAT x;
    for(x=0; x<this->sizes[0]; x++)
        cpy1D<NUMBER>(a_PI, this->pi[x], (NDAT)nS);
    for(x=0; x<this->sizes[1]; x++)
        cpy2D<NUMBER>(a_A, this->A[x], (NDAT)nS, (NDAT)nS);
    for(x=0; x<this->sizes[2]; x++)
        cpy2D<NUMBER>(a_B, this->B[x], (NDAT)nS, (NDAT)nO);

    // destroy setup params
    free(a_PI);
    free2D<NUMBER>(a_A, (NDAT)nS);
    free2D<NUMBER>(a_B, (NDAT)nS);
    if(param->initfile[0]!=0) { // from setup file
        // if needs be -- read in init params from a file
        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 = (int)(offset + i*nS + j);
			lbA[i][j] = this->p->param_lo[idx];
			ubA[i][j] = this->p->param_hi[idx];
		}
	// *B
	offset = (int)(nS + nS*nS);
	for(i=0; i<nS; i++)
		for(j=0; j<nO; j++) {
			idx = (int)(offset + i*nO + 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 $0x68, %rsp
movq %rsi, %r14
movq %rdi, %r12
movq %rsi, 0x88(%rdi)
movb $0x1, 0x80(%rdi)
movsbl 0x8b9(%rsi), %ebx
movslq %ebx, %rdi
movl $0x8, %esi
movq %rdi, -0x48(%rbp)
callq 0x4130
movq %rax, 0x18(%r12)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%r12)
movq $0x0, 0x30(%r12)
cmpb $0x3, 0x3f(%r14)
jne 0x10a4d
cmpb $-0x1, 0x40(%r14)
jne 0x10a4d
movb $0x1, 0x40(%r14)
movq %r14, -0x80(%rbp)
movsbl 0x8b8(%r14), %ecx
movq %rcx, -0x40(%rbp)
movslq %ecx, %r15
leaq -0x90(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x70(%rbp), %rcx
movl %r15d, %r8d
movq -0x48(%rbp), %r9
callq 0x10fa2
movl 0xc(%r12), %edi
movl %r15d, %esi
callq 0xbb36
movq %rax, 0x38(%r12)
movl 0x10(%r12), %edi
movl %r15d, %esi
movl %r15d, %edx
callq 0xcaae
movq %rax, 0x40(%r12)
movl 0x14(%r12), %edi
movl %r15d, %esi
movq %rbx, -0x60(%rbp)
movl %ebx, %edx
callq 0xcaae
movq %rsp, -0x88(%rbp)
movq %rax, 0x48(%r12)
movq 0x88(%r12), %rax
movzbl 0x8b8(%rax), %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
movq 0x88(%r12), %r11
movzbl 0x8b8(%r11), %r14d
leal 0xf(,%r14,8), %eax
andl $-0x10, %eax
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
testb %r14b, %r14b
jle 0x10b32
shll $0x3, %r14d
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r11, -0x38(%rbp)
callq 0x4120
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x4120
movq -0x38(%rbp), %r11
movq %r13, -0x38(%rbp)
leal -0x1(%r15), %eax
xorpd %xmm1, %xmm1
movq -0x90(%rbp), %rdi
cmpb $0x2, %r15b
jl 0x10b6c
movq 0x8(%r11), %rcx
xorl %edx, %edx
movsbq %dl, %rdx
movsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rdi,%rdx,8)
addsd %xmm0, %xmm1
incb %dl
movsbl %dl, %esi
cmpl %esi, %eax
jg 0x10b51
movsd 0x22d7c(%rip), %xmm0    # 0x338f0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movq %rdi, -0x58(%rbp)
movsd %xmm2, -0x8(%rdi,%r15,8)
testb %r15b, %r15b
movq -0x60(%rbp), %r13
movq -0x38(%rbp), %r10
jle 0x10caf
movq -0x50(%rbp), %rcx
xorl %edx, %edx
cmpb $0x1, %r15b
jne 0x10baf
movsd (%rbx,%rdx,8), %xmm1
movq (%rcx,%rdx,8), %rsi
jmp 0x10bf7
leal 0x1(%rdx), %edi
imull %eax, %edi
movq 0x8(%r11), %r8
movq (%rcx,%rdx,8), %rsi
movsd (%rbx,%rdx,8), %xmm1
xorl %r10d, %r10d
xorl %r9d, %r9d
addl %edi, %r10d
movslq %r10d, %r10
movsd (%r8,%r10,8), %xmm2
movsbq %r9b, %r9
movsd %xmm2, (%rsi,%r9,8)
addsd %xmm2, %xmm1
incb %r9b
movsbl %r9b, %r10d
cmpl %r10d, %eax
jg 0x10bc8
movsd %xmm1, (%rbx,%rdx,8)
movq -0x38(%rbp), %r10
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, -0x8(%rsi,%r15,8)
incq %rdx
cmpq %r15, %rdx
jne 0x10b9e
movq -0x40(%rbp), %rcx
incl %ecx
testb %r15b, %r15b
movl %ecx, -0x2c(%rbp)
jle 0x10cba
imull %ecx, %eax
leal -0x1(%r13), %ecx
movq -0x70(%rbp), %rdx
xorl %esi, %esi
movq -0x48(%rbp), %rbx
cmpb $0x1, %r13b
jle 0x10c8d
movl %esi, %r8d
imull %ecx, %r8d
addl %eax, %r8d
movq %r11, %r14
movq 0x8(%r11), %r9
movq (%rdx,%rsi,8), %rdi
movsd (%r10,%rsi,8), %xmm1
xorl %r11d, %r11d
xorl %r10d, %r10d
addl %r8d, %r11d
movslq %r11d, %r11
movsd (%r9,%r11,8), %xmm2
movsbq %r10b, %r10
movsd %xmm2, (%rdi,%r10,8)
addsd %xmm2, %xmm1
incb %r10b
movsbl %r10b, %r11d
cmpl %r11d, %ecx
jg 0x10c58
movq -0x38(%rbp), %r10
movsd %xmm1, (%r10,%rsi,8)
movq %r14, %r11
jmp 0x10c97
movsd (%r10,%rsi,8), %xmm1
movq (%rdx,%rsi,8), %rdi
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, -0x8(%rdi,%rbx,8)
incq %rsi
cmpq %r15, %rsi
jne 0x10c31
jmp 0x10cba
movq -0x40(%rbp), %r13
leal 0x1(%r13), %eax
movl %eax, -0x2c(%rbp)
cmpb $0x0, 0x32(%r11)
jne 0x10cdd
movq -0x50(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq %r12, %rdi
movq -0x58(%rbp), %rsi
callq 0x10ff0
testb %al, %al
je 0x10f9d
cmpl $0x0, 0xc(%r12)
movq -0x58(%rbp), %r13
jle 0x10d15
leaq (,%r15,8), %rbx
xorl %r14d, %r14d
movq 0x38(%r12), %rax
movq (%rax,%r14,8), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x41c0
incq %r14
movslq 0xc(%r12), %rax
cmpq %rax, %r14
jl 0x10cf4
movl 0x10(%r12), %eax
movl -0x40(%rbp), %r14d
testl %eax, %eax
movq %r15, -0x38(%rbp)
movq %r12, -0x78(%rbp)
jle 0x10d85
movq -0x50(%rbp), %r13
movq -0x40(%rbp), %rcx
leal (,%rcx,8), %ebx
xorl %edx, %edx
testb %r15b, %r15b
jle 0x10d7a
movq 0x40(%r12), %rax
movq %rdx, -0x68(%rbp)
movq (%rax,%rdx,8), %r15
xorl %r12d, %r12d
movq (%r15,%r12,8), %rdi
movq (%r13,%r12,8), %rsi
movq %rbx, %rdx
callq 0x41c0
incq %r12
cmpq %r12, %r14
jne 0x10d50
movq -0x78(%rbp), %r12
movl 0x10(%r12), %eax
movq -0x38(%rbp), %r15
movq -0x68(%rbp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jl 0x10d3b
movl 0x14(%r12), %eax
movq -0x70(%rbp), %rbx
testl %eax, %eax
jle 0x10de9
movq -0x48(%rbp), %rcx
leaq (,%rcx,8), %r13
xorl %edx, %edx
testb %r15b, %r15b
jle 0x10dde
movq 0x48(%r12), %rax
movq %rdx, -0x68(%rbp)
movq (%rax,%rdx,8), %r15
xorl %r12d, %r12d
movq (%r15,%r12,8), %rdi
movq (%rbx,%r12,8), %rsi
movq %r13, %rdx
callq 0x41c0
incq %r12
cmpq %r12, %r14
jne 0x10db5
movq -0x78(%rbp), %r12
movl 0x14(%r12), %eax
movq -0x38(%rbp), %r15
movq -0x68(%rbp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jl 0x10da0
movq -0x58(%rbp), %rdi
callq 0x42a0
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %r13
movl %r13d, %esi
callq 0xa5dd
movq %rbx, %rdi
movl %r13d, %esi
callq 0xa5dd
movq -0x80(%rbp), %rsi
cmpb $0x0, 0x6c(%rsi)
je 0x10e25
addq $0x6c, %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x11182
leaq 0x50(%r12), %rsi
leaq 0x58(%r12), %rdx
leaq 0x60(%r12), %rcx
movl %r13d, %r8d
movq -0x60(%rbp), %rbx
movl %ebx, %r9d
callq 0x10fa2
leaq 0x68(%r12), %rsi
leaq 0x70(%r12), %rdx
leaq 0x78(%r12), %rcx
movl %r13d, %r8d
movl %ebx, %r9d
callq 0x10fa2
testb %r15b, %r15b
jle 0x10f87
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, %r15
jne 0x10e82
testb %r15b, %r15b
jle 0x10f87
movq 0x88(%r12), %rsi
movq 0x58(%r12), %rax
movq 0x70(%r12), %rcx
movq 0x18(%rsi), %rdx
movq 0x20(%rsi), %rsi
xorl %edi, %edi
movl %r13d, %r8d
movslq %r8d, %r10
leaq (%rsi,%r10,8), %r9
leaq (%rdx,%r10,8), %r10
movq (%rax,%rdi,8), %r11
movq (%rcx,%rdi,8), %rbx
xorl %r14d, %r14d
movsd (%r10,%r14,8), %xmm0
movsd %xmm0, (%r11,%r14,8)
movsd (%r9,%r14,8), %xmm0
movsd %xmm0, (%rbx,%r14,8)
incq %r14
cmpq %r14, %r15
jne 0x10edc
incq %rdi
addl %r13d, %r8d
cmpq %r15, %rdi
jne 0x10ec6
testb %r15b, %r15b
movq -0x60(%rbp), %r14
jle 0x10f87
movl -0x2c(%rbp), %eax
imull %r13d, %eax
movl %eax, -0x2c(%rbp)
movq 0x88(%r12), %rax
movq 0x60(%r12), %rcx
movq 0x78(%r12), %rdx
movzbl -0x48(%rbp), %esi
xorl %edi, %edi
cmpb $0x0, -0x48(%rbp)
movl -0x2c(%rbp), %r12d
jle 0x10f78
movslq %r12d, %r8
shlq $0x3, %r8
movq (%rcx,%rdi,8), %r9
movq (%rdx,%rdi,8), %r10
movq 0x20(%rax), %r11
addq %r8, %r11
addq 0x18(%rax), %r8
xorl %ebx, %ebx
movsd (%r8,%rbx,8), %xmm0
movsd %xmm0, (%r9,%rbx,8)
movsd (%r11,%rbx,8), %xmm0
movsd %xmm0, (%r10,%rbx,8)
incq %rbx
cmpq %rbx, %rsi
jne 0x10f58
incq %rdi
addl %r14d, %r12d
movl %r12d, -0x2c(%rbp)
cmpq %r15, %rdi
jne 0x10f32
movq -0x88(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4a4b