#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 findNthPrime(int, long *);
long *generateSieve();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  clock_t begin, end;
  double time_spent;
  printf("Locating the 10,001st prime number\n");
  printf("Generating Sieve of size %d\n", 250000);
  begin = clock();
  long *sieve = generateSieve();
  end = clock();
  double time_Spent_Generating = (double)(end - begin) / CLOCKS_PER_SEC;
  begin = clock();
  long nthPrime = findNthPrime(10001, sieve);
  end = clock();
  double time_Spent_Locating = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("It took %f seconds to generate the sieve\n", time_Spent_Generating);
  printf("It took %f seconds to locate the 10,001st prime\n",
         time_Spent_Locating);
  printf("The total CPU time is %f\n",
         time_Spent_Generating + time_Spent_Locating);
  printf("The 10,001st prime number is %lu\n", nthPrime);
  return nthPrime;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    0xeb9(%rip),%rdi
mov    $0x3d090,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <generateSieve@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e3c(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rsi
mov    $0x2711,%edi
call   1050 <findNthPrime@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2df7(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xe3b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x48(%rbp),%xmm0
lea    0xe52(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
lea    0xe6b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xf54(%rip),%rdi
call   1030 <puts@plt>
lea    0xe94(%rip),%rdi
mov    $0x3d090,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <generateSieve@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e46(%rip),%r15
divsd  (%r15),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
mov    $0x2711,%edi
mov    %r14,%rsi
call   1060 <findNthPrime@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
movsd  %xmm0,(%rsp)
lea    0xe33(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe49(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
movsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
lea    0xe5c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe68(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Locating the 10,001st prime number\0A\00"
@.str.1 = [29 x i8] c"Generating Sieve of size %d\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [42 x i8] c"It took %f seconds to generate the sieve\0A\00"
@.str.3 = [49 x i8] c"It took %f seconds to locate the 10,001st prime\0A\00"
@.str.4 = [26 x i8] c"The total CPU time is %f\0A\00"
@.str.5 = [34 x i8] c"The 10,001st prime number is %lu\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 double
%11 = alloca i64
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 250000)
%15 = call i64 (...) @clock()
store i64 %15, i64* %6
%16 = call i64* (...) @generateSieve()
store i64* %16, i64** %9
%17 = call i64 (...) @clock()
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = load i64, i64* %6
%20 = sub nsw i64 %18, %19
%21 = sitofp i64 %20 to double
%22 = load double, double* @CLOCKS_PER_SEC
%23 = fdiv double %21, %22
store double %23, double* %10
%24 = call i64 (...) @clock()
store i64 %24, i64* %6
%25 = load i64*, i64** %9
%26 = call i64 @findNthPrime(i32 10001, i64* %25)
store i64 %26, i64* %11
%27 = call i64 (...) @clock()
store i64 %27, i64* %7
%28 = load i64, i64* %7
%29 = load i64, i64* %6
%30 = sub nsw i64 %28, %29
%31 = sitofp i64 %30 to double
%32 = load double, double* @CLOCKS_PER_SEC
%33 = fdiv double %31, %32
store double %33, double* %12
%34 = load double, double* %10
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), double %34)
%36 = load double, double* %12
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), double %36)
%38 = load double, double* %10
%39 = load double, double* %12
%40 = fadd double %38, %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), double %40)
%42 = load i64, i64* %11
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i64 %42)
%44 = load i64, i64* %11
%45 = trunc i64 %44 to i32
ret i32 %45
}

LLVM IR (-O2):
@.str.1 = [29 x i8] c"Generating Sieve of size %d\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [42 x i8] c"It took %f seconds to generate the sieve\0A\00"
@.str.3 = [49 x i8] c"It took %f seconds to locate the 10,001st prime\0A\00"
@.str.4 = [26 x i8] c"The total CPU time is %f\0A\00"
@.str.5 = [34 x i8] c"The 10,001st prime number is %lu\0A\00"
@str = [35 x i8] c"Locating the 10,001st prime number\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 250000)
%5 = tail call i64 (...) @clock()
%6 = tail call i64* (...) @generateSieve()
%7 = tail call i64 (...) @clock()
%8 = sub nsw i64 %7, %5
%9 = sitofp i64 %8 to double
%10 = load double, double* @CLOCKS_PER_SEC
%11 = fdiv double %9, %10
%12 = tail call i64 (...) @clock()
%13 = tail call i64 @findNthPrime(i32 10001, i64* %6)
%14 = tail call i64 (...) @clock()
%15 = sub nsw i64 %14, %12
%16 = sitofp i64 %15 to double
%17 = load double, double* @CLOCKS_PER_SEC
%18 = fdiv double %16, %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), double %11)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), double %18)
%21 = fadd double %11, %18
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), double %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i64 %13)
%24 = trunc i64 %13 to i32
ret i32 %24
}