// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, 0x88(%rdi)
movb $0x1, 0x80(%rdi)
movsbl 0x8b9(%rsi), %eax
movq %rax, -0x48(%rbp)
movslq %eax, %rdi
pushq $0x8
popq %rsi
movq %rdi, -0x78(%rbp)
callq 0x4120
movq %rax, 0x18(%rbx)
andq $0x0, 0x30(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rbx)
cmpb $0x3, 0x3f(%r14)
jne 0x1f545
cmpb $-0x1, 0x40(%r14)
jne 0x1f545
movb $0x1, 0x40(%r14)
movzbl 0x8b8(%r14), %r13d
movsbq %r13b, %rax
movq %rax, -0x40(%rbp)
movq %r14, -0x80(%rbp)
movzbl 0x8c8(%r14), %r14d
subq $0x8, %rsp
movsbl %r14b, %r15d
movsbl %r13b, %r12d
leaq -0xa8(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
leaq -0x98(%rbp), %rcx
movl %r15d, %r8d
movl %r12d, %r9d
pushq -0x48(%rbp)
callq 0x1fb66
popq %rax
popq %rcx
movl 0xc(%rbx), %edi
movl %r12d, %esi
callq 0x9328
movq %rax, 0x38(%rbx)
movl 0x10(%rbx), %edi
movl %r15d, %esi
movl %r12d, %edx
movl %r12d, %ecx
callq 0x24ab6
movq %rax, 0x90(%rbx)
movl 0x14(%rbx), %edi
movl %r15d, %esi
movl %r12d, %edx
movq -0x48(%rbp), %rcx
callq 0x24ab6
movq %rsp, -0x88(%rbp)
movq %rax, 0x98(%rbx)
movl %r14d, %eax
imull %r13d, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, %rsp
movq %rsp, %r8
subq %rax, %r8
movq %r8, %rsp
xorl %eax, %eax
movl %r12d, -0x30(%rbp)
testb %r12b, %r12b
movl $0x0, %ecx
cmovgl %r13d, %ecx
movq %rcx, -0x50(%rbp)
movl %r15d, -0x2c(%rbp)
testb %r15b, %r15b
cmovlel %eax, %r14d
movq %r14, -0x38(%rbp)
movl %r13d, %edx
shll $0x3, %edx
movq %rdi, -0x58(%rbp)
movq %r8, -0x90(%rbp)
cmpq -0x38(%rbp), %rax
je 0x1f65a
xorl %esi, %esi
cmpq %rsi, -0x50(%rbp)
je 0x1f64f
andq $0x0, (%rdi,%rsi,8)
andq $0x0, (%r8,%rsi,8)
incq %rsi
jmp 0x1f63a
incq %rax
addq %rdx, %r8
addq %rdx, %rdi
jmp 0x1f632
movq -0x40(%rbp), %rax
leal -0x1(%rax), %edx
movq 0x88(%rbx), %rax
xorpd %xmm1, %xmm1
movq -0xa8(%rbp), %rcx
xorl %esi, %esi
cmpl %esi, %edx
jle 0x1f690
movq 0x8(%rax), %rdi
movsd (%rdi,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
addsd %xmm0, %xmm1
incq %rsi
jmp 0x1f675
movsd 0xd258(%rip), %xmm0     # 0x2c8f0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movq -0x40(%rbp), %rax
movq %rcx, -0x60(%rbp)
movsd %xmm2, -0x8(%rcx,%rax,8)
movq -0xa0(%rbp), %r12
leal -0x1(%r13), %eax
movzbl %al, %edi
movl %r13d, %eax
mulb %dil
movzbl %al, %eax
xorl %r8d, %r8d
movq %rdi, %r9
movq %r13, -0x68(%rbp)
cmpq -0x38(%rbp), %r8
je 0x1f764
movq %r8, %rsi
imulq %r13, %rsi
movq -0x58(%rbp), %rcx
leaq (%rcx,%rsi,8), %r10
movq %r9, %r11
xorl %r13d, %r13d
cmpq -0x50(%rbp), %r13
je 0x1f755
movq 0x88(%rbx), %r14
xorl %esi, %esi
cmpl %esi, %edx
jle 0x1f731
leal (%r11,%rsi), %r15d
movq 0x8(%r14), %rcx
movsbq %r15b, %r15
movsd (%rcx,%r15,8), %xmm1
movq (%r12,%r8,8), %rcx
movq (%rcx,%r13,8), %rcx
movsd %xmm1, (%rcx,%rsi,8)
addsd (%r10,%r13,8), %xmm1
movsd %xmm1, (%r10,%r13,8)
incq %rsi
jmp 0x1f6fd
movapd %xmm0, %xmm1
subsd (%r10,%r13,8), %xmm1
movq (%r12,%r8,8), %rcx
movq (%rcx,%r13,8), %rcx
movq -0x40(%rbp), %rsi
movsd %xmm1, -0x8(%rcx,%rsi,8)
incq %r13
addq %rdi, %r11
jmp 0x1f6ee
incq %r8
addq %rax, %r9
movq -0x68(%rbp), %r13
jmp 0x1f6cf
leal -0x1(%r13), %ecx
movl -0x2c(%rbp), %esi
movl %esi, %eax
mulb %r13b
movl %eax, %edx
incb %dl
movl %ecx, %eax
mulb %dl
imull -0x30(%rbp), %esi
movl %esi, -0x6c(%rbp)
movq -0x48(%rbp), %rsi
leal -0x1(%rsi), %ecx
movq -0x98(%rbp), %r13
movzbl %al, %edx
decl %esi
movq -0x40(%rbp), %rax
mulb %sil
movzbl %al, %eax
movq %rax, -0x58(%rbp)
movzbl %sil, %edi
xorl %r8d, %r8d
cmpq -0x38(%rbp), %r8
je 0x1f83f
movq %r8, %rsi
imulq -0x68(%rbp), %rsi
movq -0x90(%rbp), %rax
leaq (%rax,%rsi,8), %r9
movq %rdx, %r10
xorl %r11d, %r11d
cmpq -0x50(%rbp), %r11
je 0x1f833
movq 0x88(%rbx), %r14
xorl %esi, %esi
cmpl %esi, %ecx
jle 0x1f80e
leal (%r10,%rsi), %r15d
movq 0x8(%r14), %rax
movsbq %r15b, %r15
movsd (%rax,%r15,8), %xmm1
movq (%r13,%r8,8), %rax
movq (%rax,%r11,8), %rax
movsd %xmm1, (%rax,%rsi,8)
addsd (%r9,%r11,8), %xmm1
movsd %xmm1, (%r9,%r11,8)
incq %rsi
jmp 0x1f7d9
movapd %xmm0, %xmm1
subsd (%r9,%r11,8), %xmm1
movq (%r13,%r8,8), %rax
movq (%rax,%r11,8), %rax
movq -0x78(%rbp), %rsi
movsd %xmm1, -0x8(%rax,%rsi,8)
incq %r11
addq %rdi, %r10
jmp 0x1f7ca
incq %r8
addq -0x58(%rbp), %rdx
jmp 0x1f7a7
movq 0x88(%rbx), %rax
cmpb $0x0, 0x32(%rax)
jne 0x1f866
movq %rbx, %rdi
movq -0x60(%rbp), %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1fbbe
testb %al, %al
je 0x1fb42
movq -0x40(%rbp), %r15
shlq $0x3, %r15
xorl %r14d, %r14d
movslq 0xc(%rbx), %rax
cmpq %rax, %r14
jge 0x1f893
movq 0x38(%rbx), %rax
movq (%rax,%r14,8), %rdi
movq -0x60(%rbp), %rsi
movq %r15, %rdx
callq 0x41c0
incq %r14
jmp 0x1f871
xorl %r14d, %r14d
movslq 0x10(%rbx), %rax
movq -0x38(%rbp), %rcx
movl %ecx, %r15d
cmpq %rax, %r14
jge 0x1f8cf
subb $0x1, %r15b
jb 0x1f8ca
movq 0x90(%rbx), %rax
movq (%rax,%r14,8), %rsi
movq %r12, %rdi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
movl %ecx, %r8d
callq 0xa1a2
jmp 0x1f8a6
incq %r14
jmp 0x1f896
xorl %r14d, %r14d
movslq 0x14(%rbx), %rax
cmpq %rax, %r14
jge 0x1f90c
movq -0x38(%rbp), %rax
movl %eax, %r15d
subb $0x1, %r15b
jb 0x1f907
movq 0x98(%rbx), %rax
movq (%rax,%r14,8), %rsi
movq %r13, %rdi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
movq -0x48(%rbp), %r8
callq 0xa1a2
jmp 0x1f8e2
incq %r14
jmp 0x1f8d2
movq -0x60(%rbp), %rdi
callq 0x4290
movq %r12, %rdi
movl -0x2c(%rbp), %r15d
movl %r15d, %esi
movl -0x30(%rbp), %r14d
movl %r14d, %edx
callq 0xa064
movq %r13, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0xa064
movq -0x80(%rbp), %rsi
cmpb $0x0, 0x6c(%rsi)
je 0x1f951
addq $0x6c, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1fd9e
leaq 0xa0(%rbx), %rsi
leaq 0xa8(%rbx), %rdx
leaq 0xb0(%rbx), %rcx
subq $0x8, %rsp
movl -0x2c(%rbp), %r15d
movl %r15d, %r8d
movq -0x40(%rbp), %r9
movq -0x48(%rbp), %r14
pushq %r14
callq 0x1fb66
popq %rax
popq %rcx
leaq 0xb8(%rbx), %rsi
leaq 0xc0(%rbx), %rdx
leaq 0xc8(%rbx), %rcx
subq $0x8, %rsp
movl %r15d, %r8d
movl -0x30(%rbp), %r9d
pushq %r14
callq 0x1fb66
addq $0x10, %rsp
movq 0x88(%rbx), %rax
movq 0xa0(%rbx), %rcx
movq 0xb8(%rbx), %rdx
xorl %esi, %esi
movq -0x68(%rbp), %r13
cmpq %rsi, -0x50(%rbp)
je 0x1f9ef
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 0x1f9c8
movq %r13, %rcx
negq %rcx
movl %r13d, %eax
mulb -0x40(%rbp)
movzbl %al, %eax
xorl %edx, %edx
movq %r13, %rsi
cmpq -0x38(%rbp), %rdx
je 0x1fa82
movq %rsi, %rdi
xorl %r8d, %r8d
cmpq -0x50(%rbp), %r8
je 0x1fa7a
movq 0x88(%rbx), %r9
movq 0xa8(%rbx), %r10
movq 0xc0(%rbx), %r11
xorl %r14d, %r14d
movq %rcx, %r15
addq %r14, %r15
je 0x1fa72
leal (%rdi,%r14), %r15d
movq 0x18(%r9), %r12
movsbq %r15b, %r15
movsd (%r12,%r15,8), %xmm0
movq (%r10,%rdx,8), %r12
movq (%r12,%r8,8), %r12
movsd %xmm0, (%r12,%r14,8)
movq 0x20(%r9), %r12
movsd (%r12,%r15,8), %xmm0
movq (%r11,%rdx,8), %r15
movq (%r15,%r8,8), %r15
movsd %xmm0, (%r15,%r14,8)
incq %r14
jmp 0x1fa2d
incq %r8
addq %r13, %rdi
jmp 0x1fa0f
incq %rdx
addq %rax, %rsi
jmp 0x1fa03
movl -0x6c(%rbp), %eax
incb %al
mulb %r13b
xorl %ecx, %ecx
movq -0x48(%rbp), %rdx
testb %dl, %dl
cmovlel %ecx, %edx
movzbl %dl, %edx
movzbl %al, %esi
movl %r13d, %eax
movq -0x78(%rbp), %rdi
mulb %dil
movzbl %al, %eax
movzbl %dil, %edi
cmpq -0x38(%rbp), %rcx
je 0x1fb2c
movq %rsi, %r8
xorl %r9d, %r9d
cmpq -0x50(%rbp), %r9
je 0x1fb24
movq 0x88(%rbx), %r10
movq 0xb0(%rbx), %r11
movq 0xc8(%rbx), %r14
xorl %r12d, %r12d
cmpq %r12, %rdx
je 0x1fb1c
leal (%r8,%r12), %r15d
movq 0x18(%r10), %r13
movsbq %r15b, %r15
movsd (%r13,%r15,8), %xmm0
movq (%r11,%rcx,8), %r13
movq (%r13,%r9,8), %r13
movsd %xmm0, (%r13,%r12,8)
movq 0x20(%r10), %r13
movsd (%r13,%r15,8), %xmm0
movq (%r14,%rcx,8), %r15
movq (%r15,%r9,8), %r15
movsd %xmm0, (%r15,%r12,8)
incq %r12
jmp 0x1fad6
incq %r9
addq %rdi, %r8
jmp 0x1fab8
incq %rcx
addq %rax, %rsi
jmp 0x1faac
movq -0x88(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1948f(%rip), %rax     # 0x38fd8
movq (%rax), %rcx
leaq 0xd8d8(%rip), %rdi      # 0x2d42b
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x44b0
pushq $0x1
popq %rdi
callq 0x42a0