#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int i, n, count;
  printf("How many prime numbers? ");
  scanf("%i", &n);
  if (n < 0) {
    printf("\n\n  A minimum of one prime number is required.\n");
    return 0;
  }
  count = 0;
  int prime[n];
  for (i = 2; count < n; ++i) {
    if (isPrime(i))
      prime[count++] = i;
  }
  printf("\n\n");
  for (i = 0; i < n; ++i)
    printf("%i ", prime[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jge    1181 <main+0x51>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <main+0x125>
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ff <main+0xcf>
mov    -0x8(%rbp),%edi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     11ec <main+0xbc>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11f1 <main+0xc1>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b6 <main+0x86>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1247 <main+0x117>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1214 <main+0xe4>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x24(%rbp),%eax
test   %eax,%eax
js     1200 <main+0xc0>
mov    %rsp,%r14
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmpl   $0x0,-0x24(%rbp)
jle    11c2 <main+0x82>
xor    %r12d,%r12d
mov    $0x2,%ebx
jmp    11a9 <main+0x69>
add    $0x1,%ebx
cmp    -0x24(%rbp),%r12d
jge    11c2 <main+0x82>
mov    %ebx,%edi
call   1050 <isPrime@plt>
test   %rax,%rax
je     11a0 <main+0x60>
movslq %r12d,%rax
add    $0x1,%r12d
mov    %ebx,(%r15,%rax,4)
jmp    11a0 <main+0x60>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,-0x24(%rbp)
jle    11fb <main+0xbb>
lea    0xe41(%rip),%r12
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r15,%rbx,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq -0x24(%rbp),%rax
cmp    %rax,%rbx
jl     11e0 <main+0xa0>
mov    %r14,%rsp
jmp    120c <main+0xcc>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"How many prime numbers? \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [48 x i8] c"\0A\0A A minimum of one prime number is required.\0A\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
@.str.4 = [4 x i8] c"%i \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %53
13: ; preds = %0
store i32 0, i32* %4
%14 = load i32, i32* %3
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %5
%17 = alloca i32, i64 %15
store i64 %15, i64* %6
store i32 2, i32* %2
br label %18
18: ; preds = %33, %13
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = load i32, i32* %2
%24 = call i64 @isPrime(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i32, i32* %2
%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 i32, i32* %17, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %26, %22
br label %33
33: ; preds = %32
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %18
36: ; preds = %18
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %38
38: ; preds = %48, %36
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %51
42: ; preds = %38
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %17, i64 %44
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %42
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
store i32 %50, i32* %2
br label %38
51: ; preds = %38
store i32 0, i32* %1
%52 = load i8*, i8** %5
br label %53
53: ; preds = %51, %11
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [25 x i8] c"How many prime numbers? \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.4 = [4 x i8] c"%i \00"
@str = [2 x i8] c"\0A\00"
@str.5 = [47 x i8] c"\0A\0A A minimum of one prime number is required.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.5, i64 0, i64 0))
br label %43
9: ; preds = %0
%10 = zext i32 %5 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %9, %24
%16 = phi i32 [ %26, %24 ], [ 2, %9 ]
%17 = phi i32 [ %25, %24 ], [ 0, %9 ]
%18 = call i64 @isPrime(i32 %16)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = add nsw i32 %17, 1
%22 = sext i32 %17 to i64
%23 = getelementptr inbounds i32, i32* %12, i64 %22
store i32 %16, i32* %23
br label %24
24: ; preds = %15, %20
%25 = phi i32 [ %21, %20 ], [ %17, %15 ]
%26 = add nuw nsw i32 %16, 1
%27 = load i32, i32* %1
%28 = icmp slt i32 %25, %27
br i1 %28, label %15, label %29
29: ; preds = %24, %9
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%31 = load i32, i32* %1
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %29, %33
%34 = phi i64 [ %38, %33 ], [ 0, %29 ]
%35 = getelementptr inbounds i32, i32* %12, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = add nuw nsw i64 %34, 1
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %33, label %42
42: ; preds = %33, %29
br label %43
43: ; preds = %42, %7
ret i32 0
}