#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__ is_prime(unsigned long);
int /*<<< orphan*/ printf(char *, float);
float timeit();
int main(int argc, char *argv[]) {
  float start = timeit();
  unsigned long long total;
  unsigned long i;
  for (i = 0, total = 0; i < 2000000; i++)
    total += is_prime(i) ? i : 0;
  float stop = timeit();
  printf("Answer: %lld\n", total);
  printf("Time: %.8f\n", stop - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <timeit@plt>
movss  %xmm0,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x1e8480,-0x28(%rbp)
jae    11b8 <main+0x88>
mov    -0x28(%rbp),%rdi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     1190 <main+0x60>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    119b <main+0x6b>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    119b <main+0x6b>
mov    -0x38(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1162 <main+0x32>
xor    %eax,%eax
call   1050 <timeit@plt>
movss  %xmm0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x40(%rbp)
test   %rax,%rax
movss  %xmm0,-0x3c(%rbp)
js     1201 <main+0xd1>
movss  -0x40(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
lea    0xdf3(%rip),%rdi
call   1030 <printf@plt>
movss  -0x2c(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
lea    0xdeb(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <timeit@plt>
movss  %xmm0,0x4(%rsp)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <is_prime@plt>
test   %rax,%rax
cmovne %rbx,%rax
add    %rax,%r14
add    $0x1,%rbx
cmp    $0x1e8480,%rbx
jne    1150 <main+0x20>
xor    %eax,%eax
call   1050 <timeit@plt>
movss  %xmm0,(%rsp)
test   %r14,%r14
js     118a <main+0x5a>
xorps  %xmm0,%xmm0
cvtsi2ss %r14,%xmm0
jmp    11a3 <main+0x73>
mov    %r14,%rax
shr    %rax
and    $0x1,%r14d
or     %rax,%r14
xorps  %xmm0,%xmm0
cvtsi2ss %r14,%xmm0
addss  %xmm0,%xmm0
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
movss  (%rsp),%xmm0
subss  0x4(%rsp),%xmm0
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Answer: %lld\0A\00"
@.str.1 = [12 x i8] c"Time: %.8f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca i64
%8 = alloca i64
%9 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call float (...) @timeit()
store float %10, float* %6
store i64 0, i64* %8
store i64 0, i64* %7
br label %11
11: ; preds = %25, %2
%12 = load i64, i64* %8
%13 = icmp ult i64 %12, 2000000
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i64, i64* %8
%16 = call i64 @is_prime(i64 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i64, i64* %8
br label %21
20: ; preds = %14
br label %21
21: ; preds = %20, %18
%22 = phi i64 [ %19, %18 ], [ 0, %20 ]
%23 = load i64, i64* %7
%24 = add i64 %23, %22
store i64 %24, i64* %7
br label %25
25: ; preds = %21
%26 = load i64, i64* %8
%27 = add i64 %26, 1
store i64 %27, i64* %8
br label %11
28: ; preds = %11
%29 = call float (...) @timeit()
store float %29, float* %9
%30 = load i64, i64* %7
%31 = uitofp i64 %30 to float
%32 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float %31)
%33 = load float, float* %9
%34 = load float, float* %6
%35 = fsub float %33, %34
%36 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), float %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Answer: %lld\0A\00"
@.str.1 = [12 x i8] c"Time: %.8f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call float (...) @timeit()
br label %4
4: ; preds = %2, %4
%5 = phi i64 [ 0, %2 ], [ %10, %4 ]
%6 = phi i64 [ 0, %2 ], [ %11, %4 ]
%7 = tail call i64 @is_prime(i64 %6)
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i64 0, i64 %6
%10 = add i64 %9, %5
%11 = add nuw nsw i64 %6, 1
%12 = icmp eq i64 %11, 2000000
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = tail call float (...) @timeit()
%15 = uitofp i64 %10 to float
%16 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float %15)
%17 = fsub float %14, %3
%18 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), float %17)
ret i32 0
}