#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*/ getch();
int /*<<< orphan*/ printf(char *, int);
int sqrt(int);
int main() {
  int i = 0, c = 0, prim[1000] = {0};
  for (i = 2; i < 1000; i++)
    prim[i] = 1;
  for (i = 2; i < sqrt(1000); i++)
    if (prim[i] == 1) {
      int j;
      for (j = i; i * j < 1000; j++)
        prim[i * j] = 0;
    }
  for (i = 2; i < 1000; i++)
    if (prim[i] != 0) {
      printf("%d\t", i);
      c++;
    }
  printf("\n\nA total of %d prime numbers were found.", c);
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0xfb0(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1040 <memset@plt>
movl   $0x2,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11a4 <main+0x64>
movslq -0x8(%rbp),%rax
movl   $0x1,-0xfb0(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117a <main+0x3a>
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xfb8(%rbp)
mov    $0x3e8,%edi
call   1060 <sqrt@plt>
mov    %eax,%ecx
mov    -0xfb8(%rbp),%eax
cmp    %ecx,%eax
jge    1241 <main+0x101>
movslq -0x8(%rbp),%rax
cmpl   $0x1,-0xfb0(%rbp,%rax,4)
01
jne    122e <main+0xee>
mov    -0x8(%rbp),%eax
mov    %eax,-0xfb4(%rbp)
mov    -0x8(%rbp),%eax
imul   -0xfb4(%rbp),%eax
cmp    $0x3e8,%eax
jge    1229 <main+0xe9>
mov    -0x8(%rbp),%eax
imul   -0xfb4(%rbp),%eax
cltq
movl   $0x0,-0xfb0(%rbp,%rax,4)
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    11e9 <main+0xa9>
jmp    122e <main+0xee>
jmp    1233 <main+0xf3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ab <main+0x6b>
movl   $0x2,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1292 <main+0x152>
movslq -0x8(%rbp),%rax
cmpl   $0x0,-0xfb0(%rbp,%rax,4)
je     127f <main+0x13f>
mov    -0x8(%rbp),%esi
lea    0xd8f(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1284 <main+0x144>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1248 <main+0x108>
mov    -0xc(%rbp),%esi
lea    0xd68(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getch@plt>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xfa8,%rsp
mov    %rsp,%rdi
mov    $0xfa0,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0x1e,%eax
movaps 0xe98(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
movups %xmm0,-0x70(%rsp,%rax,4)
movups %xmm0,-0x60(%rsp,%rax,4)
movups %xmm0,-0x50(%rsp,%rax,4)
movups %xmm0,-0x40(%rsp,%rax,4)
movups %xmm0,-0x30(%rsp,%rax,4)
movups %xmm0,-0x20(%rsp,%rax,4)
movups %xmm0,-0x10(%rsp,%rax,4)
movups %xmm0,(%rsp,%rax,4)
add    $0x20,%rax
cmp    $0x3fe,%rax
jne    1170 <main+0x30>
movups %xmm0,0xf88(%rsp)
movabs $0x100000001,%rax
mov    %rax,0xf98(%rsp)
mov    $0x3e8,%edi
call   1060 <sqrt@plt>
cmp    $0x3,%eax
jl     1245 <main+0x105>
mov    $0x2,%ebx
mov    $0x5,%r15d
mov    $0x4,%r14d
mov    $0x8,%ebp
jmp    1210 <main+0xd0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
mov    $0x3e8,%edi
call   1060 <sqrt@plt>
cltq
add    %r15d,%r14d
add    $0x2,%r15
add    $0x4,%rbp
cmp    %rax,%rbx
jge    1245 <main+0x105>
cmpl   $0x1,(%rsp,%rbx,4)
jne    11f0 <main+0xb0>
mov    %ebx,%eax
imul   %ebx,%eax
cmp    $0x3e7,%eax
ja     11f0 <main+0xb0>
mov    %r14d,%eax
lea    (%rsp,%rax,4),%rax
mov    %r14d,%ecx
nopl   0x0(%rax)
movl   $0x0,(%rax)
add    %rbp,%rax
add    %ebx,%ecx
cmp    $0x3e8,%ecx
jb     1230 <main+0xf0>
jmp    11f0 <main+0xb0>
xor    %ebp,%ebp
mov    $0x2,%ebx
lea    0xdbd(%rip),%r14
jmp    126d <main+0x12d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    $0x3e8,%rbx
je     1282 <main+0x142>
cmpl   $0x0,(%rsp,%rbx,4)
je     1260 <main+0x120>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebp
jmp    1260 <main+0x120>
lea    0xd8b(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getch@plt>
xor    %eax,%eax
add    $0xfa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\09\00"
@.str.1 = [42 x i8] c"\0A\0AA total of %d prime numbers were found.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i32]
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%6 = bitcast [1000 x i32]* %4 to i8*
store i32 2, i32* %2
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 1000
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %12
store i32 1, i32* %13
br label %14
14: ; preds = %10
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %7
17: ; preds = %7
store i32 2, i32* %2
br label %18
18: ; preds = %46, %17
%19 = load i32, i32* %2
%20 = call i32 @sqrt(i32 1000)
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %49
22: ; preds = %18
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %45
28: ; preds = %22
%29 = load i32, i32* %2
store i32 %29, i32* %5
br label %30
30: ; preds = %41, %28
%31 = load i32, i32* %2
%32 = load i32, i32* %5
%33 = mul nsw i32 %31, %32
%34 = icmp slt i32 %33, 1000
br i1 %34, label %35, label %44
35: ; preds = %30
%36 = load i32, i32* %2
%37 = load i32, i32* %5
%38 = mul nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %39
store i32 0, i32* %40
br label %41
41: ; preds = %35
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %30
44: ; preds = %30
br label %45
45: ; preds = %44, %22
br label %46
46: ; preds = %45
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %2
br label %18
49: ; preds = %18
store i32 2, i32* %2
br label %50
50: ; preds = %65, %49
%51 = load i32, i32* %2
%52 = icmp slt i32 %51, 1000
br i1 %52, label %53, label %68
53: ; preds = %50
%54 = load i32, i32* %2
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %53
%60 = load i32, i32* %2
%61 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %3
%63 = add nsw i32 %62, 1
store i32 %63, i32* %3
br label %64
64: ; preds = %59, %53
br label %65
65: ; preds = %64
%66 = load i32, i32* %2
%67 = add nsw i32 %66, 1
store i32 %67, i32* %2
br label %50
68: ; preds = %50
%69 = load i32, i32* %3
%70 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\09\00"
@.str.1 = [42 x i8] c"\0A\0AA total of %d prime numbers were found.\00"
define i32 @main() {
%1 = alloca [1000 x i32]
%2 = bitcast [1000 x i32]* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ 0, %0 ], [ %25, %3 ]
%5 = or i64 %4, 2
%6 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %5
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %7
%8 = getelementptr inbounds i32, i32* %6, i64 4
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %9
%10 = or i64 %4, 10
%11 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %10
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %12
%13 = getelementptr inbounds i32, i32* %11, i64 4
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %14
%15 = or i64 %4, 18
%16 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %15
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %16, i64 4
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %19
%20 = or i64 %4, 26
%21 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %20
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %22
%23 = getelementptr inbounds i32, i32* %21, i64 4
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %24
%25 = add nuw nsw i64 %4, 32
%26 = icmp eq i64 %25, 992
br i1 %26, label %27, label %3
27: ; preds = %3
%28 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 994
store i32 1, i32* %28
%29 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 995
store i32 1, i32* %29
%30 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 996
store i32 1, i32* %30
%31 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 997
store i32 1, i32* %31
%32 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 998
store i32 1, i32* %32
%33 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 999
store i32 1, i32* %33
%34 = tail call i32 @sqrt(i32 1000)
%35 = icmp sgt i32 %34, 2
br i1 %35, label %36, label %63
36: ; preds = %27, %55
%37 = phi i64 [ %60, %55 ], [ 5, %27 ]
%38 = phi i64 [ %56, %55 ], [ 2, %27 ]
%39 = phi i32 [ %62, %55 ], [ 4, %27 ]
%40 = trunc i64 %38 to i32
%41 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %38
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, 1
%44 = mul nsw i32 %40, %40
%45 = icmp ult i32 %44, 1000
%46 = select i1 %43, i1 %45, i1 false
br i1 %46, label %47, label %55
47: ; preds = %36
%48 = zext i32 %39 to i64
br label %49
49: ; preds = %47, %49
%50 = phi i64 [ %48, %47 ], [ %52, %49 ]
%51 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %50
store i32 0, i32* %51
%52 = add nuw nsw i64 %50, %38
%53 = trunc i64 %52 to i32
%54 = icmp ult i32 %53, 1000
br i1 %54, label %49, label %55
55: ; preds = %49, %36
%56 = add nuw nsw i64 %38, 1
%57 = tail call i32 @sqrt(i32 1000)
%58 = sext i32 %57 to i64
%59 = icmp slt i64 %56, %58
%60 = add nuw nsw i64 %37, 2
%61 = trunc i64 %37 to i32
%62 = add i32 %39, %61
br i1 %59, label %36, label %63
63: ; preds = %55, %27
br label %64
64: ; preds = %63, %74
%65 = phi i64 [ %76, %74 ], [ 2, %63 ]
%66 = phi i32 [ %75, %74 ], [ 0, %63 ]
%67 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %65
%68 = load i32, i32* %67
%69 = icmp eq i32 %68, 0
br i1 %69, label %74, label %70
70: ; preds = %64
%71 = trunc i64 %65 to i32
%72 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %71)
%73 = add nsw i32 %66, 1
br label %74
74: ; preds = %64, %70
%75 = phi i32 [ %73, %70 ], [ %66, %64 ]
%76 = add nuw nsw i64 %65, 1
%77 = icmp eq i64 %76, 1000
br i1 %77, label %78, label %64
78: ; preds = %74
%79 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %75)
%80 = tail call i32 (...) @getch()
ret i32 0
}