// File: /workspace/github_cpp_makefile_star2_O3/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), %r15d
cmpb $0x0, 0x4d(%r13)
jle 0xe832
movq %r15, 0x8(%rsp)
movl 0x38(%rbx), %ebp
movslq 0x8f8(%r13), %r14
movb 0x920(%r13), %al
movb %al, 0x7(%rsp)
testb %al, %al
movl %ebp, 0x14(%rsp)
je 0xe8e0
xorl %r15d, %r15d
movl $0x1, 0x908(%r13)
movb $0x0, 0x920(%r13)
movl $0xd8, %edi
callq 0x21c0
movq %rax, %r12
movq 0x28(%rbx), %rdx
movq 0x30(%rbx), %rcx
imull 0x8(%rsp), %ebp
movq %rax, %rdi
movq %r13, %rsi
movl %ebp, %r8d
callq 0x7a80
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x88(%rax)
movq 0x58(%r12), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, 0x8(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x98(%rax)
movq 0x68(%rbx), %rax
cmpb $0x0, 0x4c(%rax)
movl 0x14(%rsp), %ebp
jne 0xe79c
movq %r12, %rdi
xorl %esi, %esi
callq 0x7cf4
movq %r12, %rdi
callq 0x7c28
movl $0xd8, %esi
movq %r12, %rdi
callq 0x21d0
movq 0x68(%rbx), %r13
movb 0x7(%rsp), %al
movb %al, 0x920(%r13)
testb %al, %al
jne 0xe7f2
testl %r14d, %r14d
jle 0xe7e1
movq 0x898(%r13), %rax
xorl %ecx, %ecx
movl (%r15,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r14
jne 0xe7d2
movl $0x4, %esi
movq %r15, %rdi
callq 0x21d0
movq 0x68(%rbx), %r13
movq 0x8(%rsp), %r15
movl %r15d, 0x908(%r13)
cmpl $0x2, %r15d
jl 0xe832
movslq %ebp, %r14
shlq $0x3, %r14
decq %r15
movq %r14, %r12
movq 0x28(%rbx), %rsi
leaq (%rsi,%r12), %rdi
movq %r14, %rdx
callq 0x2180
addq %r14, %r12
decq %r15
jne 0xe811
movq 0x68(%rbx), %r13
movq 0x8(%rsp), %r15
cmpb $0x2, 0x4d(%r13)
jne 0xe848
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xd8, %edi
callq 0x21c0
movq %rax, %r12
movq 0x28(%rbx), %rdx
movq 0x30(%rbx), %rcx
movl 0x38(%rbx), %r8d
imull %r15d, %r8d
movq %rax, %rdi
movq %r13, %rsi
callq 0x7a80
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x88(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x98(%rax)
testl %r15d, %r15d
jle 0xe8b0
xorl %ebp, %ebp
movq 0x68(%rbx), %rax
cmpb $0x0, 0x4c(%rax)
jne 0xe8b0
movq %r12, %rdi
movl %ebp, %esi
callq 0x7cf4
incl %ebp
cmpl %ebp, %r15d
jne 0xe895
movq %r12, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7cf4
movq %r12, %rdi
callq 0x7c28
movl $0xd8, %esi
movq %r12, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21d0
movl $0x4, %esi
movq %r14, %rdi
callq 0x2110
movq %rax, %r15
testl %r14d, %r14d
jle 0xe718
movq 0x898(%r13), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movl %edx, (%r15,%rcx,4)
incq %rcx
cmpq %rcx, %r14
jne 0xe902
testl %r14d, %r14d
jle 0xe718
movq 0x898(%r13), %rdi
leaq (,%r14,4), %rdx
xorl %esi, %esi
callq 0x2100
movl 0x38(%rbx), %ebp
jmp 0xe718
jmp 0xe93a
movq %rax, %rbx
movl $0xd8, %esi
movq %r12, %rdi
callq 0x21d0
movq %rbx, %rdi
callq 0x2370