// File: /workspace/github_cpp_makefile_star2_O1/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, 0x190(%rsp)
movq %r8, 0x170(%rsp)
movq %rcx, 0x1a0(%rsp)
movq %rdx, 0x198(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0x220(%rsp), %rax
movq %rax, 0x178(%rsp)
movb 0x218(%rsp), %dl
movq 0x210(%rsp), %r9
movq 0x208(%rsp), %rax
movq %rax, 0x188(%rsp)
movq 0x200(%rsp), %rax
movq %rax, 0x180(%rsp)
movq (%r9), %rax
movq 0x88(%rax), %rax
movsbl 0x8b8(%rax), %ecx
movl %ecx, 0x84(%rsp)
movslq %ecx, %rcx
movq %rcx, 0x138(%rsp)
movsbl 0x8b9(%rax), %ecx
movb 0x918(%rax), %sil
movb %sil, 0x27(%rsp)
movb 0x64(%rax), %sil
movb %sil, 0xd(%rsp)
movl %ecx, 0x48(%rsp)
movslq %ecx, %rcx
movq %rcx, 0x88(%rsp)
movl 0x8c0(%rax), %ebp
movl 0x8bc(%rax), %r15d
movl 0x8b0(%rax), %ecx
movq %rcx, 0xc0(%rsp)
movl 0x8cc(%rax), %r8d
movl 0x60(%rax), %ecx
movl %ecx, 0x28(%rsp)
movsbq 0x5c(%rax), %r10
movb %dl, 0x26(%rsp)
cmpb $0x2, %dl
jl 0x134ed
movb 0x65(%rax), %al
movzbl 0x26(%rsp), %ecx
movl $0x1, %edx
movq (%r9,%rdx,8), %rsi
movq 0x88(%rsi), %rsi
movq 0x138(%rsp), %rdi
cmpb 0x8b8(%rsi), %dil
jne 0x14391
movq 0x88(%rsp), %rdi
cmpb 0x8b9(%rsi), %dil
jne 0x14391
cmpl 0x8c0(%rsi), %ebp
jne 0x14391
cmpl 0x8bc(%rsi), %r15d
jne 0x14391
movq 0xc0(%rsp), %rdi
cmpl 0x8b0(%rsi), %edi
jne 0x14391
cmpl 0x8cc(%rsi), %r8d
jne 0x14391
movb 0x27(%rsp), %dil
cmpb 0x918(%rsi), %dil
jne 0x14391
movb 0xd(%rsp), %dil
cmpb 0x64(%rsi), %dil
jne 0x14391
cmpb 0x65(%rsi), %al
jne 0x14391
movl 0x28(%rsp), %edi
cmpl 0x60(%rsi), %edi
jne 0x14391
cmpb 0x5c(%rsi), %r10b
jne 0x14391
incq %rdx
cmpb %dl, %cl
jne 0x13432
movq %r10, %r12
movq %r9, 0x158(%rsp)
movl %r8d, 0xe4(%rsp)
movl $0x8, %esi
movq 0x88(%rsp), %rdi
callq 0x4130
movq %rax, 0x68(%rsp)
movl $0x8, %esi
movq 0x138(%rsp), %rdi
callq 0x4130
movq %rax, 0xd8(%rsp)
movl %r15d, 0x144(%rsp)
movl %r15d, %edi
movl %ebp, 0x148(%rsp)
movl %ebp, %esi
movl 0x84(%rsp), %edx
callq 0xcaae
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x28(%rsp)
movq %r14, 0x150(%rsp)
jle 0x13584
leaq 0x21f4a(%rip), %rsi     # 0x354b6
movq %rbx, %rdi
callq 0x4290
movq %rax, %r15
testq %rax, %rax
jne 0x13587
movq %rbx, %rdi
callq 0x4bff
xorl %r15d, %r15d
movl $0x60, %edi
callq 0x4210
movq %rax, %r13
movq 0x158(%rsp), %rbx
movq (%rbx), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
xorpd %xmm2, %xmm2
xorpd %xmm0, %xmm0
movsd %xmm0, 0xe8(%rsp)
xorpd %xmm3, %xmm3
movsd %xmm0, 0xb8(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm0, 0xf0(%rsp)
cmpl $0x0, 0xc0(%rsp)
jle 0x14226
movq %rbx, %rdx
movq %r12, %r11
movl 0x84(%rsp), %esi
movzbl %sil, %r10d
cmpl $0x1, 0x28(%rsp)
leaq 0x20c62(%rip), %rax     # 0x3425d
leaq 0x225a4(%rip), %rcx     # 0x35ba6
cmoveq %rax, %rcx
movq %rcx, 0x168(%rsp)
cmpb $0x67, 0xd(%rsp)
setne %al
movq 0x88(%rsp), %r8
testb %r8b, %r8b
setle %r9b
leal 0x1(%r8), %ecx
cmpl $0x3, %ecx
movl $0x0, %ecx
movl 0x48(%rsp), %edi
cmovbl %edi, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x120(%rsp)
leaq -0x1(%r8), %r12
leal (,%r10,8), %ecx
movq %rcx, 0x1b0(%rsp)
movq %r10, 0x98(%rsp)
leal (,%r10,8), %ecx
movq %rcx, 0x1a8(%rsp)
movl $0xff, %ecx
andl %ecx, %esi
shll $0x3, %esi
movq %rsi, 0x1b8(%rsp)
andl %edi, %ecx
movq %rcx, 0x118(%rsp)
orb %al, %r9b
movb %r9b, 0x2f(%rsp)
xorl %esi, %esi
xorpd %xmm0, %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd %xmm0, 0xb8(%rsp)
movsd %xmm0, 0xe8(%rsp)
movq %r15, 0x108(%rsp)
movq %r13, 0x78(%rsp)
movq %r11, 0xc8(%rsp)
movq %r12, 0x130(%rsp)
movq 0x198(%rsp), %rax
movb (%rax,%rsi), %dil
movq 0x1a0(%rsp), %rax
movslq (%rax,%rsi,4), %r8
movl %r8d, 0x5c(%r13)
movl %esi, 0x8(%r13)
movq %rdx, %rax
cmpb $0x1, 0x26(%rsp)
je 0x13711
movq 0x178(%rsp), %rax
movsbq (%rax,%rsi), %rax
leaq (%rdx,%rax,8), %rax
movq (%rax), %rax
movq %rax, 0xa0(%rsp)
movq 0x88(%rax), %rax
movb 0x5c(%rax), %al
movb %al, 0xf(%rsp)
cmpb $0x0, 0x27(%rsp)
je 0x1375c
movq 0x188(%rsp), %rax
movslq (%rax,%rsi,4), %rax
movq 0x190(%rsp), %rcx
leaq (%rcx,%rax,4), %rcx
movl (%rcx), %eax
movl %eax, 0x4c(%rsp)
movq 0x180(%rsp), %rax
movl (%rax,%rsi,4), %edx
jmp 0x13775
movq 0x170(%rsp), %rax
movl (%rax,%rsi,4), %eax
movl %eax, 0x4c(%rsp)
movl $0x1, %edx
leaq 0x4c(%rsp), %rcx
cmpl $0x0, (%rcx)
movsd %xmm1, 0x100(%rsp)
movsd %xmm2, 0xf8(%rsp)
movsd %xmm3, 0x128(%rsp)
movq %rsi, 0x110(%rsp)
js 0x139e4
movb %dil, 0xe(%rsp)
movl %edx, %eax
movq %rax, 0x90(%rsp)
movq %rdx, 0x70(%rsp)
testl %edx, %edx
movq %r8, 0x10(%rsp)
movq %rcx, 0xd0(%rsp)
movq 0x98(%rsp), %rdx
jle 0x1385f
xorl %ebp, %ebp
movl (%rcx,%rbp,4), %eax
movl %eax, 0x4c(%rsp)
movq 0x30(%rsp), %rcx
movq (%rcx,%r8,8), %rcx
movslq %eax, %r12
movq (%rcx,%r12,8), %rcx
movsd (%rcx), %xmm0
ucomisd 0x21109(%rip), %xmm0    # 0x34900
movq 0xa0(%rsp), %rbx
jne 0x13846
jp 0x13846
movl %eax, 0x58(%r13)
testb %dl, %dl
jle 0x13846
xorl %r15d, %r15d
movq (%rbx), %rax
movsbl %r15b, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq *0x10(%rax)
movq 0x98(%rsp), %rdx
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %rax
movq (%rax,%r8,8), %rax
movq (%rax,%r12,8), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
cmpq %r15, %rdx
jne 0x1380e
incq %rbp
cmpq 0x90(%rsp), %rbp
movq 0xd0(%rsp), %rcx
jne 0x137d4
movq 0xa0(%rsp), %rdi
movq (%rdi), %rax
movq 0x30(%rsp), %rsi
movq 0x68(%rsp), %r15
movq %r15, %rdx
movq 0x110(%rsp), %rcx
callq *0x50(%rax)
movq %r15, %rdi
movq 0x88(%rsp), %rsi
callq 0x692d
cmpl $0x0, 0x28(%rsp)
movq 0x108(%rsp), %r14
leaq 0x22300(%rip), %rsi     # 0x35ba6
leaq 0x21fe2(%rip), %r8      # 0x3588f
jle 0x139aa
cmpb $0x0, 0x88(%rsp)
movq 0x68(%rsp), %r13
movq 0x168(%rsp), %rbp
movq 0x130(%rsp), %rdx
movq %r8, %r12
movq 0x118(%rsp), %rbx
jle 0x13915
xorl %r15d, %r15d
movsd (%r13,%r15,8), %xmm0
cmpq %rdx, %r15
movq %rbp, %rdx
cmovlq %rsi, %rdx
movq %r14, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x4330
movq 0x130(%rsp), %rdx
leaq 0x22299(%rip), %rsi     # 0x35ba6
incq %r15
cmpq %r15, %rbx
jne 0x138e0
cmpl $0x2, 0x28(%rsp)
leaq 0x2093c(%rip), %r9      # 0x3425d
movq %r12, %r8
movq 0x10(%rsp), %rcx
movq 0xd0(%rsp), %rdx
movq 0x90(%rsp), %r13
jne 0x139aa
cmpl $0x0, 0x70(%rsp)
jle 0x139aa
movq %r14, %rbp
movq 0x70(%rsp), %rax
decl %eax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movq 0x30(%rsp), %rax
movq (%rax,%rcx,8), %rax
movslq (%rdx,%r12,4), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
cmpq %r12, 0x18(%rsp)
movq %rsi, %rdx
cmoveq %r9, %rdx
movq %r9, %rbx
movq %rbp, %rdi
movq %r8, %rsi
movb $0x1, %al
movq %r8, %r15
callq 0x4330
movq %r15, %r8
movq 0xd0(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %rbx, %r9
leaq 0x22204(%rip), %rsi     # 0x35ba6
incq %r12
cmpq %r12, %r13
jne 0x13954
cmpb $0x67, 0xd(%rsp)
movb 0xe(%rsp), %dil
movzbl %dil, %r12d
movl $0x0, %eax
cmovel %eax, %r12d
cmpb $0x0, 0x2f(%rsp)
je 0x13a2e
movq 0x68(%rsp), %rcx
movq 0x110(%rsp), %rsi
movq 0x70(%rsp), %rbx
movq 0x78(%rsp), %r15
jmp 0x13a77
movsbl %dil, %eax
cvtsi2sd %eax, %xmm4
movq 0xa0(%rsp), %rax
movsd 0x28(%rax), %xmm0
movapd %xmm0, 0x50(%rsp)
movsd %xmm4, 0x38(%rsp)
ucomisd %xmm0, %xmm4
xorpd %xmm0, %xmm0
jne 0x14063
movq 0xc8(%rsp), %r15
jp 0x1406b
movsd 0x20ec7(%rip), %xmm0    # 0x348f0
jmp 0x1406b
xorpd %xmm0, %xmm0
xorl %eax, %eax
xorl %r12d, %r12d
movq 0x68(%rsp), %rcx
movq 0x118(%rsp), %rdx
movq 0x110(%rsp), %rsi
movq 0x70(%rsp), %rbx
movq 0x78(%rsp), %r15
movsd (%rcx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
movzbl %r12b, %r12d
cmoval %eax, %r12d
maxsd %xmm0, %xmm1
incq %rax
movapd %xmm1, %xmm0
cmpq %rax, %rdx
jne 0x13a56
movq %r8, %rbp
movsd 0x20e6e(%rip), %xmm0    # 0x348f0
cmpb %dil, 0xf(%rsp)
je 0x13a8d
xorpd %xmm0, %xmm0
movq 0xc8(%rsp), %rax
movsd (%rcx,%rax,8), %xmm1
movq 0xa0(%rsp), %rdi
movq (%rdi), %rax
movsd %xmm0, 0x160(%rsp)
callq *0x58(%rax)
testl %ebx, %ebx
jle 0x13de1
xorl %ecx, %ecx
movl %r12d, 0x14c(%rsp)
movq 0x30(%rsp), %rbx
movq 0xd0(%rsp), %rax
movq %rcx, 0x1c0(%rsp)
movslq (%rax,%rcx,4), %rdx
movl %edx, 0x4c(%rsp)
movl %edx, 0x58(%r15)
testb %r12b, %r12b
movq 0xd8(%rsp), %rdi
movq 0x98(%rsp), %r14
movq %rdx, 0x50(%rsp)
js 0x13b89
movsbl %r12b, %ecx
testb %r14b, %r14b
movq 0xa0(%rsp), %rbp
movq 0x10(%rsp), %rsi
movl %ecx, 0x40(%rsp)
xorpd %xmm0, %xmm0
jle 0x13c66
movsd %xmm0, 0x18(%rsp)
xorl %r12d, %r12d
movq 0x30(%rsp), %r13
movq (%r13,%rsi,8), %rax
movq (%rax,%rdx,8), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x38(%rsp)
movq (%rbp), %rax
movsbl %r12b, %edx
movq %rbp, %rdi
movq %r15, %rsi
callq *0x20(%rax)
movl 0x40(%rsp), %ecx
movq 0x50(%rsp), %rdx
movq 0x10(%rsp), %rsi
mulsd 0x38(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
incq %r12
cmpq %r12, %r14
jne 0x13b32
jmp 0x13c71
testb %r14b, %r14b
movq 0x10(%rsp), %rsi
jle 0x13bb2
movq (%rbx,%rsi,8), %rax
movq (%rax,%rdx,8), %rsi
movq 0x1b0(%rsp), %rdx
callq 0x41c0
movq 0x50(%rsp), %rdx
movq 0x10(%rsp), %rsi
testb %r14b, %r14b
jle 0x13bd8
movq (%rbx,%rsi,8), %rax
movq (%rax,%rdx,8), %rdi
xorl %esi, %esi
movq 0x1a8(%rsp), %rdx
callq 0x4120
movq 0x50(%rsp), %rdx
movq 0x10(%rsp), %rsi
testb %r14b, %r14b
jle 0x13d9b
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0xd8(%rsp), %r14
movq 0x30(%rsp), %r13
movq 0x78(%rsp), %rbx
movq 0xa0(%rsp), %rbp
movsd (%r14,%r15,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq (%rbp), %rax
movsbl %r12b, %ecx
movsbl %r15b, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movq 0x50(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq (%r13,%rsi,8), %rax
movq (%rax,%rdx,8), %rax
mulsd 0x18(%rsp), %xmm0
addsd (%rax,%r12,8), %xmm0
movsd %xmm0, (%rax,%r12,8)
incq %r15
cmpq %r15, 0x98(%rsp)
jne 0x13c01
incq %r12
cmpq 0x98(%rsp), %r12
jne 0x13be4
jmp 0x13d9b
movsd %xmm0, 0x18(%rsp)
movq 0x30(%rsp), %r13
testb %r14b, %r14b
movq %r14, %rbx
movq 0xd8(%rsp), %r14
jle 0x13ce7
xorl %r12d, %r12d
movq (%r13,%rsi,8), %rax
movq (%rax,%rdx,8), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x38(%rsp)
movq (%rbp), %rax
movsbl %r12b, %edx
movq %rbp, %rdi
movq %r15, %rsi
callq *0x20(%rax)
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x8d88
movl 0x40(%rsp), %ecx
movq 0x50(%rsp), %rdx
movq 0x10(%rsp), %rsi
movsd 0x38(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r14,%r12,8)
incq %r12
cmpq %r12, %rbx
jne 0x13c84
testb %bl, %bl
jle 0x13d11
movq 0x30(%rsp), %rax
movq (%rax,%rsi,8), %rax
movq (%rax,%rdx,8), %rdi
xorl %esi, %esi
movq 0x1b8(%rsp), %rdx
callq 0x4120
movq 0x50(%rsp), %rdx
movq 0x10(%rsp), %rsi
testb %bl, %bl
jle 0x13d9b
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x30(%rsp), %r13
movq 0x78(%rsp), %rbx
movq 0x98(%rsp), %rbp
movq 0xa0(%rsp), %r14
movq 0xd8(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq (%r14), %rax
movsbl %r12b, %ecx
movsbl %r15b, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movq 0x50(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq (%r13,%rsi,8), %rax
movq (%rax,%rdx,8), %rax
mulsd 0x18(%rsp), %xmm0
addsd (%rax,%r12,8), %xmm0
movsd %xmm0, (%rax,%r12,8)
incq %r15
cmpq %r15, %rbp
jne 0x13d39
incq %r12
cmpq 0x138(%rsp), %r12
jne 0x13d1c
movq 0x30(%rsp), %rax
movq (%rax,%rsi,8), %rax
movq (%rax,%rdx,8), %rdi
movl 0x84(%rsp), %esi
callq 0x692d
movq 0x1c0(%rsp), %rcx
incq %rcx
cmpq 0x90(%rsp), %rcx
movq 0x78(%rsp), %r15
leaq 0x21abc(%rip), %rbp     # 0x3588f
movl 0x14c(%rsp), %r12d
jne 0x13ac3
cmpl $0x3, 0x28(%rsp)
movq 0x108(%rsp), %r9
leaq 0x20468(%rip), %rdi     # 0x3425d
leaq 0x21daa(%rip), %r15     # 0x35ba6
movq 0x10(%rsp), %rax
movq 0xd0(%rsp), %r14
jne 0x13e72
cmpl $0x0, 0x70(%rsp)
jle 0x13e72
movq %rbp, %r13
movq 0x70(%rsp), %r8
decl %r8d
movq %r8, 0x70(%rsp)
xorl %ebx, %ebx
movq %rax, %rbp
movq 0x30(%rsp), %rax
movq (%rax,%rbp,8), %rax
movslq (%r14,%rbx,4), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
cmpq %rbx, 0x70(%rsp)
movq %r15, %rdx
cmoveq %rdi, %rdx
movq %r9, %r12
movq %r9, %rdi
movq %r13, %rsi
movb $0x1, %al
callq 0x4330
movq %rbp, %rax
leaq 0x203fb(%rip), %rdi     # 0x3425d
movq %r12, %r9
incq %rbx
cmpq %rbx, 0x90(%rsp)
jne 0x13e24
xorl %ebx, %ebx
movb 0xf(%rsp), %al
cmpb 0xe(%rsp), %al
sete %bpl
movq 0xc8(%rsp), %r15
movq 0x68(%rsp), %r12
movsd (%r12,%r15,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
movl 0x48(%rsp), %esi
callq 0x8f52
xorl %r13d, %r13d
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl $0x0, %eax
jne 0x13ecf
jp 0x13ecf
movsd (%r12,%r15,8), %xmm0
xorl %eax, %eax
ucomisd 0x120(%rsp), %xmm0
seta %al
movb %bpl, %bl
cmpl %ebx, %eax
sete 0x40(%rsp)
movsd (%r12,%r15,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x68(%rsp), %rdi
movl 0x48(%rsp), %esi
callq 0x8f52
movq 0x68(%rsp), %rax
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x13f1c
jp 0x13f1c
movsd (%rax,%r15,8), %xmm0
xorl %r13d, %r13d
ucomisd 0x120(%rsp), %xmm0
seta %r13b
movsd 0x209cc(%rip), %xmm0    # 0x348f0
cmpl %ebx, %r13d
je 0x13f2c
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0xc8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x8d62
movsd %xmm0, 0x50(%rsp)
callq 0x8dcd
movsd %xmm0, 0x18(%rsp)
movsd 0x20993(%rip), %xmm0    # 0x348f0
subsd 0x50(%rsp), %xmm0
movapd %xmm0, 0xa0(%rsp)
callq 0x8dcd
movsd 0x20977(%rip), %xmm2    # 0x348f0
movb 0xf(%rsp), %al
cmpb 0xe(%rsp), %al
movq 0x78(%rsp), %r13
movb 0x40(%rsp), %r15b
jne 0x13f91
xorpd %xmm2, %xmm2
movsd %xmm2, 0x90(%rsp)
movsd 0x160(%rsp), %xmm1
movapd %xmm1, %xmm4
movapd %xmm1, %xmm3
subsd 0x10(%rsp), %xmm4
mulsd %xmm4, %xmm4
movsd %xmm4, 0x10(%rsp)
movsd 0xb8(%rsp), %xmm1
addsd %xmm4, %xmm1
movsd %xmm1, 0xb8(%rsp)
movsd 0xf0(%rsp), %xmm1
addsd 0x38(%rsp), %xmm1
movsd %xmm1, 0xf0(%rsp)
mulsd %xmm2, %xmm0
movsd 0x18(%rsp), %xmm1
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movsd 0x50(%rsp), %xmm0
callq 0x8dcd
movsd %xmm0, 0x50(%rsp)
movapd 0xa0(%rsp), %xmm0
callq 0x8dcd
movsd 0x10(%rsp), %xmm1
mulsd 0x90(%rsp), %xmm0
movsd 0x50(%rsp), %xmm2
mulsd 0x160(%rsp), %xmm2
addsd %xmm0, %xmm2
movsd 0xe8(%rsp), %xmm0
subsd %xmm2, %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0x18(%rsp), %xmm0
jmp 0x141cb
movq 0xc8(%rsp), %r15
movsd %xmm0, 0x40(%rsp)
movq 0xa0(%rsp), %rbx
movq 0x18(%rbx), %rdi
movsd (%rdi,%r15,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x48(%rsp), %esi
callq 0x8f52
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x140ba
jp 0x140ba
movq 0x18(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
xorl %eax, %eax
ucomisd 0x120(%rsp), %xmm0
seta %al
jmp 0x140bc
xorl %eax, %eax
movsd 0x38(%rsp), %xmm0
cmpeqsd 0x50(%rsp), %xmm0
movq %xmm0, %rcx
andl $0x1, %ecx
movsd 0x40(%rsp), %xmm0
subsd %xmm1, %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
cmpl %ecx, %eax
sete %r15b
movsd 0x30(%rbx), %xmm0
callq 0x8dcd
movsd %xmm0, 0x18(%rsp)
movsd 0x207ed(%rip), %xmm0    # 0x348f0
subsd 0x30(%rbx), %xmm0
callq 0x8dcd
movapd 0x50(%rsp), %xmm1
cmpneqsd 0x38(%rsp), %xmm1
movsd 0x207ce(%rip), %xmm2    # 0x348f0
andpd %xmm2, %xmm1
mulsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
mulsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
cmpl $0x0, 0x28(%rsp)
jle 0x141c5
cmpb $0x0, 0x88(%rsp)
jle 0x141c5
movsd %xmm0, 0x18(%rsp)
movb %r15b, 0x40(%rsp)
xorl %r15d, %r15d
movq 0x108(%rsp), %r13
leaq 0x200f1(%rip), %r14     # 0x3425d
leaq 0x21a33(%rip), %rbp     # 0x35ba6
movq 0x118(%rsp), %r12
movq 0xa0(%rsp), %rbx
movq 0x18(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
cmpq 0x130(%rsp), %r15
movq %r14, %rdx
cmovlq %rbp, %rdx
movq %r13, %rdi
leaq 0x216e9(%rip), %rsi     # 0x3588f
movb $0x1, %al
callq 0x4330
incq %r15
cmpq %r15, %r12
jne 0x14183
movq 0x78(%rsp), %r13
movb 0x40(%rsp), %r15b
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0xf8(%rsp), %xmm2
subsd %xmm0, %xmm2
movzbl %r15b, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x128(%rsp), %xmm3
addsd %xmm1, %xmm3
movsd 0x100(%rsp), %xmm1
addsd %xmm0, %xmm1
movq 0x110(%rsp), %rsi
incq %rsi
cmpq 0xc0(%rsp), %rsi
movq 0x158(%rsp), %rdx
movq 0x108(%rsp), %r15
jne 0x136d6
movsd %xmm3, 0x128(%rsp)
movsd %xmm2, 0xf8(%rsp)
movsd %xmm1, 0x100(%rsp)
movl $0x60, %esi
movq %r13, %rdi
callq 0x4220
movq 0x68(%rsp), %rdi
callq 0x42a0
movq 0xd8(%rsp), %rdi
callq 0x42a0
movq 0x30(%rsp), %rdi
movl 0x144(%rsp), %esi
movl 0x148(%rsp), %edx
callq 0xca4f
movsd 0x128(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xc0(%rsp), %xmm1
movsd %xmm1, 0x18(%rsp)
divsd %xmm1, %xmm0
ucomisd 0x2065c(%rip), %xmm0    # 0x34900
jb 0x142af
xorps %xmm3, %xmm3
sqrtsd %xmm0, %xmm3
jmp 0x142b8
callq 0x41a0
movapd %xmm0, %xmm3
movq 0x150(%rsp), %rbx
movl 0xe4(%rsp), %ecx
movsd 0xb8(%rsp), %xmm0
movq 0xc0(%rsp), %rax
subl %ecx, %eax
cvtsi2sd %eax, %xmm4
divsd %xmm4, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x142f2
sqrtsd %xmm0, %xmm0
jmp 0x1430f
movsd %xmm3, 0x10(%rsp)
movsd %xmm4, 0x50(%rsp)
callq 0x41a0
movsd 0x50(%rsp), %xmm4
movsd 0x10(%rsp), %xmm3
movsd 0x100(%rsp), %xmm1
movsd 0xf8(%rsp), %xmm2
testq %rbx, %rbx
je 0x1435f
movsd %xmm2, (%rbx)
movsd 0xe8(%rsp), %xmm2
movsd %xmm2, 0x8(%rbx)
movsd %xmm3, 0x10(%rbx)
movsd %xmm0, 0x18(%rbx)
divsd 0x18(%rsp), %xmm1
movsd %xmm1, 0x20(%rbx)
movsd 0xf0(%rsp), %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, 0x28(%rbx)
cmpl $0x0, 0x28(%rsp)
jle 0x1437f
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 0x4bd8