#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 is_prime(unsigned long);
unsigned long solution2() {
  unsigned long n, total;
  total = 5;
  n = 5;
  while (n <= 2000000) {
    if (is_prime(n) == 1) {
      total = total + n;
    }
    n = n + 2;
    if (n <= 2000000 && is_prime(n) == 1) {
      total = total + n;
    }
    n = n + 4;
  }
  return total;
}


x86 assembly (clang, -O0):
<solution2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x5,-0x10(%rbp)
movq   $0x5,-0x8(%rbp)
cmpq   $0x1e8480,-0x8(%rbp)
ja     119d <solution2+0x8d>
mov    -0x8(%rbp),%rdi
call   1030 <is_prime@plt>
cmp    $0x1,%eax
jne    1154 <solution2+0x44>
mov    -0x10(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x1e8480,-0x8(%rbp)
ja     118c <solution2+0x7c>
mov    -0x8(%rbp),%rdi
call   1030 <is_prime@plt>
cmp    $0x1,%eax
jne    118c <solution2+0x7c>
mov    -0x10(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    1128 <solution2+0x18>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solution2>:
push   %r15
push   %r14
push   %rbx
mov    $0x5,%r14d
mov    $0x5,%ebx
jmp    1143 <solution2+0x33>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %r15,%r14
lea    0x6(%rbx),%rax
cmp    $0x1e847b,%rbx
mov    %rax,%rbx
jae    116e <solution2+0x5e>
mov    %rbx,%rdi
call   1030 <is_prime@plt>
mov    %rbx,%rcx
cmp    $0x1,%eax
je     1155 <solution2+0x45>
xor    %ecx,%ecx
add    %rcx,%r14
lea    0x2(%rbx),%r15
mov    %r15,%rdi
call   1030 <is_prime@plt>
cmp    $0x1,%eax
je     1130 <solution2+0x20>
xor    %r15d,%r15d
jmp    1130 <solution2+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @solution2() {
%1 = alloca i64
%2 = alloca i64
store i64 5, i64* %2
store i64 5, i64* %1
br label %3
3: ; preds = %27, %0
%4 = load i64, i64* %1
%5 = icmp ule i64 %4, 2000000
br i1 %5, label %6, label %30
6: ; preds = %3
%7 = load i64, i64* %1
%8 = call i32 @is_prime(i64 %7)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i64, i64* %2
%12 = load i64, i64* %1
%13 = add i64 %11, %12
store i64 %13, i64* %2
br label %14
14: ; preds = %10, %6
%15 = load i64, i64* %1
%16 = add i64 %15, 2
store i64 %16, i64* %1
%17 = load i64, i64* %1
%18 = icmp ule i64 %17, 2000000
br i1 %18, label %19, label %27
19: ; preds = %14
%20 = load i64, i64* %1
%21 = call i32 @is_prime(i64 %20)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i64, i64* %2
%25 = load i64, i64* %1
%26 = add i64 %24, %25
store i64 %26, i64* %2
br label %27
27: ; preds = %23, %19, %14
%28 = load i64, i64* %1
%29 = add i64 %28, 4
store i64 %29, i64* %1
br label %3
30: ; preds = %3
%31 = load i64, i64* %2
ret i64 %31
}

LLVM IR (-O2):
define i64 @solution2() {
br label %1
1: ; preds = %0, %1
%2 = phi i64 [ 5, %0 ], [ %12, %1 ]
%3 = phi i64 [ 5, %0 ], [ %13, %1 ]
%4 = tail call i32 @is_prime(i64 %3)
%5 = add nuw nsw i64 %3, 2
%6 = icmp eq i32 %4, 1
%7 = select i1 %6, i64 %3, i64 0
%8 = add i64 %7, %2
%9 = tail call i32 @is_prime(i64 %5)
%10 = icmp eq i32 %9, 1
%11 = select i1 %10, i64 %5, i64 0
%12 = add i64 %11, %8
%13 = add nuw nsw i64 %3, 6
%14 = icmp ult i64 %3, 1999995
br i1 %14, label %1, label %15
15: ; preds = %1
ret i64 %12
}