// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblemPiGKww.cpp
// Function: HMMProblemPiGKww::GradientDescent()
NUMBER HMMProblemPiGKww::GradientDescent() {
	NCAT k, g, x;
    NPAR nS = this->p->nS; NPAR nO = this->p->nO; NCAT nK = this->p->nK, nG = this->p->nG;
    NUMBER loglik = 0;
    FitResult fr;

//    // all together
//    NUMBER ** copyPI = init2D<NUMBER>((NDAT)this->sizes[0], (NDAT)nS);
//    NUMBER ** copyPIg = init2D<NUMBER>(nG, (NDAT)nS);
//    NUMBER *** copyA =  init3D<NUMBER>((NDAT)this->sizes[1], (NDAT)nS, (NDAT)nS);
//    NUMBER *** copyB =  init3D<NUMBER>((NDAT)this->sizes[2], (NDAT)nS, (NDAT)nO);

    //
	// 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(nS, nO, nK, 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
        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;
        
        
        int i = 0; // count runs
        while(skip_k<nK || skip_g<nG /*|| frww.conv==0*/ ) {
            //
            // Skills first
            //
            for(k=0; k<nK && skip_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;
                FitBit *fb = new FitBit(nS, nO, nK, nG, this->p->tol, this->p->tol_mode);
                // link and fit
                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);
                }
                
//                NCAT xndat = this->p->k_numg[k];
//                struct data** x_data = this->p->k_g_data[k];
//                cpy1D<NUMBER>(this->pi[k],copyPI[k],nS); /*prep hide*/
                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) {
                    if(fr.iter==1 /*e<=this->p->tol*/ || skip_g==nG) { // converged quick, or don't care (others all converged
                        iter_qual_skill[k]++;
                        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
                            skip_k++;
                            if( !this->p->quiet && ( /*(!conv && iter<this->p->maxiter) ||*/ (fr.conv || fr.iter==this->p->maxiter) )) {
                                computeAlphaAndPOParam(fb->xndat, fb->x_data);
                                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
//                swap1D<NUMBER>(this->pi[k],copyPI[k],nS); /*hide*/
                delete fb;
            } // for all skills
            //
            // PIg second
            //
            for(g=0; g<nG && skip_g<nG; g++) { // for all PI-by-user
                if(iter_qual_group[g]==iterations_to_qualify || iter_fail_group[g]==iterations_to_qualify)
                    continue;
                FitBit *fb = new FitBit(nS, nO, nK, nG, this->p->tol, this->p->tol_mode);
//                NCAT xndat = this->p->g_numk[g];
//                struct data** x_data = this->p->g_k_data[g];
//                cpy1D<NUMBER>(this->PIg[g],copyPIg[g],nS); /*prep hide*/
                // vvvvvvvvvvvvvvvvvvvvv ONLY PART THAT IS DIFFERENT FROM others
                fb->link(this->getPIg(g), NULL, NULL, this->p->g_numk[g], this->p->g_k_data[g]);
                fb->Cslice = 1;
                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);
                }
                // decide on convergence
                fr = GradientDescentBit(fb);
				
				// count number of concecutive failures
				if(fr.iter==this->p->maxiter) {
					iter_fail_group[g]++;
				} else {
					iter_fail_group[g]=0;
				}
				
                if(i>=first_iteration_qualify) {
                    if(fr.iter==1 /*e<=this->p->tol*/ || skip_k==nK) { // converged quick, or don't care (others all converged
                        iter_qual_group[g]++;
                        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
                            skip_g++;
                            if( !this->p->quiet && ( /*(!conv && iter<this->p->maxiter) ||*/ (fr.conv || fr.iter==this->p->maxiter) )) {
                                computeAlphaAndPOParam(fb->xndat, fb->x_data);
                                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
//                swap1D<NUMBER>(this->PIg[g],copyPIg[g],nS); /*hide*/
            } // for all groups
            
//            // vvv temporary explorative
//            NCAT xndat = this->p->nSeq;
//            struct data** x_data = this->p->k_data;
//            
//            this->ww[0]=1; this->ww[1]=1; this->ww[2]=0;
//            computeAlphaAndPOParam(xndat, x_data);
//            NUMBER l1 = loglik = getSumLogPOPara(this->p->nSeq, this->p->k_data);
//            
//            this->ww[0]=1.01; this->ww[1]=1; this->ww[2]=0;
//            computeAlphaAndPOParam(xndat, x_data);
//            NUMBER l2 = loglik = getSumLogPOPara(this->p->nSeq, this->p->k_data);
//
//            this->ww[0]=1.05; this->ww[1]=1; this->ww[2]=0;
//            computeAlphaAndPOParam(xndat, x_data);
//            NUMBER l3 = loglik = getSumLogPOPara(this->p->nSeq, this->p->k_data);
//            // ^^^ temporary explorative
//            
            
            
            //
            // ww third
            //
            // fit bit and for result for ww
            FitResult frww;
            FitBit *fbww = new FitBit(nS, nO, nK, nG, this->p->tol, 1/*do project to simplex*/);
            fbww->link(this->ww, NULL, NULL, this->p->nSeq, this->p->k_data);

            fbww->init(FBS_PARm1);
            fbww->init(FBS_GRAD);
            if(this->p->solver==METHOD_CGD) {
                fbww->init(FBS_GRADm1);
                fbww->init(FBS_DIRm1);
            }
//            NCAT xndat = this->p->nSeq;
//            struct data** x_data = this->p->k_data;
            computeAlphaAndPOParam(fbww->xndat, fbww->x_data);
//            loglik = getSumLogPOPara(this->p->nSeq, this->p->k_data);
            bool non01constraints = this->non01constraints;
            this->non01constraints = false;
            frww = GradientDescentBit(fbww);
            this->non01constraints = non01constraints;
//            loglik = getSumLogPOPara(this->p->nSeq, this->p->k_data);
            
//            // unhide
//            cpy2D<NUMBER>(copyPI,this->PI,nK,nS);
//            cpy2D<NUMBER>(copyPIg,this->PIg,nG,nS);
//            cpy3D<NUMBER>(copyA,this->A,nK,nS,nS);
//            cpy3D<NUMBER>(copyB,this->B,nK,nS,nS);
            delete fbww;
            i++;
        }
        // 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
    loglik = getSumLogPOPara(this->p->nSeq, this->p->k_data);
    return loglik;

//    // all together
//    if(copyPI!=NULL) free2D(copyPI,(NDAT)this->sizes[0]);
//    if(copyPIg!=NULL) free2D(copyPIg,(NDAT)nG);
//    if(copyA !=NULL) free3D(copyA, (NDAT)this->sizes[1], (NDAT)nS);
//    if(copyB !=NULL) free3D(copyB, (NDAT)this->sizes[2], (NDAT)nS);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq 0x88(%rdi), %rbx
movslq 0x8c0(%rbx), %r12
movslq 0x8bc(%rbx), %r15
cmpb $0x0, 0x3d(%rbx)
movsbl 0x8b8(%rbx), %ebp
movsbl 0x8b9(%rbx), %r13d
movq %rdi, (%rsp)
movq %r12, 0x10(%rsp)
movq %r15, 0x28(%rsp)
movl %r13d, 0x3c(%rsp)
jle 0x183da
movq %rdi, %r14
movl $0x110, %edi            # imm = 0x110
callq 0x4220
movq %r12, %rcx
movq %rax, %r12
movsd 0x28(%rbx), %xmm0
movsbl 0x30(%rbx), %r9d
movq %rax, %rdi
movl %ebp, %esi
movl %r13d, %edx
movl %r15d, %r8d
callq 0x81d8
movq %r14, %rdi
xorl %esi, %esi
callq 0xe1f8
movq %rax, %r15
movq (%rsp), %rdi
xorl %esi, %esi
callq 0xe230
movq %rax, %r13
movq (%rsp), %rdi
xorl %esi, %esi
callq 0xe268
movq (%rsp), %rcx
movq 0x88(%rcx), %rcx
movl 0x8dc(%rcx), %r8d
movq 0x8f0(%rcx), %r9
movq %r12, %rdi
movq %r15, %rsi
movq (%rsp), %r14
movq %r13, %rdx
movq %rax, %rcx
callq 0x8586
movq 0x88(%r14), %rax
cmpb $0x0, 0x981(%rax)
je 0x18257
andq $0x0, 0x10(%r12)
cmpb $0x0, 0x982(%rax)
je 0x18266
andq $0x0, 0x18(%r12)
cmpb $0x0, 0x983(%rax)
je 0x18275
andq $0x0, 0x20(%r12)
pushq $0x2
popq %rsi
movq %r12, %rdi
callq 0x878c
pushq $0x7
popq %rsi
movq %r12, %rdi
callq 0x878c
pushq $0x3
popq %rsi
movq %r12, %rdi
callq 0x878c
movq 0x88(%r14), %rbx
cmpb $0x3, 0x3f(%rbx)
jne 0x182c0
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x878c
pushq $0x6
popq %rsi
movq %r12, %rdi
callq 0x878c
movq 0x88(%r14), %rbx
movslq 0x8dc(%rbx), %r15
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x4120
movq %rax, %r13
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
imulq $0x18, %rcx, %rcx
movq %r13, %rdx
cmpq %rax, %rcx
je 0x1830b
movq 0x8e8(%rbx), %rsi
movl 0x58(%rsi,%rax,4), %edi
movl %edi, (%rdx)
andl $0x0, 0x58(%rsi,%rax,4)
addq $0x18, %rax
addq $0x4, %rdx
jmp 0x182ea
movl %ebp, %r14d
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
movq %r12, %rdx
callq 0x11410
movl (%r15), %ebp
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x18(%r15), %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x20(%r15), %r15d
movq 0x88(%rbx), %rbx
movl 0x8dc(%rbx), %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
imulq $0x18, %rcx, %rcx
movq %r13, %rdx
cmpq %rax, %rcx
je 0x1837b
movl (%rdx), %esi
movq 0x8e8(%rbx), %rdi
movl %esi, 0x58(%rdi,%rax,4)
addq $0x18, %rax
addq $0x4, %rdx
jmp 0x1835f
movq %r13, %rdi
callq 0x4290
cmpb $0x0, 0x3c(%rbx)
jne 0x183a8
leaq 0x155a3(%rip), %rdi     # 0x2d933
movl %ebp, %esi
movsd 0x20(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movl %r15d, %edx
movb $0x2, %al
callq 0x4050
movq %r12, %rdi
callq 0x8272
movl $0x110, %esi            # imm = 0x110
movq %r12, %rdi
callq 0x4230
movq (%rsp), %r15
movq 0x88(%r15), %rbx
cmpb $0x2, 0x3d(%rbx)
movq 0x10(%rsp), %r12
movl %r14d, %ebp
je 0x18aa4
movsbl 0x978(%rbx), %eax
movl %eax, 0x54(%rsp)
movsbl 0x979(%rbx), %eax
movl %eax, 0xc(%rsp)
pushq $0x4
popq %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x4120
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4120
movq %rax, 0x40(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x4120
movq %rax, 0x68(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq (%rsp), %r15
callq 0x4120
movq %rax, 0x60(%rsp)
xorl %r9d, %r9d
movl $0x0, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movl %ebp, 0x38(%rsp)
cmpl %r12d, %r9d
movq 0x28(%rsp), %rsi
jl 0x18468
cmpl %esi, 0x20(%rsp)
jge 0x18a75
xorl %ebp, %ebp
movl 0xc(%rsp), %edi
movq 0x40(%rsp), %r8
cmpq %r12, %rbp
jge 0x18709
cmpl %r12d, %r9d
jge 0x18709
movq 0x30(%rsp), %rax
movl (%rax,%rbp,4), %ecx
cmpl %edi, %ecx
je 0x18701
movq 0x68(%rsp), %rax
movl (%rax,%rbp,4), %ebx
cmpl %edi, %ebx
je 0x18701
movl %ecx, 0x48(%rsp)
movl %r9d, 0x8(%rsp)
movl $0x110, %edi            # imm = 0x110
movq %rsi, %r14
callq 0x4220
movq %rax, %r13
movq 0x88(%r15), %rax
movsd 0x28(%rax), %xmm0
movsbl 0x30(%rax), %r9d
movq %r13, %rdi
movl 0x38(%rsp), %esi
movl 0x3c(%rsp), %edx
movl %r12d, %ecx
movl %r14d, %r8d
callq 0x81d8
movq %r15, %rdi
movl %ebp, %esi
callq 0xe1f8
movq %rax, %r15
movq (%rsp), %rdi
movl %ebp, %esi
callq 0xe230
movq %rax, %r12
movq (%rsp), %rdi
movl %ebp, %esi
callq 0xe268
movq (%rsp), %rcx
movq 0x88(%rcx), %rcx
movq 0x8e0(%rcx), %rdx
movq 0x8f8(%rcx), %rcx
movl (%rdx,%rbp,4), %r8d
movq (%rcx,%rbp,8), %r9
movq %r13, %rdi
movq %r15, %rsi
movq (%rsp), %r15
movq %r12, %rdx
movq %rax, %rcx
callq 0x8586
movq 0x88(%r15), %rax
cmpb $0x0, 0x981(%rax)
je 0x18556
andq $0x0, 0x10(%r13)
cmpb $0x0, 0x982(%rax)
je 0x18564
andq $0x0, 0x18(%r13)
cmpb $0x0, 0x983(%rax)
je 0x18572
andq $0x0, 0x20(%r13)
movb $0x0, 0xfa(%r13)
movq %r13, %rdi
pushq $0x2
popq %rsi
callq 0x878c
movq %r13, %rdi
pushq $0x7
popq %rsi
callq 0x878c
movq %r13, %rdi
pushq $0x3
popq %rsi
callq 0x878c
movq 0x88(%r15), %rax
cmpb $0x3, 0x3f(%rax)
jne 0x185be
movq %r13, %rdi
pushq $0x4
popq %rsi
callq 0x878c
movq %r13, %rdi
pushq $0x6
popq %rsi
callq 0x878c
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x11410
movl 0x70(%rsp), %r12d
movsd 0x78(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movq %r15, %rax
movl 0x90(%rsp), %r15d
movq 0x88(%rax), %rax
movl 0x38(%rax), %ecx
incl %ebx
cmpl %ecx, %r12d
movl $0x0, %edx
cmovnel %edx, %ebx
movq 0x68(%rsp), %rdx
movl %ebx, (%rdx,%rbp,4)
movl 0x1c(%rsp), %edx
cmpl 0x54(%rsp), %edx
jl 0x186d0
cmpl $0x1, %r12d
movq 0x28(%rsp), %rdx
je 0x18639
cmpl %edx, 0x20(%rsp)
je 0x18639
movq 0x30(%rsp), %rax
andl $0x0, (%rax,%rbp,4)
jmp 0x186d0
movl 0x48(%rsp), %edi
incl %edi
movq 0x30(%rsp), %rsi
movl %edi, (%rsi,%rbp,4)
movl 0xc(%rsp), %esi
cmpl %esi, %edi
je 0x18655
cmpl %edx, 0x20(%rsp)
jne 0x186d0
cmpl %edx, 0x20(%rsp)
movl 0x8(%rsp), %edi
jne 0x18667
movq 0x30(%rsp), %rdx
movl %esi, (%rdx,%rbp,4)
cmpl %ecx, %r12d
sete %cl
incl %edi
testl %r15d, %r15d
setne %dl
cmpb $0x0, 0x3c(%rax)
movl %edi, 0x8(%rsp)
jne 0x186d0
orb %cl, %dl
je 0x186d0
movl 0xe8(%r13), %esi
movq 0xf0(%r13), %rdx
movq (%rsp), %rdi
movsd %xmm0, 0x58(%rsp)
movsd %xmm1, 0x48(%rsp)
callq 0xe7b0
leaq 0x152c3(%rip), %rdi     # 0x2d970
movl 0x1c(%rsp), %esi
movl 0x8(%rsp), %edx
movl %ebp, %ecx
movl %r12d, %r8d
movsd 0x58(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movl %r15d, %r9d
movb $0x2, %al
callq 0x4050
movq %r13, %rdi
callq 0x8272
movl $0x110, %esi            # imm = 0x110
movq %r13, %rdi
callq 0x4230
movq (%rsp), %r15
movq 0x10(%rsp), %r12
movq 0x28(%rsp), %rsi
movl 0xc(%rsp), %edi
movq 0x40(%rsp), %r8
movl 0x8(%rsp), %r9d
incq %rbp
jmp 0x18473
xorl %ebp, %ebp
movl %r9d, 0x8(%rsp)
cmpq %rsi, %rbp
jge 0x1897e
cmpl %esi, 0x20(%rsp)
jge 0x1897e
movl (%r8,%rbp,4), %r14d
cmpl %edi, %r14d
je 0x188e6
movq 0x60(%rsp), %rax
movl (%rax,%rbp,4), %ebx
cmpl %edi, %ebx
je 0x188e6
movl $0x110, %edi            # imm = 0x110
callq 0x4220
movq %rax, %r13
movq 0x88(%r15), %rax
movsd 0x28(%rax), %xmm0
movsbl 0x30(%rax), %r9d
movq %r13, %rdi
movl 0x38(%rsp), %esi
movl 0x3c(%rsp), %edx
movl %r12d, %ecx
movq 0x28(%rsp), %r8
callq 0x81d8
movq (%r15), %rax
movq %r15, %rdi
movl %ebp, %esi
callq *0xc0(%rax)
movq 0x88(%r15), %rcx
movq 0x900(%rcx), %rdx
movq 0x910(%rcx), %rcx
movl (%rdx,%rbp,4), %r8d
movq (%rcx,%rbp,8), %r9
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x8586
movb $0x1, 0xfa(%r13)
movq 0x88(%r15), %rax
cmpb $0x0, 0x981(%rax)
je 0x187cd
andq $0x0, 0x10(%r13)
cmpb $0x0, 0x982(%rax)
je 0x187db
andq $0x0, 0x18(%r13)
cmpb $0x0, 0x983(%rax)
je 0x187e9
andq $0x0, 0x20(%r13)
movq %r13, %rdi
pushq $0x2
popq %rsi
callq 0x878c
movq %r13, %rdi
pushq $0x7
popq %rsi
callq 0x878c
movq %r13, %rdi
pushq $0x3
popq %rsi
callq 0x878c
movq 0x88(%r15), %rax
cmpb $0x3, 0x3f(%rax)
jne 0x1882d
movq %r13, %rdi
pushq $0x4
popq %rsi
callq 0x878c
movq %r13, %rdi
pushq $0x6
popq %rsi
callq 0x878c
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x11410
movq %r15, %rax
movl 0x70(%rsp), %r15d
movsd 0x78(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movl 0x90(%rsp), %r12d
movq 0x88(%rax), %rax
movl 0x38(%rax), %ecx
incl %ebx
cmpl %ecx, %r15d
movl $0x0, %edx
cmovnel %edx, %ebx
movq 0x60(%rsp), %rdx
movl %ebx, (%rdx,%rbp,4)
movl 0x1c(%rsp), %edx
cmpl 0x54(%rsp), %edx
jge 0x188a3
movq (%rsp), %r15
movq 0x10(%rsp), %r12
movq 0x28(%rsp), %rsi
movl 0xc(%rsp), %edi
movq 0x40(%rsp), %r8
movl 0x8(%rsp), %r9d
jmp 0x188e6
cmpl $0x1, %r15d
movq 0x28(%rsp), %rsi
movl 0xc(%rsp), %edi
movq 0x40(%rsp), %r8
movl 0x8(%rsp), %r9d
je 0x188ca
cmpl 0x10(%rsp), %r9d
je 0x188ca
andl $0x0, (%r8,%rbp,4)
jmp 0x188dd
incl %r14d
movl %r14d, (%r8,%rbp,4)
cmpl %edi, %r14d
je 0x188ee
cmpl 0x10(%rsp), %r9d
je 0x188ee
movq (%rsp), %r15
movq 0x10(%rsp), %r12
incq %rbp
jmp 0x18710
cmpl 0x10(%rsp), %r9d
jne 0x188f9
movl %edi, (%r8,%rbp,4)
cmpl %ecx, %r15d
sete %cl
incl 0x20(%rsp)
testl %r12d, %r12d
setne %dl
cmpb $0x0, 0x3c(%rax)
jne 0x188dd
orb %cl, %dl
je 0x188dd
movl 0xe8(%r13), %esi
movq 0xf0(%r13), %rdx
movq (%rsp), %rbx
movq %rbx, %rdi
movsd %xmm0, 0x58(%rsp)
movsd %xmm1, 0x48(%rsp)
callq 0xe7b0
leaq 0x1507c(%rip), %rdi     # 0x2d9bc
movl 0x1c(%rsp), %esi
movl 0x20(%rsp), %edx
movl %ebp, %ecx
movl %r15d, %r8d
movq %rbx, %r15
movsd 0x58(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movl %r12d, %r9d
movb $0x2, %al
callq 0x4050
movl 0x8(%rsp), %r9d
movq 0x40(%rsp), %r8
movl 0xc(%rsp), %edi
movq 0x28(%rsp), %rsi
jmp 0x188e1
movl %r9d, %r14d
movl $0x110, %edi            # imm = 0x110
movq %rsi, %rbx
callq 0x4220
movq %rax, %r13
movq 0x88(%r15), %rax
movsd 0x28(%rax), %xmm0
movq %r13, %rdi
movl 0x38(%rsp), %esi
movl 0x3c(%rsp), %edx
movl %r12d, %ecx
movl %ebx, %r8d
pushq $0x1
popq %r9
callq 0x81d8
movq 0x88(%r15), %rax
movq 0x98(%r15), %rsi
movl 0x8dc(%rax), %r8d
movq 0x8f0(%rax), %r9
movq %r13, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x8586
movq %r13, %rdi
pushq $0x2
popq %rsi
callq 0x878c
movq %r13, %rdi
pushq $0x3
popq %rsi
callq 0x878c
movq 0x88(%r15), %rax
cmpb $0x3, 0x3f(%rax)
jne 0x18a18
movq %r13, %rdi
pushq $0x4
popq %rsi
callq 0x878c
movq %r13, %rdi
pushq $0x6
popq %rsi
callq 0x878c
movl 0xe8(%r13), %esi
movq 0xf0(%r13), %rdx
movq %r15, %rdi
callq 0xe7b0
movb 0x80(%r15), %bl
movb $0x0, 0x80(%r15)
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x11410
movb %bl, 0x80(%r15)
movq %r13, %rdi
callq 0x8272
movl $0x110, %esi            # imm = 0x110
movq %r13, %rdi
callq 0x4230
incl 0x1c(%rsp)
movl %r14d, %r9d
jmp 0x18454
movq 0x30(%rsp), %rdi
callq 0x4290
movq 0x40(%rsp), %rdi
callq 0x4290
movq 0x68(%rsp), %rdi
callq 0x4290
movq 0x60(%rsp), %rdi
callq 0x4290
movq 0x88(%r15), %rbx
movl 0x8dc(%rbx), %esi
movq 0x8f0(%rbx), %rdx
movq %r15, %rdi
callq 0xe400
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x110, %esi            # imm = 0x110
movq %r12, %rdi
jmp 0x18ae7
jmp 0x18adc
jmp 0x18adc
movq %rax, %rbx
movl $0x110, %esi            # imm = 0x110
movq %r13, %rdi
callq 0x4230
movq %rbx, %rdi
callq 0x4450