// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblem.cpp
// Function: HMMProblem::predict(double*, char const*, signed char*, int*, int*, int*, int*, int*, HMMProblem**, signed char, signed char*)
void HMMProblem::predict(NUMBER* metrics, const char *filename, NPAR* dat_obs, NCAT *dat_group, NCAT *dat_skill, NCAT *dat_skill_stacked, NCAT *dat_skill_rcount, NDAT *dat_skill_rix, HMMProblem **hmms, NPAR nhmms, NPAR *hmm_idx) {
	NDAT t;
	NCAT g, k;
//	NCAT it;
	NPAR i, j, m, o, isTarget = 0;
	
	NPAR nS = hmms[0]->p->nS, nO = hmms[0]->p->nO;
	NCAT nK = hmms[0]->p->nK, nG = hmms[0]->p->nG;
	NDAT N  = hmms[0]->p->N;
	NDAT N_null  = hmms[0]->p->N_null;
	char f_multiskill = hmms[0]->p->multiskill;
	char f_update_known = hmms[0]->p->update_known;
	char f_update_unknown = hmms[0]->p->update_unknown;
	int f_predictions = hmms[0]->p->predictions;
	int f_metrics_target_obs = hmms[0]->p->metrics_target_obs;
	for(i=1; i<nhmms; i++) {
		if( nS != hmms[i]->p->nS || nO != hmms[i]->p->nO || nK != hmms[i]->p->nK ||
		   nG != hmms[i]->p->nG || N != hmms[i]->p->N || N_null != hmms[i]->p->N_null ||
		   f_multiskill != hmms[i]->p->multiskill ||
		   f_update_known != hmms[i]->p->update_known ||
		   f_update_unknown != hmms[i]->p->update_unknown ||
		   f_predictions != hmms[i]->p->predictions ||
		   f_metrics_target_obs != hmms[i]->p->metrics_target_obs) {
			fprintf(stderr,"Error! One of count variables (N, N_null, nS, nO, nK, nG) or flags (multiskill, predictions, metrics_target_obs, update_known, update_unknown) does not have the same value across multiple models\n");
			exit(1);
		}
	}
	
	NUMBER *local_pred = init1D<NUMBER>(nO); // local prediction
	NUMBER *pLe = init1D<NUMBER>(nS);// p(L|evidence);
	NUMBER pLe_denom; // p(L|evidence) denominator
	NUMBER ***group_skill_map = init3D<NUMBER>(nG, nK, nS);//UNBOOST
//   ::boost::numeric::ublas::mapped_matrix<NUMBER*> gsm (nG, nK);//BOOST
	
	NUMBER ll = 0.0, ll_no_null = 0.0, rmse = 0.0, rmse_no_null = 0.0, accuracy = 0.0, accuracy_no_null = 0.0;
	NUMBER p;
	
//	NUMBER *dat_predict = Calloc(NUMBER, N * nO);
	
	
	FILE *fid = NULL; // file for storing prediction should that be necessary
	if(f_predictions>0) {
		fid = fopen(filename,"w");
		if(fid == NULL)
		{
			fprintf(stderr,"Can't write output model file %s\n",filename);
			exit(1);
		}
	}
	
	// initialize
	struct data* dt = new struct data;
	NDAT count = 0;
//	NDAT d = 0;
	HMMProblem *hmm;
    
    // call to global pre-process
    hmms[0]->preprocessglobal(); // nothing for BKT, computes Elo values for Elo-based
	
	for(t=0; t<N; t++) {
//		output_this = true;
		o = dat_obs[t];
		g = dat_group[t];
		dt->g = g;
        dt->t = t; // statefulness
		
		hmm = (nhmms==1)?hmms[0]:hmms[hmm_idx[t]]; // if just one hmm, use 0's, otherwise take the index value
		
		isTarget = hmm->p->metrics_target_obs == o;
		NCAT *ar;
		int n;
		if(f_multiskill==0) {
			k = dat_skill[t];
			ar = &k;
			n = 1;
		} else {
			k = dat_skill_stacked[ dat_skill_rix[t] ];
			ar = &dat_skill_stacked[ dat_skill_rix[t] ];
			n = dat_skill_rcount[t];
		}
		
//		// prescriptive pretest
//		it = this->p->dat_item[t];
//		string item_s = this->p->map_step_bwd->find((NCAT)it)->second;
//		std::size_t found_prev = 0, found = item_s.find("PINIT-MANUAL-SET");
//		if (found!=std::string::npos) { // set manually
//			// find last divider
//			found = item_s.find("__");
//			while(found!=std::string::npos) {
//				found_prev = found;
//				found = item_s.find("__", found+1);
//			}
//			// get number
//			NUMBER newPLearn = (NUMBER)atof( item_s.substr(found_prev+2, item_s.length()-2).c_str() );
//			group_skill_map[g][ ar[0] ][0] = newPLearn;
//			for(i=1; i<nS; i++) {
//				group_skill_map[g][ ar[0] ][i] = (1-newPLearn)/(nS-1);
//			}
//			continue;
//		}
		
		// deal with null skill
		if(ar[0]<0) { // if no skill label
			isTarget = hmm->null_skill_obs==o;
			rmse += pow(isTarget - hmm->null_obs_ratio[f_metrics_target_obs],2);
			accuracy += isTarget == (hmm->null_obs_ratio[f_metrics_target_obs]==maxn(hmm->null_obs_ratio,nO) && hmm->null_obs_ratio[f_metrics_target_obs] > 1/nO);
//			rmse += pow(isTarget - hmm->null_skill_obs_prob,2);
//			accuracy += isTarget == (hmm->null_skill_obs_prob>=0.5);
			ll -= isTarget*safelog(hmm->null_skill_obs_prob) + (1-isTarget)*safelog(1 - hmm->null_skill_obs_prob);
            if(f_predictions>0 /*&& output_this*/) { // write predictions file if it was opened
                for(m=0; m<nO; m++) {
                    fprintf(fid,"%12.10f%s",hmm->null_obs_ratio[m],(m<(nO-1))?"\t":"\n");
    //				d = (NDAT)m*N + t;
    //				dat_predict[ d ] = hmm->null_obs_ratio[m];
                }
            }
			continue;
		}
		// check if {g,k}'s were initialized
		for(int l=0; l<n; l++) {
			k = ar[l];
//          NUMBER *z = gsm(g,k); //BOOST
//          if( z==NULL )//BOOST
			if( group_skill_map[g][k][0]==0)//UNBOOST
			{
				dt->k = k;
//                NUMBER * pLbit = Calloc(NUMBER, nS);//BOOST
				
				for(i=0; i<nS; i++) {
					group_skill_map[g][k][i] = hmm->getPI(dt,i);//UNBOOST
//                    pLbit[i] = hmm->getPI(dt,i);//BOOST
					count++;
				}
//              gsm(g,k) = pLbit; //BOOST
			}// pLo/pL not set
		}// for all skills at this transaction
		
		// produce prediction and copy to result
//        hmm->producePCorrect(group_skill_map, local_pred, ar, n, dt); //UNBOOST
        hmm->producePCorrect(group_skill_map, local_pred, t); //UNBOOST
//		hmm->producePCorrectBoost(&gsm, local_pred, t); //BOOST
		projectsimplex(local_pred, nO); // addition to make sure there's not side effects
		
        // write prediction out (before pKnown update)
        if(f_predictions>0 /*&& output_this*/) { // write predictions file if it was opened
            for(m=0; m<nO; m++) {
                fprintf(fid,"%12.10f%s",local_pred[m],(m<(nO-1))?"\t": ((f_predictions==1)?"\n":"\t") );// if we print states of KCs, continut
                //				d = (NDAT)m*N + t;
                //				dat_predict[ d ] = local_pred[m];
            }
            if(f_predictions==2) { // if we print out states of KC's as welll
                for(int l=0; l<n; l++) { // all KC here
                    fprintf(fid,"%12.10f%s",group_skill_map[g][ ar[l] ][0], (l==(n-1) && l==(n-1))?"\n":"\t"); // nnon boost // if end of all states: end line//UNBOOST
                    //					fprintf(fid,"%12.10f%s",gsm(g, ar[l] )[0], (l==(n-1) && l==(n-1))?"\n":"\t"); // if end of all states: end line //BOOST
                }
            }
        }
        
		// if necessary guess the obsevaion using Pi and B
		if(f_update_known=='g') {
			NUMBER max_local_pred=0;
			NPAR ix_local_pred=0;
			for(m=0; m<nO; m++) {
				if( local_pred[m]>max_local_pred ) {
					max_local_pred = local_pred[m];
					ix_local_pred = m;
				}
			}
			o = ix_local_pred;
		}
		
        hmm->postprocesslocal(isTarget,local_pred[f_metrics_target_obs], t);
        
		// update pL
		for(int l=0; l<n; l++) {
			k = ar[l];
			dt->k = k;
//          NUMBER* pLbit = gsm(g,k); //BOOST
			
			if(o>-1) { // known observations //
				// update p(L)
				pLe_denom = 0.0;
				// 1. pLe =  (L .* B(:,o)) ./ ( L'*B(:,o)+1e-8 );
				for(i=0; i<nS; i++)
					pLe_denom += group_skill_map[g][k][i] * hmm->getB(dt,i,o);  // TODO: this is local_pred[o]!!!//UNBOOST
//                  pLe_denom += pLbit[i] * hmm->getB(dt,i,o); //BOOST
				for(i=0; i<nS; i++)
					pLe[i] = group_skill_map[g][k][i] * hmm->getB(dt,i,o) / safe0num(pLe_denom); //UNBOOST
//                  pLe[i] = pLbit[i] * hmm->getB(dt,i,o) / safe0num(pLe_denom); //BOOST
				// 2. L = (pLe'*A)';
				for(i=0; i<nS; i++)
					group_skill_map[g][k][i]= 0.0; //UNBOOST
//                  pLbit[i]= 0.0; //BOOST
                for(j=0; j<nS; j++)
                    for(i=0; i<nS; i++)
                        group_skill_map[g][k][j] += pLe[i] * hmm->getA(dt,i,j);//A[i][j]; //UNBOOST
//                    pLbit[j] += pLe[i] * hmm->getA(dt,i,j);//A[i][j]; //BOOST
			} else { // unknown observation
				// 2. L = (pL'*A)';
				for(i=0; i<nS; i++)
					pLe[i] = group_skill_map[g][k][i]; // copy first; //UNBOOST
//                  pLe[i] = pLbit[i]; // copy first; //BOOST
				for(i=0; i<nS; i++)
					group_skill_map[g][k][i] = 0.0; // erase old value //UNBOOST
//                  pLbit[i] = 0.0; // erase old value //BOOST
				for(j=0; j<nS; j++)
					for(i=0; i<nS; i++)
						group_skill_map[g][k][j] += pLe[i] * hmm->getA(dt,i,j);//UNBOOST
//               pLbit[j] += pLe[i] * hmm->getA(dt,i,j);//BOOST
			}// observations
			projectsimplex(group_skill_map[g][k], nS); // addition to make sure there's not side effects //UNBOOST
//            projectsimplex(pLbit, nS); // addition to make sure there's not side effects //BOOST
		}

        // write prediction out (AFTER pKnown update)
        if(f_predictions>0 /*&& output_this*/) { // write predictions file if it was opened
            if(f_predictions==3) { // if we print out states of KC's as welll
                for(int l=0; l<n; l++) { // all KC here
                    fprintf(fid,"%12.10f%s",group_skill_map[g][ ar[l] ][0], (l==(n-1) && l==(n-1))?"\n":"\t"); // nnon boost // if end of all states: end line//UNBOOST
                    //                    fprintf(fid,"%12.10f%s",gsm(g, ar[l] )[0], (l==(n-1) && l==(n-1))?"\n":"\t"); // if end of all states: end line //BOOST
                }
            }
        }
        
        
		rmse += pow(isTarget-local_pred[f_metrics_target_obs],2);
		rmse_no_null += pow(isTarget-local_pred[f_metrics_target_obs],2);
		accuracy += isTarget == (local_pred[f_metrics_target_obs]==maxn(local_pred,nO) && local_pred[f_metrics_target_obs]>1/nO);
		accuracy_no_null += isTarget == (local_pred[f_metrics_target_obs]==maxn(local_pred,nO) && local_pred[f_metrics_target_obs]>1/nO);
		p = safe01num(local_pred[f_metrics_target_obs]);
		ll -= safelog(  p)*   isTarget  +  safelog(1-p)*(1-isTarget);
		ll_no_null -= safelog(  p)*   isTarget  +  safelog(1-p)*(1-isTarget);
		
		// temporary experimental
//		for(int l=0; hmm->p->per_kc_rmse_acc && hmm->p->kc_counts!=NULL && l<n; l++) {
//			k = ar[l];
//			hmm->p->kc_counts[k]++;
//			hmm->p->kc_rmse[k] += pow(isTarget-local_pred[hmm->p->metrics_target_obs],2);
//			hmm->p->kc_acc[k]  += isTarget == (local_pred[hmm->p->metrics_target_obs]>=0.5);
//		}
	} // for all data
	
	// temporary experimental
//	for(int k=0; hmm->p->per_kc_rmse_acc && hmm->p->kc_counts!=NULL && k<nK; k++) {
//		hmm->p->kc_rmse[k] = sqrt(hmm->p->kc_rmse[k] / hmm->p->kc_counts[k]);
//		hmm->p->kc_acc[k]  =      hmm->p->kc_acc[k]  / hmm->p->kc_counts[k];
//	}
	
	delete(dt);
	free(local_pred);
	free(pLe);
	free3D<NUMBER>(group_skill_map, nG, nK);//UNBOOST
	
//    gsm.clear();//BOOST
//    typedef boost::numeric::ublas::mapped_matrix<NUMBER *>::iterator1 it1_t;//BOOST
//    typedef boost::numeric::ublas::mapped_matrix<NUMBER *>::iterator2 it2_t;//BOOST
//    for (it1_t itgsm1 = gsm.begin1(); itgsm1 != gsm.end1(); itgsm1++)//BOOST
//       for (it2_t itgsm2 = itgsm1.begin(); itgsm2 != itgsm1.end(); itgsm2++)//BOOST
//           free( gsm( itgsm2.index1(), itgsm2.index2() ) );//BOOST
	
	rmse = sqrt(rmse / N);
	rmse_no_null = sqrt(rmse_no_null / (N - N_null));
	if(metrics != NULL) {
		metrics[0] = ll;
		metrics[1] = ll_no_null;
		metrics[2] = rmse;
		metrics[3] = rmse_no_null;
		metrics[4] = accuracy/N;
		metrics[5] = accuracy_no_null/(N-N_null);
	}
	
	
//	if(f_predictions>0) { // close predictions file if it was opened
//		ofstream fout(filename,ios::out);
//		char str[1024];
//		if(!fout)
//		{
//			fprintf(stderr,"WARNINT! Failed to open output prediction file %s for writing\n",filename);
//			//exit(1); // do not exit with error
//		}
//		
//		for(NDAT t=0; t<N; t++) {
//			for(m=0; m<nO; m++) {
//				d = (NDAT)m*N + t;
//				sprintf(str,"%12.10f%s",dat_predict[d],(m<(nO-1))?"\t": ((f_predictions==1)?"\n":"\t") );
//				fout << str;
//			}
////			if(f_predictions==2) { // if we print out states of KC's as welll
////				if(f_multiskill==0) {
////					k = dat_skill[t];
////					ar = &k;
////					v = dat_known[t];
////					var = &v;
////					n = 1;
////				} else {
////					k = dat_skill_stacked[ dat_skill_rix[t] ];
////					ar = &dat_skill_stacked[ dat_skill_rix[t] ];
////					v = dat_known_stacked[ dat_skill_rix[t] ];
////					var = &dat_known_stacked[ dat_skill_rix[t] ];
////					n = dat_skill_rcount[t];
////				}
////				for(int l=0; l<n && ar[0]>-1; l++) { // all KC here
////					sprintf(str,"%12.10f%s",var[l], (l==(n-1) && l==(n-1))?"\n":"\t");
////					fout << str;
////				}
////			}
//		}
//		fout.close();
//	}
//	free(dat_predict);
//	
	
	if(f_predictions>0) // close predictions file if it was opened
		fclose(fid);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %r9, 0x180(%rsp)
movq %r8, 0x158(%rsp)
movq %rcx, 0x190(%rsp)
movq %rdx, 0x188(%rsp)
movq %rsi, %r8
movq %rdi, %rbx
movq 0x1f0(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq (%rax), %rax
movq 0x88(%rax), %rcx
movsbl 0x8b8(%rcx), %eax
movl %eax, 0x54(%rsp)
movsbl 0x8b9(%rcx), %esi
movl 0x8c0(%rcx), %r12d
movl 0x8bc(%rcx), %r13d
movl 0x8b0(%rcx), %ebp
movl 0x8cc(%rcx), %r14d
movb 0x918(%rcx), %al
movb %al, 0xa(%rsp)
movb 0x64(%rcx), %al
movb %al, 0x9(%rsp)
movb 0x65(%rcx), %al
movl 0x60(%rcx), %edx
movl %edx, 0xc(%rsp)
movsbq 0x5c(%rcx), %rcx
movq %rcx, 0x80(%rsp)
movb 0x1f8(%rsp), %cl
movq 0x200(%rsp), %rdx
movq %rdx, 0x168(%rsp)
movq 0x1e8(%rsp), %rdx
movq %rdx, 0x178(%rsp)
movq 0x1e0(%rsp), %rdx
movq %rdx, 0x170(%rsp)
movq %rsi, 0x78(%rsp)
movslq %esi, %rdx
movq %rdx, 0xd0(%rsp)
movb %cl, 0x1f(%rsp)
movsbq %cl, %rcx
pushq $0x1
popq %rdx
cmpq %rcx, %rdx
jge 0xfe8f
movq 0xc8(%rsp), %rsi
movq (%rsi,%rdx,8), %rsi
movq 0x88(%rsi), %rsi
movl 0x54(%rsp), %edi
cmpb 0x8b8(%rsi), %dil
jne 0xfe69
movq 0xd0(%rsp), %rdi
cmpb 0x8b9(%rsi), %dil
jne 0xfe69
cmpl 0x8c0(%rsi), %r12d
jne 0xfe69
cmpl 0x8bc(%rsi), %r13d
jne 0xfe69
cmpl 0x8b0(%rsi), %ebp
jne 0xfe69
cmpl 0x8cc(%rsi), %r14d
jne 0xfe69
movb 0xa(%rsp), %dil
cmpb 0x918(%rsi), %dil
jne 0xfe69
movb 0x9(%rsp), %dil
cmpb 0x64(%rsi), %dil
jne 0xfe69
cmpb 0x65(%rsi), %al
jne 0xfe69
movl 0xc(%rsp), %edi
cmpl 0x60(%rsi), %edi
jne 0xfe69
incq %rdx
movq 0x80(%rsp), %rdi
cmpb 0x5c(%rsi), %dil
je 0xfdd0
movq 0x29168(%rip), %rax     # 0x38fd8
movq (%rax), %rcx
leaq 0x1d71e(%rip), %rdi     # 0x2d598
pushq $0x1
popq %rdx
movl $0xc3, %esi
callq 0x44b0
pushq $0x1
popq %rdi
callq 0x42a0
movq %r8, 0x20(%rsp)
movq 0x78(%rsp), %rdi
callq 0x7dde
movq %rax, 0x68(%rsp)
movl 0x54(%rsp), %r15d
movl %r15d, %edi
callq 0x7dde
movq %rax, 0xa8(%rsp)
movl %r13d, %edi
movl %r12d, %esi
movl %r15d, %edx
callq 0xa0be
movq %rax, 0x10(%rsp)
cmpl $0x0, 0xc(%rsp)
movq %rbx, 0x128(%rsp)
movl %r14d, 0x10c(%rsp)
movl %r12d, 0x108(%rsp)
movl %r13d, 0x104(%rsp)
jle 0xff33
leaq 0x1d64d(%rip), %rsi     # 0x2d546
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x4280
movq %rax, 0x88(%rsp)
testq %rax, %rax
jne 0xff3f
movq 0x290be(%rip), %rax     # 0x38fd8
movq (%rax), %rdi
leaq 0x1d624(%rip), %rsi     # 0x2d548
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4350
jmp 0xfe87
movq $0x0, 0x88(%rsp)
pushq $0x60
popq %rdi
callq 0x4220
movq %rax, 0x48(%rsp)
movq 0xc8(%rsp), %rax
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
decq 0xd0(%rsp)
cmpl $0x1, 0xc(%rsp)
leaq 0x1c2ec(%rip), %rax     # 0x2c25d
leaq 0x1dcce(%rip), %rcx     # 0x2dc46
cmoveq %rax, %rcx
movq %rcx, 0x160(%rsp)
movq 0x78(%rsp), %rcx
leal 0x1(%rcx), %eax
cmpl $0x3, %eax
movl $0x0, %eax
cmovbl %ecx, %eax
cvtsi2sd %eax, %xmm0
movapd %xmm0, 0x140(%rsp)
movl 0x54(%rsp), %eax
testb %al, %al
movl $0x0, %edx
cmovgl %eax, %edx
testb %cl, %cl
movl $0x0, %esi
cmovgl %ecx, %esi
testl %ebp, %ebp
movl $0x0, %ecx
movl %ebp, 0x100(%rsp)
cmovgl %ebp, %ecx
movq %rcx, 0x198(%rsp)
movl $0xff, %r13d
andl %r13d, %edx
movq %rdx, 0x58(%rsp)
andl %r13d, %esi
movq %rsi, 0xf8(%rsp)
andl %eax, %r13d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x130(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0xe0(%rsp)
movsd %xmm0, 0xd8(%rsp)
movsd %xmm0, 0xe8(%rsp)
xorl %r15d, %r15d
movsd %xmm0, 0xa0(%rsp)
cmpq 0x198(%rsp), %r15
je 0x109e2
movq 0x188(%rsp), %rax
movb (%rax,%r15), %al
movb %al, 0x8(%rsp)
movq 0x190(%rsp), %rax
movslq (%rax,%r15,4), %rbp
movq 0x48(%rsp), %rax
movl %ebp, 0x5c(%rax)
movl %r15d, 0x8(%rax)
movq 0xc8(%rsp), %rax
cmpb $0x1, 0x1f(%rsp)
je 0x10087
movq 0x168(%rsp), %rax
movsbq (%rax,%r15), %rax
movq 0xc8(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq %r15, 0x60(%rsp)
movq (%rax), %r12
movq 0x88(%r12), %rax
movb 0x5c(%rax), %al
movb %al, 0xb(%rsp)
cmpb $0x0, 0xa(%rsp)
je 0x100dc
movq 0x178(%rsp), %rax
movq 0x60(%rsp), %rdx
movslq (%rax,%rdx,4), %rax
movq 0x180(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq 0x170(%rsp), %rcx
movl (%rcx,%rdx,4), %ecx
movq %rcx, 0xc0(%rsp)
movq %rax, 0x38(%rsp)
jmp 0x10102
movq 0x158(%rsp), %rax
movq 0x60(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
leaq 0x74(%rsp), %rcx
movq %rcx, 0x38(%rsp)
pushq $0x1
popq %rcx
movq %rcx, 0xc0(%rsp)
movl (%rax), %eax
movl %eax, 0x74(%rsp)
movapd 0x130(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm0, 0x110(%rsp)
testl %eax, %eax
js 0x107ee
movq 0xc0(%rsp), %rax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, 0xb0(%rsp)
xorl %ebx, %ebx
cmpq 0xb0(%rsp), %rbx
je 0x101ba
movq 0x38(%rsp), %rax
movl (%rax,%rbx,4), %eax
movl %eax, 0x74(%rsp)
movq 0x10(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movslq %eax, %r14
movq (%rcx,%r14,8), %rcx
movsd (%rcx), %xmm0
ucomisd 0x1c78c(%rip), %xmm0    # 0x2c900
jne 0x101b5
jp 0x101b5
movq 0x48(%rsp), %rcx
movl %eax, 0x58(%rcx)
xorl %r15d, %r15d
cmpq %r15, 0x58(%rsp)
je 0x101b5
movq (%r12), %rax
movsbl %r15b, %edx
movq %r12, %rdi
movq 0x48(%rsp), %rsi
callq *0x10(%rax)
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
jmp 0x10183
incq %rbx
jmp 0x10142
movq (%r12), %rax
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq 0x68(%rsp), %rbx
movq %rbx, %rdx
movq 0x60(%rsp), %rcx
callq *0x50(%rax)
movq %rbx, %rdi
movq 0x78(%rsp), %rsi
callq 0x5600
cmpl $0x0, 0xc(%rsp)
jle 0x102a6
xorl %ebx, %ebx
movq 0x160(%rsp), %r14
cmpq %rbx, 0xf8(%rsp)
je 0x1023d
movq 0x68(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
cmpq 0xd0(%rsp), %rbx
movq %r14, %rdx
leaq 0x1da28(%rip), %rax     # 0x2dc46
cmovlq %rax, %rdx
movq 0x88(%rsp), %rdi
leaq 0x1d6ee(%rip), %rsi     # 0x2d91f
movb $0x1, %al
callq 0x4350
incq %rbx
jmp 0x101f8
cmpl $0x2, 0xc(%rsp)
jne 0x102a6
movq 0xc0(%rsp), %rax
leal -0x1(%rax), %ebx
xorl %r14d, %r14d
cmpq %r14, 0xb0(%rsp)
je 0x102a6
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq 0x38(%rsp), %rcx
movslq (%rcx,%r14,4), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
cmpq %r14, %rbx
leaq 0x1d9c6(%rip), %rdx     # 0x2dc46
leaq 0x1bfd6(%rip), %rax     # 0x2c25d
cmoveq %rax, %rdx
movq 0x88(%rsp), %rdi
leaq 0x1d685(%rip), %rsi     # 0x2d91f
movb $0x1, %al
callq 0x4350
incq %r14
jmp 0x10252
movb 0x8(%rsp), %al
movl %eax, 0x90(%rsp)
cmpb $0x67, 0x9(%rsp)
jne 0x10302
xorpd %xmm0, %xmm0
xorl %eax, %eax
movl $0x0, 0x90(%rsp)
cmpq %rax, 0xf8(%rsp)
je 0x10302
movq 0x68(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
movl 0x90(%rsp), %ecx
movzbl %cl, %ecx
cmoval %eax, %ecx
movl %ecx, 0x90(%rsp)
maxsd %xmm0, %xmm1
incq %rax
movapd %xmm1, %xmm0
jmp 0x102c9
movsd 0x1c5e6(%rip), %xmm0    # 0x2c8f0
movb 0xb(%rsp), %al
cmpb 0x8(%rsp), %al
je 0x10318
xorpd %xmm0, %xmm0
movq 0x80(%rsp), %rax
movq 0x68(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm1
movq (%r12), %rax
movq %r12, %rdi
movsd %xmm0, 0xf0(%rsp)
movq 0x60(%rsp), %rsi
callq *0x58(%rax)
xorl %edx, %edx
cmpq 0xb0(%rsp), %rdx
je 0x105ab
movq 0x38(%rsp), %rax
movslq (%rax,%rdx,4), %r14
movl %r14d, 0x74(%rsp)
movq 0x48(%rsp), %rax
movl %r14d, 0x58(%rax)
cmpb $0x0, 0x90(%rsp)
movq %rdx, 0x1a0(%rsp)
js 0x104d6
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %r15d, %r15d
movsbl 0x90(%rsp), %ebx
cmpq %r15, 0x58(%rsp)
je 0x103e4
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r14,8), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq (%r12), %rax
movsbl %r15b, %edx
movq %r12, %rdi
movq 0x48(%rsp), %rsi
movl %ebx, %ecx
callq *0x20(%rax)
mulsd 0x40(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
incq %r15
jmp 0x1038c
xorl %r15d, %r15d
cmpq %r15, 0x58(%rsp)
je 0x10450
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r14,8), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq (%r12), %rax
movsbl %r15b, %edx
movq %r12, %rdi
movq 0x48(%rsp), %rsi
movl %ebx, %ecx
callq *0x20(%rax)
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x67cb
movsd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0xa8(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
incq %r15
jmp 0x103e7
xorl %eax, %eax
cmpq %rax, 0x58(%rsp)
je 0x10470
movq 0x10(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r14,8), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x10452
xorl %ebx, %ebx
cmpq 0x58(%rsp), %rbx
je 0x10585
xorl %r15d, %r15d
cmpq %r15, %r13
je 0x104d1
movq 0xa8(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq (%r12), %rax
movsbl %bl, %ecx
movsbl %r15b, %edx
movq %r12, %rdi
movq 0x48(%rsp), %rsi
callq *0x18(%rax)
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r14,8), %rax
mulsd 0x20(%rsp), %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
incq %r15
jmp 0x10480
incq %rbx
jmp 0x10472
xorl %eax, %eax
cmpq %rax, 0x58(%rsp)
je 0x10503
movq 0x10(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r14,8), %rcx
movsd (%rcx,%rax,8), %xmm0
movq 0xa8(%rsp), %rcx
movsd %xmm0, (%rcx,%rax,8)
incq %rax
jmp 0x104d8
xorl %eax, %eax
cmpq %rax, 0x58(%rsp)
je 0x10523
movq 0x10(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r14,8), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x10505
xorl %ebx, %ebx
cmpq 0x58(%rsp), %rbx
je 0x10585
xorl %r15d, %r15d
cmpq %r15, %r13
je 0x10580
movq 0xa8(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq (%r12), %rax
movsbl %bl, %ecx
movsbl %r15b, %edx
movq %r12, %rdi
movq 0x48(%rsp), %rsi
callq *0x18(%rax)
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r14,8), %rax
mulsd 0x20(%rsp), %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
incq %r15
jmp 0x1052f
incq %rbx
jmp 0x10525
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r14,8), %rdi
movl 0x54(%rsp), %esi
callq 0x5600
movq 0x1a0(%rsp), %rdx
incq %rdx
jmp 0x10344
cmpl $0x3, 0xc(%rsp)
movq 0x60(%rsp), %r15
movq 0xc0(%rsp), %r14
jne 0x10618
decl %r14d
xorl %ebx, %ebx
cmpq %rbx, 0xb0(%rsp)
je 0x10618
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq 0x38(%rsp), %rcx
movslq (%rcx,%rbx,4), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
cmpq %rbx, %r14
leaq 0x1d654(%rip), %rdx     # 0x2dc46
leaq 0x1bc64(%rip), %rax     # 0x2c25d
cmoveq %rax, %rdx
movq 0x88(%rsp), %rdi
leaq 0x1d313(%rip), %rsi     # 0x2d91f
movb $0x1, %al
callq 0x4350
incq %rbx
jmp 0x105c4
movq 0x80(%rsp), %rbx
movq 0x68(%rsp), %r14
movsd (%r14,%rbx,8), %xmm0
movapd %xmm0, 0x20(%rsp)
movq %r14, %rdi
movq 0x78(%rsp), %rsi
callq 0x6974
movsd (%r14,%rbx,8), %xmm3
movsd 0x1c2a4(%rip), %xmm1    # 0x2c8f0
movb 0xb(%rsp), %al
cmpb 0x8(%rsp), %al
sete %bpl
jne 0x1065d
xorps %xmm1, %xmm1
movsd %xmm1, 0x90(%rsp)
movsd 0xf0(%rsp), %xmm2
movapd 0x20(%rsp), %xmm4
subsd %xmm4, %xmm2
mulsd %xmm2, %xmm2
movsd %xmm2, 0x40(%rsp)
movsd 0xa0(%rsp), %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, 0xa0(%rsp)
cmpneqpd %xmm4, %xmm0
movapd 0x140(%rsp), %xmm1
cmpnltpd %xmm3, %xmm1
orpd %xmm0, %xmm1
movd %xmm1, %ebx
xorb %bpl, %bl
movq 0x68(%rsp), %r14
movq %r14, %rdi
movq 0x78(%rsp), %rsi
movapd %xmm3, 0x20(%rsp)
callq 0x6974
movq 0x80(%rsp), %rax
movsd (%r14,%rax,8), %xmm1
cmpneqpd 0x20(%rsp), %xmm0
movapd 0x140(%rsp), %xmm2
cmpnltpd %xmm1, %xmm2
orpd %xmm0, %xmm2
movd %xmm2, %eax
xorb %bpl, %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
movapd 0x110(%rsp), %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, 0x110(%rsp)
movapd %xmm1, %xmm0
callq 0x67a5
movapd %xmm0, %xmm1
movsd %xmm0, 0x38(%rsp)
movsd 0x1c1b9(%rip), %xmm0    # 0x2c8f0
subsd %xmm1, %xmm0
movapd %xmm0, 0xb0(%rsp)
movapd %xmm1, %xmm0
callq 0x67ff
movsd %xmm0, 0x20(%rsp)
movapd 0xb0(%rsp), %xmm0
callq 0x67ff
mulsd 0x90(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
mulsd 0xf0(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x38(%rsp), %xmm0
callq 0x67ff
movsd %xmm0, 0x38(%rsp)
movapd 0xb0(%rsp), %xmm0
callq 0x67ff
movapd 0x110(%rsp), %xmm4
movsd 0x40(%rsp), %xmm3
movsd 0x20(%rsp), %xmm2
mulsd 0x90(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
mulsd 0xf0(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0xd8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0xd8(%rsp)
jmp 0x10981
movsbl 0x8(%rsp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x28(%r12), %xmm0
movapd %xmm0, 0x90(%rsp)
movsd %xmm1, 0x38(%rsp)
ucomisd %xmm0, %xmm1
xorpd %xmm0, %xmm0
jne 0x1082b
movq 0x80(%rsp), %rbx
jp 0x10833
movsd 0x1c0c7(%rip), %xmm0    # 0x2c8f0
jmp 0x10833
movq 0x80(%rsp), %rbx
movsd %xmm0, 0xb0(%rsp)
movq 0x18(%r12), %rdi
movsd (%rdi,%rbx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x78(%rsp), %rsi
callq 0x6974
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1087e
jp 0x1087e
movq 0x18(%r12), %rax
movsd (%rax,%rbx,8), %xmm0
xorl %eax, %eax
ucomisd 0x140(%rsp), %xmm0
seta %al
jmp 0x10880
xorl %eax, %eax
movsd 0x38(%rsp), %xmm0
cmpeqsd 0x90(%rsp), %xmm0
movq %xmm0, %rcx
andl $0x1, %ecx
movsd 0xb0(%rsp), %xmm0
subsd %xmm1, %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
cmpl %ecx, %eax
sete %bl
movsd 0x30(%r12), %xmm0
callq 0x67ff
movsd %xmm0, 0x20(%rsp)
movsd 0x1c022(%rip), %xmm0    # 0x2c8f0
subsd 0x30(%r12), %xmm0
callq 0x67ff
movsd 0x20(%rsp), %xmm2
movapd 0x90(%rsp), %xmm1
cmpneqsd 0x38(%rsp), %xmm1
movsd 0x1bff8(%rip), %xmm3    # 0x2c8f0
andpd %xmm3, %xmm1
mulsd %xmm0, %xmm1
mulsd 0xb0(%rsp), %xmm2
addsd %xmm1, %xmm2
cmpl $0x0, 0xc(%rsp)
jle 0x1096d
xorl %r14d, %r14d
movsd %xmm2, 0x20(%rsp)
cmpq %r14, 0xf8(%rsp)
je 0x1096d
movq 0x18(%r12), %rax
movsd (%rax,%r14,8), %xmm0
cmpq 0xd0(%rsp), %r14
leaq 0x1b91c(%rip), %rdx     # 0x2c25d
leaq 0x1d2fe(%rip), %rax     # 0x2dc46
cmovlq %rax, %rdx
movq 0x88(%rsp), %rdi
leaq 0x1cfc4(%rip), %rsi     # 0x2d91f
movb $0x1, %al
callq 0x4350
movsd 0x20(%rsp), %xmm2
incq %r14
jmp 0x1091d
movq 0x60(%rsp), %r15
movapd 0x110(%rsp), %xmm4
movsd 0x40(%rsp), %xmm3
andb $0x1, %bl
movzbl %bl, %eax
cvtsi2sd %eax, %xmm0
movapd 0x130(%rsp), %xmm1
addsd %xmm0, %xmm1
unpcklpd %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0]
movapd %xmm1, 0x130(%rsp)
movsd 0xe8(%rsp), %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0xe0(%rsp), %xmm0
subsd %xmm2, %xmm0
movsd %xmm0, 0xe0(%rsp)
incq %r15
movsd 0xa0(%rsp), %xmm0
jmp 0x10020
pushq $0x60
popq %rsi
movq 0x48(%rsp), %rdi
callq 0x4230
movq 0x68(%rsp), %rdi
callq 0x4290
movq 0xa8(%rsp), %rdi
callq 0x4290
movq 0x10(%rsp), %rdi
movl 0x104(%rsp), %esi
movl 0x108(%rsp), %edx
callq 0xa064
movl 0x100(%rsp), %eax
movd %eax, %xmm0
subl 0x10c(%rsp), %eax
movd %eax, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
cvtdq2pd %xmm0, %xmm2
movsd 0xe8(%rsp), %xmm0
divsd %xmm2, %xmm0
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm0
movapd %xmm2, 0x20(%rsp)
jb 0x10a5f
sqrtsd %xmm0, %xmm3
jmp 0x10a72
callq 0x41a0
xorpd %xmm4, %xmm4
movapd 0x20(%rsp), %xmm2
movapd %xmm0, %xmm3
movq 0x128(%rsp), %rbx
movsd 0xa0(%rsp), %xmm0
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
divsd %xmm1, %xmm0
ucomisd %xmm4, %xmm0
jb 0x10a9b
sqrtsd %xmm0, %xmm0
jmp 0x10ab2
movsd %xmm3, 0x10(%rsp)
callq 0x41a0
movsd 0x10(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
testq %rbx, %rbx
je 0x10aee
movsd 0xe0(%rsp), %xmm1
movsd %xmm1, (%rbx)
movsd 0xd8(%rsp), %xmm1
movsd %xmm1, 0x8(%rbx)
movsd %xmm3, 0x10(%rbx)
movsd %xmm0, 0x18(%rbx)
movapd 0x130(%rsp), %xmm0
divpd %xmm2, %xmm0
movupd %xmm0, 0x20(%rbx)
cmpl $0x0, 0xc(%rsp)
jle 0x10b13
movq 0x88(%rsp), %rdi
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4210
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop