// File: /workspace/github_cpp_makefile_star2_O1/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 0x2354b
cmpl $0x1, 0x28(%r12)
jne 0x2354b
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 0x2608d(%rip), %rax     # 0x493a8
movq %rax, 0x10(%rdi)
incq %rax
movq %rax, 0x2607f(%rip)     # 0x493a8
movq 0x10(%rsi), %rax
movq %rax, (%rdi)
movq 0x10(%r12), %rax
movq %rax, 0x8(%rdi)
leaq 0x265c8(%rip), %r15     # 0x49908
movq (%r15), %rdi
callq 0x1083a
movl %eax, 0x44(%rbx)
addl %eax, %eax
movl %eax, 0x48(%rbx)
movq 0x10(%r15), %rdi
movq 0x58(%rsp), %rsi
callq 0x1402e
movq 0x10(%r15), %rdi
movq 0x50(%rsp), %rsi
callq 0x1402e
movq 0x68(%r13), %rsi
leaq 0x58(%r13), %rdx
movq 0x48(%rsp), %rdi
callq 0x2742c
movq 0x68(%r12), %rsi
leaq 0x58(%r12), %rdx
movq 0x40(%rsp), %rdi
callq 0x2742c
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 0x23626
leaq 0x80(%rsp), %rsi
leaq 0x60(%rsp), %rdx
movq %r12, %rdi
callq 0x23626
movq 0x28(%rsp), %rsi
subq 0x20(%rsp), %rsi
sarq $0x3, %rsi
movabsq $0x5555555555555556, %r15 # imm = 0x5555555555555556
imulq %r15, %rsi
movq %rbp, %rdi
callq 0x26934
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
imulq %r15, %rsi
movq %r14, %rdi
callq 0x26a1a
movq 0x20(%rsp), %rsi
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
cmpq %rsi, 0x28(%rsp)
je 0x23498
xorl %r15d, %r15d
xorl %r12d, %r12d
addq %r15, %rsi
movq %rbp, %rdi
callq 0x2682e
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r12, %rdx
jbe 0x23560
addq %r15, %rsi
movq %rbp, %rdi
callq 0x2682e
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 0x2343d
movq (%rsp), %rsi
cmpq %rsi, 0x8(%rsp)
je 0x234fd
xorl %r15d, %r15d
xorl %r12d, %r12d
addq %r15, %rsi
movq %r14, %rdi
callq 0x2685a
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r12, %rdx
jbe 0x23571
addq %r15, %rsi
movq %r14, %rdi
callq 0x2685a
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 0x234a9
movq %rbx, %rdi
callq 0x22396
movq %rbx, %rdi
callq 0x23024
movq %rbx, %rdi
callq 0x230b4
movq 0xa0(%rsp), %rax
movb $0x1, (%rax)
leaq 0x60(%rsp), %rdi
callq 0x26792
movq %rsp, %rdi
callq 0x26792
leaq 0x80(%rsp), %rdi
callq 0x267e0
leaq 0x20(%rsp), %rdi
callq 0x267e0
jmp 0x2354e
movb $0x0, (%rcx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x136ba(%rip), %rdi     # 0x36c21
movq %r12, %rsi
xorl %eax, %eax
callq 0x7530
leaq 0x136a9(%rip), %rdi     # 0x36c21
movq %r12, %rsi
xorl %eax, %eax
callq 0x7530
movq %rax, %r15
jmp 0x235bb
jmp 0x2358f
jmp 0x2358f
jmp 0x2358f
jmp 0x2358f
movq %rax, %r15
leaq 0x60(%rsp), %rdi
callq 0x26792
movq %rsp, %rdi
callq 0x26792
leaq 0x80(%rsp), %rdi
callq 0x267e0
leaq 0x20(%rsp), %rdi
callq 0x267e0
movq 0x140(%rbx), %rdi
testq %rdi, %rdi
je 0x235d6
movq 0x150(%rbx), %rsi
subq %rdi, %rsi
callq 0x7390
movq %r14, %rdi
callq 0x26792
movq %rbp, %rdi
callq 0x267e0
movq 0x40(%rsp), %rdi
callq 0x1bb2c
movq 0x48(%rsp), %rdi
callq 0x1bb2c
movq 0x50(%rsp), %rdi
callq 0x1bb2c
movq 0x58(%rsp), %rdi
callq 0x1bb2c
movq %r15, %rdi
callq 0x76a0