// File: myudelson[P]hmm-scalable/HMMProblemSt.cpp
// Function: HMMProblemSt::Cycle()
void /*NUMBER*/ HMMProblemSt::Cycle() {
	NCAT k, nK = this->task->nK, skill1_n = this->skill1_n;
    NDAT N = this->task->N;
	//
	// fit all as 1 skill first
	//
	if(this->task->single_skill>0) {
        // save originals and force single skill vvvvv
        char saved_multiskill = this->task->multiskill;
        NCAT saved_nK = this->task->nK;
        NCAT* saved_dat_skill = NULL;
        if(this->task->multiskill==0) {
            saved_dat_skill = init1D<NCAT>(N);
            for(NDAT t=0;t<N; t++) saved_dat_skill[t] = this->task->dat_skill[t];
            toZero1D(this->task->dat_skill, N);
        }
        this->task->nK = 1;
        this->task->multiskill = 0;
        // save originals and force single skill ^^^^^
        
        FitBitSt *fb = new FitBitSt(this->task, this->param_skill, this->gradient_skill, (NDAT)(this->skill1_n*nK) );
        createGradientScaleSimplexAffordances(fb);
        fb->fit_results[0].pO0_prefit = -1.0;

        CycleBit(fb); // single computational bit

        if(!this->task->quiet)
            fb->printFitResult(0);
        delete fb;

        // restore originals and copy single skill vvvvv
        this->task->multiskill = saved_multiskill;
        if(this->task->multiskill==0) {
            for(NDAT t=0; t<N; t++) this->task->dat_skill[t] = saved_dat_skill[t];
            delete saved_dat_skill;
        }
        this->task->nK = saved_nK;
        // copy first slot to all other slots
        for(k=1; k<nK; k++) {
            cpy1D(this->param_skill, &this->param_skill[k*skill1_n], (NDAT)skill1_n);
        }
        // restore originals and copy single skill ^^^^^
	}
	//
	// Main fit
	//
    if(this->task->single_skill!=2){
        FitBitSt *fb = new FitBitSt(this->task, this->param_skill, this->gradient_skill, (NDAT)(this->skill1_n*nK) );
        createGradientScaleSimplexAffordances(fb);
        
        CycleBit(fb); // single cycle bit
        
        for(k=0; k<nK && !this->task->quiet; k++) {
//            loglik += fb->fit_results[k].pO*(fb->fit_results[k].pO>0); // reduction'ed
//            if(!this->task->quiet)
            fb->printFitResult(k);
        }
        fb->printFitResult(-1); // overall report
        // loglik = fb->fit_result.pO;
        delete fb;
    }
    
    return;//loglik;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq 0x68(%rax), %rcx
movl 0x908(%rcx), %ecx
movl %ecx, -0x10(%rbp)
movl 0x38(%rax), %ecx
movl %ecx, -0x14(%rbp)
movq 0x68(%rax), %rcx
movl 0x8f8(%rcx), %ecx
movl %ecx, -0x18(%rbp)
movq 0x68(%rax), %rax
movsbl 0x4d(%rax), %eax
cmpl $0x0, %eax
jle 0x16338
movq -0x58(%rbp), %rax
movq 0x68(%rax), %rcx
movb 0x920(%rcx), %cl
movb %cl, -0x19(%rbp)
movq 0x68(%rax), %rcx
movl 0x908(%rcx), %ecx
movl %ecx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq 0x68(%rax), %rax
movsbl 0x920(%rax), %eax
cmpl $0x0, %eax
jne 0x1617c
movl -0x18(%rbp), %edi
callq 0x190c0
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x16165
movq -0x58(%rbp), %rax
movq 0x68(%rax), %rax
movq 0x898(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x16131
movq -0x58(%rbp), %rax
movq 0x68(%rax), %rax
movq 0x898(%rax), %rdi
movl -0x18(%rbp), %esi
callq 0x19610
movq -0x58(%rbp), %rax
movq 0x68(%rax), %rcx
movl $0x1, 0x908(%rcx)
movq 0x68(%rax), %rax
movb $0x0, 0x920(%rax)
movl $0xd8, %edi
callq 0x3270
movq %rax, %rdi
movq -0x58(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x60(%rbp)
movq 0x68(%rax), %rsi
movq 0x28(%rax), %rdx
movq 0x30(%rax), %rcx
movl 0x38(%rax), %r8d
movl -0x10(%rbp), %eax
imull %eax, %r8d
callq 0xaab0
jmp 0x161cf
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
movq (%rdi), %rax
callq *0x88(%rax)
movq -0x58(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movsd 0x5854(%rip), %xmm0     # 0x1ba50
movsd %xmm0, 0x8(%rax)
movq -0x38(%rbp), %rsi
movq (%rdi), %rax
callq *0x98(%rax)
movq -0x58(%rbp), %rax
movq 0x68(%rax), %rax
cmpb $0x0, 0x4c(%rax)
jne 0x16248
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0xaf70
jmp 0x16248
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0xd8, %esi
callq 0x3280
jmp 0x16458
movq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x1626d
movq -0x68(%rbp), %rdi
callq 0xae00
movq -0x68(%rbp), %rdi
movl $0xd8, %esi
callq 0x3280
movq -0x58(%rbp), %rax
movb -0x19(%rbp), %dl
movq 0x68(%rax), %rcx
movb %dl, 0x920(%rcx)
movq 0x68(%rax), %rax
movsbl 0x920(%rax), %eax
cmpl $0x0, %eax
jne 0x162e7
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x162c9
movq -0x58(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x48(%rbp), %rdx
movl (%rcx,%rdx,4), %edx
movq 0x68(%rax), %rax
movq 0x898(%rax), %rax
movslq -0x48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x16295
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
je 0x162e5
movq -0x70(%rbp), %rdi
movl $0x4, %esi
callq 0x3280
jmp 0x162e7
movq -0x58(%rbp), %rax
movl -0x20(%rbp), %ecx
movq 0x68(%rax), %rax
movl %ecx, 0x908(%rax)
movl $0x1, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x16336
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rdi
movq 0x28(%rax), %rsi
movl -0xc(%rbp), %eax
imull -0x14(%rbp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rsi
movl -0x14(%rbp), %edx
callq 0x9dd0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x162ff
jmp 0x16338
movq -0x58(%rbp), %rax
movq 0x68(%rax), %rax
movsbl 0x4d(%rax), %eax
cmpl $0x2, %eax
je 0x1644f
movl $0xd8, %edi
callq 0x3270
movq %rax, %rdi
movq -0x58(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x78(%rbp)
movq 0x68(%rax), %rsi
movq 0x28(%rax), %rdx
movq 0x30(%rax), %rcx
movl 0x38(%rax), %r8d
movl -0x10(%rbp), %eax
imull %eax, %r8d
callq 0xaab0
jmp 0x16383
movq -0x58(%rbp), %rdi
movq -0x78(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rsi
movq (%rdi), %rax
callq *0x88(%rax)
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq (%rdi), %rax
callq *0x98(%rax)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %ecx
xorl %eax, %eax
cmpl -0x10(%rbp), %ecx
movb %al, -0x79(%rbp)
jge 0x163d5
movq -0x58(%rbp), %rax
movq 0x68(%rax), %rax
cmpb $0x0, 0x4c(%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x163de
jmp 0x16411
movq -0x50(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0xaf70
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x163b4
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0xd8, %esi
callq 0x3280
jmp 0x16458
movq -0x50(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xaf70
movq -0x50(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, %rax
je 0x1644d
movq -0x88(%rbp), %rdi
callq 0xae00
movq -0x88(%rbp), %rdi
movl $0xd8, %esi
callq 0x3280
jmp 0x1644f
addq $0x90, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3490
nopw %cs:(%rax,%rax)