#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__ prime(int);
int /*<<< orphan*/ printf(char *, long);
int main() {
  int i = 3;
  long int sum = 2;
  int max = 2000000;
  for (i = 3; i < max; i = i + 2) {
    if (prime(i)) {
      sum += i;
    }
  }
  printf("result is %ld\n", sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0x8(%rbp)
movq   $0x2,-0x10(%rbp)
movl   $0x1e8480,-0x14(%rbp)
movl   $0x3,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1189 <main+0x69>
mov    -0x8(%rbp),%edi
call   1040 <prime@plt>
cmp    $0x0,%rax
je     1176 <main+0x56>
movslq -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    117b <main+0x5b>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    114c <main+0x2c>
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x2,%r14d
mov    $0x3,%ebx
nop
mov    %ebx,%edi
call   1040 <prime@plt>
test   %rax,%rax
cmovne %rbx,%rax
add    %rax,%r14
lea    0x2(%rbx),%rax
cmp    $0x1e847e,%rbx
mov    %rax,%rbx
jb     1130 <main+0x10>
lea    0xea8(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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