#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 */
int *calloc(int, int);
int /*<<< orphan*/ choose_random(int *, int, int *, int);
int *generate_random_population(int **playable_dates, int *playable_date_sizes,
                                int team_size) {
  int population_size = team_size * (team_size - 1);
  int *population = calloc(population_size, sizeof(int));
  for (int i = 0; i < team_size; i++) {
    choose_random((population + (i * (team_size - 1))), team_size - 1,
                  playable_dates[i], playable_date_sizes[i]);
  }
  return population;
}


x86 assembly (clang, -O0):
<generate_random_population>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11af <generate_random_population+0x8f>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
call   1030 <choose_random@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115a <generate_random_population+0x3a>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_random_population>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
lea    -0x1(%rbx),%r13d
mov    %r13d,%edi
imul   %edx,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,0x8(%rsp)
test   %ebx,%ebx
jle    1194 <generate_random_population+0x74>
mov    %r13d,%ebp
mov    %ebx,%r15d
shl    $0x2,%rbp
xor    %r14d,%r14d
mov    0x8(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r12,%r14,8),%rdx
mov    0x10(%rsp),%rax
mov    (%rax,%r14,4),%ecx
mov    %rbx,%rdi
mov    %r13d,%esi
call   1030 <choose_random@plt>
add    $0x1,%r14
add    %rbp,%rbx
cmp    %r14,%r15
jne    1170 <generate_random_population+0x50>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @generate_random_population(i32** %0, i32* %1, i32 %2) {
%4 = alloca i32**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32** %0, i32*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* %6
%12 = sub nsw i32 %11, 1
%13 = mul nsw i32 %10, %12
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = call i32* @calloc(i32 %14, i32 4)
store i32* %15, i32** %8
store i32 0, i32* %9
br label %16
16: ; preds = %41, %3
%17 = load i32, i32* %9
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %44
20: ; preds = %16
%21 = load i32*, i32** %8
%22 = load i32, i32* %9
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 1
%25 = mul nsw i32 %22, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %21, i64 %26
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
%30 = load i32**, i32*** %4
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32*, i32** %30, i64 %32
%34 = load i32*, i32** %33
%35 = load i32*, i32** %5
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @choose_random(i32* %27, i32 %29, i32* %34, i32 %39)
br label %41
41: ; preds = %20
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %16
44: ; preds = %16
%45 = load i32*, i32** %8
ret i32* %45
}

LLVM IR (-O2):
define i32* @generate_random_population(i32** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = mul nsw i32 %4, %2
%6 = tail call i32* @calloc(i32 %5, i32 4)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = zext i32 %4 to i64
%10 = zext i32 %2 to i64
br label %12
11: ; preds = %12, %3
ret i32* %6
12: ; preds = %8, %12
%13 = phi i64 [ 0, %8 ], [ %21, %12 ]
%14 = mul nsw i64 %13, %9
%15 = getelementptr inbounds i32, i32* %6, i64 %14
%16 = getelementptr inbounds i32*, i32** %0, i64 %13
%17 = load i32*, i32** %16
%18 = getelementptr inbounds i32, i32* %1, i64 %13
%19 = load i32, i32* %18
%20 = tail call i32 @choose_random(i32* %15, i32 %4, i32* %17, i32 %19)
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %10
br i1 %22, label %11, label %12
}