#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 */
int /*<<< orphan*/ Eratosthenes(int);
int /*<<< orphan*/ allNum(char *);
int /*<<< orphan*/ printWord(int);
int /*<<< orphan*/ printerror(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int prime_gen(char *maxval) {
  int val = 0;
  allNum(maxval);
  sscanf(maxval, "%d", &val);
  if (val < 2 || val > 16777216) {
    printerror("out of maxval limit");
  }
  printWord(val);
  Eratosthenes(val);
  return 0;
}


x86 assembly (clang, -O0):
<prime_gen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <allNum@plt>
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <sscanf@plt>
cmpl   $0x2,-0xc(%rbp)
jl     1197 <prime_gen+0x47>
cmpl   $0x1000000,-0xc(%rbp)
jle    11a3 <prime_gen+0x53>
lea    0xe65(%rip),%rdi
call   1030 <printerror@plt>
mov    -0xc(%rbp),%edi
call   1050 <printWord@plt>
mov    -0xc(%rbp),%edi
call   1070 <Eratosthenes@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime_gen>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
call   1040 <allNum@plt>
lea    0xe94(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
mov    0xc(%rsp),%edi
lea    -0x1000001(%rdi),%eax
cmp    $0xff000000,%eax
ja     119a <prime_gen+0x4a>
lea    0xe72(%rip),%rdi
call   1030 <printerror@plt>
mov    0xc(%rsp),%edi
call   1050 <printWord@plt>
mov    0xc(%rsp),%edi
call   1070 <Eratosthenes@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [20 x i8] c"out of maxval limit\00"
define i32 @prime_gen(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = call i32 @allNum(i8* %4)
%6 = load i8*, i8** %2
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 2
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 16777216
br i1 %12, label %13, label %15
13: ; preds = %10, %1
%14 = call i32 @printerror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = load i32, i32* %3
%17 = call i32 @printWord(i32 %16)
%18 = load i32, i32* %3
%19 = call i32 @Eratosthenes(i32 %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [20 x i8] c"out of maxval limit\00"
define i32 @prime_gen(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = tail call i32 @allNum(i8* %0)
%5 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = add i32 %6, -16777217
%8 = icmp ult i32 %7, -16777215
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @printerror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* %2
br label %12
12: ; preds = %1, %9
%13 = phi i32 [ %6, %1 ], [ %11, %9 ]
%14 = call i32 @printWord(i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @Eratosthenes(i32 %15)
ret i32 0
}