#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 /*<<< orphan*/ sieve(int *);
int main() {
  int primes[1000000] = {0};
  int i;
  for (i = 2; i <= 1000000; i++) {
    primes[i] = 1;
  }
  sieve(primes);
  printf("When search the number 2 as a prime: %d\n", primes[2]);
  printf("When search the number 137 as a prime: %d\n", primes[137]);
  printf("When search the number 233 as a prime: %d\n", primes[233]);
  printf("When search the number 997 as a prime: %d\n", primes[997]);
  printf("When search the number 0 as a prime: %d\n", !primes[0]);
  printf("When search the number 1 as a prime: %d\n", !primes[1]);
  int count = 0;
  for (i = 2; i <= 1000000; i++) {
    if (primes[i]) {
      count++;
    }
  }
  printf("How many primes there are in %d: %d", 1000000, count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0920,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3d0910(%rbp),%rdi
xor    %esi,%esi
mov    $0x3d0900,%edx
call   1040 <memset@plt>
movl   $0x2,-0x3d0914(%rbp)
cmpl   $0xf4240,-0x3d0914(%rbp)
jg     1195 <main+0x65>
movslq -0x3d0914(%rbp),%rax
movl   $0x1,-0x3d0910(%rbp,%rax,4)
mov    -0x3d0914(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0914(%rbp)
jmp    115f <main+0x2f>
lea    -0x3d0910(%rbp),%rdi
call   1050 <sieve@plt>
mov    -0x3d0908(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3d06ec(%rbp),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3d056c(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3cf97c(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x3d0910(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x3d090c(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x3d0918(%rbp)
movl   $0x2,-0x3d0914(%rbp)
cmpl   $0xf4240,-0x3d0914(%rbp)
jg     1290 <main+0x160>
movslq -0x3d0914(%rbp),%rax
cmpl   $0x0,-0x3d0910(%rbp,%rax,4)
je     1277 <main+0x147>
mov    -0x3d0918(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0918(%rbp)
jmp    127c <main+0x14c>
mov    -0x3d0914(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0914(%rbp)
jmp    1243 <main+0x113>
mov    -0x3d0918(%rbp),%edx
lea    0xe5f(%rip),%rdi
mov    $0xf4240,%esi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x3d0920,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x3d0908,%rsp
mov    %rsp,%rdi
mov    $0x3d0900,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0x1e,%eax
movdqa 0xead(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqu %xmm0,-0x70(%rsp,%rax,4)
movdqu %xmm0,-0x60(%rsp,%rax,4)
movdqu %xmm0,-0x50(%rsp,%rax,4)
movdqu %xmm0,-0x40(%rsp,%rax,4)
movdqu %xmm0,-0x30(%rsp,%rax,4)
movdqu %xmm0,-0x20(%rsp,%rax,4)
cmp    $0xf423e,%rax
je     119d <main+0x6d>
movdqu %xmm0,-0x10(%rsp,%rax,4)
movdqu %xmm0,(%rsp,%rax,4)
add    $0x20,%rax
jmp    1160 <main+0x30>
movdqu %xmm0,0x3d08e8(%rsp)
movabs $0x100000001,%rax
mov    %rax,0x3d08f8(%rsp)
movl   $0x1,0x3d0900(%rsp)
mov    %rsp,%rdi
call   1050 <sieve@plt>
mov    0x8(%rsp),%esi
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x224(%rsp),%esi
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x3a4(%rsp),%esi
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xf94(%rsp),%esi
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %esi,%esi
cmpl   $0x0,(%rsp)
sete   %sil
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %esi,%esi
cmpl   $0x0,0x4(%rsp)
sete   %sil
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
pxor   %xmm0,%xmm0
mov    $0xe,%eax
pcmpeqd %xmm1,%xmm1
pxor   %xmm5,%xmm5
pxor   %xmm4,%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqu -0x30(%rsp,%rax,4),%xmm3
movdqu -0x20(%rsp,%rax,4),%xmm2
pcmpeqd %xmm0,%xmm3
paddd  %xmm5,%xmm3
pcmpeqd %xmm0,%xmm2
paddd  %xmm4,%xmm2
psubd  %xmm1,%xmm3
psubd  %xmm1,%xmm2
cmp    $0xf423e,%rax
je     12cd <main+0x19d>
movdqu -0x10(%rsp,%rax,4),%xmm4
movdqu (%rsp,%rax,4),%xmm5
pcmpeqd %xmm0,%xmm4
pcmpeqd %xmm0,%xmm5
paddd  %xmm4,%xmm3
psubd  %xmm1,%xmm3
paddd  %xmm5,%xmm2
psubd  %xmm1,%xmm2
add    $0x10,%rax
movdqa %xmm3,%xmm5
movdqa %xmm2,%xmm4
jmp    1270 <main+0x140>
paddd  %xmm3,%xmm2
pshufd $0xee,%xmm2,%xmm0
paddd  %xmm2,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%edx
cmpl   $0x1,0x3d08e8(%rsp)
01
sbb    $0xffffffff,%edx
cmpl   $0x1,0x3d08ec(%rsp)
01
sbb    $0xffffffff,%edx
cmpl   $0x1,0x3d08f0(%rsp)
01
sbb    $0xffffffff,%edx
cmpl   $0x1,0x3d08f4(%rsp)
01
sbb    $0xffffffff,%edx
cmpl   $0x1,0x3d08f8(%rsp)
01
sbb    $0xffffffff,%edx
cmpl   $0x1,0x3d08fc(%rsp)
01
sbb    $0xffffffff,%edx
cmpl   $0x1,0x3d0900(%rsp)
01
sbb    $0xffffffff,%edx
lea    0xdd1(%rip),%rdi
mov    $0xf4240,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x3d0908,%rsp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"When search the number 2 as a prime: %d\0A\00"
@.str.1 = [43 x i8] c"When search the number 137 as a prime: %d\0A\00"
@.str.2 = [43 x i8] c"When search the number 233 as a prime: %d\0A\00"
@.str.3 = [43 x i8] c"When search the number 997 as a prime: %d\0A\00"
@.str.4 = [41 x i8] c"When search the number 0 as a prime: %d\0A\00"
@.str.5 = [41 x i8] c"When search the number 1 as a prime: %d\0A\00"
@.str.6 = [36 x i8] c"How many primes there are in %d: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000000 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [1000000 x i32]* %2 to i8*
store i32 2, i32* %3
br label %6
6: ; preds = %13, %0
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 1000000
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %11
store i32 1, i32* %12
br label %13
13: ; preds = %9
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %6
16: ; preds = %6
%17 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 0
%18 = call i32 @sieve(i32* %17)
%19 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 2
%20 = load i32, i32* %19
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 137
%23 = load i32, i32* %22
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 233
%26 = load i32, i32* %25
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 997
%29 = load i32, i32* %28
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %31
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
%35 = zext i1 %34 to i32
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 1
%38 = load i32, i32* %37
%39 = icmp ne i32 %38, 0
%40 = xor i1 %39, true
%41 = zext i1 %40 to i32
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %41)
store i32 0, i32* %4
store i32 2, i32* %3
br label %43
43: ; preds = %56, %16
%44 = load i32, i32* %3
%45 = icmp sle i32 %44, 1000000
br i1 %45, label %46, label %59
46: ; preds = %43
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %55
55: ; preds = %52, %46
br label %56
56: ; preds = %55
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
br label %43
59: ; preds = %43
%60 = load i32, i32* %4
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 1000000, i32 %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"When search the number 2 as a prime: %d\0A\00"
@.str.1 = [43 x i8] c"When search the number 137 as a prime: %d\0A\00"
@.str.2 = [43 x i8] c"When search the number 233 as a prime: %d\0A\00"
@.str.3 = [43 x i8] c"When search the number 997 as a prime: %d\0A\00"
@.str.4 = [41 x i8] c"When search the number 0 as a prime: %d\0A\00"
@.str.5 = [41 x i8] c"When search the number 1 as a prime: %d\0A\00"
@.str.6 = [36 x i8] c"How many primes there are in %d: %d\00"
define i32 @main() {
%1 = alloca [1000000 x i32]
%2 = bitcast [1000000 x i32]* %1 to i8*
br label %3
3: ; preds = %21, %0
%4 = phi i64 [ 0, %0 ], [ %27, %21 ]
%5 = or i64 %4, 2
%6 = getelementptr inbounds [1000000 x i32], [1000000 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 [1000000 x i32], [1000000 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 [1000000 x i32], [1000000 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 = icmp eq i64 %4, 999968
br i1 %20, label %28, label %21
21: ; preds = %3
%22 = or i64 %4, 26
%23 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %22
%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 = getelementptr inbounds i32, i32* %23, i64 4
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %26
%27 = add nuw nsw i64 %4, 32
br label %3
28: ; preds = %3
%29 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999994
store i32 1, i32* %29
%30 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999995
store i32 1, i32* %30
%31 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999996
store i32 1, i32* %31
%32 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999997
store i32 1, i32* %32
%33 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999998
store i32 1, i32* %33
%34 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999999
store i32 1, i32* %34
%35 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 1000000
store i32 1, i32* %35
%36 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 0
%37 = call i32 @sieve(i32* %36)
%38 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 2
%39 = load i32, i32* %38
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 137
%42 = load i32, i32* %41
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 233
%45 = load i32, i32* %44
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 997
%48 = load i32, i32* %47
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %36
%51 = icmp eq i32 %50, 0
%52 = zext i1 %51 to i32
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 1
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, 0
%57 = zext i1 %56 to i32
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %77, %28
%60 = phi i64 [ 0, %28 ], [ %91, %77 ]
%61 = phi <4 x i32> [ zeroinitializer, %28 ], [ %89, %77 ]
%62 = phi <4 x i32> [ zeroinitializer, %28 ], [ %90, %77 ]
%63 = or i64 %60, 2
%64 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %63
%65 = bitcast i32* %64 to <4 x i32>*
%66 = load <4 x i32>, <4 x i32>* %65
%67 = getelementptr inbounds i32, i32* %64, i64 4
%68 = bitcast i32* %67 to <4 x i32>*
%69 = load <4 x i32>, <4 x i32>* %68
%70 = icmp ne <4 x i32> %66, zeroinitializer
%71 = icmp ne <4 x i32> %69, zeroinitializer
%72 = zext <4 x i1> %70 to <4 x i32>
%73 = zext <4 x i1> %71 to <4 x i32>
%74 = add <4 x i32> %61, %72
%75 = add <4 x i32> %62, %73
%76 = icmp eq i64 %60, 999984
br i1 %76, label %92, label %77
77: ; preds = %59
%78 = or i64 %60, 10
%79 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %78
%80 = bitcast i32* %79 to <4 x i32>*
%81 = load <4 x i32>, <4 x i32>* %80
%82 = getelementptr inbounds i32, i32* %79, i64 4
%83 = bitcast i32* %82 to <4 x i32>*
%84 = load <4 x i32>, <4 x i32>* %83
%85 = icmp ne <4 x i32> %81, zeroinitializer
%86 = icmp ne <4 x i32> %84, zeroinitializer
%87 = zext <4 x i1> %85 to <4 x i32>
%88 = zext <4 x i1> %86 to <4 x i32>
%89 = add <4 x i32> %74, %87
%90 = add <4 x i32> %75, %88
%91 = add nuw nsw i64 %60, 16
br label %59
92: ; preds = %59
%93 = add <4 x i32> %75, %74
%94 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %93)
%95 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999994
%96 = load i32, i32* %95
%97 = icmp ne i32 %96, 0
%98 = zext i1 %97 to i32
%99 = add nuw nsw i32 %94, %98
%100 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999995
%101 = load i32, i32* %100
%102 = icmp ne i32 %101, 0
%103 = zext i1 %102 to i32
%104 = add nuw nsw i32 %99, %103
%105 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999996
%106 = load i32, i32* %105
%107 = icmp ne i32 %106, 0
%108 = zext i1 %107 to i32
%109 = add nuw nsw i32 %104, %108
%110 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999997
%111 = load i32, i32* %110
%112 = icmp ne i32 %111, 0
%113 = zext i1 %112 to i32
%114 = add nuw nsw i32 %109, %113
%115 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999998
%116 = load i32, i32* %115
%117 = icmp ne i32 %116, 0
%118 = zext i1 %117 to i32
%119 = add nuw nsw i32 %114, %118
%120 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 999999
%121 = load i32, i32* %120
%122 = icmp ne i32 %121, 0
%123 = zext i1 %122 to i32
%124 = add nuw nsw i32 %119, %123
%125 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 1000000
%126 = load i32, i32* %125
%127 = icmp ne i32 %126, 0
%128 = zext i1 %127 to i32
%129 = add nuw nsw i32 %124, %128
%130 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 1000000, i32 %129)
ret i32 0
}