// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x68(%rdi), %r13
movl 0x908(%r13), %r14d
cmpb $0x0, 0x4d(%r13)
jle 0xd0d4
movl %r14d, 0x10(%rsp)
movl 0x8f8(%r13), %r14d
movl 0x38(%rbx), %ebp
movb 0x920(%r13), %al
xorl %r15d, %r15d
movb %al, 0xf(%rsp)
testb %al, %al
movl %ebp, 0x14(%rsp)
je 0xcf61
xorl %r12d, %r12d
jmp 0xcfa4
movl %r14d, %edi
callq 0xec25
movq %rax, %r12
movq 0x68(%rbx), %rcx
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
movq 0x898(%rcx), %rdi
cmpq %r15, %rax
je 0xcf95
movl (%rdi,%r15,4), %ecx
movl %ecx, (%r12,%r15,4)
incq %r15
jmp 0xcf83
movl %r14d, %esi
callq 0xef19
movq 0x68(%rbx), %r13
movl 0x38(%rbx), %ebp
movl $0x1, 0x908(%r13)
movb $0x0, 0x920(%r13)
movl $0xd8, %edi
callq 0x31c0
movq %rax, %r15
movq 0x28(%rbx), %rdx
movq 0x30(%rbx), %rcx
imull 0x10(%rsp), %ebp
movq %rax, %rdi
movq %r13, %rsi
movl %ebp, %r8d
callq 0x6ea0
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x88(%rax)
movq 0x58(%r15), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, 0x8(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x98(%rax)
movq 0x68(%rbx), %rax
cmpb $0x0, 0x4c(%rax)
movl 0x14(%rsp), %ebp
jne 0xd027
movq %r15, %rdi
xorl %esi, %esi
callq 0x70be
movslq %ebp, %r13
movq %r15, %rdi
callq 0x7030
movl $0xd8, %esi
movq %r15, %rdi
callq 0x31d0
movq 0x68(%rbx), %rax
movb 0xf(%rsp), %cl
movb %cl, 0x920(%rax)
testb %cl, %cl
jne 0xd081
xorl %ecx, %ecx
testl %r14d, %r14d
cmovlel %ecx, %r14d
cmpq %rcx, %r14
je 0xd072
movl (%r12,%rcx,4), %edx
movq 0x898(%rax), %rsi
movl %edx, (%rsi,%rcx,4)
incq %rcx
jmp 0xd05a
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x31d0
movq 0x68(%rbx), %rax
movslq 0x10(%rsp), %r14
movl %r14d, 0x908(%rax)
shlq $0x3, %r13
pushq $0x1
popq %r15
movq %r13, %r12
cmpq %r14, %r15
jge 0xd0b5
movq 0x28(%rbx), %rsi
leaq (%rsi,%r12), %rdi
movq %r13, %rdx
callq 0x3180
incq %r15
addq %r13, %r12
jmp 0xd098
movq 0x68(%rbx), %r13
cmpb $0x2, 0x4d(%r13)
movl 0x10(%rsp), %r14d
jne 0xd0d4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xd8, %edi
callq 0x31c0
movq %rax, %r15
movq 0x28(%rbx), %rdx
movq 0x30(%rbx), %rcx
movl 0x38(%rbx), %r8d
imull %r14d, %r8d
movq %rax, %rdi
movq %r13, %rsi
callq 0x6ea0
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x88(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x98(%rax)
xorl %ebp, %ebp
testl %r14d, %r14d
cmovlel %ebp, %r14d
cmpl %ebp, %r14d
je 0xd140
movq 0x68(%rbx), %rax
cmpb $0x0, 0x4c(%rax)
jne 0xd140
movq %r15, %rdi
movl %ebp, %esi
callq 0x70be
incl %ebp
jmp 0xd123
pushq $-0x1
popq %rsi
movq %r15, %rdi
callq 0x70be
movq %r15, %rdi
callq 0x7030
movl $0xd8, %esi
movq %r15, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31d0
jmp 0xd170
movq %rax, %rbx
movl $0xd8, %esi
movq %r15, %rdi
callq 0x31d0
movq %rbx, %rdi
callq 0x3390