// File: /workspace/github_cpp_makefile_star2_O1/samuel500[P]NEAT/population.cpp
// Function: Population::xor_epoch()
void Population::xor_epoch(){

	all_nodes.clear();
	all_connections.clear();

	speciate();

	vector<vector<double>> xs {{1., 0.,0.}, {1., 0.,1.}, {1., 1.,0.}, {1., 1.,1.}};
	vector<double> ys {0., 1., 1., 0.};

	vector<Individual*>::iterator indPtr;


	double pop_avg_fitness = 0.;

	for(indPtr=individuals.begin(); indPtr!=individuals.end(); ++indPtr){
		double fitness=4.;
		for(int i=0; i<xs.size(); i++){
			(*indPtr)->activate(xs[i]);
			vector<double> out = (*indPtr)->get_outputs();
			(*indPtr)->reset_activations();
			fitness -= abs(out[0]-ys[i]);
		}
		fitness = pow(fitness, 2);
		(*indPtr)->fitness = fitness;
	}
	// cout << "x1" << endl;

	vector<Species*>::iterator spePtr;

	sort(individuals.begin(), individuals.end(), indPtr_compare2);

	elite = individuals[individuals.size()-1];
	// cout << "x2" << endl;
	if(elite->fitness>max_fitness) max_fitness = elite->fitness;


	for(spePtr=species.begin(); spePtr!=species.end(); ++spePtr){
		(*spePtr)->adjust_fitness();

	}

	sort(species.begin(), species.end(), spePtr_compare);



	for(indPtr=individuals.begin(); indPtr!=individuals.end(); ++indPtr){
		pop_avg_fitness += (*indPtr)->adjusted_fitness;
	}

	pop_avg_fitness /= individuals.size();


	for(indPtr=individuals.begin(); indPtr!=individuals.end(); ++indPtr){
		(*indPtr)->est_n_offspring = (*indPtr)->adjusted_fitness / pop_avg_fitness;
	}

	int temp_n_offspring = 0;
	for(spePtr=species.begin(); spePtr!=species.end(); ++spePtr){
		temp_n_offspring += (*spePtr)->calc_n_offspring();
	}
	// cout << "x3" << endl;

	// give missing offspring (bc double->int) to best species
	species[species.size()-1]->n_offspring += (pop_size - temp_n_offspring);


	for(spePtr=species.begin(); spePtr!=species.end(); ++spePtr){
		if((*spePtr)->n_offspring==0) species.erase(spePtr);
	}


	vector<Individual*> new_individuals;
	vector<Individual*> descendants;

	for(spePtr=species.begin(); spePtr!=species.end(); ++spePtr){
	// cout << "x4" << endl;

		descendants = (*spePtr)->evolve(&all_nodes, &all_connections);
	// cout << "x5" << endl;

		new_individuals.insert(end(new_individuals), begin(descendants), end(descendants));
	}

	for(indPtr=individuals.begin(); indPtr!=prev(individuals.end()); ++indPtr){
		delete *indPtr;
	}
	individuals.clear();
	individuals = new_individuals;


	for(spePtr=species.begin(); spePtr!=prev(species.end()); ++spePtr){
		delete *spePtr;
	}
	species.clear();


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdi, %r13
movq 0x18(%rdi), %rax
cmpq %rax, 0x20(%rdi)
je 0x20d7
movq %rax, 0x20(%r13)
movq 0x30(%r13), %rax
cmpq %rax, 0x38(%r13)
je 0x20e5
movq %rax, 0x38(%r13)
movq %r13, %rdi
callq 0x27f2
movupd 0x5073(%rip), %xmm0     # 0x7168
leaq -0x80(%rbp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq -0x100(%rbp), %r15
leaq -0x35(%rbp), %rcx
movl $0x3, %edx
movq %r15, %rdi
callq 0x297e
leaq -0xe8(%rbp), %r14
movupd 0x5054(%rip), %xmm0     # 0x7180
leaq -0x60(%rbp), %rsi
movapd %xmm0, (%rsi)
movabsq $0x3ff0000000000000, %rbx # imm = 0x3FF0000000000000
movq %rbx, 0x10(%rsi)
leaq -0x34(%rbp), %rcx
movl $0x3, %edx
movq %r14, %rdi
callq 0x297e
leaq -0xd0(%rbp), %r14
movupd 0x5036(%rip), %xmm0     # 0x7198
leaq -0x160(%rbp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq -0x33(%rbp), %rcx
movl $0x3, %edx
movq %r14, %rdi
callq 0x297e
leaq -0xb8(%rbp), %r14
movupd 0x501b(%rip), %xmm0     # 0x71b0
leaq -0x140(%rbp), %rsi
movapd %xmm0, (%rsi)
movq %rbx, 0x10(%rsi)
leaq -0x32(%rbp), %rcx
movl $0x3, %edx
movq %r14, %rdi
callq 0x297e
leaq -0x98(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x31(%rbp), %rcx
movl $0x4, %edx
callq 0x2a44
leaq 0x18(%r13), %rax
movq %rax, -0x110(%rbp)
leaq 0x30(%r13), %rax
movq %rax, -0x108(%rbp)
movl $0x60, %ebx
movq -0x118(%rbp,%rbx), %rdi
testq %rdi, %rdi
je 0x2209
movq -0x108(%rbp,%rbx), %rsi
subq %rdi, %rsi
callq 0x1110
addq $-0x18, %rbx
jne 0x21ec
movups 0x4fc2(%rip), %xmm0     # 0x71d8
leaq -0x100(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movupd 0x4f9f(%rip), %xmm0     # 0x71c8
movapd %xmm0, (%rsi)
leaq -0x80(%rbp), %rdi
leaq -0x60(%rbp), %rcx
movl $0x4, %edx
callq 0x297e
movq (%r13), %r15
movq 0x8(%r13), %r14
cmpq %r14, %r15
movq %r13, -0x40(%rbp)
je 0x236a
leaq -0x128(%rbp), %r12
movq -0x98(%rbp), %rsi
movsd 0x4de6(%rip), %xmm0     # 0x7050
movsd %xmm0, -0x30(%rbp)
cmpq %rsi, -0x90(%rbp)
je 0x2345
xorl %r13d, %r13d
xorl %ebx, %ebx
movsd 0x4dc7(%rip), %xmm0     # 0x7050
movsd %xmm0, -0x30(%rbp)
movq (%r15), %r14
addq %r13, %rsi
movq %r12, %rdi
callq 0x29c4
movq %r14, %rdi
movq %r12, %rsi
callq 0x5b76
movq -0x128(%rbp), %rdi
testq %rdi, %rdi
je 0x22c2
movq -0x118(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq (%r15), %rsi
leaq -0x100(%rbp), %rdi
callq 0x5cb8
movq (%r15), %rdi
callq 0x5d42
movq -0x100(%rbp), %rdi
movsd (%rdi), %xmm0
movq -0x80(%rbp), %rax
subsd (%rax,%rbx,8), %xmm0
movq -0xf0(%rbp), %rsi
andpd 0x4d74(%rip), %xmm0     # 0x7070
movsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
subq %rdi, %rsi
callq 0x1110
incq %rbx
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rax
subq %rsi, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %r13
cmpq %rbx, %rax
ja 0x228e
movsd -0x30(%rbp), %xmm0
mulsd %xmm0, %xmm0
movq (%r15), %rax
movsd %xmm0, (%rax)
addq $0x8, %r15
movq -0x40(%rbp), %r13
movq 0x8(%r13), %r14
cmpq %r14, %r15
jne 0x225b
movq (%r13), %r15
cmpq %r14, %r15
je 0x23ae
movq %r14, %rax
subq %r15, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xb27(%rip), %rcx      # 0x186a
movq %r15, %rdi
movq %r14, %rsi
callq 0x319b
leaq -0xb39(%rip), %rdx      # 0x186a
movq %r15, %rdi
movq %r14, %rsi
callq 0x32c6
movq 0x8(%r13), %rax
movq -0x8(%rax), %rax
movq %rax, 0x48(%r13)
movsd (%rax), %xmm0
ucomisd 0x80(%r13), %xmm0
jbe 0x23d2
movsd %xmm0, 0x80(%r13)
movq 0x50(%r13), %rbx
movq 0x58(%r13), %r14
cmpq %r14, %rbx
je 0x23ed
movq (%rbx), %rdi
callq 0x465a
addq $0x8, %rbx
jmp 0x23d6
movq 0x50(%r13), %r15
cmpq %r14, %r15
je 0x2431
movq %r14, %rax
subq %r15, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xbb4(%rip), %rcx      # 0x1860
movq %r15, %rdi
movq %r14, %rsi
callq 0x3685
leaq -0xbc6(%rip), %rdx      # 0x1860
movq %r15, %rdi
movq %r14, %rsi
callq 0x37b0
movq (%r13), %rax
movq 0x8(%r13), %rcx
xorpd %xmm0, %xmm0
cmpq %rcx, %rax
je 0x2456
movq %rax, %rdx
movq (%rdx), %rsi
addsd 0x8(%rsi), %xmm0
addq $0x8, %rdx
cmpq %rcx, %rdx
jne 0x2445
movq %rcx, %rdx
subq %rax, %rdx
je 0x24a1
sarq $0x3, %rdx
movq %rdx, %xmm1
punpckldq 0x4c11(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4c19(%rip), %xmm1     # 0x7090
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movq (%rax), %rdx
movsd 0x8(%rdx), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rdx)
addq $0x8, %rax
cmpq %rcx, %rax
jne 0x2487
movq 0x50(%r13), %r14
movq 0x58(%r13), %rax
xorl %ebx, %ebx
cmpq %rax, %r14
je 0x24c4
movq (%r14), %rdi
callq 0x4728
addl %eax, %ebx
addq $0x8, %r14
movq 0x58(%r13), %rax
jmp 0x24ab
movl 0x68(%r13), %ecx
subl %ebx, %ecx
movq 0x50(%r13), %rbx
movq -0x8(%rax), %rax
addl %ecx, 0x40(%rax)
movq 0x58(%r13), %rdx
cmpq %rdx, %rbx
je 0x2523
leaq 0x8(%rbx), %r14
movq $-0x8, %r15
subq %rbx, %r15
movq (%rbx), %rax
cmpl $0x0, 0x40(%rax)
jne 0x250e
cmpq %rdx, %r14
je 0x2509
leaq -0x8(%r14), %rdi
addq %r15, %rdx
movq %r14, %rsi
callq 0x1160
addq $-0x8, 0x58(%r13)
addq $0x8, %rbx
movq 0x58(%r13), %rdx
addq $0x8, %r14
addq $-0x8, %r15
cmpq %rdx, %rbx
jne 0x24ec
xorpd %xmm0, %xmm0
movapd %xmm0, -0x100(%rbp)
movq $0x0, -0xf0(%rbp)
movq 0x50(%r13), %rbx
cmpq 0x58(%r13), %rbx
je 0x25e8
xorl %r13d, %r13d
xorl %r12d, %r12d
movq (%rbx), %rsi
leaq -0x60(%rbp), %rdi
movq -0x110(%rbp), %rdx
movq -0x108(%rbp), %rcx
callq 0x476a
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r14
movq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
testq %r13, %r13
je 0x259c
subq %r13, %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x1110
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x25b1
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0xf8(%rbp), %rsi
leaq -0x100(%rbp), %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3b70
addq $0x8, %rbx
movq %r15, %r13
movq -0x30(%rbp), %r14
movq %r14, %r12
movq -0x40(%rbp), %rax
cmpq 0x58(%rax), %rbx
jne 0x254e
jmp 0x25ee
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %r15, %r13
movq -0x40(%rbp), %r12
movq (%r12), %rbx
movq 0x8(%r12), %rax
leaq -0x8(%rax), %rcx
cmpq %rcx, %rbx
je 0x262a
movq (%rbx), %r15
testq %r15, %r15
je 0x2624
movq %r15, %rdi
callq 0x6382
movl $0x98, %esi
movq %r15, %rdi
callq 0x1110
addq $0x8, %rbx
jmp 0x25f9
movq (%r12), %rcx
cmpq %rcx, %rax
je 0x2638
movq %rcx, 0x8(%r12)
leaq -0x100(%rbp), %rsi
movq %r12, %rdi
callq 0x2aea
movq 0x50(%r12), %rbx
movq 0x58(%r12), %rax
leaq -0x8(%rax), %rcx
cmpq %rcx, %rbx
je 0x267d
movq (%rbx), %r15
testq %r15, %r15
je 0x2677
movq %r15, %rdi
callq 0x4ada
movl $0x48, %esi
movq %r15, %rdi
callq 0x1110
addq $0x8, %rbx
jmp 0x264c
movq 0x50(%r12), %rcx
cmpq %rcx, %rax
je 0x268c
movq %rcx, 0x58(%r12)
testq %r13, %r13
je 0x269f
movq %r14, %rsi
subq %r13, %rsi
movq %r13, %rdi
callq 0x1110
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x26ba
movq -0xf0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x26cf
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
leaq -0x98(%rbp), %rdi
callq 0x2a8e
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r14, %r12
jmp 0x2773
movq %rax, %rbx
jmp 0x27de
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x1200
movb $0x1, %al
jmp 0x272a
jmp 0x271b
jmp 0x271b
movq %rax, %rbx
xorl %eax, %eax
jmp 0x272a
movq %rax, %rbx
xorl %eax, %eax
movq %r15, %r14
cmpq %r14, %r15
sete %cl
orb %al, %cl
jne 0x27ea
leaq -0x100(%rbp), %r15
movq -0x18(%r14), %rdi
testq %rdi, %rdi
je 0x2754
movq -0x8(%r14), %rsi
subq %rdi, %rsi
callq 0x1110
addq $-0x18, %r14
cmpq %r15, %r14
jne 0x273f
jmp 0x27ea
jmp 0x278e
movq %rax, %rbx
jmp 0x2773
movq %rax, %rbx
movq -0x30(%rbp), %r12
movq %r15, %r13
testq %r13, %r13
je 0x27ae
subq %r13, %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x1110
jmp 0x27ae
jmp 0x278e
jmp 0x278e
jmp 0x278e
movq %rax, %rbx
jmp 0x27c9
movq %rax, %rbx
movq -0x128(%rbp), %rdi
testq %rdi, %rdi
je 0x27c9
movq -0x118(%rbp), %rsi
jmp 0x27c1
movq %rax, %rbx
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x27c9
movq -0xf0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x27de
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
leaq -0x98(%rbp), %rdi
callq 0x2a8e
movq %rbx, %rdi
callq 0x11a0