#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 *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int *prime;
  prime = malloc(sizeof(int) * 1000);
  long int i, j;
  for (i = 2; i < 1000; i++)
    prime[i] = 1;
  for (i = 2; i < 1000; i++)
    if (prime[i])
      for (j = i; i * j < 1000; j++)
        prime[i * j] = 0;
  printf("Prime numbers in range 1 to 1000 are: \n");
  for (j = 2; j < 1000; j++)
    if (prime[j])
      printf("%d\n", j);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xfa0,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x2,-0x18(%rbp)
cmpq   $0x3e8,-0x18(%rbp)
jge    1173 <main+0x53>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1145 <main+0x25>
movq   $0x2,-0x18(%rbp)
cmpq   $0x3e8,-0x18(%rbp)
jge    11f8 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11e2 <main+0xc2>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rax
cmp    $0x3e8,%rax
jge    11dd <main+0xbd>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
imul   -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a3 <main+0x83>
jmp    11e2 <main+0xc2>
jmp    11e7 <main+0xc7>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    117b <main+0x5b>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x2,-0x20(%rbp)
cmpq   $0x3e8,-0x20(%rbp)
jge    1256 <main+0x136>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1240 <main+0x120>
mov    -0x20(%rbp),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1245 <main+0x125>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    120e <main+0xee>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x1e,%eax
movaps 0xeb2(%rip),%xmm0
xchg   %ax,%ax
movups %xmm0,-0x70(%r14,%rax,4)
movups %xmm0,-0x60(%r14,%rax,4)
movups %xmm0,-0x50(%r14,%rax,4)
movups %xmm0,-0x40(%r14,%rax,4)
movups %xmm0,-0x30(%r14,%rax,4)
movups %xmm0,-0x20(%r14,%rax,4)
movups %xmm0,-0x10(%r14,%rax,4)
movups %xmm0,(%r14,%rax,4)
add    $0x20,%rax
cmp    $0x3fe,%rax
jne    1150 <main+0x20>
movups %xmm0,0xf88(%r14)
movabs $0x100000001,%rax
mov    %rax,0xf98(%r14)
mov    %r14,%r8
add    $0x10,%r8
mov    $0x2,%ecx
mov    $0x14,%edx
mov    $0x8,%esi
mov    $0x5,%edi
mov    $0x4,%r9d
jmp    11ef <main+0xbf>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rcx
add    %rdx,%r8
add    $0x8,%rdx
add    $0x4,%rsi
add    %rdi,%r9
add    $0x2,%rdi
cmp    $0x3e8,%rcx
je     1227 <main+0xf7>
cmpl   $0x0,(%r14,%rcx,4)
je     11d0 <main+0xa0>
mov    %rcx,%rax
imul   %rcx,%rax
cmp    $0x3e7,%rax
ja     11d0 <main+0xa0>
mov    %r9,%rbx
mov    %r8,%rax
nopl   0x0(%rax,%rax,1)
movl   $0x0,(%rax)
add    %rsi,%rax
add    %rcx,%rbx
cmp    $0x3e8,%rbx
jb     1210 <main+0xe0>
jmp    11d0 <main+0xa0>
lea    0xde6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%ebx
lea    0xdd1(%rip),%r15
jmp    125d <main+0x12d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
je     1273 <main+0x143>
cmpl   $0x0,(%r14,%rbx,4)
je     1250 <main+0x120>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1250 <main+0x120>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d\0A\00"
@str = [39 x i8] c"Prime numbers in range 1 to 1000 are: \00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 4000)
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %24, %2 ]
%4 = or i64 %3, 2
%5 = getelementptr inbounds i32, i32* %1, i64 %4
%6 = bitcast i32* %5 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %6
%7 = getelementptr inbounds i32, i32* %5, i64 4
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %8
%9 = or i64 %3, 10
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %11
%12 = getelementptr inbounds i32, i32* %10, i64 4
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %13
%14 = or i64 %3, 18
%15 = getelementptr inbounds i32, i32* %1, i64 %14
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %16
%17 = getelementptr inbounds i32, i32* %15, i64 4
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %18
%19 = or i64 %3, 26
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %20, i64 4
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %23
%24 = add nuw nsw i64 %3, 32
%25 = icmp eq i64 %24, 992
br i1 %25, label %26, label %2
26: ; preds = %2
%27 = getelementptr inbounds i32, i32* %1, i64 994
store i32 1, i32* %27
%28 = getelementptr inbounds i32, i32* %1, i64 995
store i32 1, i32* %28
%29 = getelementptr inbounds i32, i32* %1, i64 996
store i32 1, i32* %29
%30 = getelementptr inbounds i32, i32* %1, i64 997
store i32 1, i32* %30
%31 = getelementptr inbounds i32, i32* %1, i64 998
store i32 1, i32* %31
%32 = getelementptr inbounds i32, i32* %1, i64 999
store i32 1, i32* %32
br label %33
33: ; preds = %26, %48
%34 = phi i64 [ %49, %48 ], [ 2, %26 ]
%35 = getelementptr inbounds i32, i32* %1, i64 %34
%36 = load i32, i32* %35
%37 = icmp ne i32 %36, 0
%38 = mul nsw i64 %34, %34
%39 = icmp ult i64 %38, 1000
%40 = select i1 %37, i1 %39, i1 false
br i1 %40, label %41, label %48
41: ; preds = %33, %41
%42 = phi i64 [ %46, %41 ], [ %38, %33 ]
%43 = phi i64 [ %45, %41 ], [ %34, %33 ]
%44 = getelementptr inbounds i32, i32* %1, i64 %42
store i32 0, i32* %44
%45 = add nuw nsw i64 %43, 1
%46 = mul nsw i64 %45, %34
%47 = icmp ult i64 %46, 1000
br i1 %47, label %41, label %48
48: ; preds = %41, %33
%49 = add nuw nsw i64 %34, 1
%50 = icmp eq i64 %49, 1000
br i1 %50, label %51, label %33
51: ; preds = %48
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %53
53: ; preds = %51, %60
%54 = phi i64 [ 2, %51 ], [ %61, %60 ]
%55 = getelementptr inbounds i32, i32* %1, i64 %54
%56 = load i32, i32* %55
%57 = icmp eq i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %53
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %54)
br label %60
60: ; preds = %53, %58
%61 = add nuw nsw i64 %54, 1
%62 = icmp eq i64 %61, 1000
br i1 %62, label %63, label %53
63: ; preds = %60
ret i32 0
}