#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 *EratosthenesSieve(unsigned int const);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, unsigned long long);
int main(void) {
  int *sieve;
  const unsigned int LIMIT = 2000000;
  unsigned long long prime_sum = 0;
  sieve = EratosthenesSieve(LIMIT);
  for (int i = 0; i < (LIMIT - 2); i++) {
    if (sieve[i] == 1) {
      prime_sum += i + 2;
    }
  }
  printf("%llu", prime_sum);
  free(sieve);
  sieve = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1e8480,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x1e8480,%edi
call   1050 <EratosthenesSieve@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x1e847e,-0x24(%rbp)
jae    11a5 <main+0x75>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1192 <main+0x62>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
cltq
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1197 <main+0x67>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1163 <main+0x33>
mov    -0x20(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1e8480,%edi
call   1050 <EratosthenesSieve@plt>
mov    %rax,%rbx
pxor   %xmm0,%xmm0
movdqa 0xeb6(%rip),%xmm5
mov    $0x2,%eax
movdqa 0xeb9(%rip),%xmm2
movdqa 0xec0(%rip),%xmm8
movdqa 0xec7(%rip),%xmm9
movdqa 0xecf(%rip),%xmm6
pxor   %xmm4,%xmm4
cs nopw 0x0(%rax,%rax,1)
nop
movq   -0x8(%rbx,%rax,4),%xmm7
movq   (%rbx,%rax,4),%xmm3
pshufd $0xd4,%xmm7,%xmm7
pcmpeqd %xmm2,%xmm7
pshufd $0xd4,%xmm3,%xmm3
pcmpeqd %xmm2,%xmm3
movdqa %xmm5,%xmm1
paddq  %xmm8,%xmm1
paddq  %xmm9,%xmm5
pand   %xmm6,%xmm1
pand   %xmm7,%xmm1
paddq  %xmm1,%xmm0
movdqa %xmm5,%xmm1
pand   %xmm6,%xmm1
pand   %xmm3,%xmm1
paddq  %xmm1,%xmm4
add    $0x4,%rax
cmp    $0x1e847e,%rax
jne    1180 <main+0x50>
paddq  %xmm0,%xmm4
pshufd $0xee,%xmm4,%xmm0
paddq  %xmm4,%xmm0
movq   %xmm0,%rax
cmpl   $0x1,0x7a11f0(%rbx)
lea    0x1e847e(%rax),%rcx
cmovne %rax,%rcx
lea    0x1e847f(%rcx),%rsi
cmpl   $0x1,0x7a11f4(%rbx)
cmovne %rcx,%rsi
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%llu\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
store i32 2000000, i32* %3
store i64 0, i64* %4
%6 = call i32* @EratosthenesSieve(i32 2000000)
store i32* %6, i32** %2
store i32 0, i32* %5
br label %7
7: ; preds = %24, %0
%8 = load i32, i32* %5
%9 = icmp ult i32 %8, 1999998
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %10
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 2
%20 = sext i32 %19 to i64
%21 = load i64, i64* %4
%22 = add i64 %21, %20
store i64 %22, i64* %4
br label %23
23: ; preds = %17, %10
br label %24
24: ; preds = %23
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %7
27: ; preds = %7
%28 = load i64, i64* %4
%29 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %28)
%30 = load i32*, i32** %2
%31 = call i32 @free(i32* %30)
store i32* null, i32** %2
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%llu\00"
define i32 @main() {
%1 = tail call i32* @EratosthenesSieve(i32 2000000)
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %23, %2 ]
%4 = phi <2 x i64> [ <i64 0, i64 1>, %0 ], [ %24, %2 ]
%5 = phi <2 x i64> [ zeroinitializer, %0 ], [ %21, %2 ]
%6 = phi <2 x i64> [ zeroinitializer, %0 ], [ %22, %2 ]
%7 = getelementptr inbounds i32, i32* %1, i64 %3
%8 = bitcast i32* %7 to <2 x i32>*
%9 = load <2 x i32>, <2 x i32>* %8
%10 = getelementptr inbounds i32, i32* %7, i64 2
%11 = bitcast i32* %10 to <2 x i32>*
%12 = load <2 x i32>, <2 x i32>* %11
%13 = icmp eq <2 x i32> %9, <i32 1, i32 1>
%14 = icmp eq <2 x i32> %12, <i32 1, i32 1>
%15 = add nuw <2 x i64> %4, <i64 2, i64 2>
%16 = add <2 x i64> %4, <i64 4, i64 4>
%17 = and <2 x i64> %15, <i64 4294967295, i64 4294967295>
%18 = and <2 x i64> %16, <i64 4294967295, i64 4294967295>
%19 = select <2 x i1> %13, <2 x i64> %17, <2 x i64> zeroinitializer
%20 = select <2 x i1> %14, <2 x i64> %18, <2 x i64> zeroinitializer
%21 = add <2 x i64> %5, %19
%22 = add <2 x i64> %6, %20
%23 = add nuw i64 %3, 4
%24 = add <2 x i64> %4, <i64 4, i64 4>
%25 = icmp eq i64 %23, 1999996
br i1 %25, label %26, label %2
26: ; preds = %2
%27 = add <2 x i64> %22, %21
%28 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %27)
%29 = getelementptr inbounds i32, i32* %1, i64 1999996
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 1
%32 = select i1 %31, i64 1999998, i64 0
%33 = add i64 %28, %32
%34 = getelementptr inbounds i32, i32* %1, i64 1999997
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 1
%37 = select i1 %36, i64 1999999, i64 0
%38 = add i64 %33, %37
%39 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %38)
%40 = tail call i32 @free(i32* %1)
ret i32 0
}