#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ sieve(char *, int);
int main(int argc, char *argv[]) {
  char *nums;
  int i;
  long sum = 0;
  nums = (char *)calloc(2000000, sizeof(char));
  if (nums == NULL)
    return 1;
  sieve(nums, 2000000);
  for (i = 0; i < 2000000; i++)
    if (!nums[i]) {
      sum += i;
    }
  printf("Sum: %ld\n", sum);
  free(nums);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x1e8480,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1188 <main+0x48>
movl   $0x1,-0x4(%rbp)
jmp    11fb <main+0xbb>
mov    -0x18(%rbp),%rdi
mov    $0x1e8480,%esi
call   1060 <sieve@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1e8480,-0x1c(%rbp)
jge    11db <main+0x9b>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11c8 <main+0x88>
movslq -0x1c(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11cd <main+0x8d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119d <main+0x5d>
mov    -0x28(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebp
mov    $0x1e8480,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     12c3 <main+0x183>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1e8480,%esi
call   1060 <sieve@plt>
pxor   %xmm12,%xmm12
movdqa 0xe83(%rip),%xmm1
mov    $0x6,%eax
movdqa 0xe85(%rip),%xmm8
movdqa 0xe8c(%rip),%xmm9
movdqa 0xe93(%rip),%xmm10
movdqa 0xe9a(%rip),%xmm11
pxor   %xmm6,%xmm6
pxor   %xmm7,%xmm7
xchg   %ax,%ax
movdqa %xmm1,%xmm4
paddq  %xmm8,%xmm4
movzwl -0x6(%rbx,%rax,1),%ecx
movd   %ecx,%xmm2
movzwl -0x4(%rbx,%rax,1),%ecx
movd   %ecx,%xmm5
pcmpeqb %xmm12,%xmm2
punpcklbw %xmm2,%xmm2
punpcklwd %xmm2,%xmm3
pxor   %xmm2,%xmm2
pcmpgtd %xmm3,%xmm2
psrad  $0x18,%xmm3
punpckldq %xmm2,%xmm3
pcmpeqb %xmm12,%xmm5
punpcklbw %xmm5,%xmm2
punpcklwd %xmm2,%xmm2
pxor   %xmm5,%xmm5
pcmpgtd %xmm2,%xmm5
psrad  $0x18,%xmm2
punpckldq %xmm5,%xmm2
pand   %xmm4,%xmm2
paddq  %xmm7,%xmm2
pand   %xmm1,%xmm3
paddq  %xmm6,%xmm3
movdqa %xmm1,%xmm4
paddq  %xmm9,%xmm4
movdqa %xmm1,%xmm5
paddq  %xmm10,%xmm5
movzwl -0x2(%rbx,%rax,1),%ecx
movd   %ecx,%xmm6
movzwl (%rbx,%rax,1),%ecx
movd   %ecx,%xmm7
pcmpeqb %xmm12,%xmm6
punpcklbw %xmm6,%xmm6
punpcklwd %xmm6,%xmm6
pxor   %xmm0,%xmm0
pcmpgtd %xmm6,%xmm0
psrad  $0x18,%xmm6
punpckldq %xmm0,%xmm6
pand   %xmm4,%xmm6
paddq  %xmm3,%xmm6
pcmpeqb %xmm12,%xmm7
punpcklbw %xmm7,%xmm0
punpcklwd %xmm0,%xmm7
pxor   %xmm0,%xmm0
pcmpgtd %xmm7,%xmm0
psrad  $0x18,%xmm7
punpckldq %xmm0,%xmm7
pand   %xmm5,%xmm7
paddq  %xmm2,%xmm7
paddq  %xmm11,%xmm1
add    $0x8,%rax
cmp    $0x1e8486,%rax
jne    11b0 <main+0x70>
paddq  %xmm6,%xmm7
pshufd $0xee,%xmm7,%xmm0
paddq  %xmm7,%xmm0
movq   %xmm0,%rsi
lea    0xd9c(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Sum: %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
%9 = call i64 @calloc(i32 2000000, i32 1)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %41
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i32 @sieve(i8* %15, i32 2000000)
store i32 0, i32* %7
br label %17
17: ; preds = %33, %14
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 2000000
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %20
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = load i64, i64* %8
%31 = add nsw i64 %30, %29
store i64 %31, i64* %8
br label %32
32: ; preds = %27, %20
br label %33
33: ; preds = %32
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %17
36: ; preds = %17
%37 = load i64, i64* %8
%38 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %37)
%39 = load i8*, i8** %6
%40 = call i32 @free(i8* %39)
store i32 0, i32* %3
br label %41
41: ; preds = %36, %13
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [10 x i8] c"Sum: %ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @calloc(i32 2000000, i32 1)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %49, label %6
6: ; preds = %2
%7 = tail call i32 @sieve(i8* %4, i32 2000000)
br label %8
8: ; preds = %8, %6
%9 = phi i64 [ 0, %6 ], [ %41, %8 ]
%10 = phi <2 x i64> [ <i64 0, i64 1>, %6 ], [ %42, %8 ]
%11 = phi <2 x i64> [ zeroinitializer, %6 ], [ %39, %8 ]
%12 = phi <2 x i64> [ zeroinitializer, %6 ], [ %40, %8 ]
%13 = add <2 x i64> %10, <i64 2, i64 2>
%14 = getelementptr inbounds i8, i8* %4, i64 %9
%15 = bitcast i8* %14 to <2 x i8>*
%16 = load <2 x i8>, <2 x i8>* %15
%17 = getelementptr inbounds i8, i8* %14, i64 2
%18 = bitcast i8* %17 to <2 x i8>*
%19 = load <2 x i8>, <2 x i8>* %18
%20 = icmp eq <2 x i8> %16, zeroinitializer
%21 = icmp eq <2 x i8> %19, zeroinitializer
%22 = select <2 x i1> %20, <2 x i64> %10, <2 x i64> zeroinitializer
%23 = select <2 x i1> %21, <2 x i64> %13, <2 x i64> zeroinitializer
%24 = add <2 x i64> %22, %11
%25 = add <2 x i64> %23, %12
%26 = or i64 %9, 4
%27 = add <2 x i64> %10, <i64 4, i64 4>
%28 = add <2 x i64> %10, <i64 6, i64 6>
%29 = getelementptr inbounds i8, i8* %4, i64 %26
%30 = bitcast i8* %29 to <2 x i8>*
%31 = load <2 x i8>, <2 x i8>* %30
%32 = getelementptr inbounds i8, i8* %29, i64 2
%33 = bitcast i8* %32 to <2 x i8>*
%34 = load <2 x i8>, <2 x i8>* %33
%35 = icmp eq <2 x i8> %31, zeroinitializer
%36 = icmp eq <2 x i8> %34, zeroinitializer
%37 = select <2 x i1> %35, <2 x i64> %27, <2 x i64> zeroinitializer
%38 = select <2 x i1> %36, <2 x i64> %28, <2 x i64> zeroinitializer
%39 = add <2 x i64> %37, %24
%40 = add <2 x i64> %38, %25
%41 = add nuw nsw i64 %9, 8
%42 = add <2 x i64> %10, <i64 8, i64 8>
%43 = icmp eq i64 %41, 2000000
br i1 %43, label %44, label %8
44: ; preds = %8
%45 = add <2 x i64> %40, %39
%46 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %45)
%47 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %46)
%48 = tail call i32 @free(i8* %4)
br label %49
49: ; preds = %2, %44
%50 = phi i32 [ 0, %44 ], [ 1, %2 ]
ret i32 %50
}