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

/* Variables and functions */
scalar_t__ ERANGE;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ LONG_MAX;
scalar_t__ LONG_MIN;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strtol(char *, char **, int);
uint16_t input(void) {
  char input[16], *endptr;
  uint16_t q;
  if (fgets(input, 16, stdin) == NULL)
    exit(EXIT_FAILURE);
  errno = 0;
  q = (uint16_t)strtol(input, &endptr, 10);
  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    $0x20,%rsp
lea    -0x10(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
jne    1187 <input+0x37>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e2a(%rip),%rax
movq   $0x0,(%rax)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%rax
mov    0x2e1c(%rip),%rcx
cmp    (%rcx),%rax
jne    11ed <input+0x9d>
mov    -0x20(%rbp),%rax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%rax
je     1209 <input+0xb9>
mov    -0x20(%rbp),%rax
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%rax
je     1209 <input+0xb9>
mov    0x2dc4(%rip),%rax
cmpq   $0x0,(%rax)
je     1223 <input+0xd3>
cmpq   $0x0,-0x20(%rbp)
jne    1223 <input+0xd3>
lea    0xdf0(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
lea    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jne    1257 <input+0x107>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     1200 <input+0xb0>
mov    0x2e39(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    (%rbx),%rcx
mov    0x2e31(%rip),%rdx
cmp    (%rdx),%rcx
jne    11c4 <input+0x74>
mov    0x2e0d(%rip),%rdx
cmp    (%rdx),%rax
je     11dd <input+0x8d>
mov    0x2e21(%rip),%rdx
cmp    (%rdx),%rax
je     11dd <input+0x8d>
test   %rcx,%rcx
je     11ce <input+0x7e>
test   %rax,%rax
je     11dd <input+0x8d>
cmp    %r14,0x8(%rsp)
je     11eb <input+0x9b>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1c(%rip),%rdi
call   1060 <perror@plt>
jmp    1200 <input+0xb0>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

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