#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 */
scalar_t__ errno;
int /*<<< orphan*/ error(scalar_t__, char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
long strtol(int /*<<< orphan*/, char **, int);
long readoptarg(const char *desc, long minval, long maxval) {
  long arg;
  char *ptr;
  arg = strtol(optarg, &ptr, 10);
  if (errno || *ptr != '\0' || arg < minval || arg > maxval) {
    error(errno, "invalid %s specified: `%s'", desc, optarg);
  }
  return arg;
}


x86 assembly (clang, -O0):
<readoptarg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e82(%rip),%rax
cmpq   $0x0,(%rax)
jne    118c <readoptarg+0x6c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    118c <readoptarg+0x6c>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jl     118c <readoptarg+0x6c>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    11af <readoptarg+0x8f>
mov    0x2e45(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rdx
mov    0x2e57(%rip),%rax
mov    (%rax),%ecx
lea    0xe56(%rip),%rsi
call   1040 <error@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readoptarg>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2ebb(%rip),%r13
mov    0x0(%r13),%edi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rbx
mov    0x2e7e(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     1186 <readoptarg+0x66>
mov    0x0(%r13),%ecx
lea    0xe93(%rip),%rsi
mov    %r14,%rdx
call   1040 <error@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1162 <readoptarg+0x42>
cmp    %r12,%rbx
jl     1162 <readoptarg+0x42>
cmp    %r15,%rbx
jle    1175 <readoptarg+0x55>
jmp    1162 <readoptarg+0x42>

LLVM IR (-O0):
@optarg = global i32 0
@errno = global i64 0
@.str = [27 x i8] c"invalid %s specified: `%s'\00"
define i64 @readoptarg(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i32, i32* @optarg
%10 = call i64 @strtol(i32 %9, i8** %8, i32 10)
store i64 %10, i64* %7
%11 = load i64, i64* @errno
%12 = icmp ne i64 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %3
%14 = load i8*, i8** %8
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %13
%19 = load i64, i64* %7
%20 = load i64, i64* %5
%21 = icmp slt i64 %19, %20
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i64, i64* %7
%24 = load i64, i64* %6
%25 = icmp sgt i64 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22, %18, %13, %3
%27 = load i64, i64* @errno
%28 = load i8*, i8** %4
%29 = load i32, i32* @optarg
%30 = call i32 @error(i64 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %28, i32 %29)
br label %31
31: ; preds = %26, %22
%32 = load i64, i64* %7
ret i64 %32
}

LLVM IR (-O2):
@optarg = global i32 0
@errno = global i64 0
@.str = [27 x i8] c"invalid %s specified: `%s'\00"
define i64 @readoptarg(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = load i32, i32* @optarg
%7 = call i64 @strtol(i32 %6, i8** %4, i32 10)
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
%14 = icmp slt i64 %7, %1
%15 = select i1 %13, i1 true, i1 %14
%16 = icmp sgt i64 %7, %2
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %21
18: ; preds = %10, %3
%19 = load i32, i32* @optarg
%20 = call i32 @error(i64 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %19)
br label %21
21: ; preds = %10, %18
ret i64 %7
}