// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1c8, %rsp            # imm = 0x1C8
movq %r9, 0x158(%rsp)
movq %r8, 0x198(%rsp)
movq %rcx, 0x1c0(%rsp)
movq %rdx, 0x1b8(%rsp)
movq %rsi, %rbx
movq %rdi, %r11
movq 0x220(%rsp), %rax
movq %rax, 0x1a0(%rsp)
movb 0x218(%rsp), %dl
movq 0x210(%rsp), %r8
movq 0x208(%rsp), %rax
movq %rax, 0x1b0(%rsp)
movq 0x200(%rsp), %rax
movq %rax, 0x1a8(%rsp)
movq (%r8), %rax
movq 0x88(%rax), %rax
movsbl 0x8b8(%rax), %ecx
movl %ecx, 0xd8(%rsp)
movslq %ecx, %rcx
movq %rcx, 0x90(%rsp)
movsbl 0x8b9(%rax), %ecx
movb 0x918(%rax), %sil
movb %sil, 0x12(%rsp)
movb 0x64(%rax), %sil
movb %sil, 0xf(%rsp)
movl %ecx, 0x4c(%rsp)
movslq %ecx, %rcx
movq %rcx, 0xc0(%rsp)
movl 0x8c0(%rax), %r15d
movl 0x8bc(%rax), %r13d
movl 0x8b0(%rax), %r14d
movl 0x8cc(%rax), %ebp
movl 0x60(%rax), %ecx
movl %ecx, 0x14(%rsp)
movsbq 0x5c(%rax), %r9
movb %dl, 0x11(%rsp)
cmpb $0x2, %dl
jl 0x132f4
movb 0x65(%rax), %al
movzbl 0x11(%rsp), %ecx
movl $0x1, %edx
movq (%r8,%rdx,8), %rsi
movq 0x88(%rsi), %rsi
movq 0x90(%rsp), %rdi
cmpb 0x8b8(%rsi), %dil
jne 0x141f1
movq 0xc0(%rsp), %rdi
cmpb 0x8b9(%rsi), %dil
jne 0x141f1
cmpl 0x8c0(%rsi), %r15d
jne 0x141f1
cmpl 0x8bc(%rsi), %r13d
jne 0x141f1
cmpl 0x8b0(%rsi), %r14d
jne 0x141f1
cmpl 0x8cc(%rsi), %ebp
jne 0x141f1
movb 0x12(%rsp), %dil
cmpb 0x918(%rsi), %dil
jne 0x141f1
movb 0xf(%rsp), %dil
cmpb 0x64(%rsi), %dil
jne 0x141f1
cmpb 0x65(%rsi), %al
jne 0x141f1
movl 0x14(%rsp), %edi
cmpl 0x60(%rsi), %edi
jne 0x141f1
cmpb 0x5c(%rsi), %r9b
jne 0x141f1
incq %rdx
cmpq %rdx, %rcx
jne 0x1323f
movq %r11, 0x148(%rsp)
movq %r9, 0xf0(%rsp)
movq %r8, 0x110(%rsp)
movl $0x8, %esi
movq 0xc0(%rsp), %rdi
callq 0x4130
movq %rax, 0x80(%rsp)
movl $0x8, %esi
movq 0x90(%rsp), %r12
movq %r12, %rdi
callq 0x4130
movq %rax, 0xa8(%rsp)
movl %r13d, 0x128(%rsp)
movl %r13d, %edi
movl %r15d, 0x12c(%rsp)
movl %r15d, %esi
movl %r12d, %edx
callq 0xcaae
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x14(%rsp)
jle 0x1338c
leaq 0x211d2(%rip), %rsi     # 0x34546
movq %rbx, %rdi
callq 0x4290
movq %rax, %r15
testq %rax, %rax
jne 0x1338f
movq %rbx, %rdi
callq 0x4c03
xorl %r15d, %r15d
movl $0x60, %edi
callq 0x4210
movq %rax, 0x98(%rsp)
movq 0x110(%rsp), %rax
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
testl %r14d, %r14d
movq 0xf0(%rsp), %r8
movq 0xa8(%rsp), %r13
movq 0x148(%rsp), %rbx
jle 0x1408b
movl %ebp, 0x124(%rsp)
movq 0xc0(%rsp), %rcx
leaq -0x1(%rcx), %rax
movq %rax, 0x108(%rsp)
cmpl $0x1, 0x14(%rsp)
leaq 0x1fe63(%rip), %rax     # 0x3325d
leaq 0x21885(%rip), %rdx     # 0x34c86
cmoveq %rax, %rdx
movq %rdx, 0x190(%rsp)
cmpb $0x67, 0xf(%rsp)
setne %al
testb %cl, %cl
setle %sil
incl %ecx
cmpl $0x3, %ecx
movl $0x0, %ecx
movl 0x4c(%rsp), %edx
cmovbl %edx, %ecx
cvtsi2sd %ecx, %xmm0
movapd %xmm0, 0x180(%rsp)
movl $0xff, %edi
movl 0xd8(%rsp), %ecx
andl %edi, %ecx
movq %rcx, 0x60(%rsp)
shll $0x3, %ecx
movq %rcx, 0x160(%rsp)
andl %edx, %edi
movq %rdi, 0x100(%rsp)
orb %al, %sil
movb %sil, 0x2f(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x130(%rsp)
movq %r15, 0xe0(%rsp)
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd %xmm0, 0xf8(%rsp)
xorpd %xmm0, %xmm0
movq %r14, 0x150(%rsp)
movq 0x110(%rsp), %rcx
movq 0x18(%rsp), %r12
movq %r8, %rbp
movq 0x1b8(%rsp), %rax
movb (%rax,%r15), %dl
movq 0x1c0(%rsp), %rax
movslq (%rax,%r15,4), %rdi
movq 0x98(%rsp), %rsi
movl %edi, 0x5c(%rsi)
movl %r15d, 0x8(%rsi)
movq %rcx, %rax
cmpb $0x1, 0x11(%rsp)
je 0x134f5
movq 0x1a0(%rsp), %rax
movsbq (%rax,%r15), %rax
leaq (%rcx,%rax,8), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x88(%rax), %rax
movb 0x5c(%rax), %al
movb %al, 0x13(%rsp)
cmpb $0x0, 0x12(%rsp)
movq %r15, 0xc8(%rsp)
movq %rdi, 0x70(%rsp)
movapd %xmm0, 0x170(%rsp)
je 0x1359e
movq 0x1b0(%rsp), %rax
movslq (%rax,%r15,4), %rax
movq 0x1a8(%rsp), %rcx
movl (%rcx,%r15,4), %r8d
movq 0x158(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x6c(%rsp)
testl %ecx, %ecx
movq 0x100(%rsp), %r13
js 0x13815
movq 0x158(%rsp), %rcx
leaq (%rcx,%rax,4), %rcx
testl %r8d, %r8d
jg 0x135c9
movq %rcx, 0x88(%rsp)
movq %r8, 0xa0(%rsp)
movb %dl, 0x10(%rsp)
movl $0x0, 0x68(%rsp)
movq 0x80(%rsp), %r14
movq 0x60(%rsp), %r13
jmp 0x13699
movq 0x198(%rsp), %rax
movl (%rax,%r15,4), %eax
movl %eax, 0x6c(%rsp)
movl $0x1, %r8d
leaq 0x6c(%rsp), %rcx
testl %eax, %eax
movq 0x100(%rsp), %r13
js 0x13815
movb %dl, 0x10(%rsp)
movq %r8, 0xa0(%rsp)
movl %r8d, %eax
movq %rax, 0x50(%rsp)
movq (%r12,%rdi,8), %rax
xorl %edx, %edx
movq 0x60(%rsp), %r13
movq %rcx, 0x88(%rsp)
movq %rdx, 0x30(%rsp)
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x6c(%rsp)
movslq %ecx, %rbx
movq (%rax,%rbx,8), %rdx
movsd (%rdx), %xmm0
ucomisd 0x202f1(%rip), %xmm0    # 0x33900
jne 0x13663
jp 0x13663
movl %ecx, 0x58(%rsi)
cmpb $0x0, 0x90(%rsp)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r15
movq 0x70(%rsp), %rbp
jle 0x13663
xorl %r12d, %r12d
movq (%rdi), %rax
movsbl %r12b, %edx
movq %r13, %r14
movq %rsi, %r13
callq *0x10(%rax)
movq %r13, %rsi
movq %r14, %r13
movq (%r15,%rbp,8), %rax
movq (%rax,%rbx,8), %rcx
movsd %xmm0, (%rcx,%r12,8)
movq 0x20(%rsp), %rdi
incq %r12
cmpq %r12, %r14
jne 0x13632
movq 0x30(%rsp), %rdx
incq %rdx
cmpq 0x50(%rsp), %rdx
movq 0x88(%rsp), %rcx
jne 0x135f0
movb $0x1, %al
movl %eax, 0x68(%rsp)
movq 0x80(%rsp), %r14
movq 0xc8(%rsp), %r15
movq 0x18(%rsp), %r12
movq 0x108(%rsp), %rbp
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq *0x50(%rax)
movq %r14, %rdi
movl 0x4c(%rsp), %esi
callq 0x6836
cmpl $0x0, 0x14(%rsp)
movq 0xe0(%rsp), %r12
leaq 0x215b1(%rip), %rsi     # 0x34c86
leaq 0x21279(%rip), %rax     # 0x34955
jle 0x137d9
cmpb $0x0, 0xc0(%rsp)
movq 0x80(%rsp), %r13
movq 0x190(%rsp), %rbx
movq %rax, %r8
jle 0x13743
xorl %r14d, %r14d
movsd (%r13,%r14,8), %xmm0
cmpq %rbp, %r14
movq %rbx, %rdx
cmovlq %rsi, %rdx
movq %r12, %rdi
movq %r8, %rsi
movb $0x1, %al
movq %rbp, %r15
movq %r8, %rbp
callq 0x4330
movq 0x100(%rsp), %rax
movq %rbp, %r8
movq %r15, %rbp
leaq 0x2154b(%rip), %rsi     # 0x34c86
incq %r14
cmpq %r14, %rax
jne 0x13702
cmpl $0x2, 0x14(%rsp)
setne %al
movl 0x68(%rsp), %ecx
xorb $0x1, %cl
orb %al, %cl
movq 0x60(%rsp), %r13
movq 0x88(%rsp), %r14
movq 0x18(%rsp), %rdx
movq 0x70(%rsp), %rdi
leaq 0x1faeb(%rip), %r15     # 0x3325d
jne 0x137d9
movq %r12, %rbp
movq %r8, %rbx
movq 0xa0(%rsp), %rax
leal -0x1(%rax), %r10d
movq %r10, 0x30(%rsp)
movl %eax, %eax
movq %rax, 0x50(%rsp)
xorl %r12d, %r12d
movq (%rdx,%rdi,8), %rax
movslq (%r14,%r12,4), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
cmpq %r12, 0x30(%rsp)
movq %rsi, %rdx
cmoveq %r15, %rdx
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x4330
movq 0x70(%rsp), %rdi
movq 0x18(%rsp), %rdx
leaq 0x214b7(%rip), %rsi     # 0x34c86
incq %r12
cmpq %r12, 0x50(%rsp)
jne 0x13795
cmpb $0x67, 0xf(%rsp)
movb 0x10(%rsp), %r9b
movzbl %r9b, %r15d
movl $0x0, %eax
cmovel %eax, %r15d
cmpb $0x0, 0x2f(%rsp)
je 0x138ad
movq 0x80(%rsp), %rcx
movq 0xc8(%rsp), %rsi
movq 0x20(%rsp), %rdi
jmp 0x138f4
movsbl %dl, %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
movq 0x20(%rsp), %rax
movsd 0x28(%rax), %xmm1
movapd %xmm1, 0x70(%rsp)
movsd %xmm2, 0x88(%rsp)
ucomisd %xmm1, %xmm2
xorpd %xmm1, %xmm1
movsd %xmm1, 0xb0(%rsp)
jne 0x1385e
jp 0x1385e
movsd 0x2009b(%rip), %xmm0    # 0x338f0
movsd %xmm0, 0xb0(%rsp)
movq 0x20(%rsp), %rbx
movq 0x18(%rbx), %rdi
movsd (%rdi,%rbp,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x4c(%rsp), %esi
callq 0x8fb2
movsd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x13ebb
jp 0x13ebb
movq 0x18(%rbx), %rax
movsd (%rax,%rbp,8), %xmm0
xorl %eax, %eax
ucomisd 0x180(%rsp), %xmm0
seta %al
jmp 0x13ebd
xorpd %xmm0, %xmm0
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x80(%rsp), %rcx
movq 0x100(%rsp), %rdx
movq 0xc8(%rsp), %rsi
movq 0x20(%rsp), %rdi
movsd (%rcx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
movzbl %r15b, %r15d
cmoval %eax, %r15d
maxsd %xmm0, %xmm1
incq %rax
movapd %xmm1, %xmm0
cmpq %rax, %rdx
jne 0x138d3
movsd 0x1fff4(%rip), %xmm0    # 0x338f0
cmpb %r9b, 0x13(%rsp)
je 0x13907
xorpd %xmm0, %xmm0
movq 0xf0(%rsp), %rax
movsd (%rcx,%rax,8), %xmm1
movq (%rdi), %rax
movsd %xmm0, 0x118(%rsp)
callq *0x58(%rax)
cmpb $0x0, 0x68(%rsp)
movq 0xa0(%rsp), %rax
movq 0x18(%rsp), %rcx
je 0x13cf2
movl %eax, %eax
movq %rax, 0x168(%rsp)
xorl %ecx, %ecx
movl %r15d, 0xdc(%rsp)
movq 0x88(%rsp), %rax
movslq (%rax,%rcx,4), %rdx
movl %edx, 0x6c(%rsp)
movq 0x98(%rsp), %rax
movl %edx, 0x58(%rax)
testb %r15b, %r15b
movq %rdx, 0x50(%rsp)
movq %rcx, 0xd0(%rsp)
js 0x13b56
cmpb $0x0, 0x90(%rsp)
jle 0x13c1c
xorpd %xmm0, %xmm0
xorl %r12d, %r12d
movq 0x20(%rsp), %r14
movq 0x70(%rsp), %rbp
movl 0xdc(%rsp), %ebx
movsd %xmm0, 0x30(%rsp)
movq 0x18(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%rdx,8), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0xb0(%rsp)
movq (%r14), %rax
movsbl %bl, %r15d
movsbl %r12b, %edx
movq %r14, %rdi
movq 0x98(%rsp), %rsi
movl %r15d, %ecx
callq *0x20(%rax)
movq 0x50(%rsp), %rdx
mulsd 0xb0(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
incq %r12
cmpq %r12, %r13
jne 0x139a6
cmpb $0x0, 0x90(%rsp)
jle 0x13c1c
xorl %r12d, %r12d
movq 0x98(%rsp), %rbx
movq 0x20(%rsp), %r14
movq 0x70(%rsp), %rbp
movq 0x18(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%rdx,8), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0xb0(%rsp)
movq (%r14), %rax
movsbl %r12b, %edx
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %ecx
callq *0x20(%rax)
mulsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x8df8
movq 0x50(%rsp), %rdx
movsd 0xb0(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0xa8(%rsp), %rax
movsd %xmm1, (%rax,%r12,8)
incq %r12
cmpq %r12, %r13
jne 0x13a33
cmpb $0x0, 0x90(%rsp)
jle 0x13c1c
movq 0x18(%rsp), %rax
movq 0x70(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax,%rdx,8), %rdi
xorl %esi, %esi
movq 0x160(%rsp), %rdx
callq 0x4120
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x18(%rsp), %rbx
movq 0x98(%rsp), %r13
movq 0x20(%rsp), %r14
movq 0x70(%rsp), %rbp
movq 0xa8(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movq (%r14), %rax
movsbl %r15b, %ecx
movsbl %r12b, %edx
movq %r14, %rdi
movq %r13, %rsi
callq *0x18(%rax)
movq 0x50(%rsp), %rdx
movq (%rbx,%rbp,8), %rax
movq (%rax,%rdx,8), %rax
mulsd 0x30(%rsp), %xmm0
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %r12
cmpq %r12, 0x60(%rsp)
jne 0x13af3
incq %r15
movq 0x60(%rsp), %r13
cmpq %r13, %r15
jne 0x13ad9
jmp 0x13c1c
cmpb $0x0, 0x90(%rsp)
jle 0x13c1c
movq 0x18(%rsp), %rax
movq 0x70(%rsp), %rcx
movq (%rax,%rcx,8), %r15
movq (%r15,%rdx,8), %rsi
movq 0xa8(%rsp), %rdi
movq 0x160(%rsp), %rbx
movq %rbx, %rdx
callq 0x41c0
movq 0x50(%rsp), %rax
movq (%r15,%rax,8), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x4120
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x18(%rsp), %rbx
movq 0x98(%rsp), %r13
movq 0x20(%rsp), %r14
movq 0x70(%rsp), %rbp
movq 0xa8(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movq (%r14), %rax
movsbl %r15b, %ecx
movsbl %r12b, %edx
movq %r14, %rdi
movq %r13, %rsi
callq *0x18(%rax)
movq 0x50(%rsp), %rdx
movq (%rbx,%rbp,8), %rax
movq (%rax,%rdx,8), %rax
mulsd 0x30(%rsp), %xmm0
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %r12
cmpq %r12, 0x60(%rsp)
jne 0x13bbe
incq %r15
movq 0x60(%rsp), %r13
cmpq %r13, %r15
jne 0x13ba4
movq 0x18(%rsp), %r14
movq 0x70(%rsp), %rbx
movq (%r14,%rbx,8), %rax
movq (%rax,%rdx,8), %rdi
movl 0xd8(%rsp), %esi
callq 0x6836
movq 0xd0(%rsp), %rcx
incq %rcx
cmpq 0x168(%rsp), %rcx
movl 0xdc(%rsp), %r15d
jne 0x1394f
cmpl $0x3, 0x14(%rsp)
setne %al
movl 0x68(%rsp), %ecx
xorb $0x1, %cl
orb %al, %cl
movq 0xe0(%rsp), %rbx
leaq 0x1f5e2(%rip), %r13     # 0x3325d
movq %r14, %rcx
leaq 0x21001(%rip), %rdx     # 0x34c86
leaq 0x20cc9(%rip), %rbp     # 0x34955
movq 0x88(%rsp), %r12
jne 0x13cf2
movq 0xa0(%rsp), %r8
decl %r8d
movq %r8, 0xa0(%rsp)
xorl %r14d, %r14d
movq 0x70(%rsp), %rax
movq (%rcx,%rax,8), %rax
movslq (%r12,%r14,4), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
cmpq %r14, 0xa0(%rsp)
movq %rdx, %r15
cmoveq %r13, %rdx
movq %rbx, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x4330
movq 0x18(%rsp), %rcx
movq %r15, %rdx
incq %r14
cmpq %r14, 0x168(%rsp)
jne 0x13cac
movq %rcx, %r12
movq 0x80(%rsp), %rbx
movq 0xf0(%rsp), %rbp
movsd (%rbx,%rbp,8), %xmm0
movapd %xmm0, 0x30(%rsp)
movq %rbx, %rdi
movl 0x4c(%rsp), %esi
callq 0x8fb2
movsd (%rbx,%rbp,8), %xmm2
movsd 0x1fbc7(%rip), %xmm1    # 0x338f0
movb 0x13(%rsp), %al
cmpb 0x10(%rsp), %al
sete %r14b
jne 0x13d3a
xorps %xmm1, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x118(%rsp), %xmm1
movapd 0x30(%rsp), %xmm3
subsd %xmm3, %xmm1
mulsd %xmm1, %xmm1
movapd %xmm1, 0x50(%rsp)
cmpneqpd %xmm3, %xmm0
movapd 0x180(%rsp), %xmm1
cmpnltpd %xmm2, %xmm1
orpd %xmm0, %xmm1
movd %xmm1, %ebx
xorb %r14b, %bl
movq 0x80(%rsp), %r13
movq %r13, %rdi
movl 0x4c(%rsp), %esi
movapd %xmm2, 0x30(%rsp)
callq 0x8fb2
movsd (%r13,%rbp,8), %xmm1
cmpneqpd 0x30(%rsp), %xmm0
movapd 0x180(%rsp), %xmm2
cmpnltpd %xmm1, %xmm2
orpd %xmm0, %xmm2
movd %xmm2, %eax
xorb %r14b, %al
andb $0x1, %al
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movapd 0x50(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd 0x130(%rsp), %xmm0
addpd %xmm2, %xmm0
movapd %xmm0, 0x130(%rsp)
movapd %xmm1, %xmm0
callq 0x8dd2
movapd %xmm0, %xmm1
movsd %xmm0, 0x70(%rsp)
movsd 0x1faed(%rip), %xmm0    # 0x338f0
subsd %xmm1, %xmm0
movapd %xmm0, 0xb0(%rsp)
movapd %xmm1, %xmm0
callq 0x8e3d
movsd %xmm0, 0x30(%rsp)
movapd 0xb0(%rsp), %xmm0
callq 0x8e3d
mulsd 0x20(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
mulsd 0x118(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd 0x70(%rsp), %xmm0
callq 0x8e3d
movsd %xmm0, 0x70(%rsp)
movapd 0xb0(%rsp), %xmm0
callq 0x8e3d
movapd 0x50(%rsp), %xmm2
movsd 0x30(%rsp), %xmm1
mulsd 0x20(%rsp), %xmm0
movsd 0x70(%rsp), %xmm3
mulsd 0x118(%rsp), %xmm3
addsd %xmm0, %xmm3
movsd 0xe8(%rsp), %xmm0
subsd %xmm3, %xmm0
movsd %xmm0, 0xe8(%rsp)
movq 0x150(%rsp), %r14
movq 0xc8(%rsp), %r15
jmp 0x13ffe
xorl %eax, %eax
movsd 0x88(%rsp), %xmm0
cmpeqsd 0x70(%rsp), %xmm0
movq %xmm0, %rcx
andl $0x1, %ecx
movsd 0xb0(%rsp), %xmm0
subsd %xmm1, %xmm0
mulsd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
cmpl %ecx, %eax
sete %al
movl %eax, 0xd0(%rsp)
movsd 0x30(%rbx), %xmm0
callq 0x8e3d
movsd %xmm0, 0x30(%rsp)
movsd 0x1f9e0(%rip), %xmm0    # 0x338f0
subsd 0x30(%rbx), %xmm0
callq 0x8e3d
movsd 0x30(%rsp), %xmm1
movapd 0x70(%rsp), %xmm2
cmpneqsd 0x88(%rsp), %xmm2
movsd 0x1f9b8(%rip), %xmm3    # 0x338f0
andpd %xmm3, %xmm2
mulsd %xmm0, %xmm2
mulsd 0xb0(%rsp), %xmm1
addsd %xmm2, %xmm1
cmpl $0x0, 0x14(%rsp)
jle 0x13ff1
cmpb $0x0, 0xc0(%rsp)
jle 0x13ff1
movsd %xmm1, 0x30(%rsp)
xorl %r14d, %r14d
leaq 0x209df(%rip), %rbx     # 0x34955
movq 0x20(%rsp), %rbp
movq 0xe0(%rsp), %r15
movq 0x108(%rsp), %r12
movq 0x18(%rbp), %rax
movsd (%rax,%r14,8), %xmm0
cmpq %r12, %r14
leaq 0x1f2be(%rip), %rdx     # 0x3325d
leaq 0x20ce0(%rip), %rax     # 0x34c86
cmovlq %rax, %rdx
movq %r15, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x4330
incq %r14
cmpq %r14, %r13
jne 0x13f8b
movq 0x150(%rsp), %r14
movq 0xc8(%rsp), %r15
movq 0x18(%rsp), %r12
movq 0xf0(%rsp), %rbp
movapd 0x50(%rsp), %xmm2
movl 0xd0(%rsp), %ebx
movsd 0x30(%rsp), %xmm1
jmp 0x13ffe
movapd 0x50(%rsp), %xmm2
movl 0xd0(%rsp), %ebx
movsd 0xf8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0xf8(%rsp)
andb $0x1, %bl
movzbl %bl, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
movapd 0x170(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, %xmm0
incq %r15
cmpq %r14, %r15
movq 0x110(%rsp), %rcx
movq 0xa8(%rsp), %r13
jne 0x134b3
movapd 0x130(%rsp), %xmm1
movsd %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1]
movapd %xmm1, 0x50(%rsp)
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm0, 0x170(%rsp)
movq 0x148(%rsp), %rbx
movl 0x124(%rsp), %ebp
movq 0xe0(%rsp), %r15
jmp 0x140bd
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0xf8(%rsp)
movsd %xmm0, 0xe8(%rsp)
movapd %xmm0, 0x170(%rsp)
movapd %xmm0, 0x130(%rsp)
movl $0x60, %esi
movq 0x98(%rsp), %rdi
callq 0x4220
movq 0x80(%rsp), %rdi
callq 0x42a0
movq %r13, %rdi
callq 0x42a0
movq 0x18(%rsp), %rdi
movl 0x128(%rsp), %esi
movl 0x12c(%rsp), %edx
callq 0xca4f
movd %r14d, %xmm0
subl %ebp, %r14d
movd %r14d, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
cvtdq2pd %xmm0, %xmm2
movapd 0x170(%rsp), %xmm0
divsd %xmm2, %xmm0
ucomisd 0x1f7da(%rip), %xmm0    # 0x33900
movapd %xmm2, 0x30(%rsp)
jb 0x14137
xorps %xmm3, %xmm3
sqrtsd %xmm0, %xmm3
jmp 0x14146
callq 0x41a0
movapd 0x30(%rsp), %xmm2
movapd %xmm0, %xmm3
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
movapd 0x130(%rsp), %xmm1
divsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movapd %xmm1, %xmm0
jb 0x1416f
sqrtsd %xmm0, %xmm0
jmp 0x14186
movsd %xmm3, 0x60(%rsp)
callq 0x41a0
movsd 0x60(%rsp), %xmm3
movapd 0x30(%rsp), %xmm2
testq %rbx, %rbx
je 0x141bf
movsd 0xf8(%rsp), %xmm1
movsd %xmm1, (%rbx)
movsd 0xe8(%rsp), %xmm1
movsd %xmm1, 0x8(%rbx)
movsd %xmm3, 0x10(%rbx)
movsd %xmm0, 0x18(%rbx)
movapd 0x50(%rsp), %xmm0
divpd %xmm2, %xmm0
movupd %xmm0, 0x20(%rbx)
cmpl $0x0, 0x14(%rsp)
jle 0x141df
movq %r15, %rdi
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4200
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4bdc