// File: /workspace/github_cpp_makefile_star2_O1/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), %rbp
movl 0x908(%rbp), %eax
movq %rax, 0x10(%rsp)
cmpb $0x0, 0x4d(%rbp)
jle 0xe737
movslq 0x38(%rbx), %r14
movslq 0x8f8(%rbp), %r15
movb 0x920(%rbp), %al
movb %al, 0xf(%rsp)
testb %al, %al
je 0xe5de
xorl %r12d, %r12d
jmp 0xe626
movl $0x4, %esi
movq %r15, %rdi
callq 0x2110
movq %rax, %r12
testl %r15d, %r15d
jle 0xe60b
movq 0x898(%rbp), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movl %edx, (%r12,%rcx,4)
incq %rcx
cmpq %rcx, %r15
jne 0xe5fc
testl %r15d, %r15d
jle 0xe626
movq 0x898(%rbp), %rdi
leaq (,%r15,4), %rdx
xorl %esi, %esi
callq 0x2100
movl $0x1, 0x908(%rbp)
movb $0x0, 0x920(%rbp)
movl $0xd8, %edi
callq 0x21c0
movq %rax, %r13
movq 0x28(%rbx), %rdx
movq 0x30(%rbx), %rcx
movl 0x38(%rbx), %r8d
imull 0x10(%rsp), %r8d
movq %rax, %rdi
movq %rbp, %rsi
callq 0x79e8
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
callq *0x88(%rax)
movq 0x58(%r13), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, 0x8(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
callq *0x98(%rax)
movq 0x68(%rbx), %rax
cmpb $0x0, 0x4c(%rax)
jne 0xe6a5
movq %r13, %rdi
xorl %esi, %esi
callq 0x7c62
movq %r13, %rdi
callq 0x7b96
movl $0xd8, %esi
movq %r13, %rdi
callq 0x21d0
movq 0x68(%rbx), %rax
movb 0xf(%rsp), %cl
movb %cl, 0x920(%rax)
testb %cl, %cl
jne 0xe6fb
testl %r15d, %r15d
jle 0xe6e9
movq 0x898(%rax), %rax
xorl %ecx, %ecx
movl (%r12,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r15
jne 0xe6da
testq %r12, %r12
je 0xe6fb
movl $0x4, %esi
movq %r12, %rdi
callq 0x21d0
movq 0x68(%rbx), %rax
movq 0x10(%rsp), %rcx
movl %ecx, 0x908(%rax)
cmpl $0x2, %ecx
jl 0xe737
shlq $0x3, %r14
movq 0x10(%rsp), %rax
leaq -0x1(%rax), %r15
movq %r14, %r12
movq 0x28(%rbx), %rsi
leaq (%rsi,%r12), %rdi
movq %r14, %rdx
callq 0x2180
addq %r14, %r12
decq %r15
jne 0xe71f
movq 0x68(%rbx), %r14
cmpb $0x2, 0x4d(%r14)
jne 0xe751
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xd8, %edi
callq 0x21c0
movq %rax, %r13
movq 0x28(%rbx), %rdx
movq 0x30(%rbx), %rcx
movl 0x38(%rbx), %r8d
movq 0x10(%rsp), %r15
imull %r15d, %r8d
movq %rax, %rdi
movq %r14, %rsi
callq 0x79e8
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
callq *0x88(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
callq *0x98(%rax)
testl %r15d, %r15d
jle 0xe7be
xorl %ebp, %ebp
movq 0x68(%rbx), %rax
cmpb $0x0, 0x4c(%rax)
jne 0xe7be
movq %r13, %rdi
movl %ebp, %esi
callq 0x7c62
incl %ebp
cmpl %ebp, %r15d
jne 0xe7a3
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7c62
movq %r13, %rdi
callq 0x7b96
movl $0xd8, %esi
movq %r13, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21d0
jmp 0xe7f0
movq %rax, %rbx
movl $0xd8, %esi
movq %r13, %rdi
callq 0x21d0
movq %rbx, %rdi
callq 0x2370