#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
long findSumOfPrimes_limited(long *, int);
long *generateSieve();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  clock_t start, end;
  double computationTime;
  printf("Locating the sum of all primes below 2-million\n");
  printf("Generating Sieve\n");
  start = clock();
  long *sieve = generateSieve();
  printf("Locating nthPrime\n");
  long sumUpToNthPrime = findSumOfPrimes_limited(sieve, 2000000);
  end = clock();
  computationTime = (double)(end - start) / CLOCKS_PER_SEC;
  printf("Sum up to the nth prime is %ld in %f\n", sumUpToNthPrime,
         computationTime);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <generateSieve@plt>
mov    %rax,-0x30(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    $0x1e8480,%esi
call   1060 <findSumOfPrimes_limited@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e21(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x38(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
lea    0xe75(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <generateSieve@plt>
mov    %rax,%rbx
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x1e8480,%esi
call   1070 <findSumOfPrimes_limited@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e36(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe43(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Locating the sum of all primes below 2-million\0A\00"
@.str.1 = [18 x i8] c"Generating Sieve\0A\00"
@.str.2 = [19 x i8] c"Locating nthPrime\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [38 x i8] c"Sum up to the nth prime is %ld in %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca double
%9 = alloca i64*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 (...) @clock()
store i64 %13, i64* %6
%14 = call i64* (...) @generateSieve()
store i64* %14, i64** %9
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%16 = load i64*, i64** %9
%17 = call i64 @findSumOfPrimes_limited(i64* %16, i32 2000000)
store i64 %17, i64* %10
%18 = call i64 (...) @clock()
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = load i64, i64* %6
%21 = sub nsw i64 %19, %20
%22 = sitofp i64 %21 to double
%23 = load double, double* @CLOCKS_PER_SEC
%24 = fdiv double %22, %23
store double %24, double* %8
%25 = load i64, i64* %10
%26 = load double, double* %8
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i64 %25, double %26)
ret i32 1
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [38 x i8] c"Sum up to the nth prime is %ld in %f\0A\00"
@str = [47 x i8] c"Locating the sum of all primes below 2-million\00"
@str.4 = [17 x i8] c"Generating Sieve\00"
@str.5 = [18 x i8] c"Locating nthPrime\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
%5 = tail call i64 (...) @clock()
%6 = tail call i64* (...) @generateSieve()
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i64 @findSumOfPrimes_limited(i64* %6, i32 2000000)
%9 = tail call i64 (...) @clock()
%10 = sub nsw i64 %9, %5
%11 = sitofp i64 %10 to double
%12 = load double, double* @CLOCKS_PER_SEC
%13 = fdiv double %11, %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i64 %8, double %13)
ret i32 1
}