// File: /workspace/github_cpp_makefile_star2_O2/melop[P]admixem/config.cpp
// Function: MarkerConfigurations::CalculateMapDistances()
void MarkerConfigurations::CalculateMapDistances() { // calculate map distances for each marker
	
	vector<double> * pvMaleMapDistances = ((SimulationConfigurations *)this->_pParentConfig)->pRecombProbConfig->GetBreakPointMapDistances(1);

	//if (!pvMaleMapDistances) return; //The recombination mode is not predetermined mode , not available;

	vector<double> * pvFemaleMapDistances = ((SimulationConfigurations *)this->_pParentConfig)->pRecombProbConfig->GetBreakPointMapDistances(0);
	vector<double> * pvAvgMapDistances = ((SimulationConfigurations *)this->_pParentConfig)->pRecombProbConfig->GetBreakPointMapDistances(2);
	vector<double> * pvBreakpointSamplePositions = ((SimulationConfigurations *)this->_pParentConfig)->pRecombProbConfig->GetBreakPointSamplePositions();
	vAbsToMapDistanceMale.clear();
	vAbsToMapDistanceFemale.clear();
	vAbsToMapDistanceAvg.clear();


	for (int nChr=0 ; nChr < this->_nHaploidChrNum; nChr++ ) {

		double nMaleExpBreakpoints = ((SimulationConfigurations *)this->_pParentConfig)->pRecombProbConfig->HowManyBreakpointsOnArm(true, nChr, 1) + 
										((SimulationConfigurations *)this->_pParentConfig)->pRecombProbConfig->HowManyBreakpointsOnArm(true, nChr, 2);
		double nFemaleExpBreakpoints = ((SimulationConfigurations *)this->_pParentConfig)->pRecombProbConfig->HowManyBreakpointsOnArm(false, nChr, 1) + 
										((SimulationConfigurations *)this->_pParentConfig)->pRecombProbConfig->HowManyBreakpointsOnArm(false, nChr, 2);
		double nAvgExpBreakpoints = (nMaleExpBreakpoints + nFemaleExpBreakpoints) / 2;

		double nChrLen = this->pChrLen[nChr];

		vector<double> * pvBreakpointSamplePositionsOnChr = &pvBreakpointSamplePositions[nChr];
		vector<double> * pvMaleMapDistancesOnChr = &pvMaleMapDistances[nChr];
		vector<double> * pvFemaleMapDistancesOnChr = &pvFemaleMapDistances[nChr];
		vector<double> * pvAvgMapDistancesOnChr = &pvAvgMapDistances[nChr];

		map<double, int> * pmMarkerIndexOnChr = &(vMarkerIndex.at(nChr));
		map<double, double> mAbsToMapDistanceOnChrMale, mAbsToMapDistanceOnChrFemale, mAbsToMapDistanceOnChrAvg ;

		double nPosLastSample = 0;

		for (map<double,int>::iterator itMarker=pmMarkerIndexOnChr->begin(); itMarker!= pmMarkerIndexOnChr->end(); ++itMarker) 
		{

			double nPos = (*itMarker).first;
			double nAbsSampleDistance, nMapMaleSampleDistance, nMapFemaleSampleDistance, nMapAvgSampleDistance, nMapMaleDistance, nMapFemaleDistance, nMapAvgDistance;

			if (((SimulationConfigurations *)this->_pParentConfig)->pRecombProbConfig->IsUseUniform()) { //if user specified using uniform rate, then no need to extrapolate.
				nMapMaleDistance = (nPos / nChrLen ) * nMaleExpBreakpoints;
				nMapFemaleDistance = (nPos / nChrLen ) * nFemaleExpBreakpoints;
				nMapAvgDistance = (nPos / nChrLen ) * nAvgExpBreakpoints;
			}
			else {

				vector<double>::iterator itClosestFollowingBreakpoint = upper_bound(pvBreakpointSamplePositionsOnChr->begin(), pvBreakpointSamplePositionsOnChr->end(), nPos);
				if (itClosestFollowingBreakpoint ==pvBreakpointSamplePositionsOnChr->end() ) {
					int nIndexLastSample = pvBreakpointSamplePositionsOnChr->size()-1;
					int nIndexSecondToLastSample = nIndexLastSample - 1;
					double nPosLastSample = pvBreakpointSamplePositionsOnChr->at(nIndexLastSample);//Last breakpoint sample
					double nPosSecondToLastSample = pvBreakpointSamplePositionsOnChr->at(nIndexSecondToLastSample);
					nAbsSampleDistance = (nPosLastSample - nPosSecondToLastSample);
					nMapMaleSampleDistance = pvMaleMapDistancesOnChr->at(nIndexLastSample);// - pvMaleMapDistancesOnChr->at(nIndexSecondToLastSample);
					nMapFemaleSampleDistance = pvFemaleMapDistancesOnChr->at(nIndexLastSample);// - pvFemaleMapDistancesOnChr->at(nIndexSecondToLastSample);
					nMapAvgSampleDistance = pvAvgMapDistancesOnChr->at(nIndexLastSample);// - pvAvgMapDistancesOnChr->at(nIndexSecondToLastSample);

					//extrapolate
					double nAbsDistanceMarkerToPrevMarker = nPos - nPosLastSample;
					double nPercentFromPrevSample = ( nAbsDistanceMarkerToPrevMarker / nAbsSampleDistance);
					nMapMaleDistance = nMapMaleSampleDistance  * nPercentFromPrevSample;
					nMapFemaleDistance = nMapFemaleSampleDistance * nPercentFromPrevSample;
					nMapAvgDistance = nMapAvgSampleDistance * nPercentFromPrevSample;
				}
				else {
					if (itClosestFollowingBreakpoint != pvBreakpointSamplePositionsOnChr->begin())
					{
						vector<double>::iterator itClosestPrevBreakpoint = itClosestFollowingBreakpoint - 1;
						size_t nIndexClosestFollowingBreakpoint = distance(pvBreakpointSamplePositionsOnChr->begin(),itClosestFollowingBreakpoint );
						size_t nIndexClosestPrevBreakpoint = nIndexClosestFollowingBreakpoint - 1;

						nAbsSampleDistance = ( *itClosestFollowingBreakpoint - *itClosestPrevBreakpoint);
						nMapMaleSampleDistance = pvMaleMapDistancesOnChr->at(nIndexClosestFollowingBreakpoint);// - pvMaleMapDistancesOnChr->at(nIndexClosestPrevBreakpoint);
						nMapFemaleSampleDistance = pvFemaleMapDistancesOnChr->at(nIndexClosestFollowingBreakpoint);// - pvFemaleMapDistancesOnChr->at(nIndexClosestPrevBreakpoint);
						nMapAvgSampleDistance = pvAvgMapDistancesOnChr->at(nIndexClosestFollowingBreakpoint);// - pvAvgMapDistancesOnChr->at(nIndexClosestPrevBreakpoint);


					}
					else {
						nAbsSampleDistance = *itClosestFollowingBreakpoint;
						nMapMaleSampleDistance = pvMaleMapDistancesOnChr->at(0);
						nMapFemaleSampleDistance = pvFemaleMapDistancesOnChr->at(0);
						nMapAvgSampleDistance = pvAvgMapDistancesOnChr->at(0);

					}



					//extrapolate
					double nAbsDistanceMarkerToPrevMarker = nPos - nPosLastSample;;
					double nPercentFromPrevSample = (nAbsDistanceMarkerToPrevMarker  / nAbsSampleDistance);

					nMapMaleDistance = nMapMaleSampleDistance * nPercentFromPrevSample;
					nMapFemaleDistance = nMapFemaleSampleDistance * nPercentFromPrevSample;
					nMapAvgDistance = nMapAvgSampleDistance * nPercentFromPrevSample;
				}

				nPosLastSample = nPos;
				/*
				if (nMapMaleDistance == 0.0) {
					printf("f");
				}
				*/
			}
			mAbsToMapDistanceOnChrMale.insert(pair<double, double>(nPos, nMapMaleDistance * 100));
			mAbsToMapDistanceOnChrFemale.insert(pair<double, double>(nPos, nMapFemaleDistance * 100 ));
			mAbsToMapDistanceOnChrAvg.insert(pair<double, double>(nPos, nMapAvgDistance * 100));
		}

		this->vAbsToMapDistanceAvg.push_back(mAbsToMapDistanceOnChrAvg);
		this->vAbsToMapDistanceMale.push_back(mAbsToMapDistanceOnChrMale);
		this->vAbsToMapDistanceFemale.push_back(mAbsToMapDistanceOnChrFemale);
	}
	//printf("hello");

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdi, %rbp
movq (%rdi), %rax
movq 0x8(%rax), %rax
cmpb $0x0, 0x70(%rax)
je 0xf1ba
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
jmp 0xf1de
movq 0x108(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x110(%rax), %rcx
movq %rcx, 0x60(%rsp)
movq 0x118(%rax), %rcx
movq %rcx, 0x50(%rsp)
movq 0x78(%rax), %rax
movq %rax, 0x88(%rsp)
leaq 0x80(%rbp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x16f96
leaq 0x98(%rbp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x16f96
leaq 0xb0(%rbp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x16f96
leaq 0x68(%rbp), %rax
movq %rax, 0x80(%rsp)
xorl %esi, %esi
leaq 0x128(%rsp), %r12
leaq 0xf8(%rsp), %rbx
leaq 0xc8(%rsp), %r13
movslq 0x8(%rbp), %rax
cmpq %rax, %rsi
jge 0xf71b
movq (%rbp), %rax
movq 0x30(%rbp), %rcx
movq 0x8(%rax), %rax
movq 0x30(%rax), %rdx
movq 0x38(%rax), %rdi
movsd (%rdx,%rsi,8), %xmm0
addsd (%rdi,%rsi,8), %xmm0
movq 0x40(%rax), %rdx
movsd (%rdx,%rsi,8), %xmm1
movq 0x48(%rax), %rax
addsd (%rax,%rsi,8), %xmm1
movsd %xmm0, 0xb0(%rsp)
movsd %xmm1, 0xa8(%rsp)
addsd %xmm1, %xmm0
mulsd 0x1e15a(%rip), %xmm0    # 0x2d3f8
movsd %xmm0, 0xa0(%rsp)
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, 0x98(%rsp)
imulq $0x18, %rsi, %rcx
movq 0x88(%rsp), %rax
leaq (%rax,%rcx), %r14
movq 0x58(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x60(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x30(%rsp)
addq 0x50(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movq 0x80(%rsp), %rdi
movq %rsi, 0x90(%rsp)
callq 0x16f9e
andl $0x0, 0x100(%rsp)
andq $0x0, 0x108(%rsp)
leaq 0x100(%rsp), %rcx
movq %rcx, 0x110(%rsp)
movq %rcx, 0x118(%rsp)
andq $0x0, 0x120(%rsp)
andl $0x0, 0xd0(%rsp)
andq $0x0, 0xd8(%rsp)
leaq 0xd0(%rsp), %rcx
movq %rcx, 0xe0(%rsp)
movq %rcx, 0xe8(%rsp)
andq $0x0, 0xf0(%rsp)
andl $0x0, 0x130(%rsp)
andq $0x0, 0x138(%rsp)
leaq 0x130(%rsp), %rcx
movq %rcx, 0x140(%rsp)
movq %rcx, 0x148(%rsp)
andq $0x0, 0x150(%rsp)
movq 0x18(%rax), %r15
addq $0x8, %rax
movq %rax, 0xc0(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r14, 0xb8(%rsp)
cmpq 0xc0(%rsp), %r15
je 0xf6cc
movsd 0x20(%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
movq (%rbp), %rax
movq 0x8(%rax), %rax
cmpb $0x1, 0x70(%rax)
jne 0xf41e
movapd %xmm0, %xmm3
divsd 0x98(%rsp), %xmm3
movsd 0xb0(%rsp), %xmm2
mulsd %xmm3, %xmm2
movsd 0xa8(%rsp), %xmm1
mulsd %xmm3, %xmm1
movsd %xmm1, 0x8(%rsp)
mulsd 0xa0(%rsp), %xmm3
movsd %xmm3, (%rsp)
jmp 0xf637
movq (%r14), %rdi
movq 0x8(%r14), %rsi
leaq 0x18(%rsp), %rdx
callq 0x19bc9
movq %rax, %rbx
movq %r12, %r13
movq %rbp, %r12
movq (%r14), %rax
cmpq 0x8(%r14), %rbx
je 0xf4b5
movq %rbx, %rbp
subq %rax, %rbp
je 0xf5a2
sarq $0x3, %rbp
movsd (%rbx), %xmm0
subsd -0x8(%rbx), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x38(%rsp), %rdi
movq %rbp, %rsi
callq 0x16fbc
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x16fbc
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x16fbc
movq %r12, %rbp
movq %r13, %r12
leaq 0xf8(%rsp), %rbx
leaq 0xc8(%rsp), %r13
jmp 0xf5f9
subq %rax, %rbx
shlq $0x1d, %rbx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq (%rbx,%rax), %rbp
sarq $0x20, %rbp
movq %r14, %rdi
movq %rbp, %rsi
callq 0x16fbc
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movabsq $-0x200000000, %rax     # imm = 0xFFFFFFFE00000000
addq %rax, %rbx
sarq $0x20, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x16fbc
movsd 0x10(%rsp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x38(%rsp), %rdi
movq %rbp, %rsi
callq 0x16fbc
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x16fbc
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x16fbc
movsd 0x18(%rsp), %xmm0
movapd %xmm0, %xmm1
subsd 0x10(%rsp), %xmm1
divsd 0x20(%rsp), %xmm1
movsd (%rsp), %xmm2
mulsd %xmm1, %xmm2
movsd 0x8(%rsp), %xmm3
mulsd %xmm1, %xmm3
movsd %xmm3, 0x8(%rsp)
mulsd (%rax), %xmm1
movsd %xmm1, (%rsp)
movsd %xmm0, 0x10(%rsp)
movq %r12, %rbp
movq %r13, %r12
leaq 0xf8(%rsp), %rbx
leaq 0xc8(%rsp), %r13
jmp 0xf637
movsd (%rbx), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x16fbc
movq %r12, %rbp
movq %r13, %r12
leaq 0xf8(%rsp), %rbx
leaq 0xc8(%rsp), %r13
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x16fbc
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x16fbc
movsd 0x18(%rsp), %xmm0
movapd %xmm0, %xmm3
subsd 0x10(%rsp), %xmm3
divsd 0x20(%rsp), %xmm3
movsd (%rsp), %xmm2
mulsd %xmm3, %xmm2
movsd 0x8(%rsp), %xmm1
mulsd %xmm3, %xmm1
movsd %xmm1, 0x8(%rsp)
mulsd (%rax), %xmm3
movsd %xmm3, (%rsp)
movsd %xmm0, 0x10(%rsp)
movsd 0x1de51(%rip), %xmm1    # 0x2d490
mulsd %xmm1, %xmm2
movsd %xmm0, 0x40(%rsp)
movsd %xmm2, 0x48(%rsp)
movq %rbx, %rdi
leaq 0x40(%rsp), %r14
movq %r14, %rsi
callq 0x19c22
movsd 0x8(%rsp), %xmm1
mulsd 0x1de23(%rip), %xmm1    # 0x2d490
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x48(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x19c22
movsd (%rsp), %xmm1
mulsd 0x1ddf9(%rip), %xmm1    # 0x2d490
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x48(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x19c22
movq %r15, %rdi
callq 0x72d0
movq %rax, %r15
movq 0xb8(%rsp), %r14
jmp 0xf3b6
movq 0x78(%rsp), %rdi
movq %r12, %rsi
callq 0x16fde
movq 0x70(%rsp), %rdi
movq %rbx, %rsi
callq 0x16fde
movq 0x68(%rsp), %rdi
movq %r13, %rsi
callq 0x16fde
movq %r12, %rdi
callq 0x17c98
movq %r13, %rdi
callq 0x17c98
movq %rbx, %rdi
callq 0x17c98
movq 0x90(%rsp), %rsi
incq %rsi
jmp 0xf243
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf73b
jmp 0xf73b
jmp 0xf73b
jmp 0xf73b
jmp 0xf73b
jmp 0xf73b
jmp 0xf73b
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x17c98
leaq 0xc8(%rsp), %rdi
callq 0x17c98
leaq 0xf8(%rsp), %rdi
callq 0x17c98
movq %rbx, %rdi
callq 0x76d0
nop