// File: /workspace/github_cpp_makefile_star2_O3/melop[P]admixem/Individual.cpp
// Function: Individual::GetGamete(std::vector<std::vector<Marker, std::allocator<Marker>>, std::allocator<std::vector<Marker, std::allocator<Marker>>>>&, std::vector<std::vector<Gene, std::allocator<Gene>>, std::allocator<std::vector<Gene, std::allocator<Gene>>>>&)
void Individual::GetGamete(vector< vector<Marker> > &vMarkers, vector< vector<Gene> > &vGenes ) {
	
		#ifdef _OPENMP
		int nCPU = omp_get_thread_num();
			#ifdef DEBUG
			printf("CPU %d: %s : %d\n", nCPU, "SexSelFormulae # ", nCPU);
			#endif
		#else
			int nCPU = 0;
		#endif
	//do recombination. 

	bool bSex = (this->_bSex == Male);
	vector< map<double, int> > * pMarkerIndex = SimulConfig.pMarkerConfig->GetMpMarkerIndex();
	vector< map<double, int> > * pGeneIndex = SimulConfig.pGeneConfig->GetMpGeneIndex();

	for (int nChr=0;nChr<this->_nHaploidChrNum;nChr++) { // go over each chromosome
		
		int nMainChr, nOtherChr;
		//int nWhichToPick = (UniformGen.Next() <=0.5)? 0:1;
		double nPaternalTransBias = SimulConfig.pMarkerConfig->GetPaternalTransBias(nChr);
		// 0 is paternal chr, 1 is maternal chr.
		int nWhichToPick = nPaternalTransBias==0.5? (int)vBinomGen[nCPU]->Next() : ( vUniformGen[nCPU]->Next()<=nPaternalTransBias? 0:1 );
		nMainChr = nChr*2 + nWhichToPick;
		nOtherChr = nWhichToPick==0? nMainChr+1:nMainChr-1;
		map<double, int> * pMarkerIndexOnChr = & (pMarkerIndex->at(nChr));
		map<double, int> * pGeneIndexOnChr = & (pGeneIndex->at(nChr));
		double nCentromerePos = SimulConfig.pMarkerConfig->GetCentromerePosition(nChr);
		double nChrLen = SimulConfig.pMarkerConfig->GetChromosomeLength(nChr);

		vector<Marker> vNewMarkers;
		vNewMarkers.reserve(pMarkerIndexOnChr->size());
		vector<Gene> vNewGenes;
		vNewGenes.reserve(pGeneIndexOnChr->size());

					
		size_t nLastIndex = pMarkerIndexOnChr->size()-1;
		map<double,int>::iterator oMarkerCentromereIt = pMarkerIndexOnChr->upper_bound(nCentromerePos);
		//nLastIndex =  pMarkerIndexOnChr->size()-1;

		size_t nCentromereIndex = (oMarkerCentromereIt == pMarkerIndexOnChr->end())? nLastIndex + 1 :oMarkerCentromereIt->second ;
			
		size_t nCentromereIndex_gene=-1, nLastIndex_gene=-1;

		//if (pGeneIndexOnChr->size() != 0)
		//{
			map<double,int>::iterator oGeneCentromereIt = pGeneIndexOnChr->upper_bound(nCentromerePos);
			nLastIndex_gene =  pGeneIndexOnChr->size()-1;
			nCentromereIndex_gene = (oGeneCentromereIt == pGeneIndexOnChr->end())? nLastIndex_gene + 1 :oGeneCentromereIt->second ;
				
		//}

		for (int nArm=1;nArm<=2;nArm++) 
		{


			vector<double> oBreakPoints;
			SimulConfig.pRecombProbConfig->GetBreakPointsByArm(bSex, nChr, nArm, oBreakPoints);
			
			/*
			if (pBreakPoints->size() > 0){
				printf("%d break points, first: %f\n",pBreakPoints->size(), *(pBreakPoints->begin()));
			}
			else {
				printf("No break point on Chr %d arm %d\n", nChr, nArm);
			}
			*/
			int nBreakPoints = oBreakPoints.size();

			bool bSelf = (nArm==1)? (nBreakPoints % 2 ==0) : true; //if it's arm 1, determine which chromosome to start
			int nBpCount = 0;




			int nStartIndex = (nArm == 1)? ((nCentromereIndex!=0)?  0 : INT_MAX ) : nCentromereIndex; // start copying from index 0
			int nEndIndex = 0;

			int nStartIndex_gene = (nArm == 1)? ((nCentromereIndex_gene!=0)?  0 : INT_MAX ): nCentromereIndex_gene; // start copying from index 0
			int nEndIndex_gene = 0;
			/*
			if (nChr == 5 ) {
				printf("break");
			}
			*/
			if (nBreakPoints == 0) { // if no break point, copy the whole damn arm.
				nEndIndex = (nArm == 1)? nCentromereIndex - 1 : nLastIndex;
				nEndIndex_gene = (nArm == 1)? nCentromereIndex_gene - 1 : nLastIndex_gene ;

				vector<Marker> * pvSourceMarkers = &this->_arrMarkers[nMainChr];
				vector<Gene> * pvSourceGenes = &this->_arrGenes[nMainChr];
				if (nStartIndex <= nEndIndex) {
					copy(pvSourceMarkers->begin()+nStartIndex,pvSourceMarkers->begin()+nEndIndex+1,back_inserter(vNewMarkers));
				}
				if (nStartIndex_gene <= nEndIndex_gene) {
					copy(pvSourceGenes->begin()+nStartIndex_gene,pvSourceGenes->begin()+nEndIndex_gene+1,back_inserter(vNewGenes));
				}
				continue; // go to next arm
			}

			bool bNoNeedContinueMarker = false;
			bool bNoNeedContinueGene = false;
			

			for (vector<double>::iterator nBreakPos=oBreakPoints.begin(); nBpCount <= nBreakPoints;) 
			{//Go over each break point
				//find index using position:
				int nChrIndex = bSelf? nMainChr:nOtherChr;
				vector<Marker> * pvSourceMarkers = &this->_arrMarkers[nChrIndex];
				vector<Gene> * pvSourceGenes = &this->_arrGenes[nChrIndex];

				//printf("max size %d\n",  pvSourceMarkers->max_size());

				if (nBpCount == nBreakPoints) // if it's beyond the last break point
				{
					nEndIndex = (nArm == 1)? nCentromereIndex - 1 : nLastIndex;
					nEndIndex_gene = (nArm == 1)? nCentromereIndex_gene - 1 : nLastIndex_gene;
				}
				else {

					map<double, int>::iterator oMarkerBreakPosIt = pMarkerIndexOnChr->upper_bound(*nBreakPos);
					map<double, int>::iterator oGeneBreakPosIt = pGeneIndexOnChr->upper_bound( *nBreakPos);

					if (oMarkerBreakPosIt == pMarkerIndexOnChr->end()) { // there is no more markers beyond the break point
						
						nEndIndex = (nArm == 1)? nCentromereIndex - 1 : nLastIndex;
						if (nStartIndex <= nEndIndex && !bNoNeedContinueMarker) {
							copy(pvSourceMarkers->begin()+nStartIndex,pvSourceMarkers->begin()+nEndIndex+1,back_inserter(vNewMarkers));
						}
						bNoNeedContinueMarker = true;
					}
					else {
						if (!bNoNeedContinueMarker) {
							nEndIndex = (oMarkerBreakPosIt->second < nCentromereIndex)? oMarkerBreakPosIt->second - 1: nCentromereIndex - 1; // need to minus 1 so that all markers on left but not right of Break point are copied
						}
					}

					if (oGeneBreakPosIt == pGeneIndexOnChr->end()) {
						nEndIndex_gene = (nArm == 1)? nCentromereIndex_gene - 1 : nLastIndex_gene;
						if (nStartIndex_gene <= nEndIndex_gene && !bNoNeedContinueGene ) {
							copy(pvSourceGenes->begin()+nStartIndex_gene,pvSourceGenes->begin()+nEndIndex_gene+1,back_inserter(vNewGenes));
						}
						bNoNeedContinueGene = true;
						
					}
					else {
						if (!bNoNeedContinueGene) {
							nEndIndex_gene = ( oGeneBreakPosIt->second < nCentromereIndex_gene)? oGeneBreakPosIt->second - 1: nCentromereIndex_gene - 1 ;
						}
					}

				}



				if (nStartIndex <= nEndIndex && !bNoNeedContinueMarker) {
					copy(pvSourceMarkers->begin()+nStartIndex,pvSourceMarkers->begin()+nEndIndex+1,back_inserter(vNewMarkers));
				}
				if (nStartIndex_gene <= nEndIndex_gene  && !bNoNeedContinueGene) {
					copy(pvSourceGenes->begin()+nStartIndex_gene,pvSourceGenes->begin()+nEndIndex_gene+1,back_inserter(vNewGenes));
				}

				bSelf = !bSelf; // flip
				nStartIndex = nEndIndex + 1;
				nStartIndex_gene = nEndIndex_gene + 1;
				nBpCount++;
				if (nBreakPos != oBreakPoints.end()) {
					++nBreakPos;
				}

	
			}

			
		}

		vMarkers.push_back(vNewMarkers);
		vGenes.push_back(vNewGenes);



	}

	//Perform mutation of genes:
	vector< map<double , GeneProperties> > * pGenes = SimulConfig.pGeneConfig->GetMpGenes();

	for (int nChr=0;nChr<this->_nHaploidChrNum;nChr++) {
		vector< Gene > * pChrmToMutate = &vGenes.at(nChr);
		int nInx = 0;
		for (map<double, GeneProperties>::iterator it2=pGenes->at(nChr).begin(); it2!=pGenes->at(nChr).end(); ++it2) {// genes
			//see if apply mutation rule:
			if (  (*it2).second.MutationProb > 0
					&&
				  (
					(*it2).second.Pops.find("!ANYPOP")!=(*it2).second.Pops.end()
						||
					(*it2).second.Pops.find( ((Population*)this->GetPop())->GetPopName()) !=(*it2).second.Pops.end()
				  )
				   &&
				  (
						(*it2).second.StartGen==-1
							||
						(
							SimulConfig.GetCurrGen() >= (*it2).second.StartGen
							&&
							SimulConfig.GetCurrGen() <= (*it2).second.EndGen
						)

				  )
				
				)
			{
			
				double nMuteProb = (*it2).second.MutationProb;
				if (nMuteProb==0) {//no mutation needed for this locus

				}
				else if( vUniformGen[nCPU]->Next() <= nMuteProb){ // if need to mutate this locus
					//#pragma omp critical
					//{
						double nCurrVal = pChrmToMutate->at(nInx).Value;
						(*it2).second.pFormula->symbols_["CurrVal"] = nCurrVal; //give value to symbol;
						double nNewVal = (*it2).second.pFormula->Evaluate();
						pChrmToMutate->at(nInx).Value = (nNewVal > (*it2).second.UpperBound)? (*it2).second.UpperBound : ((nNewVal < (*it2).second.LowerBound)? (*it2).second.LowerBound : nNewVal);
					//}
				}
			}
			nInx++;
		}
	}
	

	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rdx, 0xd8(%rsp)
movq %rsi, 0x110(%rsp)
movq %rdi, %r14
movl 0x28(%rdi), %eax
movl %eax, 0xb8(%rsp)
leaq 0x25297(%rip), %rbx     # 0x48908
movq (%rbx), %rdi
callq 0x109e8
movq %rax, 0x120(%rsp)
movq 0x18(%rbx), %rdi
callq 0x18974
movq %rax, 0x118(%rsp)
cmpl $0x0, 0x44(%r14)
movq %r14, 0x28(%rsp)
jle 0x23eaf
xorl %r12d, %r12d
leaq 0x2525c(%rip), %rax     # 0x48908
movq (%rax), %rdi
movl %r12d, %esi
callq 0x1362e
ucomisd 0x10d21(%rip), %xmm0    # 0x343e0
jne 0x236db
jp 0x236db
leaq 0x25396(%rip), %rax     # 0x48a60
movq (%rax), %rax
movq (%rax), %rdi
movq (%rdi), %rax
callq *(%rax)
cvttsd2si %xmm0, %ebp
jmp 0x23703
leaq 0x253ae(%rip), %rax     # 0x48a90
movq (%rax), %rax
movq (%rax), %rdi
movq (%rdi), %rax
movsd %xmm0, 0x8(%rsp)
callq *(%rax)
xorl %ebp, %ebp
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setb %bpl
movl %ebp, %eax
negl %eax
movl $0x0, %eax
sbbl %eax, %eax
movl %eax, 0x64(%rsp)
movq 0x120(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
cmpq %r12, %rdx
jbe 0x2420c
movq %rcx, %rsi
movq 0x118(%rsp), %rcx
movq (%rcx), %rdi
movq 0x8(%rcx), %rdx
subq %rdi, %rdx
sarq $0x4, %rdx
imulq %rax, %rdx
cmpq %r12, %rdx
jbe 0x2420c
movq %rdi, %rbx
leaq (%r12,%r12,2), %r14
shlq $0x4, %r14
movq %rsi, %r13
addq %r14, %r13
leaq 0x2518b(%rip), %r15     # 0x48908
movq (%r15), %rdi
movl %r12d, %esi
callq 0x135f2
movsd %xmm0, 0x8(%rsp)
movq (%r15), %rdi
movl %r12d, %esi
callq 0x121ae
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq %r13, 0x108(%rsp)
movq 0x28(%r13), %rsi
leaq 0x30(%rsp), %rdi
callq 0x26900
addq %r14, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movq $0x0, 0xa0(%rsp)
movq %rbx, 0x70(%rsp)
movq 0x28(%rbx), %rsi
leaq 0x90(%rsp), %rdi
callq 0x2699a
movq 0x108(%rsp), %rcx
movq 0x10(%rcx), %rax
movq 0x28(%rcx), %rdx
addq $0x8, %rcx
movq %rcx, 0x20(%rsp)
movq %rdx, 0x68(%rsp)
movq %rdx, %r14
testq %rax, %rax
movsd 0x8(%rsp), %xmm1
je 0x23851
movq 0x20(%rsp), %rcx
movsd 0x20(%rax), %xmm0
xorl %edx, %edx
ucomisd %xmm1, %xmm0
cmovaq %rax, %rcx
setbe %dl
movq 0x10(%rax,%rdx,8), %rax
testq %rax, %rax
jne 0x23825
movq 0x68(%rsp), %r14
cmpq 0x20(%rsp), %rcx
je 0x23851
movslq 0x28(%rcx), %r14
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rcx
addq $0x8, %rax
movq %rax, 0x10(%rsp)
testq %rcx, %rcx
je 0x2389a
movsd 0x20(%rcx), %xmm0
xorl %edx, %edx
ucomisd %xmm1, %xmm0
cmovaq %rcx, %rax
setbe %dl
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x23868
movq 0x70(%rsp), %rcx
movq 0x28(%rcx), %rcx
cmpq 0x10(%rsp), %rax
je 0x238a3
movslq 0x28(%rax), %r15
jmp 0x238a6
movq 0x70(%rsp), %rax
movq 0x28(%rax), %rcx
movq %rcx, %r15
leal (%rbp,%r12,2), %edx
orl $0x1, 0x64(%rsp)
decq 0x68(%rsp)
decq %rcx
movq %rcx, 0xf0(%rsp)
testq %r14, %r14
movl $0x0, %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmoveq %rax, %rcx
movq %rcx, 0x150(%rsp)
testq %r15, %r15
movl $0x0, %ecx
cmoveq %rax, %rcx
movq %rcx, 0x148(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leaq (%r14,%rax), %rcx
movq %rcx, 0xe8(%rsp)
addq %r15, %rax
movq %rax, 0xe0(%rsp)
movl %edx, 0xbc(%rsp)
movslq %edx, %rax
movq %rax, 0x128(%rsp)
movl $0x1, %r13d
movq %r15, 0xf8(%rsp)
movq %r12, 0x140(%rsp)
movq %r14, 0x100(%rsp)
xorl %esi, %esi
cmpl $0x0, 0xb8(%rsp)
sete %sil
xorpd %xmm0, %xmm0
movapd %xmm0, 0xc0(%rsp)
movq $0x0, 0xd0(%rsp)
leaq 0x24fa1(%rip), %rax     # 0x48908
movq 0x8(%rax), %rdi
movl %r12d, %edx
movl %r13d, %ecx
leaq 0xc0(%rsp), %r8
callq 0x13336
movq 0xc0(%rsp), %rbx
movq 0xc8(%rsp), %rdi
subq %rbx, %rdi
sarq $0x3, %rdi
movl %edi, %eax
xorb $0x1, %al
cmpl $0x1, %r13d
setne %r12b
movq 0x150(%rsp), %r10
cmovneq %r14, %r10
movq 0x148(%rsp), %rsi
cmovneq %r15, %rsi
orb %al, %r12b
testl %edi, %edi
movl %r13d, 0x60(%rsp)
je 0x23d52
js 0x23df8
cmpl $0x1, 0x60(%rsp)
movq 0xe8(%rsp), %r8
cmovneq 0x68(%rsp), %r8
movslq %r8d, %rax
movq 0xe0(%rsp), %r9
cmovneq 0xf0(%rsp), %r9
addq %rax, %rax
movq %rax, 0x138(%rsp)
movslq %r9d, %rax
shlq $0x4, %rax
movq %rax, 0x130(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %edx, %edx
xorl %r11d, %r11d
movq %rdi, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x78(%rsp)
testb $0x1, %r12b
movl 0x64(%rsp), %eax
movl $0x0, %ecx
cmovnel %ecx, %eax
addl 0xbc(%rsp), %eax
cltq
shlq $0x3, %rax
leaq (%rax,%rax,2), %rcx
movq 0x28(%rsp), %rax
movq 0x110(%rax), %r13
addq %rcx, %r13
movq %r13, 0x18(%rsp)
addq 0x128(%rax), %rcx
movq %rcx, 0x58(%rsp)
cmpl %edi, %r15d
jne 0x23a86
movq %rsi, %r13
movl %r9d, %r14d
movl %r8d, %ebp
jmp 0x23bf9
movq %rdx, %r13
movq %rbp, 0x8(%rsp)
movq 0x108(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x20(%rsp), %rax
testq %rcx, %rcx
je 0x23ac9
movsd (%rbx), %xmm0
movq 0x20(%rsp), %rax
movsd 0x20(%rcx), %xmm1
xorl %edx, %edx
ucomisd %xmm0, %xmm1
cmovaq %rcx, %rax
setbe %dl
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x23aad
movq 0x70(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0x10(%rsp), %rbp
testq %rcx, %rcx
je 0x23b01
movsd (%rbx), %xmm0
movq 0x10(%rsp), %rbp
movsd 0x20(%rcx), %xmm1
xorl %edx, %edx
ucomisd %xmm0, %xmm1
cmovaq %rcx, %rbp
setbe %dl
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x23ae5
cmpq 0x20(%rsp), %rax
je 0x23b2f
testb $0x1, %r13b
jne 0x23b27
movslq 0x28(%rax), %rax
movq 0x100(%rsp), %rcx
cmpq %rax, %rcx
cmoval %eax, %ecx
decl %ecx
movq %rcx, 0x8(%rsp)
movl %r13d, %edx
jmp 0x23bb1
movb $0x1, %dl
cmpl %r8d, %r10d
jg 0x23b3c
testb $0x1, %r13b
je 0x23b46
movl %r8d, %eax
movq %rax, 0x8(%rsp)
jmp 0x23bb1
movq 0x18(%rsp), %rax
movq (%rax), %rax
movslq %r10d, %rcx
leaq (%rax,%rcx,2), %rdi
movq %rsi, 0x160(%rsp)
movq 0x138(%rsp), %rcx
leaq 0x2(%rax,%rcx), %rsi
leaq 0x30(%rsp), %rdx
movq %r10, 0x158(%rsp)
movq %r11, %r13
callq 0x2780c
movb $0x1, %dl
movq %r13, %r11
movq 0x158(%rsp), %r10
movq 0x78(%rsp), %r9
movq 0x80(%rsp), %r8
movq 0x88(%rsp), %rdi
movq 0x160(%rsp), %rsi
movl %r8d, %eax
movq %rax, 0x8(%rsp)
cmpq 0x10(%rsp), %rbp
je 0x23bdc
movq %rsi, %r13
testb $0x1, %r11b
jne 0x23bda
movslq 0x28(%rbp), %rax
movq 0xf8(%rsp), %rcx
cmpq %rax, %rcx
movl %ecx, %r14d
cmoval %eax, %r14d
decl %r14d
jmp 0x23bf4
cmpl %r9d, %esi
jg 0x23beb
testb $0x1, %r11b
je 0x23cef
movq %rsi, %r13
movb $0x1, %r11b
movl %r9d, %r14d
movq 0x8(%rsp), %rbp
cmpl %ebp, %r10d
jg 0x23c59
testb $0x1, %dl
jne 0x23c59
movq 0x18(%rsp), %rax
movq (%rax), %rax
movslq %r10d, %rcx
leaq (%rax,%rcx,2), %rdi
movslq %ebp, %rcx
leaq 0x2(%rax,%rcx,2), %rsi
movq %rdx, 0x8(%rsp)
leaq 0x30(%rsp), %rdx
movq %r14, 0x18(%rsp)
movq %rbp, %r14
movq %r11, %rbp
callq 0x2780c
movq 0x8(%rsp), %rdx
movq %rbp, %r11
movq %r14, %rbp
movq 0x18(%rsp), %r14
movq 0x78(%rsp), %r9
movq 0x80(%rsp), %r8
movq 0x88(%rsp), %rdi
cmpl %r14d, %r13d
jg 0x23cbd
testb $0x1, %r11b
jne 0x23cbd
movq 0x58(%rsp), %rax
movq (%rax), %rax
movslq %r13d, %rdi
shlq $0x4, %rdi
addq %rax, %rdi
movslq %r14d, %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rsi
addq $0x10, %rsi
movq %rdx, 0x8(%rsp)
leaq 0x90(%rsp), %rdx
movq %r14, %r13
movq %r11, %r14
callq 0x27862
movq 0x8(%rsp), %rdx
movq %r14, %r11
movq %r13, %r14
movq 0x78(%rsp), %r9
movq 0x80(%rsp), %r8
movq 0x88(%rsp), %rdi
xorb $0x1, %r12b
leal 0x1(%rbp), %r10d
leal 0x1(%r14), %esi
leal 0x1(%r15), %eax
xorl %ecx, %ecx
cmpq 0xc8(%rsp), %rbx
setne %cl
leaq (%rbx,%rcx,8), %rbx
cmpl %edi, %r15d
movl %eax, %r15d
jne 0x23a32
jmp 0x23df8
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rsi, %r13
movslq %esi, %rdi
shlq $0x4, %rdi
addq %rax, %rdi
movq 0x130(%rsp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x10, %rsi
movl %edx, %r14d
leaq 0x90(%rsp), %rdx
movq %r10, %rbp
callq 0x27862
movq %rbp, %r10
movq 0x78(%rsp), %r9
movq 0x80(%rsp), %r8
movq 0x88(%rsp), %rdi
movb $0x1, %r11b
movl %r14d, %edx
movl %r9d, %r14d
movq 0x8(%rsp), %rbp
jmp 0x23bf9
cmpl $0x1, %r13d
movq 0xe8(%rsp), %rax
cmovneq 0x68(%rsp), %rax
movq 0xe0(%rsp), %rbx
cmovneq 0xf0(%rsp), %rbx
movq 0x128(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (,%rcx,8), %r14
movq 0x28(%rsp), %rdx
addq 0x128(%rdx), %r14
cmpl %eax, %r10d
jg 0x23dcb
movq 0x28(%rsp), %rdx
movq 0x110(%rdx), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %r10d, %rdx
leaq (%rcx,%rdx,2), %rdi
cltq
movq %rsi, %r15
leaq (%rcx,%rax,2), %rsi
addq $0x2, %rsi
leaq 0x30(%rsp), %rdx
callq 0x2780c
movq %r15, %rsi
cmpl %ebx, %esi
jg 0x23df8
movq (%r14), %rax
movslq %esi, %rdi
shlq $0x4, %rdi
addq %rax, %rdi
movslq %ebx, %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rsi
addq $0x10, %rsi
leaq 0x90(%rsp), %rdx
callq 0x27862
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x23e15
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x7390
movl 0x60(%rsp), %r13d
incl %r13d
cmpl $0x3, %r13d
movq 0x140(%rsp), %r12
movq 0x100(%rsp), %r14
movq 0xf8(%rsp), %r15
jne 0x23939
movq 0x110(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x265c2
movq 0xd8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x265ee
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x23e83
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x7390
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x23e9a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x7390
incq %r12
movq 0x28(%rsp), %rax
movslq 0x44(%rax), %rax
cmpq %rax, %r12
jl 0x236a5
leaq 0x24a52(%rip), %rax     # 0x48908
movq 0x18(%rax), %rdi
callq 0x1895c
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
cmpl $0x0, 0x44(%rax)
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
jle 0x241e9
xorl %r15d, %r15d
movq 0xd8(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %rsi, %rdx
cmpq %r15, %rdx
jbe 0x241fb
movq 0x20(%rsp), %rdx
movq (%rdx), %rax
movq 0x8(%rdx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %rsi, %rdx
cmpq %r15, %rdx
jbe 0x241fb
leaq (%r15,%r15,2), %rdx
leaq (%rcx,%rdx,8), %rcx
movq %rcx, 0x58(%rsp)
shlq $0x4, %rdx
movq %rdx, 0x8(%rsp)
movq 0x18(%rax,%rdx), %r13
movl $0x8, %r14d
xorl %r12d, %r12d
movq %r15, 0x18(%rsp)
movq 0x8(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
cmpq %rax, %r13
je 0x241d4
movsd 0x78(%r13), %xmm0
ucomisd 0x100b1(%rip), %xmm0    # 0x34020
jbe 0x24196
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
leaq 0x11597(%rip), %rsi     # 0x35525
leaq 0x11597(%rip), %rdx     # 0x3552c
callq 0xa91c
leaq 0xb8(%r13), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x278b8
movq %rax, %rbp
leaq 0xc0(%r13), %rax
movq %rax, 0x10(%rsp)
cmpq %rax, %rbp
jne 0x23fe9
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rsi
leaq 0x90(%rsp), %r15
movq %r15, %rdi
callq 0x2bf56
movq %rbx, %rdi
movq %r15, %rsi
callq 0x278b8
cmpq %rbp, %rax
je 0x2402f
cmpl $-0x1, 0xe8(%r13)
sete %bl
je 0x24021
leaq 0x2490b(%rip), %rdi     # 0x48908
callq 0x199ca
cmpl 0xe8(%r13), %eax
jl 0x24021
leaq 0x248f6(%rip), %rdi     # 0x48908
callq 0x199ca
cmpl 0xec(%r13), %eax
setle %bl
cmpq 0x10(%rsp), %rbp
movq 0x18(%rsp), %r15
jne 0x2405b
jmp 0x24036
xorl %ebx, %ebx
movq 0x18(%rsp), %r15
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2405b
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x7390
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x24077
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x7390
testb %bl, %bl
je 0x24196
movsd 0x78(%r13), %xmm0
ucomisd 0xff93(%rip), %xmm0     # 0x34020
jne 0x24095
jnp 0x24196
leaq 0x249f4(%rip), %rax     # 0x48a90
movq (%rax), %rax
movq (%rax), %rdi
movq (%rdi), %rax
movsd %xmm0, 0x10(%rsp)
callq *(%rax)
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x24196
movq 0x58(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
cmpq %r12, %rdx
jbe 0x2420c
movsd (%rax,%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x90(%r13), %rbx
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
leaq 0x11dfd(%rip), %rsi     # 0x35f02
leaq 0x11dfd(%rip), %rdx     # 0x35f09
callq 0xa91c
addq $0x68, %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1b47a
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x24146
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x7390
movq 0x90(%r13), %rdi
callq 0x98bc
movsd 0x88(%r13), %xmm1
ucomisd %xmm1, %xmm0
ja 0x24178
movsd 0x80(%r13), %xmm2
ucomisd %xmm0, %xmm2
movapd %xmm0, %xmm1
jbe 0x24178
movapd %xmm2, %xmm1
movq 0x58(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
cmpq %r12, %rdx
jbe 0x2420c
movsd %xmm1, (%rax,%r14)
incq %r12
movq %r13, %rdi
callq 0x7270
movq %rax, %r13
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
addq $0x10, %r14
cmpq %r15, %rdx
ja 0x23f4c
jmp 0x241fb
incq %r15
movq 0x28(%rsp), %rax
movslq 0x44(%rax), %rax
cmpq %rax, %r15
jl 0x23ee0
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x119c4(%rip), %rdi     # 0x35bc6
movq %r15, %rsi
xorl %eax, %eax
callq 0x7530
leaq 0x119b3(%rip), %rdi     # 0x35bc6
movq %r12, %rsi
jmp 0x24205
movq %rax, %rbx
jmp 0x242d0
jmp 0x24226
jmp 0x2426f
jmp 0x2426a
movq %rax, %rbx
jmp 0x242b3
movq %rax, %rbx
jmp 0x24243
jmp 0x2426f
jmp 0x24293
jmp 0x24293
movq %rax, %rbx
cmpq 0x10(%rsp), %rbp
jne 0x24272
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x24272
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x7390
jmp 0x24272
movq %rax, %rbx
jmp 0x242e7
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x242e7
movq 0x40(%rsp), %rsi
incq %rsi
jmp 0x242e2
jmp 0x24293
jmp 0x24293
jmp 0x24293
jmp 0x24293
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x242b3
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x7390
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x242d0
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x7390
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x242e7
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x7390
movq %rbx, %rdi
callq 0x76a0
nop