#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__ int32_t;

/* Variables and functions */
scalar_t__ *calloc(scalar_t__, int);
scalar_t__ isprime(scalar_t__);
int32_t *init_primes(int32_t max) {
  int32_t *primes = calloc(max, sizeof(int32_t));
  primes[0] = 2;
  int32_t c = 1;
  for (int32_t i = 3; i <= max; i += 2) {
    if (isprime(i)) {
      primes[c++] = i;
    }
  }
  return primes;
}


x86 assembly (clang, -O0):
<init_primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x2,(%rax)
movq   $0x1,-0x18(%rbp)
movq   $0x3,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jg     11ab <init_primes+0x8b>
mov    -0x20(%rbp),%rdi
call   1040 <isprime@plt>
cmp    $0x0,%rax
je     1195 <init_primes+0x75>
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    119a <init_primes+0x7a>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    1159 <init_primes+0x39>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_primes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r14
movq   $0x2,(%rax)
cmp    $0x3,%r15
jge    1154 <init_primes+0x34>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0x1,%r12d
mov    $0x3,%ebx
jmp    1179 <init_primes+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x2,%rbx
cmp    %r15,%rbx
jg     1145 <init_primes+0x25>
mov    %rbx,%rdi
call   1040 <isprime@plt>
test   %rax,%rax
je     1170 <init_primes+0x50>
mov    %rbx,(%r14,%r12,8)
add    $0x1,%r12
jmp    1170 <init_primes+0x50>

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

LLVM IR (-O2):
define i64* @init_primes(i64 %0) {
%2 = tail call i64* @calloc(i64 %0, i32 8)
store i64 2, i64* %2
%3 = icmp slt i64 %0, 3
br i1 %3, label %4, label %5
4: ; preds = %13, %1
ret i64* %2
5: ; preds = %1, %13
%6 = phi i64 [ %15, %13 ], [ 3, %1 ]
%7 = phi i64 [ %14, %13 ], [ 1, %1 ]
%8 = tail call i64 @isprime(i64 %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = add nsw i64 %7, 1
%12 = getelementptr inbounds i64, i64* %2, i64 %7
store i64 %6, i64* %12
br label %13
13: ; preds = %5, %10
%14 = phi i64 [ %11, %10 ], [ %7, %5 ]
%15 = add nuw nsw i64 %6, 2
%16 = icmp sgt i64 %15, %0
br i1 %16, label %4, label %5
}