#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 CLOCKS_PER_SEC;
int clock();
int floor(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sqrt(unsigned long long);
int main(void) {
  unsigned long long int tot = 5, i, flag = 0;
  for (i = 2; i < 2000000; i++) {
    if (i == 1)
      continue;
    if (i < 4)
      flag = 1;
    if (i % 2 == 0)
      continue;
    if (i % 3 == 0)
      continue;
    flag = 1;
    int r = floor(sqrt(i)), f = 5;
    while (f <= r) {
      if (i % f == 0) {
        flag = 0;
        break;
      }
      if (i % (f + 2) == 0) {
        flag = 0;
        break;
      }
      f += 6;
    }
    if (flag == 1)
      tot += i;
  }
  printf("%llu\n", tot);
  printf("took %lums\n", clock() / (CLOCKS_PER_SEC / 1000));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x5,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x2,-0x18(%rbp)
cmpq   $0x1e8480,-0x18(%rbp)
jae    1282 <main+0x142>
cmpq   $0x1,-0x18(%rbp)
jne    1185 <main+0x45>
jmp    1271 <main+0x131>
cmpq   $0x4,-0x18(%rbp)
jae    1198 <main+0x58>
movq   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    11af <main+0x6f>
jmp    1271 <main+0x131>
mov    -0x18(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    11cc <main+0x8c>
jmp    1271 <main+0x131>
movq   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <sqrt@plt>
mov    %eax,%edi
call   1060 <floor@plt>
mov    %eax,-0x24(%rbp)
movl   $0x5,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     1255 <main+0x115>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    121e <main+0xde>
movq   $0x0,-0x20(%rbp)
jmp    1255 <main+0x115>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    1247 <main+0x107>
movq   $0x0,-0x20(%rbp)
jmp    1255 <main+0x115>
mov    -0x28(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x28(%rbp)
jmp    11ee <main+0xae>
cmpq   $0x1,-0x20(%rbp)
jne    126c <main+0x12c>
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1271 <main+0x131>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1167 <main+0x27>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xd71(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xd46(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x2,%ebx
mov    $0x5,%r14d
mov    $0xaaaaaaab,%r15d
jmp    1174 <main+0x34>
nopl   0x0(%rax,%rax,1)
add    %rbx,%r14
add    $0x1,%rbx
cmp    $0x1e8480,%rbx
je     121c <main+0xdc>
test   $0x1,%bl
je     1163 <main+0x23>
mov    %ebx,%eax
imul   %r15,%rax
shr    $0x21,%rax
lea    (%rax,%rax,2),%eax
mov    %ebx,%ecx
sub    %eax,%ecx
je     1163 <main+0x23>
mov    %rbx,%rdi
call   1050 <sqrt@plt>
mov    %eax,%edi
call   1060 <floor@plt>
cmp    $0x5,%eax
jl     1160 <main+0x20>
mov    %eax,%ecx
mov    $0x5,%esi
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     11d0 <main+0x90>
mov    %rbx,%rax
xor    %edx,%edx
div    %rsi
test   %rdx,%rdx
jne    11db <main+0x9b>
jmp    1163 <main+0x23>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
je     1163 <main+0x23>
lea    0x2(%rsi),%rdi
mov    %rbx,%rax
or     %rdi,%rax
shr    $0x20,%rax
je     1200 <main+0xc0>
mov    %rbx,%rax
xor    %edx,%edx
div    %rdi
jmp    1206 <main+0xc6>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%eax
xor    %edx,%edx
div    %edi
test   %rdx,%rdx
je     1163 <main+0x23>
add    $0x6,%rsi
cmp    %esi,%ecx
jge    11b0 <main+0x70>
jmp    1160 <main+0x20>
lea    0xddd(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    0x2daf(%rip),%rcx
movslq (%rcx),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
cltd
idiv   %ecx
lea    0xdac(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%llu\0A\00"
@.str.1 = [12 x i8] c"took %lums\0A\00"
@CLOCKS_PER_SEC = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i64 5, i64* %2
store i64 0, i64* %4
store i64 2, i64* %3
br label %7
7: ; preds = %62, %0
%8 = load i64, i64* %3
%9 = icmp ult i64 %8, 2000000
br i1 %9, label %10, label %65
10: ; preds = %7
%11 = load i64, i64* %3
%12 = icmp eq i64 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %10
br label %62
14: ; preds = %10
%15 = load i64, i64* %3
%16 = icmp ult i64 %15, 4
br i1 %16, label %17, label %18
17: ; preds = %14
store i64 1, i64* %4
br label %18
18: ; preds = %17, %14
%19 = load i64, i64* %3
%20 = urem i64 %19, 2
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
br label %62
23: ; preds = %18
%24 = load i64, i64* %3
%25 = urem i64 %24, 3
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
br label %62
28: ; preds = %23
store i64 1, i64* %4
%29 = load i64, i64* %3
%30 = call i32 @sqrt(i64 %29)
%31 = call i32 @floor(i32 %30)
store i32 %31, i32* %5
store i32 5, i32* %6
br label %32
32: ; preds = %51, %28
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = icmp sle i32 %33, %34
br i1 %35, label %36, label %54
36: ; preds = %32
%37 = load i64, i64* %3
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = urem i64 %37, %39
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %36
store i64 0, i64* %4
br label %54
43: ; preds = %36
%44 = load i64, i64* %3
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 2
%47 = sext i32 %46 to i64
%48 = urem i64 %44, %47
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %43
store i64 0, i64* %4
br label %54
51: ; preds = %43
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 6
store i32 %53, i32* %6
br label %32
54: ; preds = %50, %42, %32
%55 = load i64, i64* %4
%56 = icmp eq i64 %55, 1
br i1 %56, label %57, label %61
57: ; preds = %54
%58 = load i64, i64* %3
%59 = load i64, i64* %2
%60 = add i64 %59, %58
store i64 %60, i64* %2
br label %61
61: ; preds = %57, %54
br label %62
62: ; preds = %61, %27, %22, %13
%63 = load i64, i64* %3
%64 = add i64 %63, 1
store i64 %64, i64* %3
br label %7
65: ; preds = %7
%66 = load i64, i64* %2
%67 = trunc i64 %66 to i32
%68 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %67)
%69 = call i32 (...) @clock()
%70 = load i32, i32* @CLOCKS_PER_SEC
%71 = sdiv i32 %70, 1000
%72 = sdiv i32 %69, %71
%73 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %1
ret i32 %74
}

LLVM IR (-O2):
@.str = [6 x i8] c"%llu\0A\00"
@.str.1 = [12 x i8] c"took %lums\0A\00"
@CLOCKS_PER_SEC = global i32 0
define i32 @main() {
br label %1
1: ; preds = %28, %0
%2 = phi i64 [ 5, %0 ], [ %29, %28 ]
%3 = phi i64 [ 2, %0 ], [ %30, %28 ]
%4 = and i64 %3, 1
%5 = icmp eq i64 %4, 0
%6 = trunc i64 %3 to i32
%7 = urem i32 %6, 3
%8 = icmp eq i32 %7, 0
%9 = or i1 %5, %8
br i1 %9, label %28, label %10
10: ; preds = %1
%11 = tail call i32 @sqrt(i64 %3)
%12 = tail call i32 @floor(i32 %11)
%13 = icmp slt i32 %12, 5
br i1 %13, label %26, label %17
14: ; preds = %21
%15 = trunc i64 %25 to i32
%16 = icmp slt i32 %12, %15
br i1 %16, label %26, label %17
17: ; preds = %10, %14
%18 = phi i64 [ %25, %14 ], [ 5, %10 ]
%19 = urem i64 %3, %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %17
%22 = add nuw nsw i64 %18, 2
%23 = urem i64 %3, %22
%24 = icmp eq i64 %23, 0
%25 = add nuw i64 %18, 6
br i1 %24, label %28, label %14
26: ; preds = %14, %10
%27 = add i64 %2, %3
br label %28
28: ; preds = %21, %17, %26, %1
%29 = phi i64 [ %2, %1 ], [ %27, %26 ], [ %2, %17 ], [ %2, %21 ]
%30 = add nuw nsw i64 %3, 1
%31 = icmp eq i64 %30, 2000000
br i1 %31, label %32, label %1
32: ; preds = %28
%33 = trunc i64 %29 to i32
%34 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = tail call i32 (...) @clock()
%36 = load i32, i32* @CLOCKS_PER_SEC
%37 = sdiv i32 %36, 1000
%38 = sdiv i32 %35, %37
%39 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %38)
ret i32 0
}