#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*/ exit(int /*<<< orphan*/);
scalar_t__ is_prime(int, int, int *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int primenum = 10001;
  int primes[10002] = {2, 3};
  int numprimes = 2;
  int test = primes[numprimes - 1] + 2;
  while (numprimes < primenum) {
    if (is_prime(test, numprimes, primes))
      primes[numprimes++] = test;
    test += 2;
  }
  printf("%d\n", primes[numprimes - 1]);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2711,-0x8(%rbp)
lea    -0x9c50(%rbp),%rdi
xor    %esi,%esi
mov    $0x9c48,%edx
call   1040 <memset@plt>
movl   $0x2,-0x9c50(%rbp)
movl   $0x3,-0x9c4c(%rbp)
movl   $0x2,-0x9c54(%rbp)
mov    -0x9c54(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x9c50(%rbp,%rax,4),%eax
add    $0x2,%eax
mov    %eax,-0x9c58(%rbp)
mov    -0x9c54(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120a <main+0xca>
mov    -0x9c58(%rbp),%edi
mov    -0x9c54(%rbp),%esi
lea    -0x9c50(%rbp),%rdx
call   1050 <is_prime@plt>
cmp    $0x0,%rax
je     11f6 <main+0xb6>
mov    -0x9c58(%rbp),%ecx
mov    -0x9c54(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x9c54(%rbp)
cltq
mov    %ecx,-0x9c50(%rbp,%rax,4)
mov    -0x9c58(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x9c58(%rbp)
jmp    11a5 <main+0x65>
mov    -0x9c54(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x9c50(%rbp,%rax,4),%esi
lea    0xddd(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x9c50,%rsp
mov    %rsp,%r14
mov    $0x9c48,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
movabs $0x300000002,%rax
mov    %rax,(%rsp)
mov    $0x2,%ebx
mov    $0x5,%ebp
jmp    118b <main+0x4b>
nopw   0x0(%rax,%rax,1)
add    $0x2,%ebp
cmp    $0x2711,%ebx
jge    11a7 <main+0x67>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1050 <is_prime@plt>
test   %rax,%rax
je     1180 <main+0x40>
movslq %ebx,%rax
add    $0x1,%ebx
mov    %ebp,(%rsp,%rax,4)
jmp    1180 <main+0x40>
add    $0xffffffff,%ebx
mov    (%rsp,%rbx,4),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10002 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 10001, i32* %2
%6 = bitcast [10002 x i32]* %3 to i8*
%7 = bitcast i8* %6 to <{ i32, i32, [10000 x i32] }>*
%8 = getelementptr inbounds <{ i32, i32, [10000 x i32] }>, <{ i32, i32, [10000 x i32] }>* %7, i32 0, i32 0
store i32 2, i32* %8
%9 = getelementptr inbounds <{ i32, i32, [10000 x i32] }>, <{ i32, i32, [10000 x i32] }>* %7, i32 0, i32 1
store i32 3, i32* %9
store i32 2, i32* %4
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10002 x i32], [10002 x i32]* %3, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 2
store i32 %15, i32* %5
br label %16
16: ; preds = %32, %0
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = getelementptr inbounds [10002 x i32], [10002 x i32]* %3, i64 0, i64 0
%24 = call i64 @is_prime(i32 %21, i32 %22, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i32, i32* %5
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [10002 x i32], [10002 x i32]* %3, i64 0, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %26, %20
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 2
store i32 %34, i32* %5
br label %16
35: ; preds = %16
%36 = load i32, i32* %4
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10002 x i32], [10002 x i32]* %3, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = call i32 @exit(i32 0)
unreachable
}

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