// File: /workspace/github_cpp_makefile_star2_O3/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 0x2077
movq %rax, 0x20(%r13)
movq 0x30(%r13), %rax
cmpq %rax, 0x38(%r13)
je 0x2085
movq %rax, 0x38(%r13)
movq %r13, %rdi
callq 0x27d2
movupd 0x50d3(%rip), %xmm0     # 0x7168
leaq -0x80(%rbp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq -0x100(%rbp), %r14
leaq -0x35(%rbp), %rcx
movl $0x3, %edx
movq %r14, %rdi
callq 0x2950
leaq -0xe8(%rbp), %r15
movupd 0x50b4(%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 %r15, %rdi
callq 0x2950
leaq -0xd0(%rbp), %r15
movupd 0x5096(%rip), %xmm0     # 0x7198
leaq -0x160(%rbp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq -0x33(%rbp), %rcx
movl $0x3, %edx
movq %r15, %rdi
callq 0x2950
leaq -0xb8(%rbp), %r15
movupd 0x507b(%rip), %xmm0     # 0x71b0
leaq -0x140(%rbp), %rsi
movapd %xmm0, (%rsi)
movq %rbx, 0x10(%rsi)
leaq -0x32(%rbp), %rcx
movl $0x3, %edx
movq %r15, %rdi
callq 0x2950
leaq -0x98(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x31(%rbp), %rcx
movl $0x4, %edx
callq 0x2a16
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 0x21a9
movq -0x108(%rbp,%rbx), %rsi
subq %rdi, %rsi
callq 0x1110
addq $-0x18, %rbx
jne 0x218c
movups 0x5022(%rip), %xmm0     # 0x71d8
leaq -0x100(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movupd 0x4fff(%rip), %xmm0     # 0x71c8
movapd %xmm0, (%rsi)
leaq -0x80(%rbp), %rdi
leaq -0x60(%rbp), %rcx
movl $0x4, %edx
callq 0x2950
movq (%r13), %r12
movq 0x8(%r13), %rbx
cmpq %rbx, %r12
movq %r13, -0x40(%rbp)
je 0x231e
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rax
leaq -0x128(%rbp), %r13
cmpq %rsi, %rax
je 0x22f2
xorl %r14d, %r14d
xorl %r15d, %r15d
movsd 0x4e30(%rip), %xmm0     # 0x7050
movsd %xmm0, -0x30(%rbp)
movq (%r12), %rbx
addq %r14, %rsi
movq %r13, %rdi
callq 0x2996
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5a7e
movq -0x128(%rbp), %rdi
testq %rdi, %rdi
je 0x225a
movq -0x118(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq (%r12), %rsi
leaq -0x100(%rbp), %rdi
callq 0x5ba8
movq (%r12), %rdi
callq 0x5c38
movq -0x100(%rbp), %rdi
movsd (%rdi), %xmm0
movq -0x80(%rbp), %rax
subsd (%rax,%r15,8), %xmm0
movq -0xf0(%rbp), %rsi
andpd 0x4dd9(%rip), %xmm0     # 0x7070
movsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
subq %rdi, %rsi
callq 0x1110
incq %r15
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rax
movq %rax, %rcx
subq %rsi, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
addq $0x18, %r14
cmpq %r15, %rcx
ja 0x2225
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rbx
movsd -0x30(%rbp), %xmm0
jmp 0x22fd
movq %rsi, %rax
movsd 0x4d53(%rip), %xmm0     # 0x7050
mulsd %xmm0, %xmm0
movq (%r12), %rcx
movsd %xmm0, (%rcx)
addq $0x8, %r12
cmpq %rbx, %r12
jne 0x2209
movq -0x40(%rbp), %r13
movq (%r13), %r12
cmpq %rbx, %r12
je 0x2362
movq %rbx, %rax
subq %r12, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xb37(%rip), %rcx      # 0x180a
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3173
leaq -0xb49(%rip), %rdx      # 0x180a
movq %r12, %rdi
movq %rbx, %rsi
callq 0x329e
movq 0x8(%r13), %r12
movq -0x8(%r12), %rax
movq %rax, 0x48(%r13)
movsd (%rax), %xmm0
ucomisd 0x80(%r13), %xmm0
jbe 0x2383
movsd %xmm0, 0x80(%r13)
movq 0x50(%r13), %r14
movq 0x58(%r13), %r15
cmpq %r15, %r14
je 0x23a9
movq (%r14), %rdi
callq 0x45bc
addq $0x8, %r14
movq 0x58(%r13), %r15
cmpq %r15, %r14
jne 0x2390
movq 0x50(%r13), %r14
cmpq %r15, %r14
je 0x23e9
movq %r15, %rax
subq %r14, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xbcc(%rip), %rcx      # 0x1800
movq %r14, %rdi
movq %r15, %rsi
callq 0x3636
leaq -0xbde(%rip), %rdx      # 0x1800
movq %r14, %rdi
movq %r15, %rsi
callq 0x3761
movq (%r13), %rax
movq 0x8(%r13), %rcx
cmpq %rcx, %rax
je 0x2459
xorpd %xmm0, %xmm0
movq %rax, %rdx
movq (%rdx), %rsi
addsd 0x8(%rsi), %xmm0
addq $0x8, %rdx
cmpq %rcx, %rdx
jne 0x23fd
movq %rcx, %rdx
subq %rax, %rdx
je 0x2459
sarq $0x3, %rdx
movq %rdx, %xmm1
punpckldq 0x4c59(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4c61(%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 0x243f
movq 0x50(%r13), %r15
movq 0x58(%r13), %rdx
xorl %ebx, %ebx
cmpq %rdx, %r15
je 0x2488
movq %r15, %r14
movq (%r14), %rdi
callq 0x468a
addl %eax, %ebx
addq $0x8, %r14
movq 0x58(%r13), %rdx
cmpq %rdx, %r14
jne 0x246b
movq 0x50(%r13), %r15
jmp 0x248b
movq %r15, %r14
movl 0x68(%r13), %eax
subl %ebx, %eax
movq -0x8(%r14), %rcx
addl %eax, 0x40(%rcx)
cmpq %rdx, %r15
je 0x24e9
leaq 0x8(%r15), %r14
movq $-0x8, %rbx
subq %r15, %rbx
movq (%r15), %rax
cmpl $0x0, 0x40(%rax)
jne 0x24d4
cmpq %rdx, %r14
je 0x24cc
leaq -0x8(%r14), %rdi
addq %rbx, %rdx
movq %r14, %rsi
callq 0x1160
movq 0x58(%r13), %rdx
addq $-0x8, %rdx
movq %rdx, 0x58(%r13)
addq $0x8, %r15
addq $0x8, %r14
addq $-0x8, %rbx
cmpq %rdx, %r15
jne 0x24ab
movq 0x50(%r13), %r15
xorpd %xmm0, %xmm0
movapd %xmm0, -0x100(%rbp)
movq $0x0, -0xf0(%rbp)
cmpq %rdx, %r15
je 0x25ac
xorl %r13d, %r13d
xorl %r12d, %r12d
movq (%r15), %rsi
leaq -0x60(%rbp), %rdi
movq -0x110(%rbp), %rdx
movq -0x108(%rbp), %rcx
callq 0x46c4
movq -0x60(%rbp), %rbx
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 0x2572
subq %r13, %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x1110
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x2572
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0xf8(%rbp), %rsi
leaq -0x100(%rbp), %rdi
movq %rbx, %r13
movq %rbx, %rdx
movq %r14, %rcx
callq 0x3afa
addq $0x8, %r15
movq %r13, %rcx
movq -0x30(%rbp), %r14
movq %r14, %r12
movq -0x40(%rbp), %rax
cmpq 0x58(%rax), %r15
jne 0x250f
jmp 0x25b1
xorl %r14d, %r14d
xorl %ecx, %ecx
movq %rcx, -0x30(%rbp)
movq %r14, %r13
movq -0x40(%rbp), %r12
movq (%r12), %r15
movq 0x8(%r12), %rax
leaq -0x8(%rax), %rcx
cmpq %rcx, %r15
je 0x2601
movq (%r15), %rbx
testq %rbx, %rbx
je 0x25de
movq %rbx, %rdi
callq 0x623e
movl $0x98, %esi
movq %rbx, %rdi
callq 0x1110
addq $0x8, %r15
movq 0x8(%r12), %rax
leaq -0x8(%rax), %rcx
cmpq %rcx, %r15
jne 0x25ce
movq (%r12), %r15
cmpq %r15, %rax
je 0x260b
movq %r15, 0x8(%r12)
leaq -0x100(%rbp), %rsi
movq %r12, %rdi
callq 0x2ac2
movq 0x50(%r12), %r15
movq 0x58(%r12), %rax
leaq -0x8(%rax), %rcx
cmpq %rcx, %r15
je 0x2661
movq (%r15), %rbx
testq %rbx, %rbx
je 0x263d
movq %rbx, %rdi
callq 0x4a30
movl $0x48, %esi
movq %rbx, %rdi
callq 0x1110
addq $0x8, %r15
movq 0x58(%r12), %rax
leaq -0x8(%rax), %rcx
cmpq %rcx, %r15
jne 0x262d
movq 0x50(%r12), %r15
cmpq %r15, %rax
movq %r13, %rsi
je 0x266e
movq %r15, 0x58(%r12)
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x267f
subq %rdi, %rsi
callq 0x1110
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x269a
movq -0xf0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x26af
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
leaq -0x98(%rbp), %rdi
callq 0x2a60
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r13, %r12
movq -0x30(%rbp), %r13
jmp 0x2752
movq %rax, %rbx
jmp 0x27bd
movq %rax, %rbx
movl $0x60, %r14d
movq -0x118(%rbp,%r14), %rdi
testq %rdi, %rdi
je 0x2707
movq -0x108(%rbp,%r14), %rsi
subq %rdi, %rsi
callq 0x1110
addq $-0x18, %r14
jne 0x26ea
jmp 0x27c9
jmp 0x2716
jmp 0x2716
movq %rax, %rbx
movq -0x18(%r15), %rdi
testq %rdi, %rdi
je 0x272e
movq -0x8(%r15), %rsi
subq %rdi, %rsi
callq 0x1110
addq $-0x18, %r15
cmpq %r14, %r15
jne 0x2719
jmp 0x27c9
movq %rax, %rbx
jmp 0x27c9
jmp 0x276d
movq %rax, %rbx
jmp 0x2752
movq %rax, %rbx
movq -0x30(%rbp), %r12
testq %r13, %r13
je 0x278d
subq %r13, %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x1110
jmp 0x278d
jmp 0x276d
jmp 0x276d
jmp 0x276d
movq %rax, %rbx
jmp 0x27a8
movq %rax, %rbx
movq -0x128(%rbp), %rdi
testq %rdi, %rdi
je 0x27a8
movq -0x118(%rbp), %rsi
jmp 0x27a0
movq %rax, %rbx
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x27a8
movq -0xf0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x27bd
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
leaq -0x98(%rbp), %rdi
callq 0x2a60
movq %rbx, %rdi
callq 0x11a0
nop