#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__ u_long;
typedef scalar_t__ u_int;

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ errx(int, char *, char const *, char const *);
scalar_t__ strtoul(char const *, char **, int /*<<< orphan*/);
u_int argtou(const char *arg, u_int lo, u_int hi, const char *msg) {
  char *s;
  u_long x;
  errno = 0;
  x = strtoul(arg, &s, 0);
  if (errno || !*arg || *s || x < lo || x > hi)
    errx(1, "%s: bad %s", arg, msg);
  return x;
}


x86 assembly (clang, -O0):
<argtou>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2ea1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e80(%rip),%rax
cmpq   $0x0,(%rax)
jne    11a3 <argtou+0x83>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a3 <argtou+0x83>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a3 <argtou+0x83>
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jl     11a3 <argtou+0x83>
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    11bc <argtou+0x9c>
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%edi
lea    0xe49(%rip),%rsi
call   1030 <errx@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argtou>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
mov    0x2ea2(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,%r15
cmpq   $0x0,0x0(%rbp)
je     1183 <argtou+0x63>
lea    0xe9f(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <errx@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpb   $0x0,(%rbx)
je     115a <argtou+0x3a>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    115a <argtou+0x3a>
cmp    %r13,%r15
jl     115a <argtou+0x3a>
cmp    %r12,%r15
jle    1171 <argtou+0x51>
jmp    115a <argtou+0x3a>

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

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