// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblemAGK.cpp
// Function: HMMProblemAGK::init(param*)
void HMMProblemAGK::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, 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>((NDAT)nK, (NDAT)nS);
    this->A   = init3D<NUMBER>((NDAT)nK, (NDAT)nS, (NDAT)nS);
    this->Ag  = init3D<NUMBER>((NDAT)nG, (NDAT)nS, (NDAT)nS);
    this->B   = init3D<NUMBER>((NDAT)nK, (NDAT)nS, (NDAT)nO);
    NCAT x;
    for(x=0; x<nK; x++) {
        cpy1D<NUMBER>(a_PI, this->pi[x], (NDAT)nS);
        cpy2D<NUMBER>(a_A,  this->A[x],  (NDAT)nS, (NDAT)nS);
        cpy2D<NUMBER>(a_B,  this->B[x],  (NDAT)nS, (NDAT)nO);
    }
    // PIg start with "no-effect" params,PI[i] = 1/nS
    for(x=0; x<nG; x++) {
        for(i=0; i<nS; i++) {
            for(j=0; j<nS; j++)
                this->Ag[x][i][j] = (NUMBER)1/nS;
        }
    }
    // destroy setup params
	free(a_PI);
	free2D<NUMBER>(a_A, (NDAT)nS);
	free2D<NUMBER>(a_B, (NDAT)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, -0x48(%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, -0x30(%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, -0x34(%rbp)
testb %r13b, %r13b
movl %r12d, %r13d
cmovlel %edx, %r13d
cmpq %rdx, %r13
je 0x19317
andq $0x0, (%rax,%rdx,8)
andq $0x0, (%rcx,%rdx,8)
incq %rdx
jmp 0x19303
movq -0x30(%rbp), %rdx
leal -0x1(%rdx), %edi
movq 0x88(%rbx), %rdx
xorpd %xmm0, %xmm0
movq -0x68(%rbp), %rsi
xorl %r8d, %r8d
cmpl %r8d, %edi
jle 0x1934e
movq 0x8(%rdx), %r9
movsd (%r9,%r8,8), %xmm1
movsd %xmm1, (%rsi,%r8,8)
addsd %xmm1, %xmm0
incq %r8
jmp 0x19330
movsd 0x1359a(%rip), %xmm2    # 0x2c8f0
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
movq -0x68(%rbp), %rsi
movq -0x30(%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, -0x40(%rbp)
movq %rsi, %r9
movq %rsi, %rdx
cmpq %r13, %r10
je 0x193f4
movq 0x88(%rbx), %r14
movq -0x60(%rbp), %rdx
xorl %r15d, %r15d
cmpl %r15d, %edi
jle 0x193d2
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 0x193a0
movapd %xmm2, %xmm0
subsd (%rax,%r10,8), %xmm0
movq (%r9,%r10,8), %rsi
movq -0x30(%rbp), %r8
movsd %xmm0, -0x8(%rsi,%r8,8)
incq %r10
addq -0x40(%rbp), %r11
jmp 0x1938d
movq -0x48(%rbp), %rsi
leal -0x1(%rsi), %edi
movq -0x50(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%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 0x1948b
movq 0x88(%rbx), %r11
movq -0x50(%rbp), %r14
xorl %r15d, %r15d
cmpl %r15d, %edi
jle 0x19466
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 0x19434
movapd %xmm2, %xmm0
subsd (%rcx,%r10,8), %xmm0
movq -0x40(%rbp), %rsi
movq (%rsi,%r10,8), %rsi
movq -0x80(%rbp), %r8
movsd %xmm0, -0x8(%rsi,%r8,8)
incq %r10
addq %r9, %rax
jmp 0x19421
movq 0x88(%rbx), %rax
cmpb $0x0, 0x32(%rax)
jne 0x194b3
movq -0x50(%rbp), %rcx
movq %rbx, %rdi
movq -0x88(%rbp), %rsi
callq 0xded0
testb %al, %al
je 0x19775
movq -0x58(%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)
movq -0x78(%rbp), %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0xa0be
movq %rax, 0x90(%rbx)
movl %r15d, %edi
movl %r14d, %esi
movq -0x48(%rbp), %rdx
callq 0xa0be
movq %rax, 0x48(%rbx)
movq -0x30(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x40(%rbp)
xorl %r15d, %r15d
movq -0x58(%rbp), %rax
testl %eax, %eax
cmovlel %r15d, %eax
movq %rax, -0x58(%rbp)
movl -0x34(%rbp), %r14d
cmpq %r15, -0x58(%rbp)
je 0x19579
movq -0x68(%rbp), %rsi
movq 0x38(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq -0x40(%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 -0x48(%rbp), %rcx
callq 0x93ad
incq %r15
jmp 0x1952a
cvtsi2sdl -0x30(%rbp), %xmm0
movsd 0x1336a(%rip), %xmm1    # 0x2c8f0
divsd %xmm0, %xmm1
xorl %eax, %eax
movq -0x78(%rbp), %r8
testl %r8d, %r8d
cmovlel %eax, %r8d
cmpq %r8, %rax
je 0x195cd
xorl %ecx, %ecx
cmpq %r13, %rcx
je 0x195c8
movq 0x90(%rbx), %rdx
xorl %esi, %esi
cmpq %rsi, %r12
je 0x195c3
movq (%rdx,%rax,8), %rdi
movq (%rdi,%rcx,8), %rdi
movsd %xmm1, (%rdi,%rsi,8)
incq %rsi
jmp 0x195ac
incq %rcx
jmp 0x1959e
incq %rax
jmp 0x19597
movq -0x68(%rbp), %rdi
callq 0x4290
movq -0x60(%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 0x1960d
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 -0x48(%rbp), %r14
movl %r14d, %r9d
callq 0xde8c
leaq 0x68(%rbx), %rsi
leaq 0x70(%rbx), %rdx
leaq 0x78(%rbx), %rcx
movq %rbx, %rdi
movq -0x30(%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 0x1967e
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 0x19658
movq %r12, %rax
negq %rax
xorl %edx, %edx
movq %r12, %rcx
cmpq %r13, %rdx
je 0x196e9
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 0x196e1
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 0x196a4
addq %r12, %rcx
movq %rsi, %rdx
jmp 0x19689
xorl %ecx, %ecx
cmpb $0x0, -0x80(%rbp)
movq -0x48(%rbp), %rax
cmovlel %ecx, %eax
movzbl %al, %edx
movl %r12d, %eax
mulb -0x6c(%rbp)
movzbl %al, %eax
movzbl %r12b, %esi
cmpq %r13, %rcx
je 0x1975f
movq 0x88(%rbx), %rdi
movq 0x60(%rbx), %r8
movq 0x78(%rbx), %r9
xorl %r10d, %r10d
cmpq %r10, %rdx
je 0x19757
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 0x1971d
incq %rcx
addq %rsi, %rax
jmp 0x19706
movq -0x98(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1f85c(%rip), %rax     # 0x38fd8
movq (%rax), %rcx
leaq 0x13ca5(%rip), %rdi     # 0x2d42b
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x44b0
pushq $0x1
popq %rdi
callq 0x42a0
nop