// File: /workspace/github_cpp_makefile_star2_O1/melop[P]admixem/makemarkerfile.cpp
// Function: UIGenerateRecombinationFreqMap(int, double, double*, double*)
void UIGenerateRecombinationFreqMap(int nChromosomes, double nLargestChromSize, double * pChromosomeSizes, double * pCentromerePos) { //UI generating recombination map
		
		//double nLogMaxAvgRecombRate; // Log(Max(recombination rate));
		char nRate; //1 - uniform, 2 - parabola
		double nTotalExpectedRecombPerMeiosis; // The total expected recombination events per meiosis in the whole genome
		double nParabolaA; // shape of male parabola
		double nParabolaAFemale; //shape of female parabola
		//double nFemCorrA ; // linear function to correct for female rates: y=ax + b; negative values make rates higher near centromere and lower at telomere and vice versa
		//double nFemCorrB ; // This should be larger than one b/c females have higher recombination rate in general. usually 3 
		double nFemFold; //Fold factor compared to max
		double nTotalSamplePoint; //How often to put a point. 
		double nSumLens = fnSum(pChromosomeSizes , nChromosomes); // get sum of chromosome lengths
		
		while(true) { //  Get std. dev of the more abundant allele in pop 2
		
			//std::cout << "\nThe logarithm of the max average recombination rate at the telomere of the longest chromosome per chromosome length unit per gamete (< 0) : ";
			
			std::cout << "\nThe total expected recombination event in the whole genome per meiosis (>= 0), set this to be 4n should be fine : ";
			std::cin >> nTotalExpectedRecombPerMeiosis;
			
			if (nTotalExpectedRecombPerMeiosis < 0 ) {
				std::cout << "Input out of bound, retry." <<endl;
				continue; // 
			}
			
			break;
		}
		/*
		while(true) { //  Get std. dev of the more abundant allele in pop 2
		
			std::cout << "\nDistribution of recombination frequencies 1 - Uniform, 2 - Parabola ... ";
			std::cin >> nRate;
			
			if (nRate < '1' || nRate > '2' ) {
				std::cout << "Input out of bound, retry." <<endl;
				continue; // 
			}
			
			break;
		}
		*/
		nRate = '1';
		
		if (nRate == '2') { 
				while(true) { //  Get std. dev of the more abundant allele in pop 2
		
					std::cout << "\nShape of the male parabola (0, 5] : ";
					std::cin >> nParabolaA;
			
					if (nParabolaA <= 0 || nParabolaA > 5 ) {
						std::cout << "Input out of bound, retry." <<endl;
						continue; // 
					}
			
					break;
				}
		
	
				while(true) { //  Get std. dev of the more abundant allele in pop 2
		
					std::cout << "\nShape of the female parabola (0, 5] : ";
					std::cin >> nParabolaAFemale;
			
					if (nParabolaAFemale <= 0 || nParabolaAFemale > 5 ) {
						std::cout << "Input out of bound, retry." <<endl;
						continue; // 
					}
			
					break;
				}
		}
		
		if (nRate == '1') { // if uniform, just put two since users can specify Use UseUniformRec = yes
			std::cout << "===========================================" <<endl;
			std::cout  <<endl;
			std::cout << "By default Admixem uses the uniform rate" <<endl;
			std::cout << "In addition to files generated here," <<endl;
			std::cout << "Please make sure you ADD THE FOLLOWING OPTION" <<endl;
			std::cout << "in your MAIN CONFIGURATION file:" <<endl;
			std::cout << endl << "        UseUniformRec  =  yes" <<endl;
			std::cout  <<endl;
			std::cout  <<"In case you really want to use the candidate ";
			std::cout  <<"break point approach, refer to the manual. ";
			std::cout << "===========================================" <<endl;

			nTotalSamplePoint = 20 * nChromosomes;
		}
		else {
			while(true) { //  Get std. dev of the more abundant allele in pop 2
		
				std::cout << "\nHow many sample points to put in total?: ";
				std::cin >> nTotalSamplePoint;
			
				if (nTotalSamplePoint <= 0  ) {
					std::cout << "Input out of bound, retry." <<endl;
					continue; // 
				}
			
				break;
			}
		}
		
		while(true) { //  Get std. dev of the more abundant allele in pop 2
		
			std::cout << "\nFold difference between female:male [0.1,10]: ";
			std::cin >> nFemFold;
			
			if (nFemFold < 0.1 || nFemFold > 10 ) {
				std::cout << "Input out of bound, retry." <<endl;
				continue; // 
			}
			
			break;
		}
		
		/*
		while(true) { //  Get std. dev of the more abundant allele in pop 2
		
			std::cout << "\n A linear model y=a*prob(male)+b will be used to generate the female recomb. rate from the male rates. "<<endl;
			std::cout << "A -b < a < 10:"<<endl;
			std::cin >> nFemCorrA;
			std::cout << "B [1,10]:"<<endl;
			std::cin >> nFemCorrB;
			

			
			if (nFemCorrB < 1 || nFemCorrB > 10 ) {
				std::cout << "Parameter B out of bound, retry." <<endl;
				continue; // 
			}
			
				if (nFemCorrA < -nFemCorrB || nFemCorrA > 10 ) {
				std::cout << "Parameter A out of bound, retry." <<endl;
				continue; // 
			}
			
			break;
		}
		*/
		
		
	cout << "Output File name : ";
	string sOutFile;
		
		while(true) { //  Get std. dev of the more abundant allele in pop 2
		
			
		
			
			getline(cin, sOutFile) ;
			
			
			if (sOutFile.size() > 3 ) {
				break;
			}
			
			
			continue;
		}
		
		
		// now prepare file:
		//Figure out how to distribute the markers
		
		ofstream fOutFile;
		fOutFile.open(sOutFile.c_str());
		
		
		for (int i=0;i< nChromosomes;i++) {
			

			
			int nChrIndex =i;
			double nChrLen = pChromosomeSizes[nChrIndex];
			double nCentromerePos =  pCentromerePos[nChrIndex];	
			//double nMaxAvgRecombRate = pow(10, nLogMaxAvgRecombRate);	
			//nLongestArmExpectedRecombPerMeiosis
			
			int	   nNumSamplePoints = (int) ceil( ((double) nTotalSamplePoint) * (nChrLen / nSumLens));

			double nArm1Len =  nCentromerePos;
			double nArm2Len =  nChrLen - nCentromerePos;
				
			fOutFile << ":chr " << (nChrIndex+1) << endl;
			
			double nExpectedMaleRecPerMeiosisArm1 = nTotalExpectedRecombPerMeiosis * ( nArm1Len/nSumLens) / 2;
			double nExpectedMaleRecPerMeiosisArm2 = nTotalExpectedRecombPerMeiosis * ( nArm2Len/nSumLens) / 2;
			double nExpectedFemaleRecPerMeiosisArm1 = nTotalExpectedRecombPerMeiosis * nFemFold * ( nArm1Len/nSumLens) / 2;
			double nExpectedFemaleRecPerMeiosisArm2 = nTotalExpectedRecombPerMeiosis * nFemFold * ( nArm2Len/nSumLens) / 2;
			double nExpectedRecPerMeiosisArm1 = ( nExpectedMaleRecPerMeiosisArm1 + nExpectedFemaleRecPerMeiosisArm1 ) / 2;
			double nExpectedRecPerMeiosisArm2 = ( nExpectedMaleRecPerMeiosisArm2 + nExpectedFemaleRecPerMeiosisArm2 ) / 2;
			
			//fOutFile << "\tmale"<<"\tmale_accumulative\tmale*max\tmale*max_accumulative" << "\tfemale\tfemale_accumulative\tfemale*max\tfemale*max_accumulative" << endl;
			fOutFile << ":ExpectedMaleRecPerMeiosisArm1 = " << nExpectedMaleRecPerMeiosisArm1 << endl;
			fOutFile << ":ExpectedMaleRecPerMeiosisArm2 = " << nExpectedMaleRecPerMeiosisArm2 << endl;
			fOutFile << ":ExpectedFemaleRecPerMeiosisArm1 = " << nExpectedFemaleRecPerMeiosisArm1 << endl;
			fOutFile << ":ExpectedFemaleRecPerMeiosisArm2 = " << nExpectedFemaleRecPerMeiosisArm2 << endl;
			fOutFile << "\tmale"<<"\tmale_accumulative" << "\tfemale\tfemale_accumulative\tMale_recombination_fraction\tFemale_recombination_fraction\tAvg_recombination_fraction\tKosambi_male_interval\tKosambi_male_pos\tKosambi_female_interval\tKosambi_female_pos\tKosambi_both_interval\tKosambi_both_pos" << endl;
		
			std::map<double, double *>  mSamplePoints;

			
			for (int j=0; j < nNumSamplePoints; j++) {
			
				double nPos = nChrLen * UniformGen.Next(); // random position
				
				double nDistanceFromCentromere = ( nPos - nCentromerePos ) / nLargestChromSize; //  distance from centromere standarized by the longest chromosome
				nDistanceFromCentromere = (nDistanceFromCentromere >= 0 )? nDistanceFromCentromere: -nDistanceFromCentromere;
				
				double nArmLen = (nPos > nCentromerePos)? nChrLen - nCentromerePos : nCentromerePos;
				double nDistanceFromCentromereOnArm = (nPos > nCentromerePos)? (nPos - nCentromerePos)/nArmLen : (nCentromerePos - nPos)/nArmLen ;
				
				double nProbAtPosMale =  (nRate=='1')? 0.1 : pow(nParabolaA * nDistanceFromCentromere, 2);
				//double nProbAtPosFemale = nProbAtPosMale * nFemCorrA  + nFemCorrB;
				
				double nProbAtPosFemale = (nRate=='1')? 0.1 * nFemFold : pow(nParabolaAFemale * nDistanceFromCentromere, 2) * nFemFold ; 
				
				double * pProbs = new double[4];
				
				pProbs[0] = NormalExt(nProbAtPosMale , nProbAtPosMale / 2, 0, 1);
				//pProbs[1] = nMaxAvgRecombRate * pProbs[0] ;
				pProbs[2] = NormalExt(nProbAtPosFemale , nProbAtPosFemale / 2, 0, 1);
				//pProbs[3] = nMaxAvgRecombRate * pProbs[2] ;
				
				if (mSamplePoints.find(nPos) == mSamplePoints.end()) {
					mSamplePoints[nPos] = pProbs ;
				}
				else {
					j--;
					continue; // won't work because same position already exists.
				}
				
			}
			
			double nMaleArm1Accum = 0;
			double nFemaleArm1Accum = 0;
			double nMaleArm2Accum = 0;
			double nFemaleArm2Accum = 0;


			
			for (std::map<double,double *>::iterator it = mSamplePoints.begin(); it != mSamplePoints.end(); ++it) {
			
				double nMaleAccum, nFemaleAccum;
				if (it->first < nCentromerePos) { //on arm 1
					/*
					nMaleAccum = nMaleArm1Accum += (it->second)[0];
					nFemaleAccum = nFemaleArm1Accum += (it->second)[2];
					*/
					nMaleArm1Accum += (it->second)[0];
					nFemaleArm1Accum += (it->second)[2];
				}
				else {
					/*
					nMaleAccum = nMaleArm2Accum += (it->second)[0];
					nFemaleAccum = nFemaleArm2Accum += (it->second)[2];
					*/
					 nMaleArm2Accum += (it->second)[0];
					 nFemaleArm2Accum += (it->second)[2];
				}
				
				//fOutFile << setprecision (10) << it->first << '\t' << (it->second)[0] << '\t' << nMaleAccum << '\t' << (it->second)[1] << '\t' << nMaleAccum * nMaxAvgRecombRate  << '\t' << (it->second)[2] << '\t' << nFemaleAccum << '\t' << (it->second)[3] << '\t' << nFemaleAccum * nMaxAvgRecombRate << endl;
			}


			double nScaledMaleArm1Accum = 0;
			double nScaledFemaleArm1Accum = 0;
			double nScaledMaleArm2Accum = 0;
			double nScaledFemaleArm2Accum = 0;

			double nScaledMaleProb = 0;
			double nScaledFemaleProb = 0;
			
			double nPrevScaledMaleArm1Accum =0;
			double nPrevScaledFemaleArm1Accum =0;
			double nPrevScaledMaleArm2Accum =0;
			double nPrevScaledFemaleArm2Accum =0;
			
			double nKosambiMapDistance_male = 0;
			double nKosambiMapDistance_female = 0;
			double nKosambiMapDistance_both = 0;			
			
			double nKosambiMapPos_male = 0;
			double nKosambiMapPos_female = 0;
			double nKosambiMapPos_both = 0;
			
			double nRecombFraction_male = 0;
			double nRecombFraction_female = 0;
			double nRecombFraction_both = 0;
			
	
			for (std::map<double,double *>::iterator it = mSamplePoints.begin(); it != mSamplePoints.end(); ++it) {
			
				double nMaleAccum, nFemaleAccum;
				if (it->first < nCentromerePos) { //on arm 1
					nScaledMaleProb = (it->second)[0] / nMaleArm1Accum;
					nScaledFemaleProb = (it->second)[2] / nFemaleArm1Accum;
					nMaleAccum = nScaledMaleArm1Accum += nScaledMaleProb;
					nFemaleAccum = nScaledFemaleArm1Accum += nScaledFemaleProb;
					
					 nRecombFraction_male = nExpectedMaleRecPerMeiosisArm1 * nScaledMaleProb  ;
					 nKosambiMapPos_male += nKosambiMapDistance_male = 0.25 * log( (1+2 * nRecombFraction_male)/(1-2 * nRecombFraction_male) ) ;
					 nRecombFraction_female = nExpectedFemaleRecPerMeiosisArm1 * nScaledFemaleProb ;
					 nKosambiMapPos_female += nKosambiMapDistance_female = 0.25 * log( (1+2 * nRecombFraction_female)/(1-2 * nRecombFraction_female) ) ;
		
					
					
				}
				else {
					nScaledMaleProb = (it->second)[0] / nMaleArm2Accum;
					nScaledFemaleProb = (it->second)[2] / nFemaleArm2Accum;
					nMaleAccum = nScaledMaleArm2Accum += nScaledMaleProb;
					nFemaleAccum = nScaledFemaleArm2Accum += nScaledFemaleProb;
					
					nRecombFraction_male = nExpectedMaleRecPerMeiosisArm2 * nScaledMaleProb  ;
					 nKosambiMapPos_male += nKosambiMapDistance_male = 0.25 * log( (1+2 * nRecombFraction_male)/(1-2 * nRecombFraction_male) ) ;
					 nRecombFraction_female = nExpectedFemaleRecPerMeiosisArm2 * nScaledFemaleProb  ;
					 nKosambiMapPos_female += nKosambiMapDistance_female = 0.25 * log( (1+2 * nRecombFraction_female)/(1-2 * nRecombFraction_female) ) ;
					 
					
				}
				
				nRecombFraction_both = (nRecombFraction_male + nRecombFraction_female)/2;
				nKosambiMapPos_both += nKosambiMapDistance_both = 0.25 * log( (1+2 * nRecombFraction_both)/(1-2 * nRecombFraction_both) ) ;
					 

				
				fOutFile << setprecision (10) << it->first << '\t' << nScaledMaleProb << '\t' << nMaleAccum << '\t' << nScaledFemaleProb << '\t' << nFemaleAccum;
				fOutFile << setprecision (10) << '\t' << nRecombFraction_male << '\t' << nRecombFraction_female << '\t' << nRecombFraction_both << '\t' << nKosambiMapDistance_male << '\t' << nKosambiMapPos_male << '\t' << nKosambiMapDistance_female << '\t' << nKosambiMapPos_female << '\t' << nKosambiMapDistance_both << '\t' << nKosambiMapPos_both << endl;
			
				double nPrevScaledMaleArm1Accum = nScaledMaleArm1Accum;
				double nPrevScaledFemaleArm1Accum = nScaledFemaleArm1Accum;
				double nPrevScaledMaleArm2Accum = nScaledMaleArm2Accum;
				double nPrevScaledFemaleArm2Accum = nScaledFemaleArm2Accum;
				
			
			}
		
		
		
		}
		
		fOutFile.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x368, %rsp            # imm = 0x368
movq %rdx, 0x118(%rsp)
movl %edi, %ebp
movq %rsi, 0x110(%rsp)
movq %rsi, %rdi
movl %ebp, %esi
callq 0x29a3e
movsd %xmm0, 0x60(%rsp)
movq 0x20812(%rip), %r14     # 0x48f90
leaq 0xed7f(%rip), %rsi      # 0x37504
movl $0x73, %edx
movq %r14, %rdi
callq 0x7400
movq 0x20837(%rip), %rdi     # 0x48fd0
leaq 0xa0(%rsp), %rbx
movq %rbx, %rsi
callq 0x7220
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
jbe 0x28831
leaq 0xedbe(%rip), %r15      # 0x37578
leaq 0xed43(%rip), %rbx      # 0x37504
movq 0x20808(%rip), %r12     # 0x48fd0
leaq 0xa0(%rsp), %r13
movl $0x1a, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7400
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movl $0x73, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7400
movq %r12, %rdi
movq %r13, %rsi
callq 0x7220
xorpd %xmm0, %xmm0
ucomisd 0xa0(%rsp), %xmm0
ja 0x287d0
leaq 0xed5b(%rip), %r15      # 0x37593
movl $0x2b, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7400
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
leaq 0xed22(%rip), %rsi      # 0x375bf
movl $0x28, %edx
movq %r14, %rdi
callq 0x7400
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
leaq 0xed10(%rip), %rsi      # 0x375e8
movl $0x24, %edx
movq %r14, %rdi
callq 0x7400
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
leaq 0xecfa(%rip), %rsi      # 0x3760d
movl $0x2d, %edx
movq %r14, %rdi
callq 0x7400
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
leaq 0xeced(%rip), %rsi      # 0x3763b
movl $0x20, %edx
movq %r14, %rdi
callq 0x7400
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movq %rax, %rbx
leaq 0xeca9(%rip), %rsi      # 0x3765c
movl $0x1d, %edx
movq %rax, %rdi
callq 0x7400
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
leaq 0xec65(%rip), %rsi      # 0x3767a
movl $0x2d, %edx
movq %r14, %rdi
callq 0x7400
leaq 0xec7f(%rip), %rsi      # 0x376a8
movl $0x2b, %edx
movq %r14, %rdi
callq 0x7400
movl $0x2b, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7400
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movq %rbp, 0x10(%rsp)
leal (,%rbp,4), %eax
leal (%rax,%rax,4), %eax
movl %eax, 0x8(%rsp)
leaq 0xec4d(%rip), %rsi      # 0x376d4
movl $0x2f, %edx
movq %r14, %rdi
callq 0x7400
movq 0x20535(%rip), %r15     # 0x48fd0
leaq 0x58(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7220
movsd (%rbx), %xmm0
movsd 0xe5b1(%rip), %xmm1     # 0x37068
ucomisd %xmm0, %xmm1
ja 0x28acb
ucomisd 0xc9eb(%rip), %xmm0     # 0x354b0
jbe 0x28b55
leaq 0xeaa6(%rip), %r12      # 0x37578
leaq 0xebfb(%rip), %r13      # 0x376d4
movq 0x204f0(%rip), %rbp     # 0x48fd0
leaq 0x58(%rsp), %rbx
movl $0x1a, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x7400
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movl $0x2f, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x7400
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x7220
movsd 0x58(%rsp), %xmm0
movsd 0xe523(%rip), %xmm1     # 0x37068
ucomisd %xmm0, %xmm1
ja 0x28ae5
ucomisd 0xc95d(%rip), %xmm0     # 0x354b0
ja 0x28ae5
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
movq 0x20422(%rip), %rdi     # 0x48f90
leaq 0xe832(%rip), %rsi      # 0x373a7
movl $0x13, %edx
callq 0x7400
leaq 0xf0(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xe0(%rsp), %rbx
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x76d0
cmpq $0x3, 0xe8(%rsp)
jbe 0x28b9e
leaq 0x168(%rsp), %rdi
callq 0x7650
movq 0xe0(%rsp), %rsi
leaq 0x168(%rsp), %r15
movq %r15, %rdi
movl $0x10, %edx
callq 0x7070
movq 0x10(%rsp), %rax
testl %eax, %eax
jle 0x295d3
leaq 0x140(%rsp), %rbp
movl %eax, %eax
movq %rax, 0x100(%rsp)
movq %rsp, %r13
xorl %ecx, %ecx
movq 0x110(%rsp), %rax
movsd (%rax,%rcx,8), %xmm1
movq 0x118(%rsp), %rax
movq %rcx, %rbx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
divsd 0x60(%rsp), %xmm0
mulsd 0x108(%rsp), %xmm0
callq 0x7710
movsd %xmm0, 0x18(%rsp)
movl $0x5, %edx
movq %r15, %rdi
leaq 0xe7d0(%rip), %rsi      # 0x3743f
callq 0x7400
movq %rbx, %rsi
incq %rsi
movq %r15, %rdi
movq %rsi, 0x120(%rsp)
callq 0x7670
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movsd 0xa0(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
movsd %xmm0, 0x20(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movl $0x21, %edx
movq %r15, %rdi
leaq 0xea22(%rip), %rsi      # 0x37704
callq 0x7400
movsd 0x48(%rsp), %xmm0
divsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
mulsd 0x20(%rsp), %xmm0
mulsd 0xc709(%rip), %xmm0     # 0x35410
movq %r15, %rdi
movsd %xmm0, 0x128(%rsp)
callq 0x75c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movl $0x21, %edx
movq %r15, %rdi
leaq 0xe9d5(%rip), %rsi      # 0x37726
callq 0x7400
movsd 0x10(%rsp), %xmm1
subsd 0x48(%rsp), %xmm1
divsd 0x60(%rsp), %xmm1
movsd 0x20(%rsp), %xmm0
movsd %xmm1, 0x68(%rsp)
mulsd %xmm1, %xmm0
mulsd 0xc690(%rip), %xmm0     # 0x35410
movq %r15, %rdi
movsd %xmm0, 0x20(%rsp)
callq 0x75c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movl $0x23, %edx
movq %r15, %rdi
leaq 0xe981(%rip), %rsi      # 0x37748
callq 0x7400
movsd 0x70(%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
mulsd 0xc630(%rip), %xmm0     # 0x35410
movq %r15, %rdi
movsd %xmm0, 0x70(%rsp)
callq 0x75c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movl $0x23, %edx
movq %r15, %rdi
leaq 0xe945(%rip), %rsi      # 0x3776c
callq 0x7400
movsd 0x68(%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
mulsd 0xc5d0(%rip), %xmm0     # 0x35410
movq %r15, %rdi
movsd %xmm0, 0x68(%rsp)
callq 0x75c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movl $0x5, %edx
movq %r15, %rdi
leaq 0xe909(%rip), %rsi      # 0x37790
callq 0x7400
movl $0x12, %edx
movq %r15, %rdi
leaq 0xe8fb(%rip), %rsi      # 0x37796
callq 0x7400
movl $0xe9, %edx
movq %r15, %rdi
leaq 0xe8fa(%rip), %rsi      # 0x377a9
callq 0x7400
movq 0x168(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
cvttsd2si 0x18(%rsp), %r12d
movl $0x0, 0x140(%rsp)
xorl %eax, %eax
movq %rax, 0x148(%rsp)
movq %rbp, 0x150(%rsp)
movq %rbp, 0x158(%rsp)
movq %rax, 0x160(%rsp)
testl %r12d, %r12d
jle 0x29013
xorl %ebx, %ebx
leaq 0x20b1a(%rip), %rdi     # 0x49a40
callq 0xbaa8
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x58(%rsp), %xmm0
mulsd 0xe124(%rip), %xmm0     # 0x37068
movsd %xmm0, 0x8(%rsp)
movl $0x20, %edi
callq 0x7030
movq %rax, %r14
xorpd %xmm2, %xmm2
movsd 0xe105(%rip), %xmm0     # 0x37068
movsd 0xe105(%rip), %xmm1     # 0x37070
movsd 0xc0a5(%rip), %xmm3     # 0x35018
callq 0x299dc
movsd %xmm0, (%r14)
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm1
mulsd 0xc481(%rip), %xmm1     # 0x35410
xorpd %xmm2, %xmm2
movsd 0xc07d(%rip), %xmm3     # 0x35018
callq 0x299dc
movsd %xmm0, 0x10(%r14)
movq 0x148(%rsp), %rcx
movq %rbp, %rax
testq %rcx, %rcx
je 0x28fd6
movsd (%rsp), %xmm0
movq %rbp, %rax
xorl %edx, %edx
ucomisd 0x20(%rcx), %xmm0
cmovbeq %rcx, %rax
seta %dl
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x28fbe
movq %rbp, %rcx
cmpq %rbp, %rax
je 0x28ff0
movsd 0x20(%rax), %xmm0
ucomisd (%rsp), %xmm0
movq %rbp, %rcx
ja 0x28ff0
movq %rax, %rcx
cmpq %rbp, %rcx
jne 0x2900a
leaq 0x138(%rsp), %rdi
movq %r13, %rsi
callq 0x296d8
movq %r14, (%rax)
incl %ebx
cmpl %r12d, %ebx
jl 0x28f1f
movq 0x150(%rsp), %r14
xorpd %xmm0, %xmm0
cmpq %rbp, %r14
je 0x290ae
movsd %xmm0, 0x40(%rsp)
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x38(%rsp)
movq %r14, %rax
movsd 0x48(%rsp), %xmm0
ucomisd 0x20(%rax), %xmm0
movq 0x28(%rax), %rcx
movsd (%rcx), %xmm1
movsd 0x10(%rcx), %xmm0
jbe 0x2907f
movsd 0x40(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x40(%rsp)
movsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
jmp 0x2909f
movsd 0x28(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x28(%rsp)
movsd 0x38(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movq %rax, %rdi
callq 0x7270
cmpq %rbp, %rax
jne 0x29043
jmp 0x290c6
movsd %xmm0, 0x38(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x40(%rsp)
cmpq %rbp, %r14
je 0x295b0
xorpd %xmm0, %xmm0
movsd %xmm0, 0xc0(%rsp)
movsd %xmm0, 0xc8(%rsp)
movsd %xmm0, 0xd0(%rsp)
movsd %xmm0, 0x90(%rsp)
movsd %xmm0, 0x88(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm0, 0x78(%rsp)
movsd 0x48(%rsp), %xmm0
ucomisd 0x20(%r14), %xmm0
movq 0x28(%r14), %rax
movsd (%rax), %xmm0
movsd 0x10(%rax), %xmm1
jbe 0x291d9
divsd 0x40(%rsp), %xmm0
divsd 0x30(%rsp), %xmm1
movsd %xmm1, 0x50(%rsp)
movsd 0x78(%rsp), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, 0x78(%rsp)
movsd 0x80(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x80(%rsp)
movsd 0x128(%rsp), %xmm1
movsd %xmm0, 0xb8(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm1, 0x98(%rsp)
movapd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd 0xbe83(%rip), %xmm2     # 0x35018
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
addsd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x7730
movsd %xmm0, 0x8(%rsp)
movsd 0x70(%rsp), %xmm0
mulsd 0x50(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
movsd %xmm1, 0xb0(%rsp)
movsd 0x80(%rsp), %xmm1
jmp 0x29285
divsd 0x28(%rsp), %xmm0
divsd 0x38(%rsp), %xmm1
movsd %xmm1, 0x50(%rsp)
movsd 0x88(%rsp), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, 0x88(%rsp)
movsd 0x90(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x90(%rsp)
movsd 0x20(%rsp), %xmm1
movsd %xmm0, 0xb8(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm1, 0x98(%rsp)
movapd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd 0xbdd5(%rip), %xmm2     # 0x35018
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
addsd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x7730
movsd %xmm0, 0x8(%rsp)
movsd 0x68(%rsp), %xmm0
mulsd 0x50(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movsd %xmm1, 0xb0(%rsp)
movsd 0x90(%rsp), %xmm1
movsd %xmm1, 0xa8(%rsp)
movsd %xmm0, 0xd8(%rsp)
addsd %xmm0, %xmm0
movsd 0xbd75(%rip), %xmm2     # 0x35018
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
addsd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x7730
movsd %xmm0, 0x10(%rsp)
movsd 0x98(%rsp), %xmm0
addsd 0xd8(%rsp), %xmm0
mulsd 0xc138(%rip), %xmm0     # 0x35410
movsd %xmm0, 0x130(%rsp)
addsd %xmm0, %xmm0
movsd 0xbd2b(%rip), %xmm2     # 0x35018
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
addsd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x7730
movsd %xmm0, 0x18(%rsp)
movq 0x168(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xa, 0x170(%rsp,%rax)
movsd 0x20(%r14), %xmm0
movq %r15, %rdi
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movsd 0xb8(%rsp), %xmm0
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movsd 0xb0(%rsp), %xmm0
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movsd 0x50(%rsp), %xmm0
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movsd 0xa8(%rsp), %xmm0
callq 0x75c0
movq 0x168(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xa, 0x170(%rsp,%rax)
movb $0x9, (%rsp)
movl $0x1, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movsd 0x98(%rsp), %xmm0
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movsd 0xd8(%rsp), %xmm0
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movsd 0x130(%rsp), %xmm0
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movsd 0x8(%rsp), %xmm0
mulsd 0xdc10(%rip), %xmm0     # 0x37078
movq %rax, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movsd 0xd0(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
movq %rax, %rdi
movsd %xmm0, 0xd0(%rsp)
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movsd 0x10(%rsp), %xmm0
mulsd 0xdbac(%rip), %xmm0     # 0x37078
movq %rax, %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movsd 0xc8(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movq %rax, %rdi
movsd %xmm0, 0xc8(%rsp)
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movsd 0x18(%rsp), %xmm0
mulsd 0xdb48(%rip), %xmm0     # 0x37078
movq %rax, %rdi
movsd %xmm0, 0x18(%rsp)
callq 0x75c0
movb $0x9, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movsd 0xc0(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movq %rax, %rdi
movsd %xmm0, 0xc0(%rsp)
callq 0x75c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r12, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movq %r14, %rdi
callq 0x7270
movq %rax, %r14
cmpq %rbp, %rax
jne 0x2910f
leaq 0x138(%rsp), %rdi
callq 0x29742
movq 0x120(%rsp), %rcx
cmpq 0x100(%rsp), %rcx
jne 0x28c19
leaq 0x168(%rsp), %rdi
callq 0x74e0
movq 0x1f961(%rip), %rax     # 0x48f48
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x170(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x168(%rsp,%rcx)
callq 0x72f0
leaq 0x260(%rsp), %rdi
callq 0x7120
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x2963d
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x7390
addq $0x368, %rsp            # imm = 0x368
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x29653
jmp 0x2965c
movq %rax, %rbx
jmp 0x296ab
jmp 0x2965c
jmp 0x29663
movq %rax, %rbx
jmp 0x29673
jmp 0x29663
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x29742
movq 0x1f8ce(%rip), %rax     # 0x48f48
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x170(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x168(%rsp,%rcx)
callq 0x72f0
leaq 0x260(%rsp), %rdi
callq 0x7120
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x296d0
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x7390
movq %rbx, %rdi
callq 0x76a0