#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 scalar_t__ uint32_t;

/* Variables and functions */
scalar_t__ isPrime(scalar_t__);
scalar_t__ *malloc(int);
uint32_t *initPrimes(uint32_t max) {
  uint32_t *primes = malloc(10000 * sizeof(uint32_t));
  if (!primes) {
    goto out;
  }
  uint32_t c = 0;
  for (uint32_t i = 0; i < max; i++) {
    if (isPrime(i))
      primes[c++] = i;
  }
out:
  return primes;
}


x86 assembly (clang, -O0):
<initPrimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x13880,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114a <initPrimes+0x2a>
jmp    11b1 <initPrimes+0x91>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11ac <initPrimes+0x8c>
mov    -0x20(%rbp),%rdi
call   1030 <isPrime@plt>
cmp    $0x0,%rax
je     1196 <initPrimes+0x76>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %rdx,(%rax,%rcx,8)
jmp    119b <initPrimes+0x7b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115a <initPrimes+0x3a>
jmp    11b1 <initPrimes+0x91>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initPrimes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x13880,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1170 <initPrimes+0x50>
test   %r15,%r15
jle    1170 <initPrimes+0x50>
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    1159 <initPrimes+0x39>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1170 <initPrimes+0x50>
mov    %rbx,%rdi
call   1030 <isPrime@plt>
test   %rax,%rax
je     1150 <initPrimes+0x30>
mov    %rbx,(%r14,%r12,8)
add    $0x1,%r12
jmp    1150 <initPrimes+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64* @initPrimes(i64 %0) {
%2 = alloca i64
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %2
%6 = call i64* @malloc(i32 80000)
store i64* %6, i64** %3
%7 = load i64*, i64** %3
%8 = icmp ne i64* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
br label %30
10: ; preds = %1
store i64 0, i64* %4
store i64 0, i64* %5
br label %11
11: ; preds = %26, %10
%12 = load i64, i64* %5
%13 = load i64, i64* %2
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load i64, i64* %5
%17 = call i64 @isPrime(i64 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i64, i64* %5
%21 = load i64*, i64** %3
%22 = load i64, i64* %4
%23 = add nsw i64 %22, 1
store i64 %23, i64* %4
%24 = getelementptr inbounds i64, i64* %21, i64 %22
store i64 %20, i64* %24
br label %25
25: ; preds = %19, %15
br label %26
26: ; preds = %25
%27 = load i64, i64* %5
%28 = add nsw i64 %27, 1
store i64 %28, i64* %5
br label %11
29: ; preds = %11
br label %30
30: ; preds = %29, %9
%31 = load i64*, i64** %3
ret i64* %31
}

LLVM IR (-O2):
define noalias i64* @initPrimes(i64 %0) {
%2 = tail call i64* @malloc(i32 80000)
%3 = icmp ne i64* %2, null
%4 = icmp sgt i64 %0, 0
%5 = and i1 %3, %4
br i1 %5, label %6, label %18
6: ; preds = %1, %14
%7 = phi i64 [ %16, %14 ], [ 0, %1 ]
%8 = phi i64 [ %15, %14 ], [ 0, %1 ]
%9 = tail call i64 @isPrime(i64 %7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = add nsw i64 %8, 1
%13 = getelementptr inbounds i64, i64* %2, i64 %8
store i64 %7, i64* %13
br label %14
14: ; preds = %6, %11
%15 = phi i64 [ %12, %11 ], [ %8, %6 ]
%16 = add nuw nsw i64 %7, 1
%17 = icmp eq i64 %16, %0
br i1 %17, label %18, label %6
18: ; preds = %14, %1
ret i64* %2
}