#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 main() {
  int i, j;
  int primes[150000];
  for (i = 2; i < 150000; i++) {
    primes[i - 1] = 0;
    for (j = 2; j <= i; j++) {
      if (j == i) {
        printf("%d ", i);
        primes[i - 1] = 1;
      } else if (i % j == 0) {
        break;
      }
    }
  }
  printf("are primes.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x927d0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
cmpl   $0x249f0,-0x8(%rbp)
jge    11d1 <main+0xc1>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movl   $0x0,-0x927d0(%rbp,%rax,4)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11be <main+0xae>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1191 <main+0x81>
mov    -0x8(%rbp),%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movl   $0x1,-0x927d0(%rbp,%rax,4)
jmp    11ab <main+0x9b>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11a6 <main+0x96>
jmp    11be <main+0xae>
jmp    11ab <main+0x9b>
jmp    11b0 <main+0xa0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1150 <main+0x40>
jmp    11c3 <main+0xb3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <main+0x19>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x927d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x2,%ebx
lea    0xecf(%rip),%r14
xor    %r15d,%r15d
jmp    115b <main+0x3b>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
add    $0xffffffff,%r15d
cmp    $0x249f0,%ebx
je     117e <main+0x5e>
mov    $0x2,%ecx
lea    (%r15,%rcx,1),%eax
cmp    $0x2,%eax
je     1140 <main+0x20>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
test   %edx,%edx
je     114c <main+0x2c>
lea    0x1(%rcx),%eax
cmp    %ebx,%ecx
mov    %eax,%ecx
jb     1160 <main+0x40>
jmp    114c <main+0x2c>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@str = [12 x i8] c"are primes.\00"
define i32 @main() {
br label %1
1: ; preds = %14, %0
%2 = phi i32 [ 2, %0 ], [ %15, %14 ]
br label %3
3: ; preds = %8, %1
%4 = phi i32 [ 2, %1 ], [ %11, %8 ]
%5 = icmp eq i32 %4, %2
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %14
8: ; preds = %3
%9 = urem i32 %2, %4
%10 = icmp eq i32 %9, 0
%11 = add nuw nsw i32 %4, 1
%12 = icmp uge i32 %4, %2
%13 = or i1 %10, %12
br i1 %13, label %14, label %3
14: ; preds = %8, %6
%15 = add nuw nsw i32 %2, 1
%16 = icmp eq i32 %15, 150000
br i1 %16, label %17, label %1
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret i32 0
}