// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/HMMProblemSlicedAB.cpp
// Function: HMMProblemSlicedAB::init(param*)
void HMMProblemSlicedAB::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 =  init4D<NUMBER>((NDAT)this->sizes[2], (NDAT)nZ, (NDAT)nS, (NDAT)nO);
    
    // write default parameters first
    NUMBER sumPI = 0;
    NUMBER sumA[nZ][nS];
    NUMBER sumB[nZ][nS];
    for(z=0; z<nZ; z++) {
        for(i=0; i<nS; i++) {
            sumA[z][i] = 0;
            sumB[z][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(z=0; z<nZ; z++) {
        for(i=0; i<nS; i++) {
            for(m=0; m<((nO)-1); m++) {
                idx = (NPAR)(offset + z * nS * ((nO)-1) + i*((nO)-1) + m);
                a_B[z][i][m] = this->p->init_params[idx];
                sumB[z][i] += this->p->init_params[idx];
            }
            a_B[z][i][((nO)-1)]  = 1 - sumB[z][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++)
        for(z=0; z<nZ; z++)
            cpy3D<NUMBER>(a_A, this->A[x], (NDAT)nZ, (NDAT)nS, (NDAT)nS);
    for(x=0; x<this->sizes[2]; x++)
        for(z=0; z<nZ; z++)
            cpy3D<NUMBER>(a_B, this->B[x], (NDAT)nZ, (NDAT)nS, (NDAT)nO);
    // destroy setup params
    free(a_PI);
    free3D<NUMBER>(a_A, (NDAT)nZ, (NDAT)nS);
    free3D<NUMBER>(a_B, (NDAT)nZ, (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(z=0; z<nZ; z++) {
        for(i=0; i<nS; i++) {
            for(j=0; j<nO; j++) {
                idx = (NPAR)(offset + z * nS * nO + i*nO + j);
                lbB[z][i][j] = this->p->param_lo[idx];
                ubB[z][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, %rbx
movq %rsi, 0x88(%rdi)
movb $0x1, 0x80(%rdi)
movsbl 0x8b9(%rsi), %eax
movq %rax, -0x78(%rbp)
movslq %eax, %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x4130
movq %rax, 0x18(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movq $0x0, 0x30(%rbx)
cmpb $0x3, 0x3f(%r15)
jne 0x25007
cmpb $-0x1, 0x40(%r15)
jne 0x25007
movb $0x1, 0x40(%r15)
movzbl 0x8b8(%r15), %r13d
movsbq %r13b, %rax
movq %rax, -0x58(%rbp)
movq %r15, -0xb8(%rbp)
movsbl 0x8c8(%r15), %r15d
subq $0x8, %rsp
movsbl %r13b, %r12d
leaq -0xb0(%rbp), %rsi
leaq -0x98(%rbp), %rdx
leaq -0x90(%rbp), %rcx
movl %r15d, %r8d
movl %r12d, %r9d
pushq %r14
callq 0x257b6
addq $0x10, %rsp
movl 0xc(%rbx), %edi
movl %r12d, %esi
callq 0xbb5c
movq %rax, 0x38(%rbx)
movl 0x10(%rbx), %edi
movl %r15d, %esi
movl %r12d, %edx
movl %r12d, %ecx
callq 0x2b168
movq %rax, 0x90(%rbx)
movl 0x14(%rbx), %edi
movl %r15d, %esi
movl %r12d, -0x38(%rbp)
movl %r12d, %edx
movq -0x78(%rbp), %rcx
callq 0x2b168
movq %rsp, -0xc0(%rbp)
movq %rbx, -0x48(%rbp)
movq %rax, 0x98(%rbx)
movzbl %r15b, %ecx
movl %r13d, %eax
movq %rcx, -0x30(%rbp)
imull %ecx, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x40(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x70(%rbp)
movq %rcx, %rsp
movl %r15d, -0x34(%rbp)
testl %r15d, %r15d
movq -0x58(%rbp), %r15
movq %r14, -0x80(%rbp)
jle 0x2512c
leal (,%r13,8), %r12d
xorl %ebx, %ebx
movq -0x30(%rbp), %r14
testb %r15b, %r15b
jle 0x25124
movq -0x40(%rbp), %rax
leaq (%rax,%rbx), %rdi
movq -0x70(%rbp), %rax
addq %rbx, %rax
movq %rax, -0x50(%rbp)
xorl %esi, %esi
movq %r12, %rdx
callq 0x4120
movq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x4120
addq %r12, %rbx
decq %r14
jne 0x250f4
leal -0x1(%r15), %ecx
xorpd %xmm1, %xmm1
cmpb $0x2, %r15b
jl 0x25170
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x8(%rax), %rax
movq -0xb0(%rbp), %rdx
xorl %esi, %esi
movsbq %sil, %rsi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
addsd (%rax,%rsi,8), %xmm1
incb %sil
movsbl %sil, %edi
cmpl %edi, %ecx
jg 0x25152
movsd 0xf778(%rip), %xmm0     # 0x348f0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movq -0xb0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movsd %xmm2, -0x8(%rax,%r15,8)
cmpb $0x0, -0x30(%rbp)
movq %r13, -0x50(%rbp)
jle 0x25271
movq -0x98(%rbp), %rdx
leal -0x1(%r13), %esi
xorl %edi, %edi
movl %r13d, %eax
mulb %sil
movb %al, -0x88(%rbp)
movl %esi, %eax
testb %r15b, %r15b
jle 0x2525e
movq -0x48(%rbp), %r8
movq 0x88(%r8), %r9
movq %rdi, %r10
imulq %r13, %r10
movq -0x40(%rbp), %r8
leaq (%r8,%r10,8), %r10
movq (%rdx,%rdi,8), %r11
movl %eax, %ebx
xorl %r12d, %r12d
cmpb $0x2, %r13b
jl 0x2523e
movq 0x8(%r9), %r14
movq (%rdx,%rdi,8), %r15
movq (%r15,%r12,8), %r13
movsd (%r10,%r12,8), %xmm1
xorl %r15d, %r15d
leal (%rbx,%r15), %r8d
movsbq %r8b, %r8
movsd (%r14,%r8,8), %xmm2
movsbq %r15b, %r15
movsd %xmm2, (%r13,%r15,8)
addsd (%r14,%r8,8), %xmm1
incb %r15b
movsbl %r15b, %r8d
cmpl %r8d, %ecx
jg 0x25205
movsd %xmm1, (%r10,%r12,8)
movq -0x50(%rbp), %r13
movq -0x58(%rbp), %r15
movapd %xmm0, %xmm1
subsd (%r10,%r12,8), %xmm1
movq (%r11,%r12,8), %r8
movsd %xmm1, -0x8(%r8,%r15,8)
incq %r12
addb %sil, %bl
cmpq %r13, %r12
jne 0x251ea
incq %rdi
addb -0x88(%rbp), %al
cmpq -0x30(%rbp), %rdi
jne 0x251be
cmpb $0x0, -0x30(%rbp)
movq -0x80(%rbp), %r14
jle 0x2535e
leal -0x1(%r14), %esi
movq -0x90(%rbp), %rdi
leal -0x1(%r13), %ecx
movl -0x34(%rbp), %eax
mulb %r13b
movl %eax, %edx
incb %dl
movl %ecx, %eax
mulb %dl
movb %al, -0x40(%rbp)
movq -0x78(%rbp), %rax
leal -0x1(%rax), %edx
xorl %r8d, %r8d
movl %r13d, %eax
mulb %dl
testb %r13b, %r13b
jle 0x2534e
movq -0x48(%rbp), %rcx
movq 0x88(%rcx), %r9
movq %r8, %r10
imulq %r13, %r10
movq -0x70(%rbp), %rcx
leaq (%rcx,%r10,8), %r10
movq (%rdi,%r8,8), %r11
movb -0x40(%rbp), %cl
movl %ecx, %ebx
xorl %r15d, %r15d
cmpb $0x2, %r14b
jl 0x2532f
movq 0x8(%r9), %r14
movq (%rdi,%r8,8), %r12
movq (%r12,%r15,8), %r12
movsd (%r10,%r15,8), %xmm1
xorl %r13d, %r13d
leal (%rbx,%r13), %ecx
movsbq %cl, %rcx
movsd (%r14,%rcx,8), %xmm2
movsbq %r13b, %r13
movsd %xmm2, (%r12,%r13,8)
addsd (%r14,%rcx,8), %xmm1
incb %r13b
movsbl %r13b, %ecx
cmpl %ecx, %esi
jg 0x252f8
movsd %xmm1, (%r10,%r15,8)
movq -0x50(%rbp), %r13
movq -0x80(%rbp), %r14
movapd %xmm0, %xmm1
subsd (%r10,%r15,8), %xmm1
movq (%r11,%r15,8), %rcx
movsd %xmm1, -0x8(%rcx,%r14,8)
incq %r15
addb %dl, %bl
cmpq %r13, %r15
jne 0x252dd
incq %r8
addb %al, -0x40(%rbp)
cmpq -0x30(%rbp), %r8
jne 0x252ae
movq -0x48(%rbp), %rbx
movq 0x88(%rbx), %rax
cmpb $0x0, 0x32(%rax)
movq -0xa8(%rbp), %r15
jne 0x25397
movq -0x98(%rbp), %rdx
movq -0x90(%rbp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x25814
testb %al, %al
je 0x257b0
cmpl $0x0, 0xc(%rbx)
movq %rbx, %r14
movq -0x58(%rbp), %rax
jle 0x253cd
leaq (,%rax,8), %r12
xorl %ebx, %ebx
movq 0x38(%r14), %rax
movq (%rax,%rbx,8), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x41c0
incq %rbx
movslq 0xc(%r14), %rax
cmpq %rax, %rbx
jl 0x253ae
cmpl $0x0, 0x10(%r14)
movl -0x34(%rbp), %eax
movq %rax, -0x70(%rbp)
movl -0x38(%rbp), %eax
movq %rax, -0x88(%rbp)
movq %r14, %rbx
jle 0x2548c
movq -0x98(%rbp), %r12
movq -0x58(%rbp), %r13
shlq $0x3, %r13
movq $0x0, -0x60(%rbp)
cmpb $0x0, -0x30(%rbp)
jle 0x25474
xorl %eax, %eax
movl %eax, -0x68(%rbp)
movq 0x90(%rbx), %rax
movq -0x60(%rbp), %rdx
movq (%rax,%rdx,8), %rax
xorl %esi, %esi
cmpb $0x0, -0x50(%rbp)
movq -0x88(%rbp), %rbx
jle 0x2545d
xorl %r15d, %r15d
movq %rsi, -0x40(%rbp)
movq %rax, %r14
movq (%rax,%rsi,8), %rax
movq (%rax,%r15,8), %rdi
movq (%r12,%rsi,8), %rax
movq (%rax,%r15,8), %rsi
movq %r13, %rdx
callq 0x41c0
movq -0x40(%rbp), %rsi
movq %r14, %rax
incq %r15
cmpq %r15, %rbx
jne 0x25433
incq %rsi
cmpq -0x70(%rbp), %rsi
jne 0x2541f
movl -0x68(%rbp), %eax
incb %al
cmpb -0x30(%rbp), %al
movq -0x48(%rbp), %rbx
jne 0x2540b
movq -0x60(%rbp), %rsi
incq %rsi
movslq 0x10(%rbx), %rax
movq %rsi, -0x60(%rbp)
cmpq %rax, %rsi
jl 0x25403
movzbl -0x78(%rbp), %eax
movq %rax, -0x68(%rbp)
cmpl $0x0, 0x14(%rbx)
movq -0x88(%rbp), %r12
jle 0x25549
movq -0x90(%rbp), %r13
movq -0x80(%rbp), %rax
leaq (,%rax,8), %r14
movq $0x0, -0xa0(%rbp)
cmpb $0x0, -0x30(%rbp)
jle 0x2552b
xorl %eax, %eax
movl %eax, -0x60(%rbp)
movq 0x98(%rbx), %rax
movq -0xa0(%rbp), %rsi
movq (%rax,%rsi,8), %rbx
xorl %esi, %esi
cmpb $0x0, -0x50(%rbp)
jle 0x25514
xorl %r15d, %r15d
movq %rsi, -0x40(%rbp)
movq (%rbx,%rsi,8), %rax
movq (%rax,%r15,8), %rdi
movq (%r13,%rsi,8), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdx
callq 0x41c0
movq -0x40(%rbp), %rsi
incq %r15
cmpq %r15, %r12
jne 0x254ef
incq %rsi
cmpq -0x70(%rbp), %rsi
jne 0x254e2
movl -0x60(%rbp), %eax
incb %al
cmpb -0x30(%rbp), %al
movq -0x48(%rbp), %rbx
jne 0x254cb
movq -0xa0(%rbp), %rdi
incq %rdi
movslq 0x14(%rbx), %rax
movq %rdi, -0xa0(%rbp)
cmpq %rax, %rdi
jl 0x254c3
movq -0xa8(%rbp), %rdi
callq 0x42a0
movq -0x98(%rbp), %rdi
movl -0x34(%rbp), %r14d
movl %r14d, %esi
movl -0x38(%rbp), %r15d
movl %r15d, %edx
callq 0xca4f
movq -0x90(%rbp), %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0xca4f
movq -0xb8(%rbp), %rsi
cmpb $0x0, 0x6c(%rsi)
je 0x2559c
addq $0x6c, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x25a56
leaq 0xa0(%rbx), %rsi
leaq 0xa8(%rbx), %rdx
leaq 0xb0(%rbx), %rcx
subq $0x8, %rsp
movl -0x34(%rbp), %r8d
movq -0x58(%rbp), %r9
pushq -0x78(%rbp)
callq 0x257b6
addq $0x10, %rsp
leaq 0xb8(%rbx), %rsi
leaq 0xc0(%rbx), %rdx
leaq 0xc8(%rbx), %rcx
subq $0x8, %rsp
movsbl -0x68(%rbp), %eax
movsbl -0x30(%rbp), %r8d
movl -0x38(%rbp), %r9d
pushq %rax
callq 0x257b6
addq $0x10, %rsp
movq -0x50(%rbp), %r13
testb %r13b, %r13b
jle 0x2563d
movq 0x88(%rbx), %rdx
movq 0xa0(%rbx), %rax
movq 0x18(%rdx), %rcx
movq 0x20(%rdx), %rdx
movq 0xb8(%rbx), %rsi
xorl %edi, %edi
movsd (%rcx,%rdi,8), %xmm0
movsd %xmm0, (%rax,%rdi,8)
movsd (%rdx,%rdi,8), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %r13
jne 0x25621
movl -0x38(%rbp), %eax
imull -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpb $0x0, -0x30(%rbp)
jle 0x256dd
movl %r13d, %eax
mulb %r13b
movzbl %al, %eax
xorl %ecx, %ecx
movq %r13, %rdx
testb %r13b, %r13b
jle 0x256d1
movq -0x48(%rbp), %rsi
movq 0x88(%rsi), %rdi
movq 0xa8(%rsi), %r8
movq 0xc0(%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 0x2569e
incq %r11
addq %r13, %r10
cmpq %r13, %r11
jne 0x25693
incq %rcx
addq %rax, %rdx
cmpq -0x30(%rbp), %rcx
jne 0x2565f
movl -0x38(%rbp), %eax
incb %al
mulb %r13b
cmpb $0x0, -0x34(%rbp)
jle 0x2579a
movzbl %al, %ecx
movl %r13d, %eax
mulb -0x80(%rbp)
movzbl %al, %eax
xorl %edx, %edx
testb %r13b, %r13b
movq -0x68(%rbp), %r11
jle 0x2578a
movq -0x48(%rbp), %r8
movq 0x88(%r8), %rsi
movq 0xb0(%r8), %rdi
movq 0xc8(%r8), %r8
movq %rcx, %r9
xorl %r10d, %r10d
testb %r11b, %r11b
movq %r11, %r13
jle 0x25778
movq 0x18(%rsi), %r11
movq 0x20(%rsi), %rbx
movq (%rdi,%rdx,8), %r14
movq (%r14,%r10,8), %r14
movq (%r8,%rdx,8), %r15
movq (%r15,%r10,8), %r15
xorl %r12d, %r12d
leal (%r9,%r12), %r13d
movsbq %r13b, %r13
movsd (%r11,%r13,8), %xmm0
movsd %xmm0, (%r14,%r12,8)
movsd (%rbx,%r13,8), %xmm0
movq -0x68(%rbp), %r13
movsd %xmm0, (%r15,%r12,8)
incq %r12
cmpq %r12, %r13
jne 0x2574c
incq %r10
addq %r13, %r9
movq %r13, %r11
movq -0x50(%rbp), %r13
cmpq %r13, %r10
jne 0x25729
incq %rdx
addq %rax, %rcx
cmpq -0x30(%rbp), %rdx
jne 0x256fd
movq -0xc0(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x52f4
nop