// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %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, -0x70(%rbp)
callq 0x4120
movq %rax, 0x18(%rbx)
andq $0x0, 0x30(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rbx)
cmpb $0x3, 0x3f(%r14)
jne 0x24d38
cmpb $-0x1, 0x40(%r14)
jne 0x24d38
movb $0x1, 0x40(%r14)
movzbl 0x8b8(%r14), %r15d
movsbq %r15b, %rax
movq %rax, -0x38(%rbp)
movq %r14, -0x78(%rbp)
movzbl 0x8c8(%r14), %eax
movq %rax, -0x50(%rbp)
subq $0x8, %rsp
movsbl %al, %r12d
movsbl %r15b, %r13d
leaq -0xa0(%rbp), %rsi
leaq -0x98(%rbp), %rdx
leaq -0x90(%rbp), %rcx
movl %r12d, %r8d
movl %r13d, %r9d
movq -0x48(%rbp), %r14
pushq %r14
callq 0x252c8
popq %rax
popq %rcx
movl 0xc(%rbx), %edi
movl %r13d, %esi
callq 0x9328
movq %rax, 0x38(%rbx)
movl 0x10(%rbx), %edi
movl %r12d, %esi
movl %r13d, %edx
movl %r13d, %ecx
callq 0x24ab6
movq %rax, 0x90(%rbx)
movl 0x14(%rbx), %edi
movl %r13d, %esi
movl %r14d, %edx
callq 0xa0be
movq %rsp, -0x80(%rbp)
movq %rax, 0x48(%rbx)
movq -0x50(%rbp), %rdx
movl %edx, %eax
imull %r15d, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, %rsp
leal 0xf(,%r15,8), %eax
andl $-0x10, %eax
movq %rsp, %rsi
subq %rax, %rsi
movq %rsi, %rsp
xorl %eax, %eax
movl %r12d, -0x30(%rbp)
testb %r12b, %r12b
movq %rdx, %rcx
cmovlel %eax, %ecx
movq %rcx, -0x50(%rbp)
movl %r13d, -0x2c(%rbp)
testb %r13b, %r13b
movl $0x0, %r12d
cmovgl %r15d, %r12d
movq %r15, -0x40(%rbp)
movl %r15d, %edx
shll $0x3, %edx
movq %rdi, -0x58(%rbp)
movq %rdi, %rcx
movq -0x50(%rbp), %r8
cmpq %r12, %rax
je 0x24e55
subq $0x1, %r8
jb 0x24e47
andq $0x0, (%rcx)
addq %rdx, %rcx
jmp 0x24e38
andq $0x0, (%rsi,%rax,8)
incq %rax
addq $0x8, %rdi
jmp 0x24e2c
movq -0x38(%rbp), %rax
leal -0x1(%rax), %edx
movq 0x88(%rbx), %rax
xorpd %xmm1, %xmm1
movq -0xa0(%rbp), %r8
xorl %ecx, %ecx
cmpl %ecx, %edx
jle 0x24e8c
movq 0x8(%rax), %rdi
movsd (%rdi,%rcx,8), %xmm0
movsd %xmm0, (%r8,%rcx,8)
addsd %xmm0, %xmm1
incq %rcx
jmp 0x24e70
movsd 0x7a5c(%rip), %xmm0     # 0x2c8f0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movq -0x38(%rbp), %rax
movq %r8, -0x60(%rbp)
movsd %xmm2, -0x8(%r8,%rax,8)
movq -0x98(%rbp), %r14
movq -0x40(%rbp), %rax
leal -0x1(%rax), %ecx
movzbl %cl, %edi
mulb %dil
movzbl %al, %eax
movq %rax, -0x88(%rbp)
xorl %r8d, %r8d
movq %rdi, %r11
cmpq -0x50(%rbp), %r8
je 0x24f6a
movq %r8, %rax
imulq -0x40(%rbp), %rax
movq -0x58(%rbp), %rcx
leaq (%rcx,%rax,8), %r10
movq %r11, -0x68(%rbp)
xorl %r15d, %r15d
cmpq %r12, %r15
je 0x24f57
movq 0x88(%rbx), %rcx
xorl %eax, %eax
cmpl %eax, %edx
jle 0x24f33
leal (%r11,%rax), %r13d
movq 0x8(%rcx), %r9
movsbq %r13b, %r13
movsd (%r9,%r13,8), %xmm1
movq (%r14,%r8,8), %r9
movq (%r9,%r15,8), %r9
movsd %xmm1, (%r9,%rax,8)
addsd (%r10,%r15,8), %xmm1
movsd %xmm1, (%r10,%r15,8)
incq %rax
jmp 0x24efe
movapd %xmm0, %xmm1
subsd (%r10,%r15,8), %xmm1
movq (%r14,%r8,8), %rax
movq (%rax,%r15,8), %rax
movq -0x38(%rbp), %rcx
movsd %xmm1, -0x8(%rax,%rcx,8)
incq %r15
addq %rdi, %r11
jmp 0x24ef0
incq %r8
movq -0x68(%rbp), %r11
addq -0x88(%rbp), %r11
jmp 0x24ecf
movq -0x40(%rbp), %rdx
leal -0x1(%rdx), %ecx
movl -0x30(%rbp), %edi
movl %edi, %eax
mulb %dl
movl %eax, %edx
incb %dl
movl %ecx, %eax
mulb %dl
imull -0x2c(%rbp), %edi
movl %edi, -0x58(%rbp)
movq -0x48(%rbp), %rdx
leal -0x1(%rdx), %ecx
movq -0x90(%rbp), %r15
movzbl %al, %eax
decl %edx
movzbl %dl, %edx
xorl %edi, %edi
cmpq %r12, %rdi
je 0x24ffe
movq 0x88(%rbx), %r8
xorl %r9d, %r9d
cmpl %r9d, %ecx
jle 0x24fde
leal (%rax,%r9), %r10d
movq 0x8(%r8), %r11
movsbq %r10b, %r10
movsd (%r11,%r10,8), %xmm1
movq (%r15,%rdi,8), %r10
movsd %xmm1, (%r10,%r9,8)
addsd (%rsi,%rdi,8), %xmm1
movsd %xmm1, (%rsi,%rdi,8)
incq %r9
jmp 0x24fae
movapd %xmm0, %xmm1
subsd (%rsi,%rdi,8), %xmm1
movq (%r15,%rdi,8), %r8
movq -0x70(%rbp), %r9
movsd %xmm1, -0x8(%r8,%r9,8)
incq %rdi
addq %rdx, %rax
jmp 0x24f9f
movq 0x88(%rbx), %rax
cmpb $0x0, 0x32(%rax)
jne 0x25025
movq %rbx, %rdi
movq -0x60(%rbp), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x2531e
testb %al, %al
je 0x252a3
movq -0x38(%rbp), %rax
shlq $0x3, %rax
movq %rax, -0x68(%rbp)
xorl %r13d, %r13d
movslq 0xc(%rbx), %rax
cmpq %rax, %r13
jge 0x25057
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rdi
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0x41c0
incq %r13
jmp 0x25034
xorl %r13d, %r13d
movslq 0x10(%rbx), %rax
cmpq %rax, %r13
jge 0x25084
movq 0x90(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl %ecx, %r8d
callq 0xa1a2
incq %r13
jmp 0x2505a
xorl %r13d, %r13d
movslq 0x14(%rbx), %rax
cmpq %rax, %r13
jge 0x250ac
movq 0x48(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %r15, %rdi
movl -0x2c(%rbp), %edx
movq -0x48(%rbp), %rcx
callq 0x93ad
incq %r13
jmp 0x25087
movq -0x60(%rbp), %rdi
callq 0x4290
movq %r14, %rdi
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %r14d
movl %r14d, %edx
callq 0xa064
movq %r15, %rdi
movl %r14d, %esi
callq 0x7f2c
movq -0x78(%rbp), %rsi
cmpb $0x0, 0x6c(%rsi)
je 0x250ea
addq $0x6c, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x25508
leaq 0x50(%rbx), %rsi
leaq 0x98(%rbx), %rdx
leaq 0x60(%rbx), %rcx
subq $0x8, %rsp
movl -0x30(%rbp), %r15d
movl %r15d, %r8d
movq -0x38(%rbp), %r9
movq -0x48(%rbp), %r14
pushq %r14
callq 0x252c8
popq %rax
popq %rcx
leaq 0x68(%rbx), %rsi
leaq 0xa0(%rbx), %rdx
leaq 0x78(%rbx), %rcx
subq $0x8, %rsp
movl %r15d, %r8d
movl -0x2c(%rbp), %r9d
pushq %r14
callq 0x252c8
addq $0x10, %rsp
movq 0x88(%rbx), %rax
movq 0x50(%rbx), %rcx
movq 0x68(%rbx), %rdx
xorl %esi, %esi
cmpq %rsi, %r12
je 0x25171
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 0x2514b
movq -0x40(%rbp), %rsi
movq %rsi, %rcx
negq %rcx
movl %esi, %eax
mulb -0x38(%rbp)
movzbl %al, %eax
xorl %edx, %edx
cmpq -0x50(%rbp), %rdx
je 0x2520f
movq %rsi, %rdi
xorl %r8d, %r8d
cmpq %r12, %r8
je 0x25204
movq 0x88(%rbx), %r9
movq 0x98(%rbx), %r10
movq 0xa0(%rbx), %r11
xorl %r14d, %r14d
movq %rcx, %r15
addq %r14, %r15
je 0x251fb
leal (%rdi,%r14), %r15d
movq 0x18(%r9), %r13
movsbq %r15b, %r15
movsd (%r13,%r15,8), %xmm0
movq (%r10,%rdx,8), %r13
movq (%r13,%r8,8), %r13
movsd %xmm0, (%r13,%r14,8)
movq 0x20(%r9), %r13
movsd (%r13,%r15,8), %xmm0
movq (%r11,%rdx,8), %r15
movq (%r15,%r8,8), %r15
movsd %xmm0, (%r15,%r14,8)
incq %r14
jmp 0x251b2
incq %r8
addq -0x40(%rbp), %rdi
jmp 0x25195
incq %rdx
addq %rax, %rsi
jmp 0x25185
movl -0x58(%rbp), %eax
incb %al
mulb -0x40(%rbp)
xorl %ecx, %ecx
cmpb $0x0, -0x70(%rbp)
movl $0x0, %edx
movq -0x48(%rbp), %r14
cmovgl %r14d, %edx
movl $0xff, %esi
andl %esi, %edx
movzbl %al, %eax
andl %esi, %r14d
cmpq %r12, %rcx
je 0x25290
movq 0x88(%rbx), %rsi
movq 0x60(%rbx), %rdi
movq 0x78(%rbx), %r8
xorl %r9d, %r9d
cmpq %r9, %rdx
je 0x25288
leal (%rax,%r9), %r10d
movq 0x18(%rsi), %r11
movsbq %r10b, %r10
movsd (%r11,%r10,8), %xmm0
movq (%rdi,%rcx,8), %r11
movsd %xmm0, (%r11,%r9,8)
movq 0x20(%rsi), %r11
movsd (%r11,%r10,8), %xmm0
movq (%r8,%rcx,8), %r10
movsd %xmm0, (%r10,%r9,8)
incq %r9
jmp 0x2524e
incq %rcx
addq %r14, %rax
jmp 0x25237
movq -0x80(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x13d2e(%rip), %rax     # 0x38fd8
movq (%rax), %rcx
leaq 0x8177(%rip), %rdi      # 0x2d42b
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x44b0
pushq $0x1
popq %rdi
callq 0x42a0
nop