#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 atoi(char const *);
int /*<<< orphan*/ free(int *const);
int isprime(int, int *const, int);
scalar_t__ malloc(int const);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, const char **argv) {
  const int primes_capacity = atoi(argv[1]);
  int *const primes = (int *)malloc(primes_capacity * sizeof(int));
  int primes_len = 0;
  int prime;
  for (int Li = 2; Li < primes_capacity; ++Li) {
    if (prime = isprime(Li, primes, primes_len)) {
      primes[primes_len++] = prime;
    }
  }
  printf("%d\n", primes[primes_len - 1]);
  free(primes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x2,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e9 <main+0x99>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <isprime@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     11d6 <main+0x86>
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11db <main+0x8b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1197 <main+0x47>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
xor    %ebp,%ebp
cmp    $0x3,%r14d
jl     11b4 <main+0x64>
xor    %ebp,%ebp
mov    $0x2,%ebx
jmp    1198 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
cmp    %ebx,%r14d
je     11b4 <main+0x64>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <isprime@plt>
test   %eax,%eax
je     1190 <main+0x40>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %eax,(%r15,%rcx,4)
jmp    1190 <main+0x40>
movslq %ebp,%rax
mov    -0x4(%r15,%rax,4),%esi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %7
store i32 0, i32* %8
store i32 2, i32* %10
br label %21
21: ; preds = %39, %2
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %42
25: ; preds = %21
%26 = load i32, i32* %10
%27 = load i32*, i32** %7
%28 = load i32, i32* %8
%29 = call i32 @isprime(i32 %26, i32* %27, i32 %28)
store i32 %29, i32* %9
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %25
%32 = load i32, i32* %9
%33 = load i32*, i32** %7
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i32, i32* %33, i64 %36
store i32 %32, i32* %37
br label %38
38: ; preds = %31, %25
br label %39
39: ; preds = %38
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %21
42: ; preds = %21
%43 = load i32*, i32** %7
%44 = load i32, i32* %8
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %43, i64 %46
%48 = load i32, i32* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %48)
%50 = load i32*, i32** %7
%51 = call i32 @free(i32* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = shl i32 %5, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp sgt i32 %5, 2
br i1 %9, label %18, label %10
10: ; preds = %27, %2
%11 = phi i32 [ 0, %2 ], [ %28, %27 ]
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %8, i64 %13
%15 = load i32, i32* %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i32 @free(i32* %8)
ret i32 0
18: ; preds = %2, %27
%19 = phi i32 [ %29, %27 ], [ 2, %2 ]
%20 = phi i32 [ %28, %27 ], [ 0, %2 ]
%21 = tail call i32 @isprime(i32 %19, i32* %8, i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %18
%24 = add nsw i32 %20, 1
%25 = sext i32 %20 to i64
%26 = getelementptr inbounds i32, i32* %8, i64 %25
store i32 %21, i32* %26
br label %27
27: ; preds = %18, %23
%28 = phi i32 [ %24, %23 ], [ %20, %18 ]
%29 = add nuw nsw i32 %19, 1
%30 = icmp eq i32 %29, %5
br i1 %30, label %10, label %18
}