// File: /workspace/github_cpp_makefile_star2_O3/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 $0x98, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, 0x88(%rdi)
movb $0x1, 0x80(%rdi)
movsbl 0x8b9(%rsi), %eax
movq %rax, -0x50(%rbp)
movslq %eax, %rdi
movl $0x8, %esi
movq %rdi, -0x58(%rbp)
callq 0x4130
movq %rax, 0x18(%r14)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x20(%r14)
movq $0x0, 0x30(%r14)
cmpb $0x3, 0x3f(%r15)
jne 0x2aea9
cmpb $-0x1, 0x40(%r15)
jne 0x2aea9
movb $0x1, 0x40(%r15)
movsbl 0x8b8(%r15), %ebx
movq %r15, -0xb0(%rbp)
movzbl 0x8c8(%r15), %r13d
subq $0x8, %rsp
movsbl %r13b, %r12d
leaq -0xa8(%rbp), %rsi
leaq -0x70(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
movl %r12d, %r8d
movl %ebx, %r9d
movq -0x50(%rbp), %r15
pushq %r15
callq 0x2b5d6
addq $0x10, %rsp
movl 0xc(%r14), %edi
movl %ebx, %esi
callq 0xbb36
movq %rax, 0x38(%r14)
movl 0x10(%r14), %edi
movl %r12d, -0x34(%rbp)
movl %r12d, %esi
movq %r13, %r12
movl %ebx, %edx
movl %ebx, %ecx
callq 0x2ac0d
movq %rax, 0x90(%r14)
movl 0x14(%r14), %edi
movl %ebx, %esi
movl %r15d, %edx
callq 0xcaae
movq %rsp, %r10
movq %rax, 0x48(%r14)
movzbl %bl, %r13d
movl %r12d, %eax
imull %r13d, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
leal 0xf(,%r13,8), %eax
andl $-0x10, %eax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x80(%rbp)
movq %rcx, %rsp
movslq %ebx, %rax
movq %rax, -0x30(%rbp)
testl %ebx, %ebx
movq %r14, -0x40(%rbp)
movq %rbx, -0x48(%rbp)
movq %r10, -0xb8(%rbp)
movq %r15, -0x98(%rbp)
jle 0x2b0a0
leal 0x1(%r12), %eax
andl $0xfe, %eax
leaq -0x1(%r12), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movl %r13d, %esi
shll $0x4, %esi
xorl %edi, %edi
movdqa 0x98db(%rip), %xmm1     # 0x34890
movdqa 0x98e3(%rip), %xmm2     # 0x348a0
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x98e3(%rip), %xmm4     # 0x348b0
movq %r15, %r8
movq -0x80(%rbp), %r11
testb %r12b, %r12b
jle 0x2b041
movq %rax, %rdx
movq %r8, %r9
movdqa %xmm1, %xmm5
movdqa %xmm5, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %ecx
notl %ecx
testb $0x1, %cl
je 0x2b01e
movq $0x0, (%r9)
pxor %xmm3, %xmm6
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x2b034
movq $0x0, (%r9,%r13,8)
paddq %xmm4, %xmm5
addq %rsi, %r9
addq $-0x2, %rdx
jne 0x2afe3
movq $0x0, (%r11,%rdi,8)
incq %rdi
addq $0x8, %r8
cmpq %r13, %rdi
jne 0x2afd4
movq -0x48(%rbp), %rax
leal -0x1(%rax), %esi
movq -0xa8(%rbp), %r9
cmpq $0x1, %r13
setne %dil
je 0x2b0b2
movq 0x88(%r14), %rax
movq 0x8(%rax), %rax
pxor %xmm1, %xmm1
xorl %ecx, %ecx
movsbq %cl, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%r9,%rcx,8)
addsd %xmm0, %xmm1
incb %cl
movsbl %cl, %edx
cmpl %edx, %esi
jg 0x2b082
jmp 0x2b0b8
leal -0x1(%rbx), %esi
pxor %xmm1, %xmm1
movq -0xa8(%rbp), %r9
xorl %edi, %edi
jmp 0x2b0b8
xorl %edi, %edi
pxor %xmm1, %xmm1
movsd 0x8830(%rip), %xmm0     # 0x338f0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movslq %esi, %r8
movq %r9, -0x78(%rbp)
movsd %xmm2, (%r9,%r8,8)
testb %r12b, %r12b
movq %r13, -0x90(%rbp)
movq %r12, -0x60(%rbp)
jle 0x2b1bd
movq -0x70(%rbp), %rax
movq %rax, -0x88(%rbp)
xorl %r10d, %r10d
movq -0x48(%rbp), %rax
mulb %r8b
movb %al, -0x68(%rbp)
movl %r8d, %eax
cmpb $0x0, -0x30(%rbp)
jle 0x2b1aa
movq -0x40(%rbp), %rcx
movq 0x88(%rcx), %rbx
movq %r10, %rcx
imulq %r13, %rcx
movq -0x98(%rbp), %rdx
leaq (%rdx,%rcx,8), %r14
movq -0x88(%rbp), %rcx
movq (%rcx,%r10,8), %r15
movl %eax, %r12d
xorl %edx, %edx
testb %dil, %dil
je 0x2b187
movq 0x8(%rbx), %r13
movq (%r15,%rdx,8), %r9
movsd (%r14,%rdx,8), %xmm1
xorl %ecx, %ecx
leal (%r12,%rcx), %r11d
movsbq %r11b, %r11
movsd (%r13,%r11,8), %xmm2
movsbq %cl, %rcx
movsd %xmm2, (%r9,%rcx,8)
addsd %xmm2, %xmm1
incb %cl
movsbl %cl, %r11d
cmpl %r11d, %esi
jg 0x2b150
movsd %xmm1, (%r14,%rdx,8)
movq -0x90(%rbp), %r13
jmp 0x2b191
movsd (%r14,%rdx,8), %xmm1
movq (%r15,%rdx,8), %r9
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, (%r9,%r8,8)
incq %rdx
addb %r8b, %r12b
cmpq %r13, %rdx
jne 0x2b13b
incq %r10
addb -0x68(%rbp), %al
movq -0x60(%rbp), %r12
cmpq %r12, %r10
jne 0x2b104
cmpb $0x0, -0x30(%rbp)
movq -0x58(%rbp), %r14
movq -0x40(%rbp), %r15
movq -0x80(%rbp), %rcx
jle 0x2b264
movq -0x50(%rbp), %rax
leal -0x1(%rax), %edx
movq 0x88(%r15), %rsi
movq -0xa0(%rbp), %rdi
movl %r12d, %eax
mulb %r13b
incb %al
mulb %r8b
leal -0x1(%r14), %r8d
xorl %r9d, %r9d
cmpb $0x1, %r14b
jle 0x2b240
movq 0x8(%rsi), %r11
movq (%rdi,%r9,8), %r10
movsd (%rcx,%r9,8), %xmm1
xorl %ecx, %ecx
leal (%rax,%rcx), %ebx
movsbq %bl, %rbx
movsd (%r11,%rbx,8), %xmm2
movsbq %cl, %rcx
movsd %xmm2, (%r10,%rcx,8)
addsd %xmm2, %xmm1
incb %cl
movsbl %cl, %ebx
cmpl %ebx, %edx
jg 0x2b210
movq -0x80(%rbp), %rcx
movsd %xmm1, (%rcx,%r9,8)
jmp 0x2b24a
movsd (%rcx,%r9,8), %xmm1
movq (%rdi,%r9,8), %r10
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, -0x8(%r10,%r14,8)
incq %r9
addb %r8b, %al
cmpq %r13, %r9
jne 0x2b1fa
movq 0x88(%r15), %rax
cmpb $0x0, 0x32(%rax)
jne 0x2b290
movq -0x70(%rbp), %rdx
movq -0xa0(%rbp), %rcx
movq %r15, %rdi
movq -0x78(%rbp), %rsi
callq 0x2b632
testb %al, %al
je 0x2b5d1
cmpl $0x0, 0xc(%r15)
movq -0x78(%rbp), %r12
jle 0x2b2c9
movq -0x30(%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 0x2b2aa
movl 0x10(%r15), %eax
movl -0x48(%rbp), %ecx
movq %rcx, -0x68(%rbp)
testl %eax, %eax
jle 0x2b36a
movq -0x70(%rbp), %r12
movq -0x30(%rbp), %rcx
leaq (,%rcx,8), %rbx
movl -0x34(%rbp), %ecx
movq %rcx, -0x98(%rbp)
xorl %edx, %edx
cmpb $0x0, -0x60(%rbp)
jle 0x2b35f
movq 0x90(%r15), %rax
movq %rdx, -0x88(%rbp)
movq (%rax,%rdx,8), %r15
xorl %r13d, %r13d
cmpb $0x0, -0x30(%rbp)
jle 0x2b33d
xorl %r14d, %r14d
movq (%r15,%r13,8), %rax
movq (%rax,%r14,8), %rdi
movq (%r12,%r13,8), %rax
movq (%rax,%r14,8), %rsi
movq %rbx, %rdx
callq 0x41c0
incq %r14
cmpq %r14, -0x68(%rbp)
jne 0x2b31c
incq %r13
cmpq -0x98(%rbp), %r13
jne 0x2b313
movq -0x40(%rbp), %r15
movl 0x10(%r15), %eax
movq -0x90(%rbp), %r13
movq -0x88(%rbp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jl 0x2b2f8
movl 0x14(%r15), %eax
movq -0xa0(%rbp), %rbx
testl %eax, %eax
jle 0x2b3cf
movq -0x58(%rbp), %rcx
leaq (,%rcx,8), %r12
xorl %r15d, %r15d
cmpb $0x0, -0x30(%rbp)
jle 0x2b3c4
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax,%r15,8), %r14
xorl %r13d, %r13d
movq (%r14,%r13,8), %rdi
movq (%rbx,%r13,8), %rsi
movq %r12, %rdx
callq 0x41c0
incq %r13
cmpq %r13, -0x68(%rbp)
jne 0x2b39d
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x90(%rbp), %r13
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x2b388
movq -0x78(%rbp), %rdi
callq 0x42a0
movq -0x70(%rbp), %rdi
movl -0x34(%rbp), %r14d
movl %r14d, %esi
movq -0x48(%rbp), %r12
movl %r12d, %edx
callq 0xca4f
movq %rbx, %rdi
movl %r12d, %esi
callq 0xa5dd
movq -0xb0(%rbp), %rsi
cmpb $0x0, 0x6c(%rsi)
movq -0x40(%rbp), %rbx
je 0x2b419
addq $0x6c, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2b8ec
leaq 0x50(%rbx), %rsi
leaq 0x98(%rbx), %rdx
leaq 0x60(%rbx), %rcx
subq $0x8, %rsp
movq -0x60(%rbp), %r15
movsbl %r15b, %r8d
movq -0x30(%rbp), %r9
pushq -0x58(%rbp)
callq 0x2b5d6
addq $0x10, %rsp
leaq 0x68(%rbx), %rsi
leaq 0xa0(%rbx), %rdx
leaq 0x78(%rbx), %rcx
subq $0x8, %rsp
movl %r14d, %r8d
movl %r12d, %r9d
pushq -0x50(%rbp)
callq 0x2b5d6
addq $0x10, %rsp
testb %r12b, %r12b
jle 0x2b4a3
movq 0x88(%rbx), %rcx
movq 0x18(%rcx), %rax
movq 0x20(%rcx), %rcx
movq 0x50(%rbx), %rdx
movq 0x68(%rbx), %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 0x2b487
imull %r12d, %r14d
movl %r14d, -0x34(%rbp)
testb %r15b, %r15b
jle 0x2b540
movl %r12d, %eax
mulb -0x30(%rbp)
movzbl %al, %eax
xorl %ecx, %ecx
movq %r13, %rdx
testb %r13b, %r13b
jle 0x2b534
movq -0x40(%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 0x2b501
incq %r11
addq %r13, %r10
cmpq %r13, %r11
jne 0x2b4f6
incq %rcx
addq %rax, %rdx
cmpq -0x60(%rbp), %rcx
jne 0x2b4c2
movl -0x34(%rbp), %eax
incb %al
movq -0x30(%rbp), %rcx
mulb %cl
testb %cl, %cl
movq -0x58(%rbp), %r12
jle 0x2b5bb
movq -0x40(%rbp), %rsi
movq 0x88(%rsi), %rcx
movq 0x60(%rsi), %rdx
movq 0x78(%rsi), %rsi
movzbl -0x50(%rbp), %edi
movzbl %al, %eax
xorl %r8d, %r8d
testb %r12b, %r12b
jle 0x2b5b0
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 0x2b588
incq %r8
addq %rdi, %rax
cmpq %r13, %r8
jne 0x2b570
movq -0xb8(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x53aa