// File: myudelson[P]hmm-scalable/HMMProblemAGK.cpp
// Function: HMMProblemAGK::GradientDescent()
NUMBER HMMProblemAGK::GradientDescent() {
	NCAT k=0, g=0, /*ki, gi, nX, */x;
    NCAT nK = this->p->nK, nG = this->p->nG;
    
	//
	// fit all as 1 skill first, set group gradients to 0, and do not fit them
	//
	if(this->p->single_skill>0) {
        FitBit *fb = new FitBit(this->p->nS, this->p->nO, this->p->nK, this->p->nG, this->p->tol, this->p->tol_mode);
        fb->link( HMMProblem::getPI(0), HMMProblem::getA(0), HMMProblem::getB(0), this->p->nSeq, this->p->k_data);// link skill 0 (we'll copy fit parameters to others
        if(this->p->block_fitting[0]!=0) fb->pi = NULL;
        if(this->p->block_fitting[1]!=0) fb->A  = NULL;
        if(this->p->block_fitting[2]!=0) fb->B  = NULL;
        
        fb->init(FBS_PARm1);
        fb->init(FBS_PARm2);
        fb->init(FBS_GRAD);
        if(this->p->solver==METHOD_CGD) {
            fb->init(FBS_GRADm1);
            fb->init(FBS_DIRm1);
        }
        
        NCAT* original_ks = Calloc(NCAT, (size_t)this->p->nSeq);
        for(x=0; x<this->p->nSeq; x++) { original_ks[x] = this->p->all_data[x].k; this->p->all_data[x].k = 0; } // save progonal k's
        FitResult fr = GradientDescentBit(fb);
        for(x=0; x<this->p->nSeq; x++) { this->p->all_data[x].k = original_ks[x]; } // restore original k's
        free(original_ks);
        if( !this->p->quiet )
            printf("single skill iter#%3d p(O|param)= %15.7f >> %15.7f, conv=%d\n", fr.iter,fr.pO0,fr.pO,fr.conv);
        delete fb;
    }
	//
	// Main fit
	//
    if( this->p->single_skill!=2 ) { // if not "force single skill"
        NCAT first_iteration_qualify = this->p->first_iteration_qualify; // at what iteration, qualification for skill/group convergence should start
        NCAT iterations_to_qualify = this->p->iterations_to_qualify; // how many concecutive iterations necessary for skill/group to qualify as converged
        NCAT* iter_qual_skill = Calloc(NCAT, (size_t)nK);
        NCAT* iter_qual_group = Calloc(NCAT, (size_t)nG);
        NCAT* iter_fail_skill = Calloc(NCAT, (size_t)nK); // counting concecutive number of failures to converge for skills
        NCAT* iter_fail_group = Calloc(NCAT, (size_t)nG); // counting concecutive number of failures to converge for groups
        int skip_k = 0, skip_g = 0;
        // utilize fitting larger data first
        
        int i = 0; // count runs
//        int parallel_now = this->p->parallel==1; //PAR
//        #pragma omp parallel if(parallel_now) shared(iter_qual_group,iter_qual_skill,iter_fail_skill,iter_fail_group)//PAR
//        {//PAR
            while(skip_k<nK || skip_g<nG) {
                //
                // Skills first
                //
//                printf("... while in,  run=%3d, k=%6d, skippedK=%6d, g=%6d, skippedG=%6d, thread id=%d\n",i,k,skip_k,g,skip_g, omp_get_thread_num());//PAR
                if(skip_k<nK) {
//                    printf("... still k,   run=%3d, k=%6d, skippedK=%6d, g=%6d, skippedG=%6d, thread id=%d\n",i,k,skip_k,g,skip_g, omp_get_thread_num());//PAR
//                    #pragma omp for schedule(dynamic) //PAR
                    for(k=0; k<nK; k++) { // for all A,B-by-skill
                        if(iter_qual_skill[k]==iterations_to_qualify || iter_fail_skill[k]==iterations_to_qualify)
                            continue;
//                        printf("... doing k,   run=%3d, k=%6d, skippedK=%6d, g=%6d, skippedG=%6d, thread id=%d\n",i,k,skip_k,g,skip_g, omp_get_thread_num());//PAR
                        FitBit *fb = new FitBit(this->p->nS, this->p->nO, this->p->nK, this->p->nG, this->p->tol, this->p->tol_mode);
                        // link
                        fb->link( HMMProblem::getPI(k), HMMProblem::getA(k), HMMProblem::getB(k), this->p->k_numg[k], this->p->k_g_data[k]);// link skill 0 (we'll copy fit parameters to others
                        if(this->p->block_fitting[0]!=0) fb->pi = NULL;
                        if(this->p->block_fitting[1]!=0) fb->A  = NULL;
                        if(this->p->block_fitting[2]!=0) fb->B  = NULL;
                        
                        fb->Cslice = 0;
                        fb->init(FBS_PARm1);
                        fb->init(FBS_PARm2);
                        fb->init(FBS_GRAD);
                        if(this->p->solver==METHOD_CGD) {
                            fb->init(FBS_GRADm1);
                            fb->init(FBS_DIRm1);
                        }
                        
                        FitResult fr = GradientDescentBit(fb);
						
						// count number of concecutive failures
						if(fr.iter==this->p->maxiter) {
							iter_fail_skill[k]++;
						} else {
							iter_fail_skill[k]=0;
						}
						
                        // decide on convergence
                        if(i>=first_iteration_qualify || fb->xndat==0) {
                            if(fr.iter==1 /*e<=this->p->tol*/ || skip_g==nG || fb->xndat==0) { // converged quick, or don't care (others all converged
                                iter_qual_skill[k]++;
                                if(fb->xndat==0) {
                                    iter_qual_skill[k]=iterations_to_qualify;
                                    fr.conv = 1;
                                }
                                if(iter_qual_skill[k]==iterations_to_qualify || skip_g==nG) {// criterion met, or don't care (others all converged)
                                    if(skip_g==nG) iter_qual_skill[k]=iterations_to_qualify; // G not changing anymore
//                                    #pragma omp critical(update_skip_k)//PAR
//                                    {//PAR
                                        skip_k++;
//                                    }//PAR
                                    if( !this->p->quiet && ( /*(!conv && iter<this->p->maxiter) ||*/ (fr.conv || fr.iter==this->p->maxiter) )) {
                                        printf("run %2d skipK %4d skill %4d iter#%3d p(O|param)= %15.7f >> %15.7f, conv=%d\n",i,skip_k,k,fr.iter,fr.pO0,fr.pO,fr.conv);
                                    }
                                }
                            }
                            else
                                iter_qual_skill[k]=0;
                        } // decide on convergence
                        delete fb;
                    } // for all skills
                }
                //
                // PIg second
                //
                if(skip_g<nG){
//                    printf("... still g,   run=%3d, k=%6d, skippedK=%6d, g=%6d, skippedG=%6d, thread id=%d\n",i,k,skip_k,g,skip_g, omp_get_thread_num());//PAR
//                    #pragma omp for schedule(dynamic)//PAR
                    for(g=0; g<nG; g++) { // for all PI-by-user
                        if(iter_qual_group[g]==iterations_to_qualify || iter_fail_group[g]==iterations_to_qualify)
                            continue;
//                        printf("... doing g,   run=%3d, k=%6d, skippedK=%6d, g=%6d, skippedG=%6d, thread id=%d\n",i,k,skip_k,g,skip_g, omp_get_thread_num());//PAR
                        FitBit *fb = new FitBit(this->p->nS, this->p->nO, this->p->nK, this->p->nG, this->p->tol, this->p->tol_mode);
                        // link
                        // vvvvvvvvvvvvvvvvvvvvv ONLY PART THAT IS DIFFERENT FROM HMMProblemPiGK
                        fb->link(NULL, this->getAg(g), NULL, this->p->g_numk[g], this->p->g_k_data[g]);
                        fb->observe_non01_boundaries = 0;
                        if(this->p->block_fitting[0]!=0) fb->pi = NULL;
                        if(this->p->block_fitting[1]!=0) fb->A  = NULL;
                        if(this->p->block_fitting[2]!=0) fb->B  = NULL;
                        // ^^^^^^^^^^^^^^^^^^^^^
                        fb->Cslice = 1;
                        fb->init(FBS_PARm1);
                        fb->init(FBS_PARm2);
                        fb->init(FBS_GRAD);
                        if(this->p->solver==METHOD_CGD) {
                            fb->init(FBS_GRADm1);
                            fb->init(FBS_DIRm1);
                        }
                        FitResult fr = GradientDescentBit(fb);
						
						// count number of concecutive failures
						if(fr.iter==this->p->maxiter) {
							iter_fail_group[g]++;
						} else {
							iter_fail_group[g]=0;
						}
						
                        // decide on convergence
                        if(i>=first_iteration_qualify || fb->xndat==0) { //can qualify or  student had no skill labelled rows
                            if(fr.iter==1 /*e<=this->p->tol*/ || skip_k==nK || fb->xndat==0) { // converged quick, or don't care (others all converged), or
                                iter_qual_group[g]++;
                                if(fb->xndat==0) {
                                    iter_qual_group[g]=iterations_to_qualify;
                                    fr.conv = 1;
                                }
                                if(iter_qual_group[g]==iterations_to_qualify || skip_k==nK) {// criterion met, or don't care (others all converged)
                                    if(skip_k==nK) iter_qual_group[g]=iterations_to_qualify; // K not changing anymore
//                                    #pragma omp critical(update_skip_g)//PAR
//                                    {//PAR
                                        skip_g++;
//                                    }//PAR
                                    if( !this->p->quiet && ( /*(!conv && iter<this->p->maxiter) ||*/ (fr.conv || fr.iter==this->p->maxiter) )) {
                                        printf("run %2d skipG %4d group %4d iter#%3d p(O|param)= %15.7f >> %15.7f, conv=%d\n",i,skip_g,g,fr.iter,fr.pO0,fr.pO,fr.conv);
                                    }
                                }
                            }
                            else
                                iter_qual_group[g]=0;
                        } // decide on convergence
                        delete fb;
                    } // for all groups
                }
                //            fr.conv = checkConvergenceBig(fbs, nK+nG, this->p->tol, &crit);
                //
                //            computeAlphaAndPOParam(this->p->nSeq, this->p->k_data);
                //            ll = HMMProblem::getSumLogPOPara(this->p->nSeq, this->p->k_data);
                //            printf("*%i ll=%15.7f, crit=%12.10f\n",i,ll,crit);
//                #pragma omp single//PAR
//                {//PAR
                    i++;
//                    printf("... done run,  run=%3d, k=%6d, skippedK=%6d, g=%6d, skippedG=%6d, thread id=%d\n",i,k,skip_k,g,skip_g, omp_get_thread_num());//PAR
//                }//PAR
//                printf("... while out, run=%3d, k=%6d, skippedK=%6d, g=%6d, skippedG=%6d, thread id=%d\n",i,k,skip_k,g,skip_g, omp_get_thread_num());//PAR
            }
//        }//PAR
        // recycle qualifications
        if( iter_qual_skill != NULL ) free(iter_qual_skill);
        if( iter_qual_group != NULL) free(iter_qual_group);
        if( iter_fail_skill != NULL ) free(iter_fail_skill);
        if( iter_fail_group != NULL) free(iter_fail_group);
        
    } // if not "force single skill
    
    // compute loglik
    return getSumLogPOPara(this->p->nSeq, this->p->k_data);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x108(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq 0x88(%rax), %rcx
movl 0x8c0(%rcx), %ecx
movl %ecx, -0x18(%rbp)
movq 0x88(%rax), %rcx
movl 0x8bc(%rcx), %ecx
movl %ecx, -0x1c(%rbp)
movq 0x88(%rax), %rax
movsbl 0x3d(%rax), %eax
cmpl $0x0, %eax
jle 0x2f6e2
movl $0x110, %edi            # imm = 0x110
callq 0x52d0
movq %rax, %rdi
movq -0x108(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x110(%rbp)
movq 0x88(%rax), %rax
movsbl 0x8b8(%rax), %esi
movsbl 0x8b9(%rax), %edx
movl 0x8c0(%rax), %ecx
movl 0x8bc(%rax), %r8d
movsd 0x28(%rax), %xmm0
movsbl 0x30(%rax), %r9d
callq 0xd080
jmp 0x2f3ed
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x128(%rbp)
xorl %esi, %esi
callq 0x1a560
movq -0x108(%rbp), %rdi
movq %rax, -0x120(%rbp)
xorl %esi, %esi
callq 0x1a5d0
movq -0x108(%rbp), %rdi
movq %rax, -0x118(%rbp)
xorl %esi, %esi
callq 0x1a640
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq 0x88(%rax), %r8
movl 0x8dc(%r8), %r8d
movq 0x88(%rax), %rax
movq 0x8f0(%rax), %r9
callq 0xd990
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x981(%rax), %eax
cmpl $0x0, %eax
je 0x2f4c5
movq -0x28(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0x2f4c5
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x110, %esi            # imm = 0x110
callq 0x52e0
jmp 0x300bf
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x982(%rax), %eax
cmpl $0x0, %eax
je 0x2f4eb
movq -0x28(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x983(%rax), %eax
cmpl $0x0, %eax
je 0x2f511
movq -0x28(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x28(%rbp), %rdi
movl $0x2, %esi
callq 0xdcb0
movq -0x28(%rbp), %rdi
movl $0x7, %esi
callq 0xdcb0
movq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0xdcb0
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x3f(%rax), %eax
cmpl $0x3, %eax
jne 0x2f56e
movq -0x28(%rbp), %rdi
movl $0x4, %esi
callq 0xdcb0
movq -0x28(%rbp), %rdi
movl $0x6, %esi
callq 0xdcb0
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movslq 0x8dc(%rax), %rdi
movl $0x4, %esi
callq 0x5180
movq %rax, -0x40(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x108(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x88(%rcx), %rcx
cmpl 0x8dc(%rcx), %eax
jge 0x2f60a
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rcx
movq 0x8e8(%rcx), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
movl 0x58(%rcx), %esi
movq -0x40(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movq 0x88(%rax), %rax
movq 0x8e8(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x58(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2f598
movq -0x108(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x1f530
movl $0x0, -0x14(%rbp)
movq -0x108(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x88(%rcx), %rcx
cmpl 0x8dc(%rcx), %eax
jge 0x2f677
movq -0x108(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movq 0x88(%rax), %rax
movq 0x8e8(%rax), %rax
movslq -0x14(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x58(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2f625
movq -0x40(%rbp), %rdi
callq 0x5380
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
cmpb $0x0, 0x3c(%rax)
jne 0x2f6b2
movl -0x68(%rbp), %esi
movsd -0x60(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
movl -0x48(%rbp), %edx
leaq 0x212cc(%rip), %rdi     # 0x50977
movb $0x2, %al
callq 0x5060
movq -0x28(%rbp), %rax
movq %rax, -0x130(%rbp)
cmpq $0x0, %rax
je 0x2f6e0
movq -0x130(%rbp), %rdi
callq 0xd3a0
movq -0x130(%rbp), %rdi
movl $0x110, %esi            # imm = 0x110
callq 0x52e0
jmp 0x2f6e2
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x3d(%rax), %eax
cmpl $0x2, %eax
je 0x3008f
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rcx
movsbl 0x978(%rcx), %ecx
movl %ecx, -0x6c(%rbp)
movq 0x88(%rax), %rax
movsbl 0x979(%rax), %eax
movl %eax, -0x70(%rbp)
movslq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x5180
movq %rax, -0x78(%rbp)
movslq -0x1c(%rbp), %rdi
movl $0x4, %esi
callq 0x5180
movq %rax, -0x80(%rbp)
movslq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x5180
movq %rax, -0x88(%rbp)
movslq -0x1c(%rbp), %rdi
movl $0x4, %esi
callq 0x5180
movq %rax, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x94(%rbp), %ecx
movb $0x1, %al
cmpl -0x18(%rbp), %ecx
movb %al, -0x131(%rbp)
jl 0x2f7b7
movl -0x98(%rbp), %eax
cmpl -0x1c(%rbp), %eax
setl %al
movb %al, -0x131(%rbp)
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x2f7c6
jmp 0x30041
movl -0x94(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x2fc0c
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x2fc0a
movq -0x78(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x70(%rbp), %eax
je 0x2f80b
movq -0x88(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x70(%rbp), %eax
jne 0x2f810
jmp 0x2fbfc
movl $0x110, %edi            # imm = 0x110
callq 0x52d0
movq %rax, %rdi
movq -0x108(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x140(%rbp)
movq 0x88(%rax), %rax
movsbl 0x8b8(%rax), %esi
movsbl 0x8b9(%rax), %edx
movl 0x8c0(%rax), %ecx
movl 0x8bc(%rax), %r8d
movsd 0x28(%rax), %xmm0
movsbl 0x30(%rax), %r9d
callq 0xd080
jmp 0x2f861
movq -0x108(%rbp), %rdi
movq -0x140(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x158(%rbp)
movl -0xc(%rbp), %esi
callq 0x1a560
movq -0x108(%rbp), %rdi
movq %rax, -0x150(%rbp)
movl -0xc(%rbp), %esi
callq 0x1a5d0
movq -0x108(%rbp), %rdi
movq %rax, -0x148(%rbp)
movl -0xc(%rbp), %esi
callq 0x1a640
movq -0x158(%rbp), %rdi
movq -0x150(%rbp), %rsi
movq -0x148(%rbp), %rdx
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq 0x88(%rax), %r8
movq 0x8e0(%r8), %r8
movslq -0xc(%rbp), %r9
movl (%r8,%r9,4), %r8d
movq 0x88(%rax), %rax
movq 0x8f8(%rax), %rax
movslq -0xc(%rbp), %r9
movq (%rax,%r9,8), %r9
callq 0xd990
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x981(%rax), %eax
cmpl $0x0, %eax
je 0x2f955
movq -0xa8(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0x2f955
movq -0x140(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x110, %esi            # imm = 0x110
callq 0x52e0
jmp 0x300bf
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x982(%rax), %eax
cmpl $0x0, %eax
je 0x2f97e
movq -0xa8(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x983(%rax), %eax
cmpl $0x0, %eax
je 0x2f9a7
movq -0xa8(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0xa8(%rbp), %rax
movb $0x0, 0xfa(%rax)
movq -0xa8(%rbp), %rdi
movl $0x2, %esi
callq 0xdcb0
movq -0xa8(%rbp), %rdi
movl $0x7, %esi
callq 0xdcb0
movq -0xa8(%rbp), %rdi
movl $0x3, %esi
callq 0xdcb0
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x3f(%rax), %eax
cmpl $0x3, %eax
jne 0x2fa21
movq -0xa8(%rbp), %rdi
movl $0x4, %esi
callq 0xdcb0
movq -0xa8(%rbp), %rdi
movl $0x6, %esi
callq 0xdcb0
movq -0x108(%rbp), %rsi
movq -0xa8(%rbp), %rdx
leaq -0xd0(%rbp), %rdi
callq 0x1f530
movq -0x108(%rbp), %rcx
movl -0xd0(%rbp), %eax
movq 0x88(%rcx), %rcx
cmpl 0x38(%rcx), %eax
jne 0x2fa6a
movq -0x88(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x2fa7c
movq -0x88(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x9c(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x2fa9b
movq -0xa8(%rbp), %rax
cmpl $0x0, 0xe8(%rax)
jne 0x2fbc9
cmpl $0x1, -0xd0(%rbp)
je 0x2fac3
movl -0x98(%rbp), %eax
cmpl -0x1c(%rbp), %eax
je 0x2fac3
movq -0xa8(%rbp), %rax
cmpl $0x0, 0xe8(%rax)
jne 0x2fbb8
movq -0x78(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0xa8(%rbp), %rax
cmpl $0x0, 0xe8(%rax)
jne 0x2fafc
movl -0x70(%rbp), %edx
movq -0x78(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x1, -0xb0(%rbp)
movq -0x78(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x70(%rbp), %eax
je 0x2fb1b
movl -0x98(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x2fbb6
movl -0x98(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x2fb34
movl -0x70(%rbp), %edx
movq -0x78(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x108(%rbp), %rax
movl -0x94(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x94(%rbp)
movq 0x88(%rax), %rax
cmpb $0x0, 0x3c(%rax)
jne 0x2fbb4
cmpl $0x0, -0xb0(%rbp)
jne 0x2fb79
movq -0x108(%rbp), %rcx
movl -0xd0(%rbp), %eax
movq 0x88(%rcx), %rcx
cmpl 0x38(%rcx), %eax
jne 0x2fbb4
movl -0x9c(%rbp), %esi
movl -0x94(%rbp), %edx
movl -0xc(%rbp), %ecx
movl -0xd0(%rbp), %r8d
movsd -0xc8(%rbp), %xmm0
movsd -0xb8(%rbp), %xmm1
movl -0xb0(%rbp), %r9d
leaq 0x20e07(%rip), %rdi     # 0x509b4
movb $0x2, %al
callq 0x5060
jmp 0x2fbb6
jmp 0x2fbc7
movq -0x78(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x2fbc9
movq -0xa8(%rbp), %rax
movq %rax, -0x160(%rbp)
cmpq $0x0, %rax
je 0x2fbfa
movq -0x160(%rbp), %rdi
callq 0xd3a0
movq -0x160(%rbp), %rdi
movl $0x110, %esi            # imm = 0x110
callq 0x52e0
jmp 0x2fbfc
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2f7dc
jmp 0x2fc0c
movl -0x98(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3002d
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3002b
movq -0x80(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x70(%rbp), %eax
je 0x2fc51
movq -0x90(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x70(%rbp), %eax
jne 0x2fc56
jmp 0x3001d
movl $0x110, %edi            # imm = 0x110
callq 0x52d0
movq %rax, %rdi
movq -0x108(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x168(%rbp)
movq 0x88(%rax), %rax
movsbl 0x8b8(%rax), %esi
movsbl 0x8b9(%rax), %edx
movl 0x8c0(%rax), %ecx
movl 0x8bc(%rax), %r8d
movsd 0x28(%rax), %xmm0
movsbl 0x30(%rax), %r9d
callq 0xd080
jmp 0x2fca7
movq -0x108(%rbp), %rdi
movq -0x168(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x170(%rbp)
movl -0x10(%rbp), %esi
callq 0x2e790
movq -0x170(%rbp), %rdi
movq %rax, %rdx
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rcx
movq 0x900(%rcx), %rcx
movslq -0x10(%rbp), %rsi
movl (%rcx,%rsi,4), %r8d
movq 0x88(%rax), %rax
movq 0x910(%rax), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %r9
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
callq 0xd990
movq -0x108(%rbp), %rax
movq -0xd8(%rbp), %rcx
movb $0x0, 0xf9(%rcx)
movq 0x88(%rax), %rax
movsbl 0x981(%rax), %eax
cmpl $0x0, %eax
je 0x2fd76
movq -0xd8(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0x2fd76
movq -0x168(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x110, %esi            # imm = 0x110
callq 0x52e0
jmp 0x300bf
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x982(%rax), %eax
cmpl $0x0, %eax
je 0x2fd9f
movq -0xd8(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x983(%rax), %eax
cmpl $0x0, %eax
je 0x2fdc8
movq -0xd8(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0xd8(%rbp), %rax
movb $0x1, 0xfa(%rax)
movq -0xd8(%rbp), %rdi
movl $0x2, %esi
callq 0xdcb0
movq -0xd8(%rbp), %rdi
movl $0x7, %esi
callq 0xdcb0
movq -0xd8(%rbp), %rdi
movl $0x3, %esi
callq 0xdcb0
movq -0x108(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x3f(%rax), %eax
cmpl $0x3, %eax
jne 0x2fe42
movq -0xd8(%rbp), %rdi
movl $0x4, %esi
callq 0xdcb0
movq -0xd8(%rbp), %rdi
movl $0x6, %esi
callq 0xdcb0
movq -0x108(%rbp), %rsi
movq -0xd8(%rbp), %rdx
leaq -0x100(%rbp), %rdi
callq 0x1f530
movq -0x108(%rbp), %rcx
movl -0x100(%rbp), %eax
movq 0x88(%rcx), %rcx
cmpl 0x38(%rcx), %eax
jne 0x2fe8b
movq -0x90(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x2fe9d
movq -0x90(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x9c(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x2febc
movq -0xd8(%rbp), %rax
cmpl $0x0, 0xe8(%rax)
jne 0x2ffea
cmpl $0x1, -0x100(%rbp)
je 0x2fee4
movl -0x94(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0x2fee4
movq -0xd8(%rbp), %rax
cmpl $0x0, 0xe8(%rax)
jne 0x2ffd9
movq -0x80(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0xd8(%rbp), %rax
cmpl $0x0, 0xe8(%rax)
jne 0x2ff1d
movl -0x70(%rbp), %edx
movq -0x80(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x1, -0xe0(%rbp)
movq -0x80(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x70(%rbp), %eax
je 0x2ff3c
movl -0x94(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x2ffd7
movl -0x94(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x2ff55
movl -0x70(%rbp), %edx
movq -0x80(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x108(%rbp), %rax
movl -0x98(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x98(%rbp)
movq 0x88(%rax), %rax
cmpb $0x0, 0x3c(%rax)
jne 0x2ffd5
cmpl $0x0, -0xe0(%rbp)
jne 0x2ff9a
movq -0x108(%rbp), %rcx
movl -0x100(%rbp), %eax
movq 0x88(%rcx), %rcx
cmpl 0x38(%rcx), %eax
jne 0x2ffd5
movl -0x9c(%rbp), %esi
movl -0x98(%rbp), %edx
movl -0x10(%rbp), %ecx
movl -0x100(%rbp), %r8d
movsd -0xf8(%rbp), %xmm0
movsd -0xe8(%rbp), %xmm1
movl -0xe0(%rbp), %r9d
leaq 0x20a32(%rip), %rdi     # 0x50a00
movb $0x2, %al
callq 0x5060
jmp 0x2ffd7
jmp 0x2ffe8
movq -0x80(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x2ffea
movq -0xd8(%rbp), %rax
movq %rax, -0x178(%rbp)
cmpq $0x0, %rax
je 0x3001b
movq -0x178(%rbp), %rdi
callq 0xd3a0
movq -0x178(%rbp), %rdi
movl $0x110, %esi            # imm = 0x110
callq 0x52e0
jmp 0x3001d
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x2fc22
jmp 0x3002d
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x2f792
cmpq $0x0, -0x78(%rbp)
je 0x30051
movq -0x78(%rbp), %rdi
callq 0x5380
cmpq $0x0, -0x80(%rbp)
je 0x30061
movq -0x80(%rbp), %rdi
callq 0x5380
cmpq $0x0, -0x88(%rbp)
je 0x30077
movq -0x88(%rbp), %rdi
callq 0x5380
cmpq $0x0, -0x90(%rbp)
je 0x3008d
movq -0x90(%rbp), %rdi
callq 0x5380
jmp 0x3008f
movq -0x108(%rbp), %rdi
movq 0x88(%rdi), %rax
movl 0x8dc(%rax), %esi
movq 0x88(%rdi), %rax
movq 0x8f0(%rax), %rdx
callq 0x1a9f0
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x5540
nopl (%rax,%rax)