// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/HMMProblemSlicedA.cpp
// Function: HMMProblemSlicedA::init(param*)
void HMMProblemSlicedA::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, nZ = this->p->nZ;
    NUMBER *a_PI, *** a_A, ** a_B;
    init3Params(a_PI, a_A, a_B, nZ, nS, nO);
    
    //
    // setup params
    //
	NPAR i, j, z, m, idx, offset;
    this->pi = init2D<NUMBER>((NDAT)this->sizes[0], (NDAT)nS);
    this->A =  init4D<NUMBER>((NDAT)this->sizes[1], (NDAT)nZ, (NDAT)nS, (NDAT)nS);
    this->B =  init3D<NUMBER>((NDAT)this->sizes[2], (NDAT)nS, (NDAT)nO);
    
    // write default parameters first
    NUMBER sumPI = 0;
    NUMBER sumA[nZ][nS];
    NUMBER sumB[nS];
    for(i=0; i<nS; i++) {
        for(z=0; z<nZ; z++) {
            sumA[z][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 = (NPAR)(nS-1);
    for(z=0; z<nZ; z++) {
        for(i=0; i<nS; i++) {
            for(j=0; j<((nS)-1); j++) {
                idx = (NPAR)(offset + z * nS * ((nS)-1) + i*((nS)-1) + j);
                a_A[z][i][j] = this->p->init_params[idx];
                sumA[z][i]  += this->p->init_params[idx];
            }
            a_A[z][i][((nS)-1)]  = 1 - sumA[z][i];
        }
    }
    // populate B
    offset = (NPAR)((nS-1) + nZ*nS*(nS-1));
    for(i=0; i<nS; i++) {
        for(m=0; m<((nO)-1); m++) {
            idx = (NPAR)(offset + i*((nO)-1) + m);
            a_B[i][m] = 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++)
        cpy3D<NUMBER>(a_A, this->A[x], (NDAT)nZ, (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);
    free3D<NUMBER>(a_A, (NDAT)nZ, (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, nZ, nS, nO);
    init3Params(this->ubPI, this->ubA, this->ubB, nZ, 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(z=0; z<nZ; z++) {
        for(i=0; i<nS; i++) {
            for(j=0; j<nS; j++) {
                idx = (NPAR)(offset + z * nS * nS + i*nS + j);
                lbA[z][i][j] = this->p->param_lo[idx];
                ubA[z][i][j] = this->p->param_hi[idx];
            }
        }
    }
	// *B
	offset = (NPAR)(nS + nZ*nS*nS);
    for(i=0; i<nS; i++) {
        for(j=0; j<nO; j++) {
            idx = (NPAR)(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 $0x88, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, 0x88(%rdi)
movb $0x1, 0x80(%rdi)
movsbl 0x8b9(%rsi), %eax
movq %rax, -0x90(%rbp)
movslq %eax, %rdi
movl $0x8, %esi
movq %rdi, -0x68(%rbp)
callq 0x4130
movq %rax, 0x18(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%r14)
movq $0x0, 0x30(%r14)
cmpb $0x3, 0x3f(%rbx)
jne 0x2b3ed
cmpb $-0x1, 0x40(%rbx)
jne 0x2b3ed
movb $0x1, 0x40(%rbx)
movsbl 0x8b8(%rbx), %r13d
movq %rbx, -0xa8(%rbp)
movzbl 0x8c8(%rbx), %r12d
subq $0x8, %rsp
movsbl %r12b, %r15d
leaq -0xa0(%rbp), %rsi
leaq -0x88(%rbp), %rdx
leaq -0x80(%rbp), %rcx
movl %r15d, %r8d
movl %r13d, %r9d
movq -0x90(%rbp), %rbx
pushq %rbx
callq 0x2ba6e
addq $0x10, %rsp
movl 0xc(%r14), %edi
movl %r13d, %esi
callq 0xbb5c
movq %rax, 0x38(%r14)
movl 0x10(%r14), %edi
movl %r15d, -0x44(%rbp)
movl %r15d, %esi
movl %r13d, %edx
movl %r13d, %ecx
callq 0x2b168
movq %rax, 0x90(%r14)
movl 0x14(%r14), %edi
movl %r13d, %esi
movl %ebx, %edx
callq 0xcaae
movq %rsp, -0xb0(%rbp)
movq %rax, 0x48(%r14)
movzbl %r13b, %r10d
movq %r12, -0x50(%rbp)
movl %r12d, %eax
imull %r10d, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x70(%rbp)
movq %rcx, %rsp
leal 0xf(,%r10,8), %eax
andl $-0x10, %eax
movq %rsp, %r9
subq %rax, %r9
movq %r9, %rsp
movslq %r13d, %rax
movq %rax, -0x40(%rbp)
movl %r13d, -0x2c(%rbp)
testl %r13d, %r13d
jle 0x2b505
leal (,%r10,8), %eax
xorl %edx, %edx
movq -0x70(%rbp), %rdi
movq -0x50(%rbp), %r8
movq %r8, %rcx
movq %rdi, %rsi
testb %r8b, %r8b
jle 0x2b4f1
movq $0x0, (%rsi)
addq %rax, %rsi
decq %rcx
jne 0x2b4e2
movq $0x0, (%r9,%rdx,8)
incq %rdx
addq $0x8, %rdi
cmpq %r10, %rdx
jne 0x2b4d7
movq %r9, -0x60(%rbp)
movq -0x40(%rbp), %rax
leal -0x1(%rax), %edx
xorpd %xmm1, %xmm1
cmpb $0x2, %r10b
jl 0x2b54c
movq 0x88(%r14), %rax
movq 0x8(%rax), %rax
movq -0xa0(%rbp), %rcx
xorl %esi, %esi
movsbq %sil, %rsi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
addsd (%rax,%rsi,8), %xmm1
incb %sil
movsbl %sil, %edi
cmpl %edi, %edx
jg 0x2b52e
movq %r14, -0x38(%rbp)
movsd 0x9398(%rip), %xmm0     # 0x348f0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movq -0xa0(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, -0x98(%rbp)
movsd %xmm2, -0x8(%rcx,%rax,8)
cmpb $0x0, -0x50(%rbp)
movq %r10, -0x58(%rbp)
jle 0x2b64d
movq -0x88(%rbp), %rdi
leal -0x1(%r10), %r8d
xorl %r9d, %r9d
movl -0x2c(%rbp), %eax
mulb %r8b
movb %al, -0x78(%rbp)
movl %r8d, %eax
testb %r10b, %r10b
jle 0x2b63d
movq -0x38(%rbp), %rcx
movq 0x88(%rcx), %r11
movq %r9, %rcx
imulq %r10, %rcx
movq -0x70(%rbp), %rsi
leaq (%rsi,%rcx,8), %rbx
movq (%rdi,%r9,8), %r14
movl %eax, %r12d
xorl %r13d, %r13d
cmpb $0x2, %r10b
jl 0x2b61a
movq 0x8(%r11), %r15
movq (%rdi,%r9,8), %rcx
movq (%rcx,%r13,8), %rcx
movsd (%rbx,%r13,8), %xmm1
xorl %esi, %esi
leal (%r12,%rsi), %r10d
movsbq %r10b, %r10
movsd (%r15,%r10,8), %xmm2
movsbq %sil, %rsi
movsd %xmm2, (%rcx,%rsi,8)
addsd (%r15,%r10,8), %xmm1
incb %sil
movsbl %sil, %r10d
cmpl %r10d, %edx
jg 0x2b5e7
movsd %xmm1, (%rbx,%r13,8)
movq -0x58(%rbp), %r10
movapd %xmm0, %xmm1
subsd (%rbx,%r13,8), %xmm1
movq (%r14,%r13,8), %rcx
movq -0x40(%rbp), %rsi
movsd %xmm1, -0x8(%rcx,%rsi,8)
incq %r13
addb %r8b, %r12b
cmpq %r10, %r13
jne 0x2b5cd
incq %r9
addb -0x78(%rbp), %al
cmpq -0x50(%rbp), %r9
jne 0x2b5a0
testb %r10b, %r10b
movq -0x68(%rbp), %r14
movq -0x38(%rbp), %r15
movq -0x98(%rbp), %r12
movq -0x60(%rbp), %r13
jle 0x2b704
movq -0x40(%rbp), %rax
leal -0x1(%rax), %ecx
movq -0x50(%rbp), %rax
mulb -0x58(%rbp)
movl %eax, %edx
incb %dl
movl %ecx, %eax
mulb %dl
leal -0x1(%r14), %ecx
movq 0x88(%r15), %rdx
movq -0x80(%rbp), %rdi
movq -0x90(%rbp), %rsi
leal -0x1(%rsi), %r8d
xorl %r9d, %r9d
cmpb $0x2, %r14b
jl 0x2b6e2
movq 0x8(%rdx), %r10
movq (%rdi,%r9,8), %r11
movsd (%r13,%r9,8), %xmm1
xorl %esi, %esi
leal (%rax,%rsi), %ebx
movsbq %bl, %rbx
movsd (%r10,%rbx,8), %xmm2
movsbq %sil, %rsi
movsd %xmm2, (%r11,%rsi,8)
addsd (%r10,%rbx,8), %xmm1
incb %sil
movsbl %sil, %ebx
cmpl %ebx, %ecx
jg 0x2b6b3
movsd %xmm1, (%r13,%r9,8)
movapd %xmm0, %xmm1
subsd (%r13,%r9,8), %xmm1
movq (%rdi,%r9,8), %rsi
movsd %xmm1, -0x8(%rsi,%r14,8)
incq %r9
addb %r8b, %al
cmpq -0x58(%rbp), %r9
jne 0x2b69c
movq 0x88(%r15), %rax
cmpb $0x0, 0x32(%rax)
jne 0x2b72f
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2baca
testb %al, %al
je 0x2ba69
cmpl $0x0, 0xc(%r15)
jle 0x2b764
movq -0x40(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %r14d, %r14d
movq 0x38(%r15), %rax
movq (%rax,%r14,8), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x41c0
incq %r14
movslq 0xc(%r15), %rax
cmpq %rax, %r14
jl 0x2b745
cmpl $0x0, 0x10(%r15)
movl -0x2c(%rbp), %eax
movq %rax, -0x78(%rbp)
jle 0x2b7ff
movq -0x88(%rbp), %r14
movq -0x40(%rbp), %rax
leaq (,%rax,8), %rbx
movl -0x44(%rbp), %eax
movq %rax, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
cmpb $0x0, -0x50(%rbp)
jle 0x2b7e7
movq -0x38(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %r12
xorl %r15d, %r15d
cmpb $0x0, -0x40(%rbp)
jle 0x2b7de
xorl %r13d, %r13d
movq (%r12,%r15,8), %rax
movq (%rax,%r13,8), %rdi
movq (%r14,%r15,8), %rax
movq (%rax,%r13,8), %rsi
movq %rbx, %rdx
callq 0x41c0
incq %r13
cmpq %r13, -0x78(%rbp)
jne 0x2b7bd
incq %r15
cmpq -0x70(%rbp), %r15
jne 0x2b7b4
movq -0x60(%rbp), %rdx
incq %rdx
movq -0x38(%rbp), %r15
movslq 0x10(%r15), %rax
movq %rdx, -0x60(%rbp)
cmpq %rax, %rdx
jl 0x2b798
cmpl $0x0, 0x14(%r15)
jle 0x2b857
movq -0x80(%rbp), %r14
movq -0x68(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %r12d, %r12d
cmpb $0x0, -0x58(%rbp)
jle 0x2b847
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax,%r12,8), %r15
xorl %r13d, %r13d
movq (%r15,%r13,8), %rdi
movq (%r14,%r13,8), %rsi
movq %rbx, %rdx
callq 0x41c0
incq %r13
cmpq %r13, -0x78(%rbp)
jne 0x2b82e
incq %r12
movq -0x38(%rbp), %r15
movslq 0x14(%r15), %rax
cmpq %rax, %r12
jl 0x2b819
movq -0x98(%rbp), %rdi
callq 0x42a0
movq -0x88(%rbp), %rdi
movl -0x44(%rbp), %ebx
movl %ebx, %esi
movl -0x2c(%rbp), %r14d
movl %r14d, %edx
callq 0xca4f
movq -0x80(%rbp), %rdi
movl %r14d, %esi
callq 0xa5e0
movq -0xa8(%rbp), %rsi
cmpb $0x0, 0x6c(%rsi)
je 0x2b8a2
addq $0x6c, %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x2bcf4
leaq 0x50(%r15), %rsi
leaq 0x98(%r15), %rdx
leaq 0x60(%r15), %rcx
subq $0x8, %rsp
movq -0x50(%rbp), %r14
movsbl %r14b, %r8d
movl -0x2c(%rbp), %r9d
pushq -0x90(%rbp)
callq 0x2ba6e
addq $0x10, %rsp
leaq 0x68(%r15), %rsi
leaq 0xa0(%r15), %rdx
leaq 0x78(%r15), %rcx
subq $0x8, %rsp
movsbl %r14b, %r8d
movq -0x40(%rbp), %r9
movq -0x68(%rbp), %r13
pushq %r13
callq 0x2ba6e
addq $0x10, %rsp
movq -0x58(%rbp), %r13
testb %r13b, %r13b
jle 0x2b93c
movq -0x38(%rbp), %rsi
movq 0x88(%rsi), %rcx
movq 0x18(%rcx), %rax
movq 0x20(%rcx), %rcx
movq 0x50(%rsi), %rdx
movq 0x68(%rsi), %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 0x2b920
imull -0x2c(%rbp), %ebx
movl %ebx, -0x44(%rbp)
cmpb $0x0, -0x50(%rbp)
jle 0x2b9d9
movl %r13d, %eax
mulb -0x40(%rbp)
movzbl %al, %eax
xorl %ecx, %ecx
movq %r13, %rdx
testb %r13b, %r13b
jle 0x2b9cd
movq -0x38(%rbp), %rsi
movq 0x88(%rsi), %rdi
movq 0x98(%rsi), %r8
movq 0xa0(%rsi), %r9
movq 0x18(%rdi), %rsi
movq 0x20(%rdi), %rdi
movq (%r8,%rcx,8), %r8
movq (%r9,%rcx,8), %r9
movq %rdx, %r10
xorl %r11d, %r11d
movq (%r8,%r11,8), %rbx
movq (%r9,%r11,8), %r14
xorl %r15d, %r15d
leal (%r10,%r15), %r12d
movsbq %r12b, %r12
movsd (%rsi,%r12,8), %xmm0
movsd %xmm0, (%rbx,%r15,8)
movsd (%rdi,%r12,8), %xmm0
movsd %xmm0, (%r14,%r15,8)
incq %r15
cmpq %r15, %r13
jne 0x2b99a
incq %r11
addq %r13, %r10
cmpq %r13, %r11
jne 0x2b98f
incq %rcx
addq %rax, %rdx
cmpq -0x50(%rbp), %rcx
jne 0x2b95b
movl -0x44(%rbp), %eax
incb %al
mulb %r13b
testb %r13b, %r13b
movq -0x68(%rbp), %r12
jle 0x2ba53
movq -0x38(%rbp), %rsi
movq 0x88(%rsi), %rcx
movq 0x60(%rsi), %rdx
movq 0x78(%rsi), %rsi
movzbl %r12b, %edi
movzbl %al, %eax
xorl %r8d, %r8d
testb %r12b, %r12b
jle 0x2ba47
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 0x2ba1f
incq %r8
addq %rdi, %rax
cmpq -0x58(%rbp), %r8
jne 0x2ba07
movq -0xb0(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5432