#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 */
typedef int /*<<< orphan*/ uint;

/* Variables and functions */
int *calloc(int, int);
double fitness(int *, int, int, int, int);
int /*<<< orphan*/ free(int *);
int *generate_random_population(int **, int *, int);
int index_of_max_element(double *, int);
int index_of_tournament_selection_winner(int, double *, int);
int /*<<< orphan*/ mutate(double, int *, int, int **, int *, int);
int /*<<< orphan*/ one_point_crossover(int *, int *, int *, int *, int, int);
int /*<<< orphan*/ printf(char *, int, int, double);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/ *);
int *plan_calendar(int **playable_dates_per_team, int *playable_date_sizes,
                   int team_size, int prefered_days_between_consecutives,
                   int prefered_days_between_returns) {
  srand((uint)time(NULL));
  int population_size = team_size * (team_size - 1);
  int *generation[2 * 1000];
  double generation_fitness[2 * 1000];
  for (int i = 0; i < 1000; i++) {
    int *random_population = generate_random_population(
        playable_dates_per_team, playable_date_sizes, team_size);
    generation_fitness[i] = fitness(
        random_population, population_size, team_size,
        prefered_days_between_consecutives, prefered_days_between_returns);
    generation[i] = random_population;
  }
  for (int i = 1000; i < 1000 * 2; i++) {
    generation[i] = calloc(population_size, sizeof(int));
  }
  int index_of_fittest = 0;
  for (int k = 0; k < 500; k++) {
    int amount_of_children = 0;
    while (amount_of_children < 1000) {
      int *first_child = generation[amount_of_children + 1000];
      int *second_child = generation[amount_of_children + 1000 + 1];
      int father_index =
          index_of_tournament_selection_winner(2, generation_fitness, 1000);
      int mother_index =
          index_of_tournament_selection_winner(2, generation_fitness, 1000);
      one_point_crossover(first_child, second_child, generation[father_index],
                          generation[mother_index], population_size, team_size);
      mutate(0.01, first_child, population_size, playable_dates_per_team,
             playable_date_sizes, team_size);
      mutate(0.01, second_child, population_size, playable_dates_per_team,
             playable_date_sizes, team_size);
      generation_fitness[amount_of_children + 1000] = fitness(
          first_child, population_size, team_size,
          prefered_days_between_consecutives, prefered_days_between_returns);
      amount_of_children++;
      generation_fitness[amount_of_children + 1000] = fitness(
          second_child, population_size, team_size,
          prefered_days_between_consecutives, prefered_days_between_returns);
      amount_of_children++;
    }
    index_of_fittest = index_of_max_element(generation_fitness, 1000 * 2);
    int *tmp = generation[index_of_fittest];
    int fittmp = generation_fitness[index_of_fittest];
    generation[index_of_fittest] = generation[0];
    generation_fitness[index_of_fittest] = generation_fitness[0];
    generation[0] = tmp;
    generation_fitness[0] = fittmp;
    for (int i = 1; i < 1000; i++) {
      int survivor_index = index_of_tournament_selection_winner(
                               2, (generation_fitness + i), (1000 * 2) - i) +
                           i;
      int *tmp_survivor = generation[survivor_index];
      int tmp_fitness = generation_fitness[survivor_index];
      generation[survivor_index] = generation[i];
      generation_fitness[survivor_index] = generation_fitness[i];
      generation[i] = tmp_survivor;
      generation_fitness[i] = tmp_fitness;
    }
    printf("Generation %d:\t%d\t%f\n", k, index_of_fittest,
           generation_fitness[0]);
  }
  fitness(generation[0], population_size, team_size,
          prefered_days_between_consecutives, prefered_days_between_returns);
  for (int i = 1; i < 2 * 1000; i++) {
    free(generation[i]);
  }
  return generation[0];
}


x86 assembly (clang, -O0):
<plan_calendar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7d80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x7d24(%rbp)
cmpl   $0x3e8,-0x7d24(%rbp)
jge    1270 <plan_calendar+0xc0>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10c0 <generate_random_population@plt>
mov    %rax,-0x7d30(%rbp)
mov    -0x7d30(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1070 <fitness@plt>
movslq -0x7d24(%rbp),%rax
movsd  %xmm0,-0x7d20(%rbp,%rax,8)
ff ff
mov    -0x7d30(%rbp),%rcx
movslq -0x7d24(%rbp),%rax
mov    %rcx,-0x3ea0(%rbp,%rax,8)
ff
mov    -0x7d24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7d24(%rbp)
jmp    11f6 <plan_calendar+0x46>
movl   $0x3e8,-0x7d34(%rbp)
cmpl   $0x7d0,-0x7d34(%rbp)
jge    12bd <plan_calendar+0x10d>
mov    -0x20(%rbp),%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
mov    %rax,%rcx
movslq -0x7d34(%rbp),%rax
mov    %rcx,-0x3ea0(%rbp,%rax,8)
ff
mov    -0x7d34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7d34(%rbp)
jmp    127a <plan_calendar+0xca>
movl   $0x0,-0x7d38(%rbp)
movl   $0x0,-0x7d3c(%rbp)
cmpl   $0x1f4,-0x7d3c(%rbp)
jge    162d <plan_calendar+0x47d>
movl   $0x0,-0x7d40(%rbp)
cmpl   $0x3e8,-0x7d40(%rbp)
jge    146e <plan_calendar+0x2be>
mov    -0x7d40(%rbp),%eax
add    $0x3e8,%eax
cltq
mov    -0x3ea0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x7d48(%rbp)
mov    -0x7d40(%rbp),%eax
add    $0x3e8,%eax
add    $0x1,%eax
cltq
mov    -0x3ea0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x7d50(%rbp)
lea    -0x7d20(%rbp),%rsi
mov    $0x2,%edi
mov    $0x3e8,%edx
call   1050 <index_of_tournament_selection_winner@plt>
mov    %eax,-0x7d54(%rbp)
lea    -0x7d20(%rbp),%rsi
mov    $0x2,%edi
mov    $0x3e8,%edx
call   1050 <index_of_tournament_selection_winner@plt>
mov    %eax,-0x7d58(%rbp)
mov    -0x7d48(%rbp),%rdi
mov    -0x7d50(%rbp),%rsi
movslq -0x7d54(%rbp),%rax
mov    -0x3ea0(%rbp,%rax,8),%rdx
ff
movslq -0x7d58(%rbp),%rax
mov    -0x3ea0(%rbp,%rax,8),%rcx
ff
mov    -0x20(%rbp),%r8d
mov    -0x14(%rbp),%r9d
call   1090 <one_point_crossover@plt>
mov    -0x7d48(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
movsd  0xc3b(%rip),%xmm0
call   10d0 <mutate@plt>
mov    -0x7d50(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
movsd  0xc18(%rip),%xmm0
call   10d0 <mutate@plt>
mov    -0x7d48(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1070 <fitness@plt>
mov    -0x7d40(%rbp),%eax
add    $0x3e8,%eax
cltq
movsd  %xmm0,-0x7d20(%rbp,%rax,8)
ff ff
mov    -0x7d40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7d40(%rbp)
mov    -0x7d50(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1070 <fitness@plt>
mov    -0x7d40(%rbp),%eax
add    $0x3e8,%eax
cltq
movsd  %xmm0,-0x7d20(%rbp,%rax,8)
ff ff
mov    -0x7d40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7d40(%rbp)
jmp    12eb <plan_calendar+0x13b>
lea    -0x7d20(%rbp),%rdi
mov    $0x7d0,%esi
call   1040 <index_of_max_element@plt>
mov    %eax,-0x7d38(%rbp)
movslq -0x7d38(%rbp),%rax
mov    -0x3ea0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x7d60(%rbp)
movslq -0x7d38(%rbp),%rax
cvttsd2si -0x7d20(%rbp,%rax,8),%eax
ff ff
mov    %eax,-0x7d64(%rbp)
mov    -0x3ea0(%rbp),%rcx
movslq -0x7d38(%rbp),%rax
mov    %rcx,-0x3ea0(%rbp,%rax,8)
ff
movsd  -0x7d20(%rbp),%xmm0
ff
movslq -0x7d38(%rbp),%rax
movsd  %xmm0,-0x7d20(%rbp,%rax,8)
ff ff
mov    -0x7d60(%rbp),%rax
mov    %rax,-0x3ea0(%rbp)
cvtsi2sdl -0x7d64(%rbp),%xmm0
ff
movsd  %xmm0,-0x7d20(%rbp)
ff
movl   $0x1,-0x7d68(%rbp)
cmpl   $0x3e8,-0x7d68(%rbp)
jge    15f9 <plan_calendar+0x449>
lea    -0x7d20(%rbp),%rsi
movslq -0x7d68(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x7d0,%edx
sub    -0x7d68(%rbp),%edx
mov    $0x2,%edi
call   1050 <index_of_tournament_selection_winner@plt>
add    -0x7d68(%rbp),%eax
mov    %eax,-0x7d6c(%rbp)
movslq -0x7d6c(%rbp),%rax
mov    -0x3ea0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x7d78(%rbp)
movslq -0x7d6c(%rbp),%rax
cvttsd2si -0x7d20(%rbp,%rax,8),%eax
ff ff
mov    %eax,-0x7d7c(%rbp)
movslq -0x7d68(%rbp),%rax
mov    -0x3ea0(%rbp,%rax,8),%rcx
ff
movslq -0x7d6c(%rbp),%rax
mov    %rcx,-0x3ea0(%rbp,%rax,8)
ff
movslq -0x7d68(%rbp),%rax
movsd  -0x7d20(%rbp,%rax,8),%xmm0
ff ff
movslq -0x7d6c(%rbp),%rax
movsd  %xmm0,-0x7d20(%rbp,%rax,8)
ff ff
mov    -0x7d78(%rbp),%rcx
movslq -0x7d68(%rbp),%rax
mov    %rcx,-0x3ea0(%rbp,%rax,8)
ff
cvtsi2sdl -0x7d7c(%rbp),%xmm0
ff
movslq -0x7d68(%rbp),%rax
movsd  %xmm0,-0x7d20(%rbp,%rax,8)
ff ff
mov    -0x7d68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7d68(%rbp)
jmp    1507 <plan_calendar+0x357>
mov    -0x7d3c(%rbp),%esi
mov    -0x7d38(%rbp),%edx
movsd  -0x7d20(%rbp),%xmm0
ff
lea    0x9f4(%rip),%rdi
call   1060 <printf@plt>
mov    -0x7d3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7d3c(%rbp)
jmp    12d1 <plan_calendar+0x121>
mov    -0x3ea0(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1070 <fitness@plt>
movl   $0x1,-0x7d80(%rbp)
cmpl   $0x7d0,-0x7d80(%rbp)
jge    1688 <plan_calendar+0x4d8>
movslq -0x7d80(%rbp),%rax
mov    -0x3ea0(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x7d80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7d80(%rbp)
jmp    1650 <plan_calendar+0x4a0>
mov    -0x3ea0(%rbp),%rax
add    $0x7d80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plan_calendar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7d38,%rsp
mov    %r8d,(%rsp)
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %rsi,0x18(%rsp)
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    -0x1(%r15),%r13d
imul   %r15d,%r13d
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    0x18(%rsp),%rsi
mov    %r15d,%edx
call   10c0 <generate_random_population@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13d,%esi
mov    %r15d,%edx
mov    %r12d,%ecx
mov    (%rsp),%r8d
call   1070 <fitness@plt>
movsd  %xmm0,0x3eb0(%rsp,%rbp,8)
mov    %rbx,0x30(%rsp,%rbp,8)
add    $0x1,%rbp
cmp    $0x3e8,%rbp
jne    11f0 <plan_calendar+0x40>
mov    %r14,0x20(%rsp)
mov    %r15,0x10(%rsp)
xor    %ebx,%ebx
nop
mov    %r13d,%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
mov    %rax,0x1f70(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1240 <plan_calendar+0x90>
mov    %r13d,0x4(%rsp)
xor    %ebp,%ebp
mov    %r12d,0xc(%rsp)
xchg   %ax,%ax
mov    %ebp,0x8(%rsp)
mov    $0xfffffffffffffffe,%r13
nopl   0x0(%rax,%rax,1)
mov    0x1f80(%rsp,%r13,8),%rbp
mov    %rbp,0x28(%rsp)
mov    0x1f88(%rsp,%r13,8),%r15
mov    $0x2,%edi
lea    0x3eb0(%rsp),%r14
mov    %r14,%rsi
mov    $0x3e8,%edx
call   1050 <index_of_tournament_selection_winner@plt>
mov    %eax,%ebx
mov    $0x2,%edi
mov    %r14,%rsi
mov    $0x3e8,%edx
call   1050 <index_of_tournament_selection_winner@plt>
movslq %ebx,%rcx
mov    0x30(%rsp,%rcx,8),%rdx
cltq
mov    0x30(%rsp,%rax,8),%rcx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r15,%r14
mov    0x4(%rsp),%r15d
mov    %r15d,%r8d
mov    0x10(%rsp),%rbx
mov    %ebx,%r9d
call   1090 <one_point_crossover@plt>
movsd  0xd08(%rip),%xmm0
mov    %rbp,%rdi
mov    %r15d,%esi
mov    0x20(%rsp),%r12
mov    %r12,%rdx
mov    0x18(%rsp),%rbp
mov    %rbp,%rcx
mov    %ebx,%r8d
call   10d0 <mutate@plt>
movsd  0xce2(%rip),%xmm0
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
mov    %rbp,%rcx
mov    %ebx,%r8d
call   10d0 <mutate@plt>
mov    0x28(%rsp),%rdi
mov    0xc(%rsp),%r12d
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    (%rsp),%ebp
mov    %ebp,%r8d
call   1070 <fitness@plt>
movsd  %xmm0,0x5e00(%rsp,%r13,8)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
call   1070 <fitness@plt>
movsd  %xmm0,0x5e08(%rsp,%r13,8)
add    $0x2,%r13
cmp    $0x3e6,%r13
jb     1280 <plan_calendar+0xd0>
lea    0x3eb0(%rsp),%rdi
mov    $0x7d0,%esi
call   1040 <index_of_max_element@plt>
mov    %eax,%r15d
cltq
mov    0x30(%rsp,%rax,8),%rcx
mov    0x30(%rsp),%rdx
mov    %rdx,0x30(%rsp,%rax,8)
movsd  0x3eb0(%rsp),%xmm0
movsd  0x3eb0(%rsp,%rax,8),%xmm1
movsd  %xmm0,0x3eb0(%rsp,%rax,8)
mov    %rcx,0x30(%rsp)
cvttpd2dq %xmm1,%xmm0
cvtdq2pd %xmm0,%xmm0
movlps %xmm0,0x3eb0(%rsp)
mov    $0x1,%ebp
mov    $0x7cf,%r14d
mov    $0x8,%ebx
nopl   (%rax)
lea    (%rsp,%rbx,1),%rsi
add    $0x3eb0,%rsi
mov    $0x2,%edi
mov    %r14d,%edx
call   1050 <index_of_tournament_selection_winner@plt>
add    %ebp,%eax
cltq
mov    0x30(%rsp,%rax,8),%rcx
mov    0x30(%rsp,%rbp,8),%rdx
mov    %rdx,0x30(%rsp,%rax,8)
movsd  0x3eb0(%rsp,%rbp,8),%xmm0
movsd  0x3eb0(%rsp,%rax,8),%xmm1
movsd  %xmm0,0x3eb0(%rsp,%rax,8)
cvttpd2dq %xmm1,%xmm0
mov    %rcx,0x30(%rsp,%rbp,8)
cvtdq2pd %xmm0,%xmm0
movlps %xmm0,0x3eb0(%rsp,%rbp,8)
add    $0x1,%rbp
add    $0xffffffff,%r14d
add    $0x8,%rbx
cmp    $0x3e8,%rbp
jne    13f0 <plan_calendar+0x240>
movsd  0x3eb0(%rsp),%xmm0
lea    0xb98(%rip),%rdi
mov    0x8(%rsp),%ebp
mov    %ebp,%esi
mov    %r15d,%edx
call   1060 <printf@plt>
add    $0x1,%ebp
cmp    $0x1f4,%ebp
mov    (%rsp),%ebx
jne    1270 <plan_calendar+0xc0>
mov    0x30(%rsp),%r14
mov    %r14,%rdi
mov    0x4(%rsp),%esi
mov    0x10(%rsp),%rdx
mov    %r12d,%ecx
mov    %ebx,%r8d
call   1070 <fitness@plt>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x30(%rsp,%rbp,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbp
cmp    $0x7d0,%rbp
jne    14c0 <plan_calendar+0x310>
mov    %r14,%rax
add    $0x7d38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Generation %d:\09%d\09%f\0A\00"
define i32* @plan_calendar(i32** %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [2000 x i32*]
%13 = alloca [2000 x double]
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32*
%21 = alloca i32*
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32*
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32*
%29 = alloca i32
%30 = alloca i32
store i32** %0, i32*** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%31 = call i64 @time(i32* null)
%32 = trunc i64 %31 to i32
%33 = call i32 @srand(i32 %32)
%34 = load i32, i32* %8
%35 = load i32, i32* %8
%36 = sub nsw i32 %35, 1
%37 = mul nsw i32 %34, %36
store i32 %37, i32* %11
store i32 0, i32* %14
br label %38
38: ; preds = %59, %5
%39 = load i32, i32* %14
%40 = icmp slt i32 %39, 1000
br i1 %40, label %41, label %62
41: ; preds = %38
%42 = load i32**, i32*** %6
%43 = load i32*, i32** %7
%44 = load i32, i32* %8
%45 = call i32* @generate_random_population(i32** %42, i32* %43, i32 %44)
store i32* %45, i32** %15
%46 = load i32*, i32** %15
%47 = load i32, i32* %11
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = load i32, i32* %10
%51 = call double @fitness(i32* %46, i32 %47, i32 %48, i32 %49, i32 %50)
%52 = load i32, i32* %14
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 %53
store double %51, double* %54
%55 = load i32*, i32** %15
%56 = load i32, i32* %14
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %57
store i32* %55, i32** %58
br label %59
59: ; preds = %41
%60 = load i32, i32* %14
%61 = add nsw i32 %60, 1
store i32 %61, i32* %14
br label %38
62: ; preds = %38
store i32 1000, i32* %16
br label %63
63: ; preds = %72, %62
%64 = load i32, i32* %16
%65 = icmp slt i32 %64, 2000
br i1 %65, label %66, label %75
66: ; preds = %63
%67 = load i32, i32* %11
%68 = call i32* @calloc(i32 %67, i32 4)
%69 = load i32, i32* %16
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %70
store i32* %68, i32** %71
br label %72
72: ; preds = %66
%73 = load i32, i32* %16
%74 = add nsw i32 %73, 1
store i32 %74, i32* %16
br label %63
75: ; preds = %63
store i32 0, i32* %17
store i32 0, i32* %18
br label %76
76: ; preds = %229, %75
%77 = load i32, i32* %18
%78 = icmp slt i32 %77, 500
br i1 %78, label %79, label %232
79: ; preds = %76
store i32 0, i32* %19
br label %80
80: ; preds = %83, %79
%81 = load i32, i32* %19
%82 = icmp slt i32 %81, 1000
br i1 %82, label %83, label %148
83: ; preds = %80
%84 = load i32, i32* %19
%85 = add nsw i32 %84, 1000
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %86
%88 = load i32*, i32** %87
store i32* %88, i32** %20
%89 = load i32, i32* %19
%90 = add nsw i32 %89, 1000
%91 = add nsw i32 %90, 1
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %92
%94 = load i32*, i32** %93
store i32* %94, i32** %21
%95 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 0
%96 = call i32 @index_of_tournament_selection_winner(i32 2, double* %95, i32 1000)
store i32 %96, i32* %22
%97 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 0
%98 = call i32 @index_of_tournament_selection_winner(i32 2, double* %97, i32 1000)
store i32 %98, i32* %23
%99 = load i32*, i32** %20
%100 = load i32*, i32** %21
%101 = load i32, i32* %22
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %102
%104 = load i32*, i32** %103
%105 = load i32, i32* %23
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %106
%108 = load i32*, i32** %107
%109 = load i32, i32* %11
%110 = load i32, i32* %8
%111 = call i32 @one_point_crossover(i32* %99, i32* %100, i32* %104, i32* %108, i32 %109, i32 %110)
%112 = load i32*, i32** %20
%113 = load i32, i32* %11
%114 = load i32**, i32*** %6
%115 = load i32*, i32** %7
%116 = load i32, i32* %8
%117 = call i32 @mutate(double 1.000000e-02, i32* %112, i32 %113, i32** %114, i32* %115, i32 %116)
%118 = load i32*, i32** %21
%119 = load i32, i32* %11
%120 = load i32**, i32*** %6
%121 = load i32*, i32** %7
%122 = load i32, i32* %8
%123 = call i32 @mutate(double 1.000000e-02, i32* %118, i32 %119, i32** %120, i32* %121, i32 %122)
%124 = load i32*, i32** %20
%125 = load i32, i32* %11
%126 = load i32, i32* %8
%127 = load i32, i32* %9
%128 = load i32, i32* %10
%129 = call double @fitness(i32* %124, i32 %125, i32 %126, i32 %127, i32 %128)
%130 = load i32, i32* %19
%131 = add nsw i32 %130, 1000
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 %132
store double %129, double* %133
%134 = load i32, i32* %19
%135 = add nsw i32 %134, 1
store i32 %135, i32* %19
%136 = load i32*, i32** %21
%137 = load i32, i32* %11
%138 = load i32, i32* %8
%139 = load i32, i32* %9
%140 = load i32, i32* %10
%141 = call double @fitness(i32* %136, i32 %137, i32 %138, i32 %139, i32 %140)
%142 = load i32, i32* %19
%143 = add nsw i32 %142, 1000
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 %144
store double %141, double* %145
%146 = load i32, i32* %19
%147 = add nsw i32 %146, 1
store i32 %147, i32* %19
br label %80
148: ; preds = %80
%149 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 0
%150 = call i32 @index_of_max_element(double* %149, i32 2000)
store i32 %150, i32* %17
%151 = load i32, i32* %17
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %152
%154 = load i32*, i32** %153
store i32* %154, i32** %24
%155 = load i32, i32* %17
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 %156
%158 = load double, double* %157
%159 = fptosi double %158 to i32
store i32 %159, i32* %25
%160 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 0
%161 = load i32*, i32** %160
%162 = load i32, i32* %17
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %163
store i32* %161, i32** %164
%165 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 0
%166 = load double, double* %165
%167 = load i32, i32* %17
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 %168
store double %166, double* %169
%170 = load i32*, i32** %24
%171 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 0
store i32* %170, i32** %171
%172 = load i32, i32* %25
%173 = sitofp i32 %172 to double
%174 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 0
store double %173, double* %174
store i32 1, i32* %26
br label %175
175: ; preds = %220, %148
%176 = load i32, i32* %26
%177 = icmp slt i32 %176, 1000
br i1 %177, label %178, label %223
178: ; preds = %175
%179 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 0
%180 = load i32, i32* %26
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds double, double* %179, i64 %181
%183 = load i32, i32* %26
%184 = sub nsw i32 2000, %183
%185 = call i32 @index_of_tournament_selection_winner(i32 2, double* %182, i32 %184)
%186 = load i32, i32* %26
%187 = add nsw i32 %185, %186
store i32 %187, i32* %27
%188 = load i32, i32* %27
%189 = sext i32 %188 to i64
%190 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %189
%191 = load i32*, i32** %190
store i32* %191, i32** %28
%192 = load i32, i32* %27
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 %193
%195 = load double, double* %194
%196 = fptosi double %195 to i32
store i32 %196, i32* %29
%197 = load i32, i32* %26
%198 = sext i32 %197 to i64
%199 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %198
%200 = load i32*, i32** %199
%201 = load i32, i32* %27
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %202
store i32* %200, i32** %203
%204 = load i32, i32* %26
%205 = sext i32 %204 to i64
%206 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 %205
%207 = load double, double* %206
%208 = load i32, i32* %27
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 %209
store double %207, double* %210
%211 = load i32*, i32** %28
%212 = load i32, i32* %26
%213 = sext i32 %212 to i64
%214 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %213
store i32* %211, i32** %214
%215 = load i32, i32* %29
%216 = sitofp i32 %215 to double
%217 = load i32, i32* %26
%218 = sext i32 %217 to i64
%219 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 %218
store double %216, double* %219
br label %220
220: ; preds = %178
%221 = load i32, i32* %26
%222 = add nsw i32 %221, 1
store i32 %222, i32* %26
br label %175
223: ; preds = %175
%224 = load i32, i32* %18
%225 = load i32, i32* %17
%226 = getelementptr inbounds [2000 x double], [2000 x double]* %13, i64 0, i64 0
%227 = load double, double* %226
%228 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %224, i32 %225, double %227)
br label %229
229: ; preds = %223
%230 = load i32, i32* %18
%231 = add nsw i32 %230, 1
store i32 %231, i32* %18
br label %76
232: ; preds = %76
%233 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 0
%234 = load i32*, i32** %233
%235 = load i32, i32* %11
%236 = load i32, i32* %8
%237 = load i32, i32* %9
%238 = load i32, i32* %10
%239 = call double @fitness(i32* %234, i32 %235, i32 %236, i32 %237, i32 %238)
store i32 1, i32* %30
br label %240
240: ; preds = %249, %232
%241 = load i32, i32* %30
%242 = icmp slt i32 %241, 2000
br i1 %242, label %243, label %252
243: ; preds = %240
%244 = load i32, i32* %30
%245 = sext i32 %244 to i64
%246 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 %245
%247 = load i32*, i32** %246
%248 = call i32 @free(i32* %247)
br label %249
249: ; preds = %243
%250 = load i32, i32* %30
%251 = add nsw i32 %250, 1
store i32 %251, i32* %30
br label %240
252: ; preds = %240
%253 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %12, i64 0, i64 0
%254 = load i32*, i32** %253
ret i32* %254
}

LLVM IR (-O2):
@.str = [22 x i8] c"Generation %d:\09%d\09%f\0A\00"
define i32* @plan_calendar(i32** %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [2000 x i32*]
%7 = alloca [2000 x double]
%8 = tail call i64 @time(i32* null)
%9 = trunc i64 %8 to i32
%10 = tail call i32 @srand(i32 %9)
%11 = add nsw i32 %2, -1
%12 = mul nsw i32 %11, %2
%13 = bitcast [2000 x i32*]* %6 to i8*
%14 = bitcast [2000 x double]* %7 to i8*
br label %15
15: ; preds = %5, %15
%16 = phi i64 [ 0, %5 ], [ %21, %15 ]
%17 = tail call i32* @generate_random_population(i32** %0, i32* %1, i32 %2)
%18 = tail call double @fitness(i32* %17, i32 %12, i32 %2, i32 %3, i32 %4)
%19 = getelementptr inbounds [2000 x double], [2000 x double]* %7, i64 0, i64 %16
store double %18, double* %19
%20 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %16
store i32* %17, i32** %20
%21 = add nuw nsw i64 %16, 1
%22 = icmp eq i64 %21, 1000
br i1 %22, label %26, label %15
23: ; preds = %26
%24 = getelementptr inbounds [2000 x double], [2000 x double]* %7, i64 0, i64 0
%25 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 0
br label %32
26: ; preds = %15, %26
%27 = phi i64 [ %30, %26 ], [ 1000, %15 ]
%28 = tail call i32* @calloc(i32 %12, i32 4)
%29 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %27
store i32* %28, i32** %29
%30 = add nuw nsw i64 %27, 1
%31 = icmp eq i64 %30, 2000
br i1 %31, label %23, label %26
32: ; preds = %23, %73
%33 = phi i32 [ 0, %23 ], [ %76, %73 ]
br label %37
34: ; preds = %73
%35 = load i32*, i32** %25
%36 = call double @fitness(i32* %35, i32 %12, i32 %2, i32 %3, i32 %4)
br label %99
37: ; preds = %32, %37
%38 = phi i64 [ 0, %32 ], [ %60, %37 ]
%39 = add nuw nsw i64 %38, 1000
%40 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %39
%41 = load i32*, i32** %40
%42 = add nuw nsw i64 %38, 1001
%43 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %42
%44 = load i32*, i32** %43
%45 = call i32 @index_of_tournament_selection_winner(i32 2, double* %24, i32 1000)
%46 = call i32 @index_of_tournament_selection_winner(i32 2, double* %24, i32 1000)
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %47
%49 = load i32*, i32** %48
%50 = sext i32 %46 to i64
%51 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %50
%52 = load i32*, i32** %51
%53 = call i32 @one_point_crossover(i32* %41, i32* %44, i32* %49, i32* %52, i32 %12, i32 %2)
%54 = call i32 @mutate(double 1.000000e-02, i32* %41, i32 %12, i32** %0, i32* %1, i32 %2)
%55 = call i32 @mutate(double 1.000000e-02, i32* %44, i32 %12, i32** %0, i32* %1, i32 %2)
%56 = call double @fitness(i32* %41, i32 %12, i32 %2, i32 %3, i32 %4)
%57 = getelementptr inbounds [2000 x double], [2000 x double]* %7, i64 0, i64 %39
store double %56, double* %57
%58 = call double @fitness(i32* %44, i32 %12, i32 %2, i32 %3, i32 %4)
%59 = getelementptr inbounds [2000 x double], [2000 x double]* %7, i64 0, i64 %42
store double %58, double* %59
%60 = add nuw nsw i64 %38, 2
%61 = icmp ult i64 %38, 998
br i1 %61, label %37, label %62
62: ; preds = %37
%63 = call i32 @index_of_max_element(double* %24, i32 2000)
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %64
%66 = load i32*, i32** %65
%67 = getelementptr inbounds [2000 x double], [2000 x double]* %7, i64 0, i64 %64
%68 = load double, double* %67
%69 = fptosi double %68 to i32
%70 = load i32*, i32** %25
store i32* %70, i32** %65
%71 = load double, double* %24
store double %71, double* %67
store i32* %66, i32** %25
%72 = sitofp i32 %69 to double
store double %72, double* %24
br label %78
73: ; preds = %78
%74 = load double, double* %24
%75 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %63, double %74)
%76 = add nuw nsw i32 %33, 1
%77 = icmp eq i32 %76, 500
br i1 %77, label %34, label %32
78: ; preds = %62, %78
%79 = phi i64 [ 1, %62 ], [ %96, %78 ]
%80 = getelementptr inbounds [2000 x double], [2000 x double]* %7, i64 0, i64 %79
%81 = trunc i64 %79 to i32
%82 = sub i32 2000, %81
%83 = call i32 @index_of_tournament_selection_winner(i32 2, double* %80, i32 %82)
%84 = trunc i64 %79 to i32
%85 = add nsw i32 %83, %84
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %86
%88 = load i32*, i32** %87
%89 = getelementptr inbounds [2000 x double], [2000 x double]* %7, i64 0, i64 %86
%90 = load double, double* %89
%91 = fptosi double %90 to i32
%92 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %79
%93 = load i32*, i32** %92
store i32* %93, i32** %87
%94 = load double, double* %80
store double %94, double* %89
store i32* %88, i32** %92
%95 = sitofp i32 %91 to double
store double %95, double* %80
%96 = add nuw nsw i64 %79, 1
%97 = icmp eq i64 %96, 1000
br i1 %97, label %73, label %78
98: ; preds = %99
ret i32* %35
99: ; preds = %34, %99
%100 = phi i64 [ 1, %34 ], [ %104, %99 ]
%101 = getelementptr inbounds [2000 x i32*], [2000 x i32*]* %6, i64 0, i64 %100
%102 = load i32*, i32** %101
%103 = call i32 @free(i32* %102)
%104 = add nuw nsw i64 %100, 1
%105 = icmp eq i64 %104, 2000
br i1 %105, label %98, label %99
}