// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, 0x88(%rdi)
movb $0x1, 0x80(%rdi)
movsbl 0x8b9(%rsi), %eax
movq %rax, -0x78(%rbp)
movslq %eax, %rdi
movl $0x8, %esi
movq %rdi, -0x88(%rbp)
callq 0x4130
movq %rax, 0x18(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rbx)
movq $0x0, 0x30(%rbx)
cmpb $0x3, 0x3f(%r14)
jne 0x24b1f
cmpb $-0x1, 0x40(%r14)
jne 0x24b1f
movb $0x1, 0x40(%r14)
movzbl 0x8b8(%r14), %r12d
movsbq %r12b, %rax
movq %rax, -0x48(%rbp)
movq %r14, -0xc8(%rbp)
movsbl 0x8c8(%r14), %r15d
subq $0x8, %rsp
movsbl %r12b, %r13d
leaq -0xd8(%rbp), %rsi
leaq -0x98(%rbp), %rdx
leaq -0xb8(%rbp), %rcx
movl %r15d, %r8d
movl %r13d, %r9d
movq -0x78(%rbp), %r14
pushq %r14
callq 0x25304
addq $0x10, %rsp
movl 0xc(%rbx), %edi
movl %r13d, %esi
callq 0xbb36
movq %rax, 0x38(%rbx)
movl 0x10(%rbx), %edi
movl %r15d, %esi
movl %r13d, %edx
movl %r13d, %ecx
callq 0x2ac0d
movq %rax, 0x90(%rbx)
movl 0x14(%rbx), %edi
movl %r15d, %esi
movl %r13d, -0x4c(%rbp)
movl %r13d, %edx
movl %r14d, %ecx
callq 0x2ac0d
movq %rsp, -0xd0(%rbp)
movq %rbx, -0x40(%rbp)
movq %rax, 0x98(%rbx)
movzbl %r15b, %eax
movq %rax, -0x38(%rbp)
imull %r12d, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x58(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x70(%rbp)
movq %rcx, %rsp
movl %r15d, -0x2c(%rbp)
testl %r15d, %r15d
movq %r12, -0x68(%rbp)
jle 0x24c42
leal (,%r12,8), %ebx
xorl %r14d, %r14d
movq -0x38(%rbp), %r15
testb %r12b, %r12b
jle 0x24c3a
movq -0x58(%rbp), %rax
leaq (%rax,%r14), %rdi
movq -0x70(%rbp), %rax
leaq (%rax,%r14), %r13
xorl %esi, %esi
movq %rbx, %rdx
callq 0x4120
movq %r13, %rdi
movq -0x68(%rbp), %r12
xorl %esi, %esi
movq %rbx, %rdx
callq 0x4120
addq %rbx, %r14
decq %r15
jne 0x24c0a
movq -0x48(%rbp), %rbx
leal -0x1(%rbx), %ecx
xorpd %xmm1, %xmm1
movq -0xd8(%rbp), %r15
cmpb $0x2, %bl
movq -0x40(%rbp), %r14
jl 0x24c86
movq 0x88(%r14), %rax
movq 0x8(%rax), %rax
xorl %edx, %edx
movsbq %dl, %rdx
movsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%r15,%rdx,8)
addsd %xmm0, %xmm1
incb %dl
movsbl %dl, %esi
cmpl %esi, %ecx
jg 0x24c6a
movsd 0xec62(%rip), %xmm0     # 0x338f0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, -0x8(%r15,%rbx,8)
movl -0x2c(%rbp), %eax
testb %al, %al
movq %r15, -0xa0(%rbp)
jle 0x24e8c
movq -0x98(%rbp), %rax
movq %rax, -0x90(%rbp)
leal -0x1(%r12), %esi
xorl %edi, %edi
movl %r12d, %eax
mulb %sil
movl %esi, %r8d
testb %r12b, %r12b
jle 0x24d70
movq -0x40(%rbp), %rdx
movq 0x88(%rdx), %r9
movq %rdi, %rdx
imulq %r12, %rdx
movq -0x58(%rbp), %r10
leaq (%r10,%rdx,8), %r10
movq -0x90(%rbp), %rdx
movq (%rdx,%rdi,8), %r11
movl %r8d, %r14d
xorl %r15d, %r15d
cmpb $0x1, %bl
jle 0x24d48
movq 0x8(%r9), %r12
movq (%r11,%r15,8), %r13
movsd (%r10,%r15,8), %xmm1
xorl %edx, %edx
leal (%r14,%rdx), %ebx
movsbq %bl, %rbx
movsd (%r12,%rbx,8), %xmm2
movsbq %dl, %rdx
movsd %xmm2, (%r13,%rdx,8)
addsd %xmm2, %xmm1
incb %dl
movsbl %dl, %ebx
cmpl %ebx, %ecx
jg 0x24d16
movsd %xmm1, (%r10,%r15,8)
movq -0x48(%rbp), %rbx
jmp 0x24d52
movsd (%r10,%r15,8), %xmm1
movq (%r11,%r15,8), %r13
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, -0x8(%r13,%rbx,8)
incq %r15
addb %sil, %r14b
movq -0x68(%rbp), %r12
cmpq %r12, %r15
jne 0x24d01
incq %rdi
addb %al, %r8b
cmpq -0x38(%rbp), %rdi
jne 0x24ccd
movl -0x2c(%rbp), %edx
movl %edx, %eax
imull -0x4c(%rbp), %eax
movl %eax, -0x7c(%rbp)
cmpb $0x0, -0x38(%rbp)
jle 0x24e9a
movq -0x78(%rbp), %rax
leal -0x1(%rax), %esi
movq -0xb8(%rbp), %rax
movq %rax, -0x58(%rbp)
leal -0x1(%rbx), %ecx
movl %edx, %eax
mulb %bl
movl %eax, %edx
incb %dl
movl %ecx, %eax
mulb %dl
movl %eax, %ecx
movq -0x88(%rbp), %r13
leal -0x1(%r13), %edx
xorl %r8d, %r8d
movl %r12d, %eax
mulb %dl
testb %bl, %bl
jle 0x24e6f
movq -0x40(%rbp), %rdi
movq 0x88(%rdi), %r9
movq %r8, %r10
imulq %r12, %r10
movq -0x70(%rbp), %rdi
leaq (%rdi,%r10,8), %r10
movq -0x58(%rbp), %rdi
movq (%rdi,%r8,8), %r11
movl %ecx, %ebx
xorl %r14d, %r14d
cmpb $0x1, %r13b
jle 0x24e4c
movq 0x8(%r9), %r12
movq (%r11,%r14,8), %r15
movsd (%r10,%r14,8), %xmm1
xorl %r13d, %r13d
leal (%rbx,%r13), %edi
movsbq %dil, %rdi
movsd (%r12,%rdi,8), %xmm2
movsbq %r13b, %r13
movsd %xmm2, (%r15,%r13,8)
addsd %xmm2, %xmm1
incb %r13b
movsbl %r13b, %edi
cmpl %edi, %esi
jg 0x24e12
movsd %xmm1, (%r10,%r14,8)
movq -0x68(%rbp), %r12
movq -0x88(%rbp), %r13
jmp 0x24e56
movsd (%r10,%r14,8), %xmm1
movq (%r11,%r14,8), %r15
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, -0x8(%r15,%r13,8)
incq %r14
addb %dl, %bl
cmpq %r12, %r14
jne 0x24dfb
incq %r8
addb %al, %cl
cmpq -0x38(%rbp), %r8
movq -0x48(%rbp), %rbx
jne 0x24dcc
movq -0x40(%rbp), %r14
movl -0x2c(%rbp), %r12d
jmp 0x24ea1
movl %eax, %ecx
imull -0x4c(%rbp), %ecx
movl %ecx, -0x7c(%rbp)
movl %eax, %r12d
jmp 0x24ea8
movq -0x40(%rbp), %r14
movl %edx, %r12d
movq -0xa0(%rbp), %r15
movq 0x88(%r14), %rax
cmpb $0x0, 0x32(%rax)
jne 0x24ed6
movq -0x98(%rbp), %rdx
movq -0xb8(%rbp), %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25362
testb %al, %al
je 0x252ff
cmpl $0x0, 0xc(%r14)
jle 0x24f0a
movq -0x48(%rbp), %rax
leaq (,%rax,8), %r13
xorl %ebx, %ebx
movq 0x38(%r14), %rax
movq (%rax,%rbx,8), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x41c0
incq %rbx
movslq 0xc(%r14), %rax
cmpq %rax, %rbx
jl 0x24eeb
movl 0x10(%r14), %eax
movl %r12d, %ecx
movq %rcx, -0x90(%rbp)
movl -0x4c(%rbp), %esi
testl %eax, %eax
movq -0x48(%rbp), %rbx
movq %rsi, -0x58(%rbp)
jle 0x24fcb
movq -0x98(%rbp), %r15
leaq (,%rbx,8), %rdx
movq $0x0, -0x60(%rbp)
testb %r12b, %r12b
jle 0x24fb4
xorl %eax, %eax
movl %eax, -0x70(%rbp)
movq 0x90(%r14), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %r12
xorl %r13d, %r13d
cmpb $0x0, -0x68(%rbp)
jle 0x24f8e
xorl %r14d, %r14d
movq (%r12,%r13,8), %rax
movq (%rax,%r14,8), %rdi
movq (%r15,%r13,8), %rax
movq (%rax,%r14,8), %rsi
movq %rdx, %rbx
callq 0x41c0
movq %rbx, %rdx
movq -0x58(%rbp), %rsi
incq %r14
cmpq %r14, %rsi
jne 0x24f67
incq %r13
cmpq -0x90(%rbp), %r13
jne 0x24f5e
movl -0x70(%rbp), %eax
incb %al
movl -0x2c(%rbp), %r12d
cmpb %r12b, %al
movq -0x40(%rbp), %r14
jne 0x24f49
movl 0x10(%r14), %eax
movq -0x48(%rbp), %rbx
movq -0x60(%rbp), %r8
incq %r8
movslq %eax, %rcx
movq %r8, -0x60(%rbp)
cmpq %rcx, %r8
jl 0x24f42
movzbl -0x78(%rbp), %eax
movq %rax, -0xb0(%rbp)
movl 0x14(%r14), %eax
movq -0xb8(%rbp), %r13
testl %eax, %eax
jle 0x250b1
shlq $0x3, -0x88(%rbp)
movq $0x0, -0xa8(%rbp)
movq %r13, -0x60(%rbp)
movq -0x88(%rbp), %r15
cmpb $0x0, -0x38(%rbp)
jle 0x25094
xorl %eax, %eax
movl %eax, -0xbc(%rbp)
movq 0x98(%r14), %rax
movq -0xa8(%rbp), %rcx
movq (%rax,%rcx,8), %r13
xorl %esi, %esi
cmpb $0x0, -0x48(%rbp)
movq -0x60(%rbp), %r14
movq -0x58(%rbp), %rbx
jle 0x25067
xorl %r12d, %r12d
movq %rsi, -0x70(%rbp)
movq (%r13,%rsi,8), %rax
movq (%rax,%r12,8), %rdi
movq (%r14,%rsi,8), %rax
movq (%rax,%r12,8), %rsi
movq %r15, %rdx
callq 0x41c0
movq -0x70(%rbp), %rsi
incq %r12
cmpq %r12, %rbx
jne 0x25042
incq %rsi
cmpq -0x90(%rbp), %rsi
jne 0x2502d
movl -0xbc(%rbp), %eax
incb %al
cmpb -0x38(%rbp), %al
movq -0x40(%rbp), %r14
jne 0x25013
movl 0x14(%r14), %eax
movq -0x48(%rbp), %rbx
movl -0x2c(%rbp), %r12d
movq -0x60(%rbp), %r13
movq -0xa8(%rbp), %rdi
incq %rdi
movslq %eax, %rcx
movq %rdi, -0xa8(%rbp)
cmpq %rcx, %rdi
jl 0x25007
movq -0xa0(%rbp), %rdi
callq 0x42a0
movq -0x98(%rbp), %rdi
movl %r12d, %esi
movl -0x4c(%rbp), %r15d
movl %r15d, %edx
callq 0xca4f
movq %r13, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0xca4f
movq -0xc8(%rbp), %rsi
cmpb $0x0, 0x6c(%rsi)
je 0x250fc
addq $0x6c, %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x255d4
leaq 0xa0(%r14), %rsi
leaq 0xa8(%r14), %rdx
leaq 0xb0(%r14), %rcx
subq $0x8, %rsp
movsbl -0x38(%rbp), %r8d
movq -0x68(%rbp), %r13
movsbl %r13b, %r9d
pushq -0x78(%rbp)
callq 0x25304
addq $0x10, %rsp
leaq 0xb8(%r14), %rsi
leaq 0xc0(%r14), %rdx
leaq 0xc8(%r14), %rcx
subq $0x8, %rsp
movsbl -0xb0(%rbp), %eax
movl %r12d, %r8d
movl %ebx, %r9d
pushq %rax
callq 0x25304
addq $0x10, %rsp
testb %bl, %bl
jle 0x2519d
movq 0x88(%r14), %rdx
movq 0xa0(%r14), %rax
movq 0x18(%rdx), %rcx
movq 0x20(%rdx), %rdx
movq 0xb8(%r14), %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 0x25181
testb %r12b, %r12b
jle 0x252e9
movl %r13d, %eax
mulb %r13b
movzbl %al, %eax
xorl %ecx, %ecx
movq %r13, %rdx
testb %r13b, %r13b
jle 0x25226
movq -0x40(%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 0x251f3
incq %r11
addq %r13, %r10
cmpq %r13, %r11
jne 0x251e8
incq %rcx
addq %rax, %rdx
cmpq -0x38(%rbp), %rcx
jne 0x251b4
movl -0x7c(%rbp), %eax
incb %al
mulb %r13b
cmpb $0x0, -0x38(%rbp)
jle 0x252e9
movzbl %al, %ecx
movl %r13d, %eax
mulb -0x78(%rbp)
movzbl %al, %eax
xorl %edx, %edx
cmpb $0x0, -0x48(%rbp)
movq -0xb0(%rbp), %r13
jle 0x252d9
movq -0x40(%rbp), %r8
movq 0x88(%r8), %rsi
movq 0xb0(%r8), %rdi
movq 0xc8(%r8), %r8
movq %rcx, %r9
xorl %r10d, %r10d
testb %r13b, %r13b
jle 0x252cd
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 -0xb0(%rbp), %r13
movsd %xmm0, (%r15,%r12,8)
incq %r12
cmpq %r12, %r13
jne 0x2529e
incq %r10
addq %r13, %r9
cmpq -0x68(%rbp), %r10
jne 0x2527e
incq %rdx
addq %rax, %rcx
cmpq -0x38(%rbp), %rdx
jne 0x25252
movq -0xd0(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x52a4