#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double *CreateBastard(double *);
double *CreateChild(double *, double *);
double *CreateImmigrant();
int /*<<< orphan*/ free(double *);
double *malloc(int);
int /*<<< orphan*/ memcpy(double *, double *, int);
double **CreateNewGeneration(double **currentGen, double *fitness) {
  double *firstBest = malloc(sizeof(double) * 8);
  double *secondBest = malloc(sizeof(double) * 8);
  double *child;
  double largestFitness = 0;
  int i;
  for (i = 0; i < 20; i++) {
    if (fitness[i] > largestFitness) {
      memcpy(secondBest, firstBest, sizeof(double) * 8);
      memcpy(firstBest, currentGen[i], sizeof(double) * 8);
      largestFitness = fitness[i];
    }
  }
  for (i = 0; i < 20; i++) {
    if (i < 7) {
      child = CreateChild(firstBest, secondBest);
      memcpy(currentGen[i], child, sizeof(double) * 8);
      free(child);
      child = NULL;
    } else if (i < 14) {
      child = CreateBastard(firstBest);
      memcpy(currentGen[i], child, sizeof(double) * 8);
      free(child);
      child = NULL;
    } else {
      child = CreateImmigrant();
      memcpy(currentGen[i], child, sizeof(double) * 8);
      free(child);
      child = NULL;
    }
  }
  free(firstBest);
  free(secondBest);
  return currentGen;
}


x86 assembly (clang, -O0):
<CreateNewGeneration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x14,-0x34(%rbp)
jge    120e <CreateNewGeneration+0xae>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11fb <CreateNewGeneration+0x9b>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1200 <CreateNewGeneration+0xa0>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119b <CreateNewGeneration+0x3b>
movl   $0x0,-0x34(%rbp)
cmpl   $0x14,-0x34(%rbp)
jge    12ff <CreateNewGeneration+0x19f>
cmpl   $0x7,-0x34(%rbp)
jge    126a <CreateNewGeneration+0x10a>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <CreateChild@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
jmp    12ec <CreateNewGeneration+0x18c>
cmpl   $0xe,-0x34(%rbp)
jge    12b1 <CreateNewGeneration+0x151>
mov    -0x18(%rbp),%rdi
call   1080 <CreateBastard@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
jmp    12e7 <CreateNewGeneration+0x187>
mov    $0x0,%al
call   1070 <CreateImmigrant@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
jmp    12ec <CreateNewGeneration+0x18c>
jmp    12f1 <CreateNewGeneration+0x191>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1215 <CreateNewGeneration+0xb5>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateNewGeneration>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r14
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    11aa <CreateNewGeneration+0x4a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x14,%rbx
je     11e1 <CreateNewGeneration+0x81>
movsd  0x0(%r13,%rbx,8),%xmm1
ucomisd %xmm0,%xmm1
jbe    11a0 <CreateNewGeneration+0x40>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    (%r14,%rbx,8),%rsi
mov    %r12,%rdi
mov    $0x40,%edx
call   1050 <memcpy@plt>
movsd  0x0(%r13,%rbx,8),%xmm0
jmp    11a0 <CreateNewGeneration+0x40>
xor    %ebx,%ebx
jmp    1221 <CreateNewGeneration+0xc1>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <CreateChild@plt>
mov    %rax,%r13
mov    (%r14,%rbx,8),%rdi
mov    %rax,%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    %r13,%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x14,%rbx
je     1249 <CreateNewGeneration+0xe9>
cmp    $0x6,%rbx
jbe    11f0 <CreateNewGeneration+0x90>
cmp    $0xd,%rbx
ja     1240 <CreateNewGeneration+0xe0>
mov    %r12,%rdi
call   1080 <CreateBastard@plt>
jmp    11fb <CreateNewGeneration+0x9b>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <CreateImmigrant@plt>
jmp    11fb <CreateNewGeneration+0x9b>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double** @CreateNewGeneration(double** %0, double* %1) {
%3 = alloca double**
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca i32
store double** %0, double*** %3
store double* %1, double** %4
%10 = call double* @malloc(i32 64)
store double* %10, double** %5
%11 = call double* @malloc(i32 64)
store double* %11, double** %6
store double 0.000000e+00, double* %8
store i32 0, i32* %9
br label %12
12: ; preds = %40, %2
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 20
br i1 %14, label %15, label %43
15: ; preds = %12
%16 = load double*, double** %4
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = load double, double* %8
%22 = fcmp ogt double %20, %21
br i1 %22, label %23, label %39
23: ; preds = %15
%24 = load double*, double** %6
%25 = load double*, double** %5
%26 = call i32 @memcpy(double* %24, double* %25, i32 64)
%27 = load double*, double** %5
%28 = load double**, double*** %3
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
%32 = load double*, double** %31
%33 = call i32 @memcpy(double* %27, double* %32, i32 64)
%34 = load double*, double** %4
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
store double %38, double* %8
br label %39
39: ; preds = %23, %15
br label %40
40: ; preds = %39
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %12
43: ; preds = %12
store i32 0, i32* %9
br label %44
44: ; preds = %91, %43
%45 = load i32, i32* %9
%46 = icmp slt i32 %45, 20
br i1 %46, label %47, label %94
47: ; preds = %44
%48 = load i32, i32* %9
%49 = icmp slt i32 %48, 7
br i1 %49, label %50, label %63
50: ; preds = %47
%51 = load double*, double** %5
%52 = load double*, double** %6
%53 = call double* @CreateChild(double* %51, double* %52)
store double* %53, double** %7
%54 = load double**, double*** %3
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double*, double** %54, i64 %56
%58 = load double*, double** %57
%59 = load double*, double** %7
%60 = call i32 @memcpy(double* %58, double* %59, i32 64)
%61 = load double*, double** %7
%62 = call i32 @free(double* %61)
store double* null, double** %7
br label %90
63: ; preds = %47
%64 = load i32, i32* %9
%65 = icmp slt i32 %64, 14
br i1 %65, label %66, label %78
66: ; preds = %63
%67 = load double*, double** %5
%68 = call double* @CreateBastard(double* %67)
store double* %68, double** %7
%69 = load double**, double*** %3
%70 = load i32, i32* %9
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double*, double** %69, i64 %71
%73 = load double*, double** %72
%74 = load double*, double** %7
%75 = call i32 @memcpy(double* %73, double* %74, i32 64)
%76 = load double*, double** %7
%77 = call i32 @free(double* %76)
store double* null, double** %7
br label %89
78: ; preds = %63
%79 = call double* (...) @CreateImmigrant()
store double* %79, double** %7
%80 = load double**, double*** %3
%81 = load i32, i32* %9
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double*, double** %80, i64 %82
%84 = load double*, double** %83
%85 = load double*, double** %7
%86 = call i32 @memcpy(double* %84, double* %85, i32 64)
%87 = load double*, double** %7
%88 = call i32 @free(double* %87)
store double* null, double** %7
br label %89
89: ; preds = %78, %66
br label %90
90: ; preds = %89, %50
br label %91
91: ; preds = %90
%92 = load i32, i32* %9
%93 = add nsw i32 %92, 1
store i32 %93, i32* %9
br label %44
94: ; preds = %44
%95 = load double*, double** %5
%96 = call i32 @free(double* %95)
%97 = load double*, double** %6
%98 = call i32 @free(double* %97)
%99 = load double**, double*** %3
ret double** %99
}

LLVM IR (-O2):
define double** @CreateNewGeneration(double** returned %0, double* nocapture %1) {
%3 = tail call double* @malloc(i32 64)
%4 = tail call double* @malloc(i32 64)
br label %5
5: ; preds = %2, %17
%6 = phi i64 [ 0, %2 ], [ %19, %17 ]
%7 = phi double [ 0.000000e+00, %2 ], [ %18, %17 ]
%8 = getelementptr inbounds double, double* %1, i64 %6
%9 = load double, double* %8
%10 = fcmp ogt double %9, %7
br i1 %10, label %11, label %17
11: ; preds = %5
%12 = tail call i32 @memcpy(double* %4, double* %3, i32 64)
%13 = getelementptr inbounds double*, double** %0, i64 %6
%14 = load double*, double** %13
%15 = tail call i32 @memcpy(double* %3, double* %14, i32 64)
%16 = load double, double* %8
br label %17
17: ; preds = %5, %11
%18 = phi double [ %16, %11 ], [ %7, %5 ]
%19 = add nuw nsw i64 %6, 1
%20 = icmp eq i64 %19, 20
br i1 %20, label %21, label %5
21: ; preds = %17, %32
%22 = phi i64 [ %38, %32 ], [ 0, %17 ]
%23 = icmp ult i64 %22, 7
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call double* @CreateChild(double* %3, double* %4)
br label %32
26: ; preds = %21
%27 = icmp ult i64 %22, 14
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = tail call double* @CreateBastard(double* %3)
br label %32
30: ; preds = %26
%31 = tail call double* (...) @CreateImmigrant()
br label %32
32: ; preds = %24, %30, %28
%33 = phi double* [ %25, %24 ], [ %31, %30 ], [ %29, %28 ]
%34 = getelementptr inbounds double*, double** %0, i64 %22
%35 = load double*, double** %34
%36 = tail call i32 @memcpy(double* %35, double* %33, i32 64)
%37 = tail call i32 @free(double* %33)
%38 = add nuw nsw i64 %22, 1
%39 = icmp eq i64 %38, 20
br i1 %39, label %40, label %21
40: ; preds = %32
%41 = tail call i32 @free(double* %3)
%42 = tail call i32 @free(double* %4)
ret double** %0
}