#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int n;
  int i, j;
  int flag;
  int primes[1000];
  int level;
  printf("Enter value of N > ");
  scanf("%d", &n);
  level = 0;
  for (i = 2; i <= n; i++) {
    for (j = 0, flag = 1; j < level && flag; j++)
      flag = (i % primes[j]);
    if (flag) {
      printf("%12d\n", i);
      if (level < 1000)
        primes[level++] = i;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecd(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xfc4(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1232 <main+0x112>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
cmp    -0xfc4(%rbp),%ecx
mov    %al,-0xfc5(%rbp)
jge    119f <main+0x7f>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0xfc5(%rbp)
mov    -0xfc5(%rbp),%al
test   $0x1,%al
jne    11b2 <main+0x92>
jmp    11d2 <main+0xb2>
mov    -0xc(%rbp),%eax
movslq -0x10(%rbp),%rcx
cltd
idivl  -0xfc0(%rbp,%rcx,4)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117b <main+0x5b>
cmpl   $0x0,-0x14(%rbp)
je     121f <main+0xff>
mov    -0xc(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x3e8,-0xfc4(%rbp)
jge    121a <main+0xfa>
mov    -0xc(%rbp),%ecx
mov    -0xfc4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xfc4(%rbp)
cltq
mov    %ecx,-0xfc0(%rbp,%rax,4)
jmp    121f <main+0xff>
jmp    1224 <main+0x104>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <main+0x41>
mov    -0x4(%rbp),%eax
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xfb0,%rsp
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x2,0xc(%rsp)
jge    115f <main+0x3f>
xor    %eax,%eax
add    $0xfb0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x2,%ebx
lea    0xeac(%rip),%r14
xor    %ebp,%ebp
jmp    1191 <main+0x71>
nop
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movslq %ebp,%rax
add    $0x1,%ebp
mov    %ebx,0x10(%rsp,%rax,4)
lea    0x1(%rbx),%eax
cmp    0xc(%rsp),%ebx
mov    %eax,%ebx
jge    1151 <main+0x31>
test   %ebp,%ebp
jle    1170 <main+0x50>
mov    %ebp,%ecx
mov    $0x1,%esi
nopl   0x0(%rax)
mov    %ebx,%eax
cltd
idivl  0xc(%rsp,%rsi,4)
cmp    %rcx,%rsi
jae    11b4 <main+0x94>
add    $0x1,%rsi
test   %edx,%edx
jne    11a0 <main+0x80>
test   %edx,%edx
je     1186 <main+0x66>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x3e7,%ebp
jle    117c <main+0x5c>
jmp    1186 <main+0x66>

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

LLVM IR (-O2):
@.str = [20 x i8] c"Enter value of N > \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"%12d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [1000 x i32]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 2
br i1 %8, label %39, label %9
9: ; preds = %0, %34
%10 = phi i32 [ %35, %34 ], [ 0, %0 ]
%11 = phi i32 [ %36, %34 ], [ 2, %0 ]
%12 = icmp sgt i32 %10, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %30
15: ; preds = %9
%16 = zext i32 %10 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %22, %17 ]
%19 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = srem i32 %11, %20
%22 = add nuw nsw i64 %18, 1
%23 = icmp ult i64 %22, %16
%24 = icmp ne i32 %21, 0
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %17, label %26
26: ; preds = %17
br i1 %24, label %27, label %34
27: ; preds = %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%29 = icmp slt i32 %10, 1000
br i1 %29, label %30, label %34
30: ; preds = %13, %27
%31 = add nsw i32 %10, 1
%32 = sext i32 %10 to i64
%33 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %32
store i32 %11, i32* %33
br label %34
34: ; preds = %26, %30, %27
%35 = phi i32 [ %31, %30 ], [ %10, %27 ], [ %10, %26 ]
%36 = add nuw nsw i32 %11, 1
%37 = load i32, i32* %1
%38 = icmp slt i32 %11, %37
br i1 %38, label %9, label %39
39: ; preds = %34, %0
ret i32 0
}