// File: /workspace/github_cpp_makefile_star2_O3/melop[P]admixem/Individual.cpp
// Function: Individual::Individual(Individual*, Individual*, bool&)
Individual::Individual(Individual * pFather, Individual * pMother, bool &bSuccess) {
	this->_bDead = false;
	this->_pPrevPop = NULL;
	this->_pPop = pMother->GetPop();

	if (pFather->GetSex() != Male || pMother -> GetSex() != Female) { // gay sex not implemented.
		bSuccess = false;
		//throw "Cannot create a new individual from same-sex parents!";
		return;
	}
	
	this -> _nId = nCurrIndividualId;
	nCurrIndividualId++;
	
	this->_nFatherId = pFather->GetID();
	this->_nMotherId = pMother->GetID();

	
	this->_nHaploidChrNum = SimulConfig.pMarkerConfig->GetHaploidChromosomeNum();
	this->_nTotalChrNum = 2* this->_nHaploidChrNum ;

	SimulConfig.pPhenotypeConfig->InitKeys(&this->_mpPhenotypes);
	SimulConfig.pPhenotypeConfig->InitKeys(&this->_mpEnvPhenotypes);
	
	this->_mpDadPhenotypes.insert(pFather->_mpPhenotypes.begin(), pFather->_mpPhenotypes.end()); // save parent's phenotypes
	this->_mpMomPhenotypes.insert(pMother->_mpPhenotypes.begin(), pMother->_mpPhenotypes.end());
	
	vector< vector<Marker> > vFatherMarkers, vMotherMarkers;
	vector< vector<Gene> > vFatherGenes, vMotherGenes;
	//#pragma omp critical 
	//{
		pFather->GetGamete(vFatherMarkers, vFatherGenes);
		pMother->GetGamete(vMotherMarkers, vMotherGenes);
	//}

	//printf("vFatherMarkers.size() %d\n", vFatherMarkers.size());
	//printf("vFatherGenes.size() %d\n", vFatherGenes.size());
	this->_arrMarkers.reserve(vFatherMarkers.size() * 2);
	this->_arrGenes.reserve(vFatherGenes.size() * 2);

	//put chromosomes in order:
	for (int i=0;i<vFatherMarkers.size();i++) {
		this->_arrMarkers.push_back(vFatherMarkers.at(i));
		this->_arrMarkers.push_back(vMotherMarkers.at(i));

	}

	for (int i=0;i<vFatherGenes.size();i++) {
		this->_arrGenes.push_back(vFatherGenes.at(i));
		this->_arrGenes.push_back(vMotherGenes.at(i));
	}

	//printf("_arrMarkers.size() %d\n", _arrMarkers.size());
	//printf("_arrGenes.size() %d\n", _arrGenes.size());
	this->fnDeterminePhenotypes();
	this->fnDetermineSex();
	this->fnDetermineNumGametes();
	bSuccess = true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %r12
leaq 0x58(%rdi), %rdx
xorl %eax, %eax
movl %eax, 0x58(%rdi)
movq %rax, 0x60(%rdi)
movq %rdx, 0x68(%rdi)
movq %rdx, 0x70(%rdi)
movq %rax, 0x78(%rdi)
leaq 0x88(%rdi), %rdx
movl %eax, 0x88(%rdi)
movq %rax, 0x90(%rdi)
movq %rdx, 0x98(%rdi)
movq %rdx, 0xa0(%rdi)
movq %rax, 0xa8(%rdi)
leaq 0xb8(%rdi), %rdx
movl %eax, 0xb8(%rdi)
movq %rax, 0xc0(%rdi)
movq %rdx, 0xc8(%rdi)
movq %rdx, 0xd0(%rdi)
movq %rax, 0xd8(%rdi)
leaq 0xe8(%rdi), %rdx
movl %eax, 0xe8(%rdi)
movq %rax, 0xf0(%rdi)
movq %rdx, 0xf8(%rdi)
movq %rdx, 0x100(%rdi)
movb $0x0, 0x2d(%rdi)
movq %rax, 0x20(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x108(%rdi)
movups %xmm0, 0x118(%rdi)
movups %xmm0, 0x128(%rdi)
movups %xmm0, 0x138(%rdi)
movups %xmm0, 0x148(%rdi)
movq 0x18(%r12), %rdx
movq %rdx, 0x18(%rdi)
cmpl %eax, 0x28(%rsi)
jne 0x23561
cmpl $0x1, 0x28(%r12)
jne 0x23561
movq %rsi, %r13
movq %rdi, %rbx
movq %rcx, 0xa0(%rsp)
leaq 0x50(%rdi), %rax
movq %rax, 0x58(%rsp)
leaq 0x80(%rdi), %rax
movq %rax, 0x50(%rsp)
leaq 0xb0(%rdi), %rax
movq %rax, 0x48(%rsp)
leaq 0xe0(%rdi), %rax
movq %rax, 0x40(%rsp)
leaq 0x110(%rdi), %rbp
leaq 0x128(%rdi), %r14
movq 0x25077(%rip), %rax     # 0x483a8
movq %rax, 0x10(%rdi)
incq %rax
movq %rax, 0x25069(%rip)     # 0x483a8
movq 0x10(%rsi), %rax
movq %rax, (%rdi)
movq 0x10(%r12), %rax
movq %rax, 0x8(%rdi)
leaq 0x255b2(%rip), %r15     # 0x48908
movq (%r15), %rdi
callq 0x109ee
movl %eax, 0x44(%rbx)
addl %eax, %eax
movl %eax, 0x48(%rbx)
movq 0x10(%r15), %rdi
movq 0x58(%rsp), %rsi
callq 0x141ec
movq 0x10(%r15), %rdi
movq 0x50(%rsp), %rsi
callq 0x141ec
movq 0x68(%r13), %rsi
leaq 0x58(%r13), %rdx
movq 0x48(%rsp), %rdi
callq 0x27184
movq 0x68(%r12), %rsi
leaq 0x58(%r12), %rdx
movq 0x40(%rsp), %rdi
callq 0x27184
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
xorl %eax, %eax
movq %rax, 0x10(%rsi)
movq %rax, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movq %rsp, %rdx
movq %rax, 0x10(%rdx)
movaps %xmm0, (%rdx)
movq %rax, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq %r13, %rdi
callq 0x2363c
leaq 0x80(%rsp), %rsi
leaq 0x60(%rsp), %rdx
movq %r12, %rdi
callq 0x2363c
movq 0x28(%rsp), %rsi
subq 0x20(%rsp), %rsi
sarq $0x3, %rsi
movabsq $0x5555555555555556, %r15 # imm = 0x5555555555555556
imulq %r15, %rsi
movq %rbp, %rdi
callq 0x266c8
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
imulq %r15, %rsi
movq %r14, %rdi
callq 0x267a6
movq 0x20(%rsp), %rsi
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
cmpq %rsi, 0x28(%rsp)
je 0x234ae
xorl %r15d, %r15d
xorl %r12d, %r12d
addq %r15, %rsi
movq %rbp, %rdi
callq 0x265c2
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r12, %rdx
jbe 0x23576
addq %r15, %rsi
movq %rbp, %rdi
callq 0x265c2
incq %r12
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
subq %rsi, %rax
sarq $0x3, %rax
imulq %r13, %rax
addq $0x18, %r15
cmpq %r12, %rax
ja 0x23453
movq (%rsp), %rsi
cmpq %rsi, 0x8(%rsp)
je 0x23513
xorl %r15d, %r15d
xorl %r12d, %r12d
addq %r15, %rsi
movq %r14, %rdi
callq 0x265ee
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r12, %rdx
jbe 0x23587
addq %r15, %rsi
movq %r14, %rdi
callq 0x265ee
incq %r12
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
subq %rsi, %rax
sarq $0x3, %rax
imulq %r13, %rax
addq $0x18, %r15
cmpq %r12, %rax
ja 0x234bf
movq %rbx, %rdi
callq 0x2238e
movq %rbx, %rdi
callq 0x2303a
movq %rbx, %rdi
callq 0x230ca
movq 0xa0(%rsp), %rax
movb $0x1, (%rax)
leaq 0x60(%rsp), %rdi
callq 0x2651a
movq %rsp, %rdi
callq 0x2651a
leaq 0x80(%rsp), %rdi
callq 0x2656e
leaq 0x20(%rsp), %rdi
callq 0x2656e
jmp 0x23564
movb $0x0, (%rcx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12649(%rip), %rdi     # 0x35bc6
movq %r12, %rsi
xorl %eax, %eax
callq 0x7530
leaq 0x12638(%rip), %rdi     # 0x35bc6
movq %r12, %rsi
xorl %eax, %eax
callq 0x7530
movq %rax, %r15
jmp 0x235d1
jmp 0x235a5
jmp 0x235a5
jmp 0x235a5
jmp 0x235a5
movq %rax, %r15
leaq 0x60(%rsp), %rdi
callq 0x2651a
movq %rsp, %rdi
callq 0x2651a
leaq 0x80(%rsp), %rdi
callq 0x2656e
leaq 0x20(%rsp), %rdi
callq 0x2656e
movq 0x140(%rbx), %rdi
testq %rdi, %rdi
je 0x235ec
movq 0x150(%rbx), %rsi
subq %rdi, %rsi
callq 0x7390
movq %r14, %rdi
callq 0x2651a
movq %rbp, %rdi
callq 0x2656e
movq 0x40(%rsp), %rdi
callq 0x1bc0a
movq 0x48(%rsp), %rdi
callq 0x1bc0a
movq 0x50(%rsp), %rdi
callq 0x1bc0a
movq 0x58(%rsp), %rdi
callq 0x1bc0a
movq %r15, %rdi
callq 0x76a0