// File: /workspace/github_cpp_makefile_star2_O1/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 $0x138, %rsp            # imm = 0x138
movq %rdi, %r13
movq (%rdi), %rax
movq 0x8(%rax), %rax
movb 0x70(%rax), %cl
testb %cl, %cl
je 0x10123
movq $0x0, 0x40(%rsp)
jmp 0x1012f
movq 0x108(%rax), %rdx
movq %rdx, 0x40(%rsp)
testb %cl, %cl
je 0x1013e
movq $0x0, 0x38(%rsp)
jmp 0x1014a
movq 0x110(%rax), %rdx
movq %rdx, 0x38(%rsp)
testb %cl, %cl
je 0x10159
movq $0x0, 0x30(%rsp)
jmp 0x10165
movq 0x118(%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0x78(%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x80(%r13), %rbx
movq 0x88(%r13), %r15
cmpq %rbx, %r15
je 0x1019c
movq %rbx, %r14
movq %r14, %rdi
callq 0x1ad82
addq $0x30, %r14
cmpq %r15, %r14
jne 0x10184
movq %rbx, 0x88(%r13)
movq 0x98(%r13), %rbx
movq 0xa0(%r13), %r15
cmpq %rbx, %r15
je 0x101ca
movq %rbx, %r14
movq %r14, %rdi
callq 0x1ad82
addq $0x30, %r14
cmpq %r15, %r14
jne 0x101b2
movq %rbx, 0xa0(%r13)
movq 0xb0(%r13), %rbx
movq 0xb8(%r13), %r15
cmpq %rbx, %r15
je 0x101f8
movq %rbx, %r14
movq %r14, %rdi
callq 0x1ad82
addq $0x30, %r14
cmpq %r15, %r14
jne 0x101e0
movq %rbx, 0xb8(%r13)
cmpl $0x0, 0x8(%r13)
jle 0x10708
leaq 0x80(%r13), %rax
movq %rax, 0x70(%rsp)
leaq 0x98(%r13), %rax
movq %rax, 0x68(%rsp)
leaq 0xb0(%r13), %rax
movq %rax, 0x78(%rsp)
leaq 0x20(%rsp), %r12
xorl %esi, %esi
movq %r13, 0x50(%rsp)
movq (%r13), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rcx
movq 0x38(%rax), %rdx
movsd (%rcx,%rsi,8), %xmm0
addsd (%rdx,%rsi,8), %xmm0
movq 0x40(%rax), %rcx
movsd (%rcx,%rsi,8), %xmm1
movq 0x48(%rax), %rax
addsd (%rax,%rsi,8), %xmm1
movsd %xmm0, 0xa0(%rsp)
movsd %xmm1, 0x98(%rsp)
addsd %xmm1, %xmm0
mulsd 0x25193(%rip), %xmm0    # 0x35410
movsd %xmm0, 0x90(%rsp)
movq 0x70(%r13), %rdx
movq 0x68(%r13), %rax
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x1075c
movq 0x30(%r13), %rcx
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, 0x88(%rsp)
movq %rsi, 0x48(%rsp)
leaq (%rsi,%rsi,2), %rcx
shlq $0x4, %rcx
xorl %esi, %esi
movl %esi, 0x110(%rsp)
movq %rsi, 0x118(%rsp)
leaq 0x110(%rsp), %rdx
movq %rdx, 0x120(%rsp)
movq %rdx, 0x128(%rsp)
movq %rsi, 0x130(%rsp)
movl %esi, 0xe0(%rsp)
movq %rsi, 0xe8(%rsp)
leaq 0xe0(%rsp), %rdx
movq %rdx, 0xf0(%rsp)
movq %rdx, 0xf8(%rsp)
movq %rsi, 0x100(%rsp)
movl %esi, 0xb0(%rsp)
movq %rsi, 0xb8(%rsp)
leaq 0xb0(%rsp), %rdx
movq %rdx, 0xc0(%rsp)
movq %rdx, 0xc8(%rsp)
movq %rsi, 0xd0(%rsp)
leaq (%rax,%rcx), %r14
addq $0x8, %r14
movq 0x10(%r14), %r13
cmpq %r14, %r13
je 0x10691
movq 0x48(%rsp), %rax
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %r15
movq 0x60(%rsp), %rax
addq %r15, %rax
movq %rax, 0x80(%rsp)
movq 0x40(%rsp), %rax
leaq (%rax,%r15), %rbx
movq 0x38(%rsp), %rax
leaq (%rax,%r15), %rbp
addq 0x30(%rsp), %r15
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x20(%r13), %xmm2
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
cmpb $0x1, 0x70(%rax)
jne 0x1040a
movapd %xmm2, %xmm1
divsd 0x88(%rsp), %xmm1
movsd 0xa0(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd 0x98(%rsp), %xmm3
mulsd %xmm1, %xmm3
movsd %xmm3, 0x18(%rsp)
mulsd 0x90(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
jmp 0x105ef
movq 0x80(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdi
movq %rdi, %rsi
subq %rcx, %rsi
movq %rsi, %rdx
sarq $0x3, %rdx
movq %rcx, %rax
testq %rdx, %rdx
jle 0x1045c
movq %rdx, %r9
movq %rcx, %rax
movq %rdx, %r8
shrq %r8
movsd (%rax,%r8,8), %xmm0
ucomisd %xmm2, %xmm0
ja 0x10454
leaq (%rax,%r8,8), %rax
addq $0x8, %rax
notq %r8
addq %r9, %r8
movq %r8, %r9
testq %r8, %r8
jg 0x10437
cmpq %rdi, %rax
je 0x104d4
movq %rax, %r8
subq %rcx, %r8
je 0x1058f
movq %r8, %rsi
sarq $0x3, %rsi
movq (%rbx), %r9
movq 0x8(%rbx), %rdx
subq %r9, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x1071a
movq (%rbp), %rcx
movq 0x8(%rbp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x1071a
movq (%r15), %rdi
movq 0x8(%r15), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x1071a
movsd (%rax), %xmm1
subsd -0x8(%rax), %xmm1
movsd (%r9,%r8), %xmm0
addq %r8, %rcx
addq %r8, %rdi
jmp 0x105bf
shlq $0x1d, %rsi
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rsi, %rax
sarq $0x20, %rax
cmpq %rax, %rdx
jbe 0x1074b
movabsq $-0x200000000, %rdi     # imm = 0xFFFFFFFE00000000
addq %rdi, %rsi
sarq $0x20, %rsi
cmpq %rsi, %rdx
jbe 0x1072b
movq (%rbx), %rdi
movq 0x8(%rbx), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x10728
movq (%rbp), %r8
movq 0x8(%rbp), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x10728
movq (%r15), %r9
movq 0x8(%r15), %rdx
subq %r9, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x10728
movsd (%rcx,%rax,8), %xmm0
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
subsd (%rcx,%rsi,8), %xmm0
divsd %xmm0, %xmm1
movsd (%rdi,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd (%r8,%rax,8), %xmm3
mulsd %xmm1, %xmm3
movsd %xmm3, 0x18(%rsp)
mulsd (%r9,%rax,8), %xmm1
movsd %xmm1, 0x10(%rsp)
jmp 0x105e9
movq (%rbx), %rdx
cmpq %rdx, 0x8(%rbx)
je 0x10739
movq (%rbp), %rcx
cmpq %rcx, 0x8(%rbp)
je 0x10739
movq (%r15), %rdi
cmpq %rdi, 0x8(%r15)
je 0x10739
movsd (%rax), %xmm1
movsd (%rdx), %xmm0
movapd %xmm2, %xmm3
subsd 0x8(%rsp), %xmm3
divsd %xmm1, %xmm3
mulsd %xmm3, %xmm0
movsd (%rcx), %xmm1
mulsd %xmm3, %xmm1
movsd %xmm1, 0x18(%rsp)
mulsd (%rdi), %xmm3
movsd %xmm3, 0x10(%rsp)
movsd %xmm2, 0x8(%rsp)
movsd 0x24a19(%rip), %xmm1    # 0x35010
mulsd %xmm1, %xmm0
movsd %xmm2, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0x108(%rsp), %rdi
movq %r12, %rsi
movsd %xmm2, 0x58(%rsp)
callq 0x1c782
movsd 0x18(%rsp), %xmm0
mulsd 0x249e5(%rip), %xmm0    # 0x35010
movsd 0x58(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0xd8(%rsp), %rdi
movq %r12, %rsi
callq 0x1c782
movsd 0x10(%rsp), %xmm0
mulsd 0x249b5(%rip), %xmm0    # 0x35010
movsd 0x58(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
callq 0x1c782
movq %r13, %rdi
callq 0x7270
movq %rax, %r13
cmpq %r14, %rax
jne 0x103b1
movq 0x78(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x19eb0
movq 0x70(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x19eb0
movq 0x68(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x19eb0
leaq 0xa8(%rsp), %rdi
callq 0x1ad82
leaq 0xd8(%rsp), %rdi
callq 0x1ad82
leaq 0x108(%rsp), %rdi
callq 0x1ad82
movq 0x48(%rsp), %rsi
incq %rsi
movq 0x50(%rsp), %r13
movslq 0x8(%r13), %rax
cmpq %rax, %rsi
jl 0x10233
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x26500(%rip), %rdi     # 0x36c21
xorl %eax, %eax
callq 0x7530
movq %rax, %rsi
leaq 0x264ef(%rip), %rdi     # 0x36c21
xorl %eax, %eax
callq 0x7530
leaq 0x264e1(%rip), %rdi     # 0x36c21
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x7530
leaq 0x264cf(%rip), %rdi     # 0x36c21
movq %rax, %rsi
xorl %eax, %eax
callq 0x7530
leaq 0x264be(%rip), %rdi     # 0x36c21
xorl %eax, %eax
callq 0x7530
jmp 0x10778
jmp 0x10778
jmp 0x10778
jmp 0x10778
jmp 0x10778
jmp 0x10778
jmp 0x10778
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x1ad82
leaq 0xd8(%rsp), %rdi
callq 0x1ad82
leaq 0x108(%rsp), %rdi
callq 0x1ad82
movq %rbx, %rdi
callq 0x76a0