#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 /*<<< orphan*/ isPrime(int);
void calculateFirstNPrimes(int n, int primes[15001]) {
  int loop, attempt;
  primes[0] = 0;
  primes[1] = 2;
  primes[2] = 3;
  attempt = 5;
  for (loop = 3; loop <= n; loop++) {
    while (!isPrime(attempt))
      attempt = attempt + 2;
    primes[loop] = attempt;
    attempt = attempt + 2;
  }
}


x86 assembly (clang, -O0):
<calculateFirstNPrimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x2,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x8(%rax)
movl   $0x5,-0x18(%rbp)
movl   $0x3,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11ae <calculateFirstNPrimes+0x9e>
jmp    115e <calculateFirstNPrimes+0x4e>
mov    -0x18(%rbp),%edi
call   1030 <isPrime@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    117b <calculateFirstNPrimes+0x6b>
jmp    1189 <calculateFirstNPrimes+0x79>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    115e <calculateFirstNPrimes+0x4e>
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <calculateFirstNPrimes+0x3d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateFirstNPrimes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movabs $0x200000000,%rax
mov    %rax,(%rsi)
movl   $0x3,0x8(%rsi)
cmp    $0x3,%edi
jl     116e <calculateFirstNPrimes+0x5e>
mov    %rsi,%r14
mov    %edi,%r15d
add    $0x1,%r15d
mov    $0x5,%ebx
mov    $0x3,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <isPrime@plt>
add    $0x2,%ebx
test   %eax,%eax
je     1150 <calculateFirstNPrimes+0x40>
lea    -0x2(%rbx),%eax
mov    %eax,(%r14,%r12,4)
add    $0x1,%r12
cmp    %r15,%r12
jne    1150 <calculateFirstNPrimes+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @calculateFirstNPrimes(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = getelementptr inbounds i32, i32* %7, i64 0
store i32 0, i32* %8
%9 = load i32*, i32** %4
%10 = getelementptr inbounds i32, i32* %9, i64 1
store i32 2, i32* %10
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 2
store i32 3, i32* %12
store i32 5, i32* %6
store i32 3, i32* %5
br label %13
13: ; preds = %34, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %37
17: ; preds = %13
br label %18
18: ; preds = %23, %17
%19 = load i32, i32* %6
%20 = call i32 @isPrime(i32 %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 2
store i32 %25, i32* %6
br label %18
26: ; preds = %18
%27 = load i32, i32* %6
%28 = load i32*, i32** %4
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 2
store i32 %33, i32* %6
br label %34
34: ; preds = %26
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %13
37: ; preds = %13
ret void
}

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