// File: melop[P]admixem/Population.cpp
// Function: Population::Init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, char, int, int, double)
void Population::Init(string sPopName,int nPopId,  char nAncestryLabel, int nPopInitSize, int nPopMaxSize, double nMaleRatio) {
	
	this->_nPopId = nPopId;
	this->_sPopName = sPopName;
	this->_nAncestryLabel = nAncestryLabel;
	this->_nPopInitSize = nPopInitSize;
	this->_nMaleRatio = nMaleRatio;
	this->_nPopMaxSize = nPopMaxSize;

	int nMalesToCreate = (int)((double)nPopInitSize * nMaleRatio);
	int nFemalesToCreate = nPopInitSize - nMalesToCreate;

	this->_mpvNewGenMales = new vector< Individual *>[nTotalCPUCore];
	this->_mpvNewGenFemales = new vector< Individual *>[nTotalCPUCore];


	printf("To create... Male: %d  Female %d\n", nMalesToCreate, nFemalesToCreate );
	this->_mpMales.reserve(nMalesToCreate);
	this->_mpFemales.reserve(nFemalesToCreate);
	#pragma omp parallel shared(nMalesToCreate, nFemalesToCreate) 
	//private(pFemale, nCourters, pCourter, vOffSprings, itOffSpring)
	{
	


	#pragma omp for 
	for (int nCPU=0; nCPU<nTotalCPUCore;nCPU++)
	{
		
		//printf("Created Male: %d  Female %d\n", this->_nCurrMales, this->_nCurrFemales );
		while(true) {
			if (nMalesToCreate <= this->_nCurrMales && nFemalesToCreate <= this->_nCurrFemales) {
				break;
			}

			Individual * pNewInd = new Individual(this, nAncestryLabel);

			if (pNewInd->GetSex() == Individual::Male) { // If the created individual is male

				if (nMalesToCreate > this->_nCurrMales) { // if still have room for new males
					#pragma omp critical 
					{
					this->_mpMales.push_back(pNewInd); // put the new male in the population;
					this->_nCurrMales++;
					}
				}
				else {
					delete pNewInd;
					continue;
				}
			}

			if (pNewInd->GetSex() == Individual::Female) { // If the created individual is female

				if (nFemalesToCreate > this->_nCurrFemales) { // if still have room for new females
					#pragma omp critical 
					{
						this->_mpFemales.push_back(pNewInd); // put the new female in the population;
						this->_nCurrFemales++;
					}
				}
				else {
					delete pNewInd;
					continue;
				}
			}
		}//while end.
	} //for end

	} //end parallel
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movb %al, -0x15(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x68(%rbp)
movl -0x14(%rbp), %eax
movl %eax, 0x20(%rdi)
callq 0x8070
movq -0x68(%rbp), %rax
movb -0x15(%rbp), %cl
movb %cl, 0x24(%rax)
movl -0x1c(%rbp), %ecx
movl %ecx, 0x28(%rax)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, 0x38(%rax)
movl -0x20(%rbp), %ecx
movl %ecx, 0x2c(%rax)
cvtsi2sdl -0x1c(%rbp), %xmm0
mulsd -0x28(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
leaq 0x44160(%rip), %rax     # 0xaa4fc
movslq (%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8040
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x58(%rbp)
cmpq $0x0, %rax
je 0x66421
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x78(%rbp)
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x5b570
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x70(%rbp)
jne 0x663ff
movq -0x68(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, 0xa8(%rax)
leaq 0x440c5(%rip), %rax     # 0xaa4fc
movslq (%rax), %rax
movq %rax, -0x90(%rbp)
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8040
movq %rax, %rcx
movq -0x90(%rbp), %rax
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x88(%rbp)
cmpq $0x0, %rax
je 0x664e0
movq -0x88(%rbp), %rax
movq -0x90(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0xa0(%rbp)
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x5b570
movq -0xa8(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x98(%rbp)
jne 0x664af
movq -0x68(%rbp), %rax
movq -0x88(%rbp), %rcx
movq %rcx, 0xb0(%rax)
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
leaq 0x1264b(%rip), %rdi     # 0x78b4a
movb $0x0, %al
callq 0x8080
movq -0x68(%rbp), %rdi
addq $0x48, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x6c970
movq -0x68(%rbp), %rdi
addq $0x60, %rdi
movslq -0x30(%rbp), %rsi
callq 0x6c970
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
leaq 0x43fc3(%rip), %rcx     # 0xaa4fc
cmpl (%rcx), %eax
jge 0x666aa
jmp 0x66543
movq -0x68(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x30(%rcx), %eax
jg 0x66560
movq -0x68(%rbp), %rcx
movl -0x30(%rbp), %eax
cmpl 0x34(%rcx), %eax
jg 0x66560
jmp 0x6669a
movl $0x158, %edi            # imm = 0x158
callq 0x84c0
movq -0x68(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
movsbl -0x15(%rbp), %edx
callq 0x55450
jmp 0x66586
movq -0xb0(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x570f0
cmpl $0x0, %eax
jne 0x66626
movq -0x68(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x30(%rcx), %eax
jle 0x665f1
movq -0x68(%rbp), %rdi
addq $0x48, %rdi
leaq -0x40(%rbp), %rsi
callq 0x5c0f0
movq -0x68(%rbp), %rax
movl 0x30(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x30(%rax)
jmp 0x66624
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl $0x158, %esi            # imm = 0x158
callq 0x84d0
jmp 0x666b3
movq -0x40(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, %rax
je 0x6661f
movq -0xb8(%rbp), %rdi
callq 0x553c0
movq -0xb8(%rbp), %rdi
movl $0x158, %esi            # imm = 0x158
callq 0x84d0
jmp 0x66543
jmp 0x66626
movq -0x40(%rbp), %rdi
callq 0x570f0
cmpl $0x1, %eax
jne 0x66695
movq -0x68(%rbp), %rcx
movl -0x30(%rbp), %eax
cmpl 0x34(%rcx), %eax
jle 0x66660
movq -0x68(%rbp), %rdi
addq $0x60, %rdi
leaq -0x40(%rbp), %rsi
callq 0x5c0f0
movq -0x68(%rbp), %rax
movl 0x34(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x34(%rax)
jmp 0x66693
movq -0x40(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x6668e
movq -0xc0(%rbp), %rdi
callq 0x553c0
movq -0xc0(%rbp), %rdi
movl $0x158, %esi            # imm = 0x158
callq 0x84d0
jmp 0x66543
jmp 0x66695
jmp 0x66543
jmp 0x6669c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6652f
addq $0xc0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x8860
nopl (%rax)