#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 int uint16_t;

/* Variables and functions */
scalar_t__ ERANGE;
int /*<<< orphan*/ EXIT_FAILURE;
int LONG_MAX;
int LONG_MIN;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int const, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strtol(char *, char **, int const);
uint16_t input(void) {
  const uint16_t inp_size = 10;
  char input[inp_size], *endptr;
  assert(fgets(input, inp_size, stdin));
  errno = 0;
  uint16_t q = (uint16_t)strtol(input, &endptr, inp_size);
  if ((errno == ERANGE && (q == LONG_MAX || q == LONG_MIN)) ||
      (errno != 0 && q == 0)) {
    perror("strtol");
    exit(EXIT_FAILURE);
  }
  if (endptr == input) {
    fprintf(stderr, "No digits were found\n");
    exit(EXIT_FAILURE);
  }
  return q;
}


x86 assembly (clang, -O0):
<input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0xa,-0x4(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1030 <fgets@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    0x2e1d(%rip),%rax
movq   $0x0,(%rax)
lea    -0x30(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%rax
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%rax
jne    11f5 <input+0x95>
mov    -0x1c(%rbp),%eax
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%eax
je     1210 <input+0xb0>
mov    -0x1c(%rbp),%eax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%eax
je     1210 <input+0xb0>
mov    0x2dbc(%rip),%rax
cmpq   $0x0,(%rax)
je     122a <input+0xca>
cmpl   $0x0,-0x1c(%rbp)
jne    122a <input+0xca>
lea    0xde9(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x30(%rbp),%rax
cmp    %rax,-0x18(%rbp)
jne    125b <input+0xfb>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xa,%esi
call   1030 <fgets@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    0x2e28(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    (%rbx),%rcx
mov    0x2e25(%rip),%rdx
cmp    (%rdx),%rcx
jne    11ce <input+0x6e>
mov    0x2e01(%rip),%rdx
cmp    (%rdx),%eax
je     11e6 <input+0x86>
mov    0x2e16(%rip),%rdx
cmp    (%rdx),%eax
je     11e6 <input+0x86>
test   %rcx,%rcx
je     11d7 <input+0x77>
test   %eax,%eax
je     11e6 <input+0x86>
cmp    %r14,0x8(%rsp)
je     11f4 <input+0x94>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe13(%rip),%rdi
call   1070 <perror@plt>
jmp    1209 <input+0xa9>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i32 0
@LONG_MIN = global i32 0
@.str = [7 x i8] c"strtol\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"No digits were found\0A\00"
define i32 @input() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i32 10, i32* %1
%5 = call i8* @llvm.stacksave()
store i8* %5, i8** %2
%6 = alloca i8, i64 10
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 10, i32 %7)
%9 = call i32 @assert(i32 %8)
store i64 0, i64* @errno
%10 = call i32 @strtol(i8* %6, i8** %3, i32 10)
store i32 %10, i32* %4
%11 = load i64, i64* @errno
%12 = load i64, i64* @ERANGE
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %0
%15 = load i32, i32* %4
%16 = load i32, i32* @LONG_MAX
%17 = icmp eq i32 %15, %16
br i1 %17, label %28, label %18
18: ; preds = %14
%19 = load i32, i32* %4
%20 = load i32, i32* @LONG_MIN
%21 = icmp eq i32 %19, %20
br i1 %21, label %28, label %22
22: ; preds = %18, %0
%23 = load i64, i64* @errno
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25, %18, %14
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %25, %22
%33 = load i8*, i8** %3
%34 = icmp eq i8* %33, %6
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %32
%41 = load i32, i32* %4
%42 = load i8*, i8** %2
ret i32 %41
}

LLVM IR (-O2):
@stdin = global i32 0
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i32 0
@LONG_MIN = global i32 0
@.str = [7 x i8] c"strtol\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"No digits were found\0A\00"
define i32 @input() {
%1 = alloca i8*
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = bitcast i8** %1 to i8*
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %3, i32 10, i32 %5)
%7 = call i32 @assert(i32 %6)
store i64 0, i64* @errno
%8 = call i32 @strtol(i8* %3, i8** %1, i32 10)
%9 = load i64, i64* @errno
%10 = load i64, i64* @ERANGE
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %0
%13 = load i32, i32* @LONG_MAX
%14 = icmp eq i32 %8, %13
%15 = load i32, i32* @LONG_MIN
%16 = icmp eq i32 %8, %15
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %22, label %18
18: ; preds = %12, %0
%19 = icmp ne i64 %9, 0
%20 = icmp eq i32 %8, 0
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %22, label %26
22: ; preds = %18, %12
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %18
%27 = load i8*, i8** %1
%28 = icmp eq i8* %27, %3
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %26
ret i32 %8
}