// File: /workspace/github_cpp_makefile_star2_O3/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 $0x3a8, %rsp            # imm = 0x3A8
movq %rdx, 0x120(%rsp)
movl %edi, %ebp
movq %rsi, 0x118(%rsp)
movq %rsi, %rdi
movl %ebp, %esi
callq 0x296b2
movsd %xmm0, 0x50(%rsp)
movq 0x1fab8(%rip), %r14     # 0x47f90
leaq 0xe005(%rip), %rsi      # 0x364e4
movl $0x73, %edx
movq %r14, %rdi
callq 0x7400
movq 0x1fadd(%rip), %rdi     # 0x47fd0
leaq 0x58(%rsp), %rbx
movq %rbx, %rsi
callq 0x7220
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
jbe 0x28582
leaq 0xe047(%rip), %r15      # 0x36558
leaq 0xdfcc(%rip), %rbx      # 0x364e4
movq 0x1fab1(%rip), %r12     # 0x47fd0
leaq 0x58(%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 0x58(%rsp), %xmm0
ja 0x28524
leaq 0xdfea(%rip), %r15      # 0x36573
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 0xdfb1(%rip), %rsi      # 0x3659f
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 0xdf9f(%rip), %rsi      # 0x365c8
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 0xdf89(%rip), %rsi      # 0x365ed
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 0xdf7c(%rip), %rsi      # 0x3661b
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 0xdf38(%rip), %rsi      # 0x3663c
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 0xdef4(%rip), %rsi      # 0x3665a
movl $0x2d, %edx
movq %r14, %rdi
callq 0x7400
leaq 0xdf0e(%rip), %rsi      # 0x36688
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, 0x20(%rsp)
leal (,%rbp,4), %eax
leal (%rax,%rax,4), %eax
movl %eax, 0x10(%rsp)
leaq 0xdedc(%rip), %rsi      # 0x366b4
movl $0x2f, %edx
movq %r14, %rdi
callq 0x7400
movq 0x1f7e4(%rip), %r15     # 0x47fd0
leaq 0x38(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7220
movsd (%rbx), %xmm0
movsd 0xd800(%rip), %xmm1     # 0x36008
ucomisd %xmm0, %xmm1
ja 0x2881c
ucomisd 0xbc62(%rip), %xmm0     # 0x34478
jbe 0x288a6
leaq 0xdd35(%rip), %r12      # 0x36558
leaq 0xde8a(%rip), %r13      # 0x366b4
movq 0x1f79f(%rip), %rbp     # 0x47fd0
leaq 0x38(%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 0x38(%rsp), %xmm0
movsd 0xd772(%rip), %xmm1     # 0x36008
ucomisd %xmm0, %xmm1
ja 0x28836
ucomisd 0xbbd4(%rip), %xmm0     # 0x34478
ja 0x28836
xorps %xmm0, %xmm0
cvtsi2sdl 0x10(%rsp), %xmm0
movsd %xmm0, 0x110(%rsp)
movq 0x1f6d1(%rip), %rdi     # 0x47f90
leaq 0xdac1(%rip), %rsi      # 0x36387
movl $0x13, %edx
callq 0x7400
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x80(%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, 0x88(%rsp)
jbe 0x288ef
leaq 0x1a8(%rsp), %rdi
callq 0x7650
movq 0x80(%rsp), %rsi
leaq 0x1a8(%rsp), %r15
movq %r15, %rdi
movl $0x10, %edx
callq 0x7070
movq 0x20(%rsp), %rax
testl %eax, %eax
jle 0x2924f
leaq 0x138(%rsp), %rbp
movl %eax, %eax
movq %rax, 0x108(%rsp)
leaq 0x8(%rsp), %r13
xorl %ebx, %ebx
movq 0x118(%rsp), %rax
movsd (%rax,%rbx,8), %xmm1
movq 0x120(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd %xmm1, 0x20(%rsp)
movapd %xmm1, %xmm0
divsd 0x50(%rsp), %xmm0
mulsd 0x110(%rsp), %xmm0
callq 0x7710
movsd %xmm0, 0x60(%rsp)
movl $0x5, %edx
movq %r15, %rdi
leaq 0xda60(%rip), %rsi      # 0x3641f
callq 0x7400
incq %rbx
movq %r15, %rdi
movl %ebx, %esi
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 0x58(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movapd %xmm0, 0x10(%rsp)
mulsd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
movl $0x21, %edx
movq %r15, %rdi
leaq 0xdcbe(%rip), %rsi      # 0x366e4
callq 0x7400
movsd 0x30(%rsp), %xmm0
divsd 0x50(%rsp), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd 0x10(%rsp), %xmm1
unpcklpd 0x40(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movapd %xmm1, 0x10(%rsp)
mulpd %xmm1, %xmm0
mulpd 0xd5c7(%rip), %xmm0     # 0x36020
movq %r15, %rdi
movapd %xmm0, 0x170(%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 0xdc63(%rip), %rsi      # 0x36706
callq 0x7400
movsd 0x20(%rsp), %xmm0
subsd 0x30(%rsp), %xmm0
divsd 0x50(%rsp), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0x10(%rsp), %xmm0
mulpd 0xd554(%rip), %xmm0     # 0x36020
movq %r15, %rdi
movapd %xmm0, 0x160(%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 0xdc12(%rip), %rsi      # 0x36728
callq 0x7400
movapd 0x170(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movq %r15, %rdi
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 0xdbe3(%rip), %rsi      # 0x3674c
callq 0x7400
movapd 0x160(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movq %r15, %rdi
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 0xdbb4(%rip), %rsi      # 0x36770
callq 0x7400
movl $0x12, %edx
movq %r15, %rdi
leaq 0xdba6(%rip), %rsi      # 0x36776
callq 0x7400
movl $0xe9, %edx
movq %r15, %rdi
leaq 0xdba5(%rip), %rsi      # 0x36789
callq 0x7400
movq 0x1a8(%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 0x60(%rsp), %r12d
movl $0x0, 0x138(%rsp)
xorl %eax, %eax
movq %rax, 0x140(%rsp)
movq %rbp, 0x148(%rsp)
movq %rbp, 0x150(%rsp)
movq %rax, 0x158(%rsp)
testl %r12d, %r12d
jle 0x29234
movq %rbx, 0x128(%rsp)
xorl %ebx, %ebx
leaq 0x1fddd(%rip), %rdi     # 0x48a40
callq 0xbba0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x38(%rsp), %xmm0
mulsd 0xd386(%rip), %xmm0     # 0x36008
movsd %xmm0, 0x10(%rsp)
movl $0x20, %edi
callq 0x7030
movq %rax, %r14
xorpd %xmm2, %xmm2
movsd 0xd367(%rip), %xmm0     # 0x36008
movsd 0xd367(%rip), %xmm1     # 0x36010
movsd 0xb367(%rip), %xmm3     # 0x34018
callq 0x29650
movsd %xmm0, (%r14)
movsd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
mulsd 0xb713(%rip), %xmm1     # 0x343e0
xorpd %xmm2, %xmm2
movsd 0xb33f(%rip), %xmm3     # 0x34018
callq 0x29650
movsd %xmm0, 0x10(%r14)
movq 0x140(%rsp), %rdx
testq %rdx, %rdx
je 0x28d37
movsd 0x8(%rsp), %xmm0
movq %rbp, %rsi
movq %rsi, %rax
movq %rdx, %rcx
movsd 0x20(%rdx), %xmm1
xorl %edx, %edx
ucomisd %xmm1, %xmm0
movq %rcx, %rsi
cmovaq %rax, %rsi
seta %dl
movq 0x10(%rcx,%rdx,8), %rdx
testq %rdx, %rdx
jne 0x28cfa
cmpq %rbp, %rsi
je 0x28d37
ucomisd %xmm1, %xmm0
cmovaq %rax, %rcx
movsd 0x20(%rcx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x28d4c
leaq 0x130(%rsp), %rdi
movq %r13, %rsi
callq 0x29354
movq %r14, (%rax)
incl %ebx
cmpl %r12d, %ebx
jl 0x28c5c
movq 0x148(%rsp), %r14
cmpq %rbp, %r14
movq 0x128(%rsp), %rbx
je 0x29234
xorpd %xmm0, %xmm0
movapd %xmm0, 0xd0(%rsp)
movq %r14, %rax
movapd %xmm0, 0xc0(%rsp)
movsd 0x30(%rsp), %xmm0
ucomisd 0x20(%rax), %xmm0
movq 0x28(%rax), %rcx
movsd (%rcx), %xmm0
movhpd 0x10(%rcx), %xmm0       # xmm0 = xmm0[0],mem[0]
ja 0x28db9
movapd 0xc0(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0xc0(%rsp)
jmp 0x28dcf
movapd 0xd0(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0xd0(%rsp)
movq %rax, %rdi
callq 0x7270
cmpq %rbp, %rax
jne 0x28d87
cmpq %rbp, %r14
je 0x29234
xorpd %xmm0, %xmm0
movapd %xmm0, 0xb0(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0x60(%rsp)
movsd 0x30(%rsp), %xmm0
ucomisd 0x20(%r14), %xmm0
movq 0x28(%r14), %rax
movsd (%rax), %xmm1
movsd 0x10(%rax), %xmm0
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
jbe 0x28e9e
divpd 0xd0(%rsp), %xmm1
movapd 0xb0(%rsp), %xmm0
addpd %xmm1, %xmm0
movapd %xmm0, 0xb0(%rsp)
movapd 0x170(%rsp), %xmm0
movapd %xmm1, 0xf0(%rsp)
mulpd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0xd1bb(%rip), %xmm0     # 0x36030
addpd 0xd1c3(%rip), %xmm0     # 0x36040
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
divsd %xmm1, %xmm0
callq 0x7730
movsd %xmm0, 0x10(%rsp)
movaps 0xb0(%rsp), %xmm0
jmp 0x28f0c
divpd 0xc0(%rsp), %xmm1
movapd 0xa0(%rsp), %xmm0
addpd %xmm1, %xmm0
movapd %xmm0, 0xa0(%rsp)
movapd 0x160(%rsp), %xmm0
movapd %xmm1, 0xf0(%rsp)
mulpd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0xd14b(%rip), %xmm0     # 0x36030
addpd 0xd153(%rip), %xmm0     # 0x36040
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
divsd %xmm1, %xmm0
callq 0x7730
movsd %xmm0, 0x10(%rsp)
movaps 0xa0(%rsp), %xmm0
movaps %xmm0, 0xe0(%rsp)
movapd 0x20(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm0, 0x180(%rsp)
addsd %xmm0, %xmm0
movsd 0xb0e5(%rip), %xmm2     # 0x34018
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
addsd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x7730
movapd %xmm0, 0x40(%rsp)
movsd 0x10(%rsp), %xmm0
mulsd 0xd0bc(%rip), %xmm0     # 0x36018
movsd %xmm0, 0x10(%rsp)
movapd 0x20(%rsp), %xmm0
addsd 0x180(%rsp), %xmm0
mulsd 0xb467(%rip), %xmm0     # 0x343e0
movapd %xmm0, 0x190(%rsp)
addsd %xmm0, %xmm0
movsd 0xb08a(%rip), %xmm2     # 0x34018
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
addsd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x7730
unpcklpd 0x40(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
mulpd 0xd09f(%rip), %xmm0     # 0x36050
movapd %xmm0, 0x40(%rsp)
movq 0x1a8(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xa, 0x1b0(%rsp,%rax)
movsd 0x20(%r14), %xmm0
movq %r15, %rdi
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movapd 0xf0(%rsp), %xmm0
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movapd 0xe0(%rsp), %xmm0
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movapd 0xf0(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movq %rax, %rdi
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movapd 0xe0(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movq %rax, %rdi
callq 0x75c0
movq 0x1a8(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xa, 0x1b0(%rsp,%rax)
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movapd 0x20(%rsp), %xmm0
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movapd 0x180(%rsp), %xmm0
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movapd 0x190(%rsp), %xmm0
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movsd 0x78(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movq %rax, %rdi
movsd %xmm0, 0x78(%rsp)
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movapd 0x40(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movq %rax, %rdi
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movapd 0x60(%rsp), %xmm0
addpd 0x40(%rsp), %xmm0
movapd %xmm0, 0x60(%rsp)
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movq %rax, %rdi
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movapd 0x40(%rsp), %xmm0
callq 0x75c0
movb $0x9, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7400
movq %rax, %rdi
movapd 0x60(%rsp), %xmm0
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 0x28e0f
leaq 0x130(%rsp), %rdi
callq 0x293c0
cmpq 0x108(%rsp), %rbx
jne 0x2896c
leaq 0x1a8(%rsp), %rdi
callq 0x74e0
movq 0x1ece5(%rip), %rax     # 0x47f48
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x1b0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x1a8(%rsp,%rcx)
callq 0x72f0
leaq 0x2a0(%rsp), %rdi
callq 0x7120
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x292b9
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x7390
addq $0x3a8, %rsp            # imm = 0x3A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x292cf
jmp 0x292d8
movq %rax, %rbx
jmp 0x29327
jmp 0x292d8
jmp 0x292df
movq %rax, %rbx
jmp 0x292ef
jmp 0x292df
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x293c0
movq 0x1ec52(%rip), %rax     # 0x47f48
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x1b0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x1a8(%rsp,%rcx)
callq 0x72f0
leaq 0x2a0(%rsp), %rdi
callq 0x7120
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x2934c
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x7390
movq %rbx, %rdi
callq 0x76a0