#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;
int ask_number();
scalar_t__ clock();
int /*<<< orphan*/ init_array(int *, int);
int /*<<< orphan*/ print_primes(int *, int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sieve_eratosthene(int *, int);
int main(void) {
  clock_t tic = clock();
  int i, j;
  int value = ask_number();
  int prime[value];
  init_array(prime, value);
  sieve_eratosthene(prime, value);
  print_primes(prime, value);
  clock_t toc = clock();
  printf("elapsed: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %al,-0x41(%rbp)
call   1040 <clock@plt>
mov    %rax,%rcx
mov    -0x41(%rbp),%al
mov    %rcx,-0x10(%rbp)
call   1070 <ask_number@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%esi
call   1060 <init_array@plt>
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <sieve_eratosthene@plt>
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <print_primes@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2df7(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe04(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <ask_number@plt>
mov    %eax,%r15d
mov    %eax,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15d,%esi
call   1060 <init_array@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1080 <sieve_eratosthene@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <print_primes@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e1c(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"elapsed: %f seconds\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
%9 = call i64 (...) @clock()
store i64 %9, i64* %2
%10 = call i32 (...) @ask_number()
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i32, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* %5
%16 = call i32 @init_array(i32* %14, i32 %15)
%17 = load i32, i32* %5
%18 = call i32 @sieve_eratosthene(i32* %14, i32 %17)
%19 = load i32, i32* %5
%20 = call i32 @print_primes(i32* %14, i32 %19)
%21 = call i64 (...) @clock()
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = load i64, i64* %2
%24 = sub nsw i64 %22, %23
%25 = sitofp i64 %24 to double
%26 = load double, double* @CLOCKS_PER_SEC
%27 = fdiv double %25, %26
%28 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %27)
store i32 0, i32* %1
%29 = load i8*, i8** %6
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [21 x i8] c"elapsed: %f seconds\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main() {
%1 = tail call i64 (...) @clock()
%2 = tail call i32 (...) @ask_number()
%3 = zext i32 %2 to i64
%4 = alloca i32, i64 %3
%5 = call i32 @init_array(i32* %4, i32 %2)
%6 = call i32 @sieve_eratosthene(i32* %4, i32 %2)
%7 = call i32 @print_primes(i32* %4, i32 %2)
%8 = call i64 (...) @clock()
%9 = sub nsw i64 %8, %1
%10 = sitofp i64 %9 to double
%11 = load double, double* @CLOCKS_PER_SEC
%12 = fdiv double %10, %11
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %12)
ret i32 0
}