#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 */
int /*<<< orphan*/ free_prime();
int /*<<< orphan*/ generate_sieve(int);
int /*<<< orphan*/ is_composite(int);
int /*<<< orphan*/ printf(char *, int, unsigned long long);
void p010() {
  int target = 2000000;
  int i;
  unsigned long long sum = 0;
  generate_sieve(target);
  for (i = 0; i < target; i++) {
    if (!is_composite(i)) {
      sum += i;
    }
  }
  free_prime();
  printf("The sum of all primes below %d is %llu", target, sum);
}


x86 assembly (clang, -O0):
<p010>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1e8480,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <generate_sieve@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a2 <p010+0x62>
mov    -0x8(%rbp),%edi
call   1060 <is_composite@plt>
cmp    $0x0,%eax
jne    118f <p010+0x4f>
movslq -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1194 <p010+0x54>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1166 <p010+0x26>
mov    $0x0,%al
call   1030 <free_prime@plt>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p010>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1e8480,%edi
call   1040 <generate_sieve@plt>
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1060 <is_composite@plt>
test   %eax,%eax
mov    $0x0,%eax
cmove  %ebp,%eax
add    %rax,%rbx
add    $0x1,%ebp
cmp    $0x1e8480,%ebp
jne    1160 <p010+0x20>
xor    %eax,%eax
call   1030 <free_prime@plt>
lea    0xe73(%rip),%rdi
mov    $0x1e8480,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"The sum of all primes below %d is %llu\00"
define void @p010() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
store i32 2000000, i32* %1
store i64 0, i64* %3
%4 = load i32, i32* %1
%5 = call i32 @generate_sieve(i32 %4)
store i32 0, i32* %2
br label %6
6: ; preds = %20, %0
%7 = load i32, i32* %2
%8 = load i32, i32* %1
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %23
10: ; preds = %6
%11 = load i32, i32* %2
%12 = call i32 @is_composite(i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = load i64, i64* %3
%18 = add i64 %17, %16
store i64 %18, i64* %3
br label %19
19: ; preds = %14, %10
br label %20
20: ; preds = %19
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %6
23: ; preds = %6
%24 = call i32 (...) @free_prime()
%25 = load i32, i32* %1
%26 = load i64, i64* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %25, i64 %26)
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"The sum of all primes below %d is %llu\00"
define void @p010() {
%1 = tail call i32 @generate_sieve(i32 2000000)
br label %2
2: ; preds = %0, %2
%3 = phi i64 [ 0, %0 ], [ %9, %2 ]
%4 = phi i32 [ 0, %0 ], [ %10, %2 ]
%5 = tail call i32 @is_composite(i32 %4)
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i32 %4, i32 0
%8 = zext i32 %7 to i64
%9 = add i64 %3, %8
%10 = add nuw nsw i32 %4, 1
%11 = icmp eq i32 %10, 2000000
br i1 %11, label %12, label %2
12: ; preds = %2
%13 = tail call i32 (...) @free_prime()
%14 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 2000000, i64 %9)
ret void
}