#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 EXIT_SUCCESS;
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  char isPrime[1 + 1000];
  memset(isPrime, 1, 1 + 1000);
  isPrime[0] = 0;
  isPrime[1] = 0;
  for (int i = 2; i <= 1000; i++) {
    if (isPrime[i] == 1) {
      for (int j = 2 * i; j <= 1000; j += i) {
        isPrime[j] = 0;
      }
    }
  }
  for (int i = 0; i < 1 + 1000; i++) {
    if (isPrime[i] == 1) {
      printf("%d\n", i);
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rdi
mov    $0x1,%esi
mov    $0x3e9,%edx
call   1040 <memset@plt>
movb   $0x0,-0x3f0(%rbp)
movb   $0x0,-0x3ef(%rbp)
movl   $0x2,-0x3f4(%rbp)
cmpl   $0x3e8,-0x3f4(%rbp)
jg     11eb <main+0xcb>
movslq -0x3f4(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0x1,%eax
jne    11d2 <main+0xb2>
mov    -0x3f4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x3f8(%rbp)
cmpl   $0x3e8,-0x3f8(%rbp)
jg     11cd <main+0xad>
movslq -0x3f8(%rbp),%rax
movb   $0x0,-0x3f0(%rbp,%rax,1)
mov    -0x3f4(%rbp),%eax
add    -0x3f8(%rbp),%eax
mov    %eax,-0x3f8(%rbp)
jmp    1197 <main+0x77>
jmp    11d2 <main+0xb2>
jmp    11d7 <main+0xb7>
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f4(%rbp)
jmp    1160 <main+0x40>
movl   $0x0,-0x3fc(%rbp)
cmpl   $0x3e9,-0x3fc(%rbp)
jge    1248 <main+0x128>
movslq -0x3fc(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0x1,%eax
jne    122f <main+0x10f>
mov    -0x3fc(%rbp),%esi
lea    0xdd6(%rip),%rdi
call   1030 <printf@plt>
jmp    1234 <main+0x114>
mov    -0x3fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3fc(%rbp)
jmp    11f5 <main+0xd5>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3f8,%rsp
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x3e9,%edx
call   1040 <memset@plt>
movw   $0x0,(%rsp)
mov    $0x4,%eax
mov    $0x2,%ecx
jmp    1161 <main+0x41>
xchg   %ax,%ax
add    $0x1,%rcx
add    $0x2,%rax
cmp    $0x3e9,%rcx
je     1192 <main+0x72>
cmpb   $0x1,(%rsp,%rcx,1)
jne    1150 <main+0x30>
cmp    $0x1f4,%rcx
ja     1150 <main+0x30>
mov    %rax,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x0,(%rsp,%rdx,1)
add    %rcx,%rdx
cmp    $0x3e9,%rdx
jb     1180 <main+0x60>
jmp    1150 <main+0x30>
xor    %ebx,%ebx
lea    0xe65(%rip),%r14
jmp    11ad <main+0x8d>
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x3e9,%rbx
je     11bf <main+0x9f>
cmpb   $0x1,(%rsp,%rbx,1)
jne    11a0 <main+0x80>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
jmp    11a0 <main+0x80>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [1001 x i8]
%2 = getelementptr inbounds [1001 x i8], [1001 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 1, i32 1001)
store i8 0, i8* %2
%4 = getelementptr inbounds [1001 x i8], [1001 x i8]* %1, i64 0, i64 1
store i8 0, i8* %4
br label %5
5: ; preds = %0, %18
%6 = phi i64 [ 2, %0 ], [ %19, %18 ]
%7 = phi i64 [ 4, %0 ], [ %20, %18 ]
%8 = getelementptr inbounds [1001 x i8], [1001 x i8]* %1, i64 0, i64 %6
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 1
%11 = icmp ult i64 %6, 501
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %18
13: ; preds = %5, %13
%14 = phi i64 [ %16, %13 ], [ %7, %5 ]
%15 = getelementptr inbounds [1001 x i8], [1001 x i8]* %1, i64 0, i64 %14
store i8 0, i8* %15
%16 = add nuw nsw i64 %14, %6
%17 = icmp ult i64 %16, 1001
br i1 %17, label %13, label %18
18: ; preds = %13, %5
%19 = add nuw nsw i64 %6, 1
%20 = add nuw nsw i64 %7, 2
%21 = icmp eq i64 %19, 1001
br i1 %21, label %24, label %5
22: ; preds = %32
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
24: ; preds = %18, %32
%25 = phi i64 [ %33, %32 ], [ 0, %18 ]
%26 = getelementptr inbounds [1001 x i8], [1001 x i8]* %1, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = trunc i64 %25 to i32
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %24, %29
%33 = add nuw nsw i64 %25, 1
%34 = icmp eq i64 %33, 1001
br i1 %34, label %22, label %24
}