// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movsd %xmm0, 0x10(%rsp)
movl %r9d, %ebp
movl %r8d, %ebx
movl %ecx, %r15d
movq %rdi, %r14
movl %edx, 0x20(%rdi)
callq 0x71d0
movl %r15d, 0x24(%rsp)
movb %r15b, 0x24(%r14)
movl %ebx, 0x28(%r14)
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x38(%r14)
movl %ebp, 0x2c(%r14)
leaq 0x1e7be(%rip), %rax     # 0x483bc
movl (%rax), %eax
movslq %eax, %r15
movl $0x18, %ecx
movq %r15, %rax
mulq %rcx
movq %rax, %r13
seto %al
movq %r13, 0x18(%rsp)
addq $0x8, %r13
movq $-0x1, %rcx
cmovbq %rcx, %r13
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
testb %al, %al
cmovneq %rcx, %r13
subl %ebp, %ebx
movq %r13, %rdi
callq 0x7030
movq %rax, %r12
movq %r15, (%rax)
addq $0x8, %r12
movq %r15, 0x10(%rsp)
testl %r15d, %r15d
je 0x29cbf
movq 0x18(%rsp), %rax
addq $-0x18, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %rdx
movq %rdx, 0x18(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x71e0
movq %r12, 0xa8(%r14)
movq %r13, %rdi
callq 0x7030
movq %rax, %r15
movq 0x10(%rsp), %rax
movq %rax, (%r15)
addq $0x8, %r15
movq %r15, %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x71e0
jmp 0x29cdd
movq %r12, 0xa8(%r14)
movq %r13, %rdi
callq 0x7030
movq %rax, %r15
movq 0x10(%rsp), %rax
movq %rax, (%r15)
addq $0x8, %r15
movq %r15, 0xb0(%r14)
leaq 0xcbe7(%rip), %rdi      # 0x368d2
xorl %r12d, %r12d
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x7060
leaq 0x48(%r14), %rdi
movslq %ebp, %rsi
movq %rdi, 0x18(%rsp)
callq 0x2e33a
leaq 0x60(%r14), %rdi
movslq %ebx, %rsi
movq %rdi, 0x10(%rsp)
callq 0x2e33a
leaq 0x1e69a(%rip), %rax     # 0x483bc
movl (%rax), %edx
testl %edx, %edx
jle 0x29e47
movl 0x30(%r14), %eax
movl 0x34(%r14), %ecx
movsbl 0x24(%rsp), %r13d
cmpl %ebp, %eax
jl 0x29d46
cmpl %ecx, %ebx
jle 0x29e3b
movl $0x158, %edi            # imm = 0x158
callq 0x7380
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x21e78
movq %r15, 0x8(%rsp)
movq %r15, %rdi
callq 0x23632
testl %eax, %eax
jne 0x29dac
movl 0x30(%r14), %eax
cmpl %ebp, %eax
jge 0x29ddc
movq 0x50(%r14), %rsi
cmpq 0x58(%r14), %rsi
je 0x29d93
movq 0x8(%rsp), %rcx
movq %rcx, (%rsi)
addq $0x8, 0x50(%r14)
jmp 0x29da6
movq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2730a
movl 0x30(%r14), %eax
incl %eax
movl %eax, 0x30(%r14)
movq 0x8(%rsp), %rdi
callq 0x23632
cmpl $0x1, %eax
jne 0x29e16
movl 0x34(%r14), %eax
cmpl %eax, %ebx
jle 0x29ddc
movq 0x68(%r14), %rsi
cmpq 0x70(%r14), %rsi
je 0x29dfd
movq 0x8(%rsp), %rcx
movq %rcx, (%rsi)
addq $0x8, 0x68(%r14)
jmp 0x29e10
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x29dee
movq %r15, %rdi
callq 0x21e10
movl $0x158, %esi            # imm = 0x158
movq %r15, %rdi
callq 0x7390
jmp 0x29e16
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2730a
movl 0x34(%r14), %eax
incl %eax
movl %eax, 0x34(%r14)
movl 0x30(%r14), %eax
movl 0x34(%r14), %ecx
cmpl %ebp, %eax
setl %dl
cmpl %ecx, %ebx
setg %sil
orb %dl, %sil
jne 0x29d46
leaq 0x1e583(%rip), %rdx     # 0x483bc
movl (%rdx), %edx
incl %r12d
cmpl %edx, %r12d
jl 0x29d3a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x158, %esi            # imm = 0x158
movq %r15, %rdi
callq 0x7390
movq %rbx, %rdi
callq 0x76a0