// File: /workspace/github_cpp_makefile_star2_O3/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
cmpb $0x0, 0x70(%rax)
je 0x102f4
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
jmp 0x10318
movq 0x108(%rax), %rcx
movq %rcx, 0x38(%rsp)
movq 0x110(%rax), %rcx
movq %rcx, 0x40(%rsp)
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 0x1034f
movq %rbx, %r14
movq %r14, %rdi
callq 0x1ae8c
addq $0x30, %r14
cmpq %r15, %r14
jne 0x10337
movq %rbx, 0x88(%r13)
movq 0x98(%r13), %rbx
movq 0xa0(%r13), %r15
cmpq %rbx, %r15
je 0x1037d
movq %rbx, %r14
movq %r14, %rdi
callq 0x1ae8c
addq $0x30, %r14
cmpq %r15, %r14
jne 0x10365
movq %rbx, 0xa0(%r13)
movq 0xb0(%r13), %rbx
movq 0xb8(%r13), %r15
cmpq %rbx, %r15
je 0x103ab
movq %rbx, %r14
movq %r14, %rdi
callq 0x1ae8c
addq $0x30, %r14
cmpq %r15, %r14
jne 0x10393
movq %rbx, 0xb8(%r13)
cmpl $0x0, 0x8(%r13)
jle 0x108bc
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 0x23fb0(%rip), %xmm0    # 0x343e0
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 0x10910
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 0x10845
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 0x38(%rsp), %rax
leaq (%rax,%r15), %rbx
movq 0x40(%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 0x105bd
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 0x107a3
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 0x1060f
movq %rdx, %r9
movq %rcx, %rax
movq %rdx, %r8
shrq %r8
movsd (%rax,%r8,8), %xmm0
ucomisd %xmm2, %xmm0
ja 0x10607
leaq (%rax,%r8,8), %rax
addq $0x8, %rax
notq %r8
addq %r9, %r8
movq %r8, %r9
testq %r8, %r8
jg 0x105ea
cmpq %rdi, %rax
je 0x10687
movq %rax, %r9
subq %rcx, %r9
je 0x10742
movq %r9, %rsi
sarq $0x3, %rsi
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x108ce
movq (%rbp), %rdi
movq 0x8(%rbp), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x108ce
movq (%r15), %r8
movq 0x8(%r15), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x108ce
movsd (%rax), %xmm1
subsd -0x8(%rax), %xmm1
movsd (%rcx,%r9), %xmm0
addq %r9, %rdi
addq %r9, %r8
jmp 0x10772
shlq $0x1d, %rsi
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rsi, %rax
sarq $0x20, %rax
cmpq %rax, %rdx
jbe 0x108ff
movabsq $-0x200000000, %rdi     # imm = 0xFFFFFFFE00000000
addq %rdi, %rsi
sarq $0x20, %rsi
cmpq %rsi, %rdx
jbe 0x108df
movq (%rbx), %rdi
movq 0x8(%rbx), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x108dc
movq (%rbp), %r8
movq 0x8(%rbp), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x108dc
movq (%r15), %r9
movq 0x8(%r15), %rdx
subq %r9, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x108dc
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 0x1079d
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x108ed
movq (%rbp), %rdi
cmpq %rdi, 0x8(%rbp)
je 0x108ed
movq (%r15), %r8
cmpq %r8, 0x8(%r15)
je 0x108ed
movsd (%rcx), %xmm1
movsd (%rax), %xmm0
movapd %xmm2, %xmm3
subsd 0x8(%rsp), %xmm3
divsd %xmm1, %xmm3
mulsd %xmm3, %xmm0
movsd (%rdi), %xmm1
mulsd %xmm3, %xmm1
movsd %xmm1, 0x18(%rsp)
mulsd (%r8), %xmm3
movsd %xmm3, 0x10(%rsp)
movsd %xmm2, 0x8(%rsp)
movsd 0x23865(%rip), %xmm1    # 0x34010
mulsd %xmm1, %xmm0
movsd %xmm2, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0x108(%rsp), %rdi
movq %r12, %rsi
movsd %xmm2, 0x58(%rsp)
callq 0x1c842
movsd 0x18(%rsp), %xmm0
mulsd 0x23831(%rip), %xmm0    # 0x34010
movsd 0x58(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0xd8(%rsp), %rdi
movq %r12, %rsi
callq 0x1c842
movsd 0x10(%rsp), %xmm0
mulsd 0x23801(%rip), %xmm0    # 0x34010
movsd 0x58(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
callq 0x1c842
movq %r13, %rdi
callq 0x7270
movq %rax, %r13
cmpq %r14, %rax
jne 0x10564
movq 0x78(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x19f32
movq 0x70(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x19f32
movq 0x68(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x19f32
leaq 0xa8(%rsp), %rdi
callq 0x1ae8c
leaq 0xd8(%rsp), %rdi
callq 0x1ae8c
leaq 0x108(%rsp), %rdi
callq 0x1ae8c
movq 0x48(%rsp), %rsi
incq %rsi
movq 0x50(%rsp), %r13
movslq 0x8(%r13), %rax
cmpq %rax, %rsi
jl 0x103e6
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x252f1(%rip), %rdi     # 0x35bc6
xorl %eax, %eax
callq 0x7530
movq %rax, %rsi
leaq 0x252e0(%rip), %rdi     # 0x35bc6
xorl %eax, %eax
callq 0x7530
leaq 0x252d2(%rip), %rdi     # 0x35bc6
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x7530
leaq 0x252c0(%rip), %rdi     # 0x35bc6
movq %rax, %rsi
xorl %eax, %eax
callq 0x7530
leaq 0x252af(%rip), %rdi     # 0x35bc6
xorl %eax, %eax
callq 0x7530
jmp 0x1092c
jmp 0x1092c
jmp 0x1092c
jmp 0x1092c
jmp 0x1092c
jmp 0x1092c
jmp 0x1092c
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x1ae8c
leaq 0xd8(%rsp), %rdi
callq 0x1ae8c
leaq 0x108(%rsp), %rdi
callq 0x1ae8c
movq %rbx, %rdi
callq 0x76a0