#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__ check_prime(unsigned long long);
int /*<<< orphan*/ printf(char *, unsigned long long, unsigned long long,
                          unsigned long long);
int main() {
  unsigned long long int i, c = 0, sum = 0;
  for (i = 1; i <= 2000000LL; i++) {
    if (check_prime(i)) {
      c += 1;
      sum += i;
    }
  }
  printf("\nSum = %llu, count = %llu, i = %llu", sum, c, i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x1,-0x10(%rbp)
cmpq   $0x1e8480,-0x10(%rbp)
ja     1196 <main+0x76>
mov    -0x10(%rbp),%rdi
call   1030 <check_prime@plt>
cmp    $0x0,%rax
je     1180 <main+0x60>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1185 <main+0x65>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1147 <main+0x27>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x1,%ebx
xor    %r14d,%r14d
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1030 <check_prime@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
cmovne %rbx,%rax
add    %rcx,%r15
add    %rax,%r14
add    $0x1,%rbx
cmp    $0x1e8481,%rbx
jne    1130 <main+0x10>
lea    0xea2(%rip),%rdi
mov    $0x1e8481,%ecx
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [36 x i8] c"\0ASum = %llu, count = %llu, i = %llu\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i64 [ 0, %0 ], [ %11, %1 ]
%3 = phi i64 [ 0, %0 ], [ %9, %1 ]
%4 = phi i64 [ 1, %0 ], [ %12, %1 ]
%5 = tail call i64 @check_prime(i64 %4)
%6 = icmp eq i64 %5, 0
%7 = xor i1 %6, true
%8 = zext i1 %7 to i64
%9 = add i64 %3, %8
%10 = select i1 %6, i64 0, i64 %4
%11 = add i64 %10, %2
%12 = add nuw nsw i64 %4, 1
%13 = icmp eq i64 %12, 2000001
br i1 %13, label %14, label %1
14: ; preds = %1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i64 %11, i64 %9, i64 2000001)
ret i32 0
}