#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 */
scalar_t__ isPrime(int, int *, int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *arv[]) {
  int primes[10001];
  int primeCount = 1, i = 3;
  primes[0] = 2;
  while (primeCount <= 10001) {
    if (isPrime(i, primes, primeCount))
      primes[primeCount++] = i;
    i += 2;
  }
  printf("10 001th prime: %d\n", primes[10000]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x9c64(%rbp)
movl   $0x3,-0x9c68(%rbp)
movl   $0x2,-0x9c60(%rbp)
cmpl   $0x2711,-0x9c64(%rbp)
jg     11bd <main+0x9d>
mov    -0x9c68(%rbp),%edi
lea    -0x9c60(%rbp),%rsi
mov    -0x9c64(%rbp),%edx
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     11a9 <main+0x89>
mov    -0x9c68(%rbp),%ecx
mov    -0x9c64(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x9c64(%rbp)
cltq
mov    %ecx,-0x9c60(%rbp,%rax,4)
mov    -0x9c68(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x9c68(%rbp)
jmp    1157 <main+0x37>
mov    -0x20(%rbp),%esi
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x9c50,%rsp
movl   $0x2,(%rsp)
mov    $0x1,%ebx
mov    $0x3,%ebp
mov    %rsp,%r14
jmp    115b <main+0x3b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x2,%ebp
cmp    $0x2712,%ebx
jge    1177 <main+0x57>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <isPrime@plt>
test   %rax,%rax
je     1150 <main+0x30>
movslq %ebx,%rax
add    $0x1,%ebx
mov    %ebp,(%rsp,%rax,4)
jmp    1150 <main+0x30>
mov    0x9c40(%rsp),%esi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"10 001th prime: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10001 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 3, i32* %8
%9 = getelementptr inbounds [10001 x i32], [10001 x i32]* %6, i64 0, i64 0
store i32 2, i32* %9
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %7
%12 = icmp sle i32 %11, 10001
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i32, i32* %8
%15 = getelementptr inbounds [10001 x i32], [10001 x i32]* %6, i64 0, i64 0
%16 = load i32, i32* %7
%17 = call i64 @isPrime(i32 %14, i32* %15, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds [10001 x i32], [10001 x i32]* %6, i64 0, i64 %23
store i32 %20, i32* %24
br label %25
25: ; preds = %19, %13
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 2
store i32 %27, i32* %8
br label %10
28: ; preds = %10
%29 = getelementptr inbounds [10001 x i32], [10001 x i32]* %6, i64 0, i64 10000
%30 = load i32, i32* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"10 001th prime: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10001 x i32]
%4 = bitcast [10001 x i32]* %3 to i8*
%5 = getelementptr inbounds [10001 x i32], [10001 x i32]* %3, i64 0, i64 0
store i32 2, i32* %5
br label %6
6: ; preds = %2, %15
%7 = phi i32 [ 3, %2 ], [ %17, %15 ]
%8 = phi i32 [ 1, %2 ], [ %16, %15 ]
%9 = call i64 @isPrime(i32 %7, i32* %5, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = add nsw i32 %8, 1
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds [10001 x i32], [10001 x i32]* %3, i64 0, i64 %13
store i32 %7, i32* %14
br label %15
15: ; preds = %11, %6
%16 = phi i32 [ %12, %11 ], [ %8, %6 ]
%17 = add nuw nsw i32 %7, 2
%18 = icmp slt i32 %16, 10002
br i1 %18, label %6, label %19
19: ; preds = %15
%20 = getelementptr inbounds [10001 x i32], [10001 x i32]* %3, i64 0, i64 10000
%21 = load i32, i32* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %21)
ret i32 0
}