#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 */
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int main(int argc, const char *argv[]) {
  bool numbers[2000000] = {0};
  uint64_t sum = 0;
  int i;
  numbers[0] = 1;
  numbers[1] = 1;
  i = 2;
  while (i < 2000000) {
    int n = i;
    sum += n;
    numbers[i] = 1;
    i = i * i;
    while (i > 0 && i < 2000000) {
      numbers[i] = 1;
      i += n;
    }
    while (n < 2000000 && numbers[n]) {
      n++;
    }
    i = n;
  }
  printf("%lld\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7a1220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x7a1210(%rbp),%rdi
xor    %esi,%esi
mov    $0x7a1200,%edx
call   1040 <memset@plt>
movl   $0x0,-0x7a1214(%rbp)
movl   $0x1,-0x7a1210(%rbp)
movl   $0x1,-0x7a120c(%rbp)
movl   $0x2,-0x7a1218(%rbp)
cmpl   $0x1e8480,-0x7a1218(%rbp)
jge    1298 <main+0x178>
mov    -0x7a1218(%rbp),%eax
mov    %eax,-0x7a121c(%rbp)
mov    -0x7a121c(%rbp),%eax
add    -0x7a1214(%rbp),%eax
mov    %eax,-0x7a1214(%rbp)
movslq -0x7a1218(%rbp),%rax
movl   $0x1,-0x7a1210(%rbp,%rax,4)
mov    -0x7a1218(%rbp),%eax
imul   -0x7a1218(%rbp),%eax
mov    %eax,-0x7a1218(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x7a1218(%rbp)
mov    %al,-0x7a121d(%rbp)
jle    11ef <main+0xcf>
cmpl   $0x1e8480,-0x7a1218(%rbp)
setl   %al
mov    %al,-0x7a121d(%rbp)
mov    -0x7a121d(%rbp),%al
test   $0x1,%al
jne    1202 <main+0xe2>
jmp    122b <main+0x10b>
movslq -0x7a1218(%rbp),%rax
movl   $0x1,-0x7a1210(%rbp,%rax,4)
mov    -0x7a121c(%rbp),%eax
add    -0x7a1218(%rbp),%eax
mov    %eax,-0x7a1218(%rbp)
jmp    11c7 <main+0xa7>
jmp    1230 <main+0x110>
xor    %eax,%eax
cmpl   $0x1e8480,-0x7a121c(%rbp)
mov    %al,-0x7a121e(%rbp)
jge    1260 <main+0x140>
movslq -0x7a121c(%rbp),%rax
cmpl   $0x0,-0x7a1210(%rbp,%rax,4)
setne  %al
mov    %al,-0x7a121e(%rbp)
mov    -0x7a121e(%rbp),%al
test   $0x1,%al
jne    1273 <main+0x153>
jmp    1287 <main+0x167>
mov    -0x7a121c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7a121c(%rbp)
jmp    1230 <main+0x110>
mov    -0x7a121c(%rbp),%eax
mov    %eax,-0x7a1218(%rbp)
jmp    1174 <main+0x54>
mov    -0x7a1214(%rbp),%esi
lea    0xd5b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x7a1220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x7a1200,%rsp
mov    %rsp,%rdi
xor    %ebx,%ebx
mov    $0x7a1200,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movabs $0x100000001,%rax
mov    %rax,(%rsp)
mov    $0x2,%ecx
add    %ecx,%ebx
movslq %ecx,%rax
movl   $0x1,(%rsp,%rax,4)
mov    %eax,%edx
imul   %edx,%edx
lea    -0x1(%rdx),%esi
cmp    $0x1e847e,%esi
ja     11a0 <main+0x80>
nopl   0x0(%rax,%rax,1)
mov    %edx,%esi
movl   $0x1,(%rsp,%rsi,4)
lea    (%rdx,%rcx,1),%esi
add    $0xffffffff,%esi
add    %ecx,%edx
cmp    $0x1e847f,%esi
jb     1170 <main+0x50>
cmp    $0x1e847f,%ecx
jg     11c9 <main+0xa9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpl   $0x0,(%rsp,%rax,4)
je     11c0 <main+0xa0>
add    $0x1,%rax
cmp    $0x1e8480,%rax
jne    11a0 <main+0x80>
jmp    11c9 <main+0xa9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%ecx
cmp    $0x1e8480,%eax
jl     114c <main+0x2c>
lea    0xe30(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x7a1200,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%lld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2000000 x i32]
%4 = bitcast [2000000 x i32]* %3 to i8*
%5 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %3, i64 0, i64 0
store i32 1, i32* %5
%6 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %3, i64 0, i64 1
store i32 1, i32* %6
br label %7
7: ; preds = %2, %34
%8 = phi i32 [ 2, %2 ], [ %35, %34 ]
%9 = phi i32 [ 0, %2 ], [ %10, %34 ]
%10 = add nsw i32 %8, %9
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %3, i64 0, i64 %11
store i32 1, i32* %12
%13 = mul nsw i32 %8, %8
%14 = add nsw i32 %13, -1
%15 = icmp ult i32 %14, 1999999
br i1 %15, label %19, label %18
16: ; preds = %19
%17 = icmp slt i32 %8, 2000000
br i1 %17, label %18, label %37
18: ; preds = %7, %16
br label %26
19: ; preds = %7, %19
%20 = phi i32 [ %23, %19 ], [ %13, %7 ]
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %3, i64 0, i64 %21
store i32 1, i32* %22
%23 = add nsw i32 %20, %8
%24 = add nsw i32 %23, -1
%25 = icmp ult i32 %24, 1999999
br i1 %25, label %19, label %16
26: ; preds = %18, %31
%27 = phi i64 [ %32, %31 ], [ %11, %18 ]
%28 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %3, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = add nsw i64 %27, 1
%33 = icmp eq i64 %32, 2000000
br i1 %33, label %37, label %26
34: ; preds = %26
%35 = trunc i64 %27 to i32
%36 = icmp slt i32 %35, 2000000
br i1 %36, label %7, label %37
37: ; preds = %16, %34, %31
%38 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
ret i32 0
}