#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(int);
int /*<<< orphan*/ printf(char *, unsigned long long);
int main(int argc, char *argv[]) {
  int num = 1;
  unsigned long long sum = 0;
  while (true) {
    ++num;
    if (num >= 2000000)
      break;
    if (is_prime(num))
      sum += (unsigned long long)num;
  }
  printf("Sum: %llu\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1e8480,-0x14(%rbp)
jl     1160 <main+0x40>
jmp    1183 <main+0x63>
mov    -0x14(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     117e <main+0x5e>
movslq -0x14(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1145 <main+0x25>
mov    -0x20(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%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 <is_prime@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>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"Sum: %llu\0A\00"
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 @is_prime(i32 %6)
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i64 0, i64 %4
%10 = add 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 ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 %10)
ret i32 0
}