#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 */
long INT_MAX;
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sieve(int, int *);
long strtol(char *, char **, int);
int main(int argc, char **argv) {
  char *p;
  int num = 0;
  long conv = strtol(argv[1], &p, 10);
  if (errno != 0 || *p != '\0' || conv > INT_MAX) {
    printf("\nconversion to long has failed.\n");
    return (-1);
  } else {
    num = conv;
    printf("\nmax number is %d", num);
  }
  bool primes[num];
  for (int i = 0; i < num; i++) {
    primes[i] = true;
  }
  sieve(num, primes);
  return 0;
}


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)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e6a(%rip),%rax
cmpq   $0x0,(%rax)
jne    119c <main+0x6c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119c <main+0x6c>
mov    -0x28(%rbp),%rax
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%rax
jle    11b6 <main+0x86>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <main+0x10f>
mov    -0x28(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1225 <main+0xf5>
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11fc <main+0xcc>
mov    -0x48(%rbp),%rsi
mov    -0x1c(%rbp),%edi
call   1040 <sieve@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%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
mov    0x8(%rsi),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
mov    0x2e72(%rip),%rax
cmpq   $0x0,(%rax)
je     118c <main+0x4c>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    116c <main+0x2c>
mov    0x2e4c(%rip),%rax
cmp    (%rax),%rbx
jg     116c <main+0x2c>
lea    0xe68(%rip),%rdi
xor    %r14d,%r14d
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%r15
mov    %ebx,%eax
mov    %rsp,%rsi
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rsi
mov    %rsi,%rsp
test   %ebx,%ebx
jle    1230 <main+0xf0>
mov    %ebx,%eax
cmp    $0x8,%rax
jae    11de <main+0x9e>
xor    %ecx,%ecx
jmp    1220 <main+0xe0>
mov    %ebx,%edx
and    $0x7,%edx
mov    %rax,%rcx
sub    %rdx,%rcx
xor    %edi,%edi
movaps 0xe0e(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movaps %xmm0,(%rsi,%rdi,4)
movaps %xmm0,0x10(%rsi,%rdi,4)
add    $0x8,%rdi
cmp    %rdi,%rcx
jne    1200 <main+0xc0>
test   %rdx,%rdx
je     1230 <main+0xf0>
nopw   0x0(%rax,%rax,1)
movl   $0x1,(%rsi,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1220 <main+0xe0>
mov    %ebx,%edi
call   1050 <sieve@plt>
mov    %r15,%rsp
jmp    117e <main+0x3e>

LLVM IR (-O0):
@errno = global i64 0
@INT_MAX = global i64 0
@.str = [33 x i8] c"\0Aconversion to long has failed.\0A\00"
@.str.1 = [18 x i8] c"\0Amax number is %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strtol(i8* %14, i8** %6, i32 10)
store i64 %15, i64* %8
%16 = load i64, i64* @errno
%17 = icmp ne i64 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %18
%24 = load i64, i64* %8
%25 = load i64, i64* @INT_MAX
%26 = icmp sgt i64 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23, %18, %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %54
29: ; preds = %23
%30 = load i64, i64* %8
%31 = trunc i64 %30 to i32
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %29
%35 = load i32, i32* %7
%36 = zext i32 %35 to i64
%37 = call i8* @llvm.stacksave()
store i8* %37, i8** %9
%38 = alloca i32, i64 %36
store i64 %36, i64* %10
store i32 0, i32* %11
br label %39
39: ; preds = %47, %34
%40 = load i32, i32* %11
%41 = load i32, i32* %7
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %38, i64 %45
store i32 1, i32* %46
br label %47
47: ; preds = %43
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %39
50: ; preds = %39
%51 = load i32, i32* %7
%52 = call i32 @sieve(i32 %51, i32* %38)
store i32 0, i32* %3
%53 = load i8*, i8** %9
br label %54
54: ; preds = %50, %27
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@errno = global i64 0
@INT_MAX = global i64 0
@.str.1 = [18 x i8] c"\0Amax number is %d\00"
@str = [32 x i8] c"\0Aconversion to long has failed.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i64 @strtol(i8* %6, i8** %3, i32 10)
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
%14 = load i64, i64* @INT_MAX
%15 = icmp sgt i64 %7, %14
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %17, label %19
17: ; preds = %10, %2
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %51
19: ; preds = %10
%20 = trunc i64 %7 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = and i64 %7, 4294967295
%23 = tail call i8* @llvm.stacksave()
%24 = alloca i32, i64 %22
%25 = icmp sgt i32 %20, 0
br i1 %25, label %26, label %44
26: ; preds = %19
%27 = and i64 %7, 4294967295
%28 = icmp ult i64 %27, 8
br i1 %28, label %42, label %29
29: ; preds = %26
%30 = and i64 %7, 7
%31 = sub nsw i64 %27, %30
br label %32
32: ; preds = %32, %29
%33 = phi i64 [ 0, %29 ], [ %38, %32 ]
%34 = getelementptr inbounds i32, i32* %24, i64 %33
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %35
%36 = getelementptr inbounds i32, i32* %34, i64 4
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %37
%38 = add nuw i64 %33, 8
%39 = icmp eq i64 %38, %31
br i1 %39, label %40, label %32
40: ; preds = %32
%41 = icmp eq i64 %30, 0
br i1 %41, label %44, label %42
42: ; preds = %26, %40
%43 = phi i64 [ 0, %26 ], [ %31, %40 ]
br label %46
44: ; preds = %46, %40, %19
%45 = call i32 @sieve(i32 %20, i32* %24)
br label %51
46: ; preds = %42, %46
%47 = phi i64 [ %49, %46 ], [ %43, %42 ]
%48 = getelementptr inbounds i32, i32* %24, i64 %47
store i32 1, i32* %48
%49 = add nuw nsw i64 %47, 1
%50 = icmp eq i64 %49, %27
br i1 %50, label %44, label %46
51: ; preds = %44, %17
%52 = phi i32 [ -1, %17 ], [ 0, %44 ]
ret i32 %52
}