#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 */
struct timeval {
  long long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ isPrime(long);
int /*<<< orphan*/ printf(char *, long long);
int main(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  long i = 3;
  long long sum = 2;
  for (; i <= 2000000; i += 2) {
    if (isPrime(i)) {
      sum += i;
    }
  }
  printf("the sum is: %lld", sum);
  gettimeofday(&stop, NULL);
  printf("\ntook %lu usec\n", stop.tv_usec - start.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movq   $0x3,-0x20(%rbp)
movq   $0x2,-0x28(%rbp)
cmpq   $0x1e8480,-0x20(%rbp)
jg     119f <main+0x6f>
mov    -0x20(%rbp),%rdi
call   1050 <isPrime@plt>
cmp    $0x0,%rax
je     1189 <main+0x59>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    118e <main+0x5e>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    115c <main+0x2c>
mov    -0x28(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rsi
sub    -0x18(%rbp),%rsi
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x2,%r14d
mov    $0x1,%ebx
xchg   %ax,%ax
add    $0x2,%rbx
mov    %rbx,%rdi
call   1050 <isPrime@plt>
test   %rax,%rax
cmovne %rbx,%rax
add    %rax,%r14
cmp    $0x1e847f,%rbx
jb     1150 <main+0x20>
lea    0xe8a(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x10(%rsp),%rsi
sub    0x8(%rsp),%rsi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [17 x i8] c"the sum is: %lld\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
store i64 3, i64* %4
store i64 2, i64* %5
br label %7
7: ; preds = %19, %0
%8 = load i64, i64* %4
%9 = icmp sle i64 %8, 2000000
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i64, i64* %4
%12 = call i64 @isPrime(i64 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i64, i64* %4
%16 = load i64, i64* %5
%17 = add nsw i64 %16, %15
store i64 %17, i64* %5
br label %18
18: ; preds = %14, %10
br label %19
19: ; preds = %18
%20 = load i64, i64* %4
%21 = add nsw i64 %20, 2
store i64 %21, i64* %4
br label %7
22: ; preds = %7
%23 = load i64, i64* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%27 = load i64, i64* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%29 = load i64, i64* %28
%30 = sub nsw i64 %27, %29
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %30)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [17 x i8] c"the sum is: %lld\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 2, %0 ], [ %12, %6 ]
%8 = phi i64 [ 3, %0 ], [ %13, %6 ]
%9 = tail call i64 @isPrime(i64 %8)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i64 0, i64 %8
%12 = add nuw nsw i64 %11, %7
%13 = add nuw nsw i64 %8, 2
%14 = icmp ult i64 %8, 1999999
br i1 %14, label %6, label %15
15: ; preds = %6
%16 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %12)
%17 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%21 = load i64, i64* %20
%22 = sub nsw i64 %19, %21
%23 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %22)
ret i32 0
}