#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 EXIT_SUCCESS;
scalar_t__ isPrime(int);
int /*<<< orphan*/ printf(char *, long);
int main(int argc, char *argv[]) {
  const int limit = 2e6;
  long sum = 0;
  int i;
  for (i = 2; i < limit; i++) {
    if (isPrime(i)) {
      sum += i;
    }
  }
  printf("Solution: %ld.\n", sum);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1e8480,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
cmpl   $0x1e8480,-0x24(%rbp)
jge    118a <main+0x6a>
mov    -0x24(%rbp),%edi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     1177 <main+0x57>
movslq -0x24(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    117c <main+0x5c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114c <main+0x2c>
mov    -0x20(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x2,%ebx
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %ebx,%edi
call   1040 <isPrime@plt>
test   %rax,%rax
cmovne %rbx,%rax
add    %rax,%r14
add    $0x1,%rbx
cmp    $0x1e8480,%rbx
jne    1130 <main+0x10>
lea    0xeab(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Solution: %ld.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2000000, i32* %6
store i64 0, i64* %7
store i32 2, i32* %8
br label %9
9: ; preds = %22, %2
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 2000000
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i32, i32* %8
%14 = call i64 @isPrime(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = load i64, i64* %7
%20 = add nsw i64 %19, %18
store i64 %20, i64* %7
br label %21
21: ; preds = %16, %12
br label %22
22: ; preds = %21
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
store i32 %24, i32* %8
br label %9
25: ; preds = %9
%26 = load i64, i64* %7
%27 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = load i32, i32* @EXIT_SUCCESS
ret i32 %28
}

LLVM IR (-O2):
@.str = [16 x i8] c"Solution: %ld.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i64 [ 2, %2 ], [ %11, %3 ]
%5 = phi i64 [ 0, %2 ], [ %10, %3 ]
%6 = trunc i64 %4 to i32
%7 = tail call i64 @isPrime(i32 %6)
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i64 0, i64 %4
%10 = add nuw nsw i64 %9, %5
%11 = add nuw nsw i64 %4, 1
%12 = icmp eq i64 %11, 2000000
br i1 %12, label %13, label %3
13: ; preds = %3
%14 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %10)
%15 = load i32, i32* @EXIT_SUCCESS
ret i32 %15
}