#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);
int sqrt(double);
int main() {
  int i;
  int p = 1;
  int np = 0;
  int primes[10000];
  for (p = 3, np = 0; np < 10000; p += 2) {
    int prime = 1, j;
    for (j = 0; j < np && primes[j] <= sqrt((double)p); j++)
      if ((p % primes[j]) == 0) {
        prime = 0;
        break;
      }
    if (prime) {
      primes[np++] = p;
      printf("%d\n", p);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x3,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x2710,-0x10(%rbp)
jge    1253 <main+0x133>
movl   $0x1,-0x9c54(%rbp)
movl   $0x0,-0x9c58(%rbp)
mov    -0x9c58(%rbp),%ecx
xor    %eax,%eax
cmp    -0x10(%rbp),%ecx
mov    %al,-0x9c59(%rbp)
jge    11b7 <main+0x97>
movslq -0x9c58(%rbp),%rax
mov    -0x9c50(%rbp,%rax,4),%eax
mov    %eax,-0x9c60(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    -0x9c60(%rbp),%eax
cmp    %ecx,%eax
setle  %al
mov    %al,-0x9c59(%rbp)
mov    -0x9c59(%rbp),%al
test   $0x1,%al
jne    11ca <main+0xaa>
jmp    120d <main+0xed>
mov    -0xc(%rbp),%eax
movslq -0x9c58(%rbp),%rcx
cltd
idivl  -0x9c50(%rbp,%rcx,4)
cmp    $0x0,%edx
jne    11f4 <main+0xd4>
movl   $0x0,-0x9c54(%rbp)
jmp    120d <main+0xed>
jmp    11f9 <main+0xd9>
mov    -0x9c58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c58(%rbp)
jmp    116f <main+0x4f>
cmpl   $0x0,-0x9c54(%rbp)
je     1240 <main+0x120>
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %ecx,-0x9c50(%rbp,%rax,4)
mov    -0xc(%rbp),%esi
lea    0xdc5(%rip),%rdi
call   1030 <printf@plt>
jmp    1245 <main+0x125>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    114e <main+0x2e>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c58,%rsp
mov    $0x3,%r13d
xor    %r15d,%r15d
lea    0xebf(%rip),%r14
jmp    1174 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %r15d,%rax
add    $0x1,%r15d
mov    %r13d,0x10(%rsp,%rax,4)
mov    %r14,%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
add    $0x2,%r13d
cmp    $0x2710,%r15d
jge    11b8 <main+0x98>
test   %r15d,%r15d
jle    1150 <main+0x30>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x10(%rsp,%rbx,4),%ebp
movsd  0x8(%rsp),%xmm0
call   1040 <sqrt@plt>
cmp    %eax,%ebp
jg     1150 <main+0x30>
mov    %r13d,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     1167 <main+0x47>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <main+0x70>
jmp    1150 <main+0x30>
xor    %eax,%eax
add    $0x9c58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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