// File: /workspace/github_c_makefile_star2_O0/kernfel[P]fNEAT/neat.c
// Function: speciate_population
int speciate_population( Population *pop, struct NEAT_Params *params, const Individual *reps ) {
	int i, j, num_new_species=0, num_extinct=0;
	
	for ( i=0; i<pop->num_species; i++ ) {
		pop->species[i].size = 0;
	}
	
	int new_species_size[pop->num_members];
	Individual *new_reps[pop->num_members];
	for ( i=0; i<pop->num_members; i++ ) {
		int assigned=0;
		
		// Check for same species first...
		if ( pop->members[i].species_id ) {
			for ( j=0; j<pop->num_species; j++ ) {
				if ( reps[j].species_id == pop->members[i].species_id ) {
					double distance = get_genetic_distance( &pop->members[i].genotype, &reps[j].genotype, params );
					if ( distance < params->speciation_threshold ) {
						pop->species[j].size++;
						assigned = 1;
						break;
					}
				}
			}
		}
		
		// Check for other ancestor species...
		if ( ! assigned ) {
			for ( j=0; j<pop->num_species; j++ ) {
				if ( reps[j].species_id && reps[j].species_id != pop->members[i].species_id ) {
					double distance = get_genetic_distance( &pop->members[i].genotype, &reps[j].genotype, params );
					if ( distance < params->speciation_threshold ) {
						pop->members[i].species_id = reps[j].species_id;
						pop->species[j].size++;
						assigned = 1;
						break;
					}
				}
			}
		}
		
		// ... or to a newly created species...
		if ( ! assigned ) {
			for ( j=num_new_species-1; j>=0; j-- ) {
				double distance = get_genetic_distance( &pop->members[i].genotype, &new_reps[j]->genotype, params );
				if ( distance < params->speciation_threshold ) {
					pop->members[i].species_id = new_reps[j]->species_id;
					new_species_size[j]++;
					assigned = 1;
					break;
				}
			}
		}
		
		// ... or create a new species, proudly representing!
		if ( ! assigned ) {
			pop->members[i].species_id = ++params->species_counter;
			new_reps[num_new_species] = pop->members + i;
			new_species_size[num_new_species++] = 1;
		}
	}
	
	for ( i=0; i<pop->num_species; i++ ) {
		if ( ! pop->species[i].size )
			num_extinct++;
	}
	
	// No structural changes to species list, bail
	if ( ! num_new_species && ! num_extinct )
		return 0;
	
	// Compose a new list with all the (living) species and replace the old one with that
	int err=0;
	int num_all = pop->num_species + num_new_species - num_extinct;
	Species *all_species;
	if (( err = Calloc( all_species, num_all, sizeof *all_species ) ))
		return err;
	
	j=0;
	for ( i=0; i<pop->num_species; i++ ) {
		if ( pop->species[i].size ) {
			all_species[j] = pop->species[i];
			j++;
		}
	}
	for ( i=0; i<num_new_species; i++ ) {
		all_species[j].id = new_reps[i]->species_id;
		all_species[j].size = new_species_size[i];
		j++;
	}
	
	free( pop->species );
	pop->species = all_species;
	pop->num_species = num_all;
	
	return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x553d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x4(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x550c
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq %rsp, %rcx
movq %rcx, -0x38(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x90(%rbp)
movq %rcx, %rsp
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x88(%rbp)
movq %rcx, %rsp
movq %rax, -0x48(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x58c3
movl $0x0, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x30(%rax)
je 0x5688
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x5686
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x30(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x24(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x30(%rcx), %eax
jne 0x5676
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movslq -0x24(%rbp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movslq -0x28(%rbp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rsi
movq -0x18(%rbp), %rdx
callq 0x39d0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm1
movq -0x18(%rbp), %rax
movsd 0x68(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5674
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl $0x1, -0x4c(%rbp)
jmp 0x5686
jmp 0x5676
jmp 0x5678
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x55d3
jmp 0x5688
cmpl $0x0, -0x4c(%rbp)
jne 0x5792
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x5790
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x30(%rax)
je 0x5780
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x30(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x24(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x30(%rcx), %eax
je 0x5780
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movslq -0x24(%rbp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movslq -0x28(%rbp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rsi
movq -0x18(%rbp), %rdx
callq 0x39d0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm1
movq -0x18(%rbp), %rax
movsd 0x68(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x577e
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x30(%rax), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl $0x1, -0x4c(%rbp)
jmp 0x5790
jmp 0x5780
jmp 0x5782
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x5699
jmp 0x5792
cmpl $0x0, -0x4c(%rbp)
jne 0x5848
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jl 0x5846
movq -0x88(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdi
movslq -0x24(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rdi
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x18(%rbp), %rdx
callq 0x39d0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm1
movq -0x18(%rbp), %rax
movsd 0x68(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5836
movq -0x90(%rbp), %rax
movq -0x88(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl 0x30(%rcx), %edx
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x24(%rbp), %rsi
imulq $0x38, %rsi, %rsi
addq %rsi, %rcx
movl %edx, 0x30(%rcx)
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl $0x1, -0x4c(%rbp)
jmp 0x5846
jmp 0x5838
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x57a5
jmp 0x5848
cmpl $0x0, -0x4c(%rbp)
jne 0x58b3
movq -0x90(%rbp), %rax
movq -0x88(%rbp), %rcx
movq -0x18(%rbp), %rdx
movl 0x10c(%rdx), %esi
addl $0x1, %esi
movl %esi, 0x10c(%rdx)
movq -0x10(%rbp), %rdx
movq (%rdx), %rdx
movslq -0x24(%rbp), %rdi
imulq $0x38, %rdi, %rdi
addq %rdi, %rdx
movl %esi, 0x30(%rdx)
movq -0x10(%rbp), %rdx
movq (%rdx), %rsi
movslq -0x24(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rsi
movslq -0x2c(%rbp), %rdx
movq %rsi, (%rcx,%rdx,8)
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x58b5
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x5599
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x5905
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
jne 0x58f8
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x58fa
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x58ca
cmpl $0x0, -0x2c(%rbp)
jne 0x5924
cmpl $0x0, -0x30(%rbp)
jne 0x5924
movl $0x0, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x5a7e
movl $0x0, -0x70(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
addl -0x2c(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, -0x74(%rbp)
movslq -0x74(%rbp), %rsi
leaq -0x80(%rbp), %rdi
movl $0x18, %edx
callq 0x6370
movl %eax, -0x70(%rbp)
cmpl $0x0, %eax
je 0x5967
movl -0x70(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x5a7e
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x59e8
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
je 0x59db
movq -0x80(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x24(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x59dd
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x5975
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x5a4e
movq -0x90(%rbp), %rax
movq -0x88(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl 0x30(%rcx), %edx
movq -0x80(%rbp), %rcx
movslq -0x28(%rbp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rcx
movl %edx, (%rcx)
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movq -0x80(%rbp), %rax
movslq -0x28(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x59ef
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1030
movq -0x80(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x74(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x70(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
movq -0x38(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)