#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 */
unsigned int atoi(char *);
double elapsed_time();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(unsigned int *);
int /*<<< orphan*/ initialize_timer();
scalar_t__ malloc(int);
int /*<<< orphan*/ prep_list(unsigned int **, unsigned int *);
int /*<<< orphan*/ print_primes(unsigned int **, unsigned int *, double *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sieve(unsigned int **, unsigned int *);
int /*<<< orphan*/ start_timer();
int /*<<< orphan*/ stop_timer();
int main(int argc, char *argv[]) {
  unsigned int N, i;
  unsigned int *list;
  double time;
  N = i = 0;
  time = 0.0;
  list = NULL;
  if (argc != 2) {
    printf("Usage: %s <N> where N > 2\n", argv[0]);
    exit(1);
  }
  N = atoi(argv[1]);
  if (N <= 2) {
    printf("Usage: %s <N> where N > 2\n", argv[0]);
    exit(1);
  }
  list = (unsigned int *)malloc(sizeof(unsigned int) * (N + 1));
  if (list == NULL) {
    printf("Could not allocate head memory. Fail.\n");
    exit(2);
  }
  prep_list(&list, &N);
  initialize_timer();
  start_timer();
  sieve(&list, &N);
  stop_timer();
  time = elapsed_time();
  print_primes(&list, &N, &time);
  free(list);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     121d <main+0x5d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
ja     1256 <main+0x96>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1290 <main+0xd0>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
lea    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   10a0 <prep_list@plt>
mov    $0x0,%al
call   1060 <initialize_timer@plt>
mov    $0x0,%al
call   10b0 <start_timer@plt>
lea    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <sieve@plt>
mov    $0x0,%al
call   10d0 <stop_timer@plt>
mov    $0x0,%al
call   1040 <elapsed_time@plt>
movsd  %xmm0,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <print_primes@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1279 <main+0xa9>
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,0x4(%rsp)
cmp    $0x2,%eax
jbe    1279 <main+0xa9>
lea    0x4(,%rax,4),%edi
call   10a0 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1294 <main+0xc4>
lea    0x8(%rsp),%rbx
lea    0x4(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <prep_list@plt>
xor    %eax,%eax
call   1070 <initialize_timer@plt>
xor    %eax,%eax
call   10c0 <start_timer@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <sieve@plt>
xor    %eax,%eax
call   10e0 <stop_timer@plt>
xor    %eax,%eax
call   1050 <elapsed_time@plt>
movsd  %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <print_primes@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rbx),%rsi
lea    0xd7d(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd80(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Usage: %s <N> where N > 2\0A\00"
@.str.1 = [39 x i8] c"Could not allocate head memory. Fail.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %6
store double 0.000000e+00, double* %9
store i32* null, i32** %8
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp ule i32 %23, 2
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %18
%32 = load i32, i32* %6
%33 = add i32 %32, 1
%34 = zext i32 %33 to i64
%35 = mul i64 4, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i32*
store i32* %38, i32** %8
%39 = load i32*, i32** %8
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %31
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 2)
unreachable
44: ; preds = %31
%45 = call i32 @prep_list(i32** %8, i32* %6)
%46 = call i32 (...) @initialize_timer()
%47 = call i32 (...) @start_timer()
%48 = call i32 @sieve(i32** %8, i32* %6)
%49 = call i32 (...) @stop_timer()
%50 = call double (...) @elapsed_time()
store double %50, double* %9
%51 = call i32 @print_primes(i32** %8, i32* %6, double* %9)
%52 = load i32*, i32** %8
%53 = call i32 @free(i32* %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Usage: %s <N> where N > 2\0A\00"
@str = [38 x i8] c"Could not allocate head memory. Fail.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca double
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32** %4 to i8*
%8 = bitcast double* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
store i32 %17, i32* %3
%18 = icmp ult i32 %17, 3
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i8*, i8** %1
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = shl i32 %17, 2
%25 = add i32 %24, 4
%26 = tail call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i32*
store i32* %27, i32** %4
%28 = icmp eq i64 %26, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%31 = tail call i32 @exit(i32 2)
unreachable
32: ; preds = %23
%33 = call i32 @prep_list(i32** %4, i32* %3)
%34 = call i32 (...) @initialize_timer()
%35 = call i32 (...) @start_timer()
%36 = call i32 @sieve(i32** %4, i32* %3)
%37 = call i32 (...) @stop_timer()
%38 = call double (...) @elapsed_time()
store double %38, double* %5
%39 = call i32 @print_primes(i32** %4, i32* %3, double* %5)
%40 = load i32*, i32** %4
%41 = call i32 @free(i32* %40)
ret i32 0
}