// File: /workspace/github_cpp_makefile_star2_O3/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 $0xa8, %rsp
movq %rdi, %rbp
movq 0x88(%rdi), %rbx
movb 0x8b8(%rbx), %r14b
movb 0x8b9(%rbx), %r12b
movslq 0x8c0(%rbx), %r15
movslq 0x8bc(%rbx), %r13
cmpb $0x0, 0x3d(%rbx)
movq %rdi, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r13, 0x20(%rsp)
jle 0x1c8dc
movl $0x110, %edi            # imm = 0x110
callq 0x4210
movl %r12d, %ecx
movq %rax, %r12
movsd 0x28(%rbx), %xmm0
movsbl 0x30(%rbx), %r9d
movsbl %r14b, %esi
movb %cl, 0xc(%rsp)
movsbl %cl, %edx
movq %rax, %rdi
movl %r15d, %ecx
movl %r13d, %r8d
callq 0xa858
movq %rbp, %rdi
xorl %esi, %esi
callq 0x11354
movq %rax, %r15
movq %rbp, %rdi
xorl %esi, %esi
callq 0x11370
movq %rax, %r13
movq %rbp, %rdi
xorl %esi, %esi
callq 0x1138c
movq 0x88(%rbp), %rcx
movl 0x8dc(%rcx), %r8d
movq 0x8f0(%rcx), %r9
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0xac70
movq 0x88(%rbp), %rax
cmpb $0x0, 0x981(%rax)
je 0x1c750
movq $0x0, 0x10(%r12)
cmpb $0x0, 0x982(%rax)
je 0x1c762
movq $0x0, 0x18(%r12)
cmpb $0x0, 0x983(%rax)
je 0x1c774
movq $0x0, 0x20(%r12)
movq %r12, %rdi
movl $0x2, %esi
callq 0xaf10
movq %r12, %rdi
movl $0x7, %esi
callq 0xaf10
movq %r12, %rdi
movl $0x3, %esi
callq 0xaf10
movq 0x88(%rbp), %rbx
cmpb $0x3, 0x3f(%rbx)
jne 0x1c7c9
movq %r12, %rdi
movl $0x4, %esi
callq 0xaf10
movq %r12, %rdi
movl $0x6, %esi
callq 0xaf10
movq 0x88(%rbp), %rbx
movslq 0x8dc(%rbx), %r13
movl $0x4, %esi
movq %r13, %rdi
callq 0x4130
movq %rax, %r15
testq %r13, %r13
jle 0x1c80a
movq 0x8e8(%rbx), %rax
addq $0x58, %rax
xorl %ecx, %ecx
movl (%rax), %edx
movl %edx, (%r15,%rcx,4)
movl $0x0, (%rax)
incq %rcx
addq $0x60, %rax
cmpq %rcx, %r13
jne 0x1c7f2
leaq 0x80(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x14c44
movq %rbp, %rax
movl (%r13), %ebp
movsd 0x8(%r13), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x18(%r13), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x20(%r13), %r13d
movq 0x88(%rax), %rbx
movslq 0x8dc(%rbx), %rax
testq %rax, %rax
jle 0x1c875
movq 0x8e8(%rbx), %rcx
addq $0x58, %rcx
xorl %edx, %edx
movl (%r15,%rdx,4), %esi
movl %esi, (%rcx)
incq %rdx
addq $0x60, %rcx
cmpq %rdx, %rax
jne 0x1c863
movq %r15, %rdi
callq 0x42a0
cmpb $0x0, 0x3c(%rbx)
jne 0x1c8a2
leaq 0x180df(%rip), %rdi     # 0x34969
movl %ebp, %esi
movsd 0x48(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movl %r13d, %edx
movb $0x2, %al
callq 0x4050
movq %r12, %rdi
callq 0xa8fa
movl $0x110, %esi            # imm = 0x110
movq %r12, %rdi
callq 0x4220
movq 0x10(%rsp), %rbp
movq 0x88(%rbp), %rbx
cmpb $0x2, 0x3d(%rbx)
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r13
movb 0xc(%rsp), %r12b
je 0x1d059
movsbl 0x978(%rbx), %eax
movl %eax, 0x64(%rsp)
movsbl 0x979(%rbx), %eax
movl %eax, 0x40(%rsp)
movl $0x4, %esi
movq %r15, %rdi
callq 0x4130
movq %rax, 0x58(%rsp)
movl $0x4, %esi
movq %r13, %rdi
callq 0x4130
movq %rax, 0x30(%rsp)
movl $0x4, %esi
movq %r15, %rdi
callq 0x4130
movq %rax, 0x68(%rsp)
movl $0x4, %esi
movq %r13, %rdi
callq 0x4130
movq %rax, 0x38(%rsp)
testl %r15d, %r15d
setg %al
testl %r13d, %r13d
setg %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x1d01d
movsbl %r14b, %eax
movl %eax, 0x54(%rsp)
movsbl %r12b, %eax
movl %eax, 0x50(%rsp)
movl $0x0, 0x2c(%rsp)
movl $0x0, 0xc(%rsp)
xorl %edx, %edx
testl %r15d, %r15d
movq 0x58(%rsp), %rcx
jle 0x1cc4a
cmpl %r15d, %edx
movq 0x68(%rsp), %rax
movl 0x40(%rsp), %esi
jge 0x1cc4e
xorl %r12d, %r12d
movl (%rcx,%r12,4), %r14d
cmpl %esi, %r14d
je 0x1cc37
movl (%rax,%r12,4), %ebx
cmpl %esi, %ebx
je 0x1cc37
movl %edx, 0x48(%rsp)
movl $0x110, %edi            # imm = 0x110
callq 0x4210
movq %r13, %r8
movq %rax, %r13
movq 0x88(%rbp), %rax
movsd 0x28(%rax), %xmm0
movsbl 0x30(%rax), %r9d
movq %r13, %rdi
movl 0x54(%rsp), %esi
movl 0x50(%rsp), %edx
movl %r15d, %ecx
callq 0xa858
movq %rbp, %rdi
movl %r12d, %esi
callq 0x11354
movq %rax, %r15
movq %rbp, %rdi
movl %r12d, %esi
callq 0x11370
movq %rax, %rbp
movq 0x10(%rsp), %rdi
movl %r12d, %esi
callq 0x1138c
movq 0x10(%rsp), %rcx
movq 0x88(%rcx), %rcx
movq 0x8e0(%rcx), %rdx
movq 0x8f8(%rcx), %rcx
movl (%rdx,%r12,4), %r8d
movq (%rcx,%r12,8), %r9
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq 0x10(%rsp), %r15
movq %rax, %rcx
callq 0xac70
movq 0x88(%r15), %rax
cmpb $0x0, 0x981(%rax)
je 0x1ca60
movq $0x0, 0x10(%r13)
cmpb $0x0, 0x982(%rax)
je 0x1ca71
movq $0x0, 0x18(%r13)
cmpb $0x0, 0x983(%rax)
je 0x1ca82
movq $0x0, 0x20(%r13)
movb $0x0, 0xfa(%r13)
movq %r13, %rdi
movl $0x2, %esi
callq 0xaf10
movq %r13, %rdi
movl $0x7, %esi
callq 0xaf10
movq %r13, %rdi
movl $0x3, %esi
callq 0xaf10
movq 0x88(%r15), %rax
cmpb $0x3, 0x3f(%rax)
jne 0x1cad8
movq %r13, %rdi
movl $0x4, %esi
callq 0xaf10
movq %r13, %rdi
movl $0x6, %esi
callq 0xaf10
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x14c44
movq %r15, %rax
movl 0x80(%rsp), %ebp
movsd 0x88(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
movl 0xa0(%rsp), %r15d
movq 0x88(%rax), %rax
movl 0x38(%rax), %ecx
incl %ebx
cmpl %ecx, %ebp
movl $0x0, %edx
cmovnel %edx, %ebx
movq 0x68(%rsp), %rdx
movl %ebx, (%rdx,%r12,4)
movl 0x2c(%rsp), %edx
cmpl 0x64(%rsp), %edx
jl 0x1cc01
cmpl $0x1, %ebp
je 0x1cb5d
movl 0xc(%rsp), %edx
cmpl 0x20(%rsp), %edx
je 0x1cb5d
movq 0x58(%rsp), %rax
movl $0x0, (%rax,%r12,4)
jmp 0x1cc01
incl %r14d
movq 0x58(%rsp), %rdx
movl %r14d, (%rdx,%r12,4)
movl 0x40(%rsp), %edx
cmpl %edx, %r14d
je 0x1cb80
movl 0xc(%rsp), %esi
cmpl 0x20(%rsp), %esi
jne 0x1cc01
movl 0xc(%rsp), %esi
cmpl 0x20(%rsp), %esi
movl 0x48(%rsp), %edi
jne 0x1cb97
movq 0x58(%rsp), %rsi
movl %edx, (%rsi,%r12,4)
cmpl %ecx, %ebp
sete %cl
incl %edi
testl %r15d, %r15d
setne %dl
cmpb $0x0, 0x3c(%rax)
movl %edi, 0x48(%rsp)
jne 0x1cc01
orb %cl, %dl
je 0x1cc01
movl 0xe8(%r13), %esi
movq 0xf0(%r13), %rdx
movq 0x10(%rsp), %rdi
movsd %xmm0, 0x70(%rsp)
movsd %xmm1, 0x78(%rsp)
callq 0x11908
leaq 0x17dc9(%rip), %rdi     # 0x349a6
movl 0x2c(%rsp), %esi
movl 0x48(%rsp), %edx
movl %r12d, %ecx
movl %ebp, %r8d
movsd 0x70(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
movl %r15d, %r9d
movb $0x2, %al
callq 0x4050
movq %r13, %rdi
callq 0xa8fa
movl $0x110, %esi            # imm = 0x110
movq %r13, %rdi
callq 0x4220
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r13
movq 0x68(%rsp), %rax
movl 0x40(%rsp), %esi
movq 0x58(%rsp), %rcx
movl 0x48(%rsp), %edx
incq %r12
cmpq %r15, %r12
jge 0x1cc4e
cmpl %r15d, %edx
jl 0x1c996
jmp 0x1cc4e
movl 0x40(%rsp), %esi
movl %edx, 0x48(%rsp)
testl %r13d, %r13d
setg %al
cmpl %r13d, 0xc(%rsp)
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1cf10
xorl %r12d, %r12d
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movl (%rcx,%r12,4), %r14d
cmpl %esi, %r14d
je 0x1cefd
movl (%rax,%r12,4), %ebx
cmpl %esi, %ebx
je 0x1cefd
movl $0x110, %edi            # imm = 0x110
callq 0x4210
movq %r13, %r8
movq %rax, %r13
movq 0x88(%rbp), %rax
movsd 0x28(%rax), %xmm0
movsbl 0x30(%rax), %r9d
movq %r13, %rdi
movl 0x54(%rsp), %esi
movl 0x50(%rsp), %edx
movl %r15d, %ecx
callq 0xa858
movq (%rbp), %rax
movq %rbp, %rdi
movl %r12d, %esi
callq *0xc0(%rax)
movq 0x88(%rbp), %rcx
movq 0x900(%rcx), %rdx
movq 0x910(%rcx), %rcx
movl (%rdx,%r12,4), %r8d
movq (%rcx,%r12,8), %r9
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xac70
movb $0x1, 0xfa(%r13)
movq 0x88(%rbp), %rax
cmpb $0x0, 0x981(%rax)
je 0x1cd21
movq $0x0, 0x10(%r13)
cmpb $0x0, 0x982(%rax)
je 0x1cd32
movq $0x0, 0x18(%r13)
cmpb $0x0, 0x983(%rax)
je 0x1cd43
movq $0x0, 0x20(%r13)
movq %r13, %rdi
movl $0x2, %esi
callq 0xaf10
movq %r13, %rdi
movl $0x7, %esi
callq 0xaf10
movq %r13, %rdi
movl $0x3, %esi
callq 0xaf10
movq 0x88(%rbp), %rax
cmpb $0x3, 0x3f(%rax)
jne 0x1cd91
movq %r13, %rdi
movl $0x4, %esi
callq 0xaf10
movq %r13, %rdi
movl $0x6, %esi
callq 0xaf10
leaq 0x80(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x14c44
movq %rbp, %rax
movl 0x80(%rsp), %ebp
movsd 0x88(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
movl 0xa0(%rsp), %r15d
movq 0x88(%rax), %rax
movl 0x38(%rax), %ecx
incl %ebx
cmpl %ecx, %ebp
movl $0x0, %edx
cmovnel %edx, %ebx
movq 0x38(%rsp), %rdx
movl %ebx, (%rdx,%r12,4)
movl 0x2c(%rsp), %edx
cmpl 0x64(%rsp), %edx
jge 0x1ce0e
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r13
movq 0x38(%rsp), %rax
movl 0x40(%rsp), %esi
jmp 0x1cef8
cmpl $0x1, %ebp
movl 0x40(%rsp), %esi
movl 0x48(%rsp), %edi
je 0x1ce47
cmpl 0x18(%rsp), %edi
je 0x1ce47
movq 0x30(%rsp), %rcx
movl $0x0, (%rcx,%r12,4)
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r13
movq 0x38(%rsp), %rax
jmp 0x1cefd
incl %r14d
movq 0x30(%rsp), %rdx
movl %r14d, (%rdx,%r12,4)
cmpl %esi, %r14d
je 0x1ce68
cmpl 0x18(%rsp), %edi
je 0x1ce68
movq 0x10(%rsp), %rbp
jmp 0x1cee9
cmpl 0x18(%rsp), %edi
jne 0x1ce77
movq 0x30(%rsp), %rdx
movl %esi, (%rdx,%r12,4)
cmpl %ecx, %ebp
sete %cl
incl 0xc(%rsp)
testl %r15d, %r15d
setne %dl
cmpb $0x0, 0x3c(%rax)
jne 0x1ce5e
orb %cl, %dl
je 0x1ce5e
movl 0xe8(%r13), %esi
movq 0xf0(%r13), %rdx
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movsd %xmm0, 0x70(%rsp)
movsd %xmm1, 0x78(%rsp)
callq 0x11908
leaq 0x17b34(%rip), %rdi     # 0x349f2
movl 0x2c(%rsp), %esi
movl 0xc(%rsp), %edx
movl %r12d, %ecx
movl %ebp, %r8d
movq %rbx, %rbp
movsd 0x70(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
movl %r15d, %r9d
movb $0x2, %al
callq 0x4050
movl 0x40(%rsp), %esi
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r13
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
incq %r12
cmpq %r13, %r12
jge 0x1cf10
cmpl %r13d, 0xc(%rsp)
jl 0x1cc78
movl $0x110, %edi            # imm = 0x110
callq 0x4210
movq %rax, %r12
movq 0x88(%rbp), %rax
movsd 0x28(%rax), %xmm0
movq %r12, %rdi
movl 0x54(%rsp), %esi
movl 0x50(%rsp), %edx
movl %r15d, %ecx
movl %r13d, %r8d
movl $0x1, %r9d
callq 0xa858
movq 0x88(%rbp), %rax
movq 0x98(%rbp), %rsi
movl 0x8dc(%rax), %r8d
movq 0x8f0(%rax), %r9
movq %r12, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xac70
movq %r12, %rdi
movl $0x2, %esi
callq 0xaf10
movq %r12, %rdi
movl $0x3, %esi
callq 0xaf10
movq 0x88(%rbp), %rax
cmpb $0x3, 0x3f(%rax)
jne 0x1cfae
movq %r12, %rdi
movl $0x4, %esi
callq 0xaf10
movq %r12, %rdi
movl $0x6, %esi
callq 0xaf10
movl 0xe8(%r12), %esi
movq 0xf0(%r12), %rdx
movq %rbp, %rdi
callq 0x11908
movb 0x80(%rbp), %bl
movb $0x0, 0x80(%rbp)
leaq 0x80(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x14c44
movb %bl, 0x80(%rbp)
movq %r12, %rdi
callq 0xa8fa
movl $0x110, %esi            # imm = 0x110
movq %r12, %rdi
callq 0x4220
incl 0x2c(%rsp)
movl 0x48(%rsp), %edx
cmpl %r15d, %edx
jl 0x1c973
cmpl %r13d, 0xc(%rsp)
jl 0x1c973
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x1d02c
callq 0x42a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1d03b
callq 0x42a0
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x1d04a
callq 0x42a0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x1d059
callq 0x42a0
movq 0x88(%rbp), %rax
movl 0x8dc(%rax), %esi
movq 0x8f0(%rax), %rdx
movq %rbp, %rdi
callq 0x114ae
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1d089
movq %rax, %rbx
movl $0x110, %esi            # imm = 0x110
movq %r12, %rdi
jmp 0x1d0a3
jmp 0x1d098
movq %rax, %rbx
movl $0x110, %esi            # imm = 0x110
movq %r13, %rdi
callq 0x4220
movq %rbx, %rdi
callq 0x4430