#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__ isprime(int);
int /*<<< orphan*/ printf(char *, int, unsigned long long, ...);
int /*<<< orphan*/ system(char *);
int main(void) {
  int i, limit = 2000000;
  unsigned long long int sum = 0;
  for (i = 2; i < limit; i++)
    if (isprime(i)) {
      sum += i;
      printf("i = %d || sum = %llu\n", i, sum);
    }
  printf("Sum of primes up to %d: %llu\n", limit, sum, sum);
  system("PAUSE");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1e8480,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a7 <main+0x77>
mov    -0x8(%rbp),%edi
call   1050 <isprime@plt>
cmp    $0x0,%rax
je     1194 <main+0x64>
movslq -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1199 <main+0x69>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1155 <main+0x25>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6d(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x2,%ebx
lea    0xebf(%rip),%r15
xor    %r14d,%r14d
jmp    115d <main+0x2d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x1e8480,%rbx
je     117d <main+0x4d>
mov    %ebx,%edi
call   1050 <isprime@plt>
test   %rax,%rax
je     1150 <main+0x20>
add    %rbx,%r14
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1150 <main+0x20>
lea    0xe92(%rip),%rdi
mov    $0x1e8480,%esi
mov    %r14,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [22 x i8] c"i = %d || sum = %llu\0A\00"
@.str.1 = [30 x i8] c"Sum of primes up to %d: %llu\0A\00"
@.str.2 = [6 x i8] c"PAUSE\00"
define i32 @main() {
br label %1
1: ; preds = %0, %10
%2 = phi i64 [ 2, %0 ], [ %12, %10 ]
%3 = phi i64 [ 0, %0 ], [ %11, %10 ]
%4 = trunc i64 %2 to i32
%5 = tail call i64 @isprime(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = add i64 %3, %2
%9 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %4, i64 %8)
br label %10
10: ; preds = %1, %7
%11 = phi i64 [ %8, %7 ], [ %3, %1 ]
%12 = add nuw nsw i64 %2, 1
%13 = icmp eq i64 %12, 2000000
br i1 %13, label %14, label %1
14: ; preds = %10
%15 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 2000000, i64 %11, i64 %11)
%16 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}