#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 *, unsigned long);
int main(int argc, const char *argv[]) {
  unsigned long sum = 0;
  for (int i = 2; i < 2000000; i++) {
    sum += IsPrime(i) != 0 ? i : 0;
  }
  printf("Sum is %li\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)
movq   $0x0,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
cmpl   $0x1e8480,-0x1c(%rbp)
jge    1194 <main+0x74>
mov    -0x1c(%rbp),%edi
call   1040 <IsPrime@plt>
cmp    $0x0,%rax
je     116f <main+0x4f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1179 <main+0x59>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    1179 <main+0x59>
mov    -0x20(%rbp),%eax
cltq
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <main+0x25>
mov    -0x18(%rbp),%rsi
lea    0xe61(%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 <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>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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