#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strncasecmp(char *, char *, int);
long strtol(char *, char **, int);
uint8_t argval(char *strval) {
  long intval;
  int base = 10;
  char *postfix;
  if (strncasecmp(strval, "0x", 2) == 0) {
    base = 16;
    strval += 2;
  } else if (*strval == '0') {
    base = 8;
  } else if (!*strval) {
    strval = "(empty)";
  }
  intval = strtol(strval, &postfix, base);
  if ((*postfix) || (intval < 0) || (intval > 255)) {
    fprintf(stderr,
            "Value error: Value %s should be an integer in the range 0x00 to "
            "0xff\n",
            strval);
    exit(1);
  }
  return (uint8_t)intval;
}


x86 assembly (clang, -O0):
<argval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xa,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    118a <argval+0x4a>
movl   $0x10,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    11c8 <argval+0x88>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11a6 <argval+0x66>
movl   $0x8,-0x14(%rbp)
jmp    11c3 <argval+0x83>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11be <argval+0x7e>
lea    0xe49(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c3 <argval+0x83>
jmp    11c8 <argval+0x88>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1040 <strtol@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1205 <argval+0xc5>
cmpq   $0x0,-0x10(%rbp)
jl     1205 <argval+0xc5>
cmpq   $0xff,-0x10(%rbp)
jle    1228 <argval+0xe8>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdf2(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argval>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xeb1(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     117d <argval+0x3d>
mov    (%rbx),%al
mov    $0x8,%edx
cmp    $0x30,%al
je     1186 <argval+0x46>
test   %al,%al
lea    0xe91(%rip),%rax
cmove  %rax,%rbx
mov    $0xa,%edx
jmp    1186 <argval+0x46>
add    $0x2,%rbx
mov    $0x10,%edx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <strtol@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    11b0 <argval+0x70>
test   %rax,%rax
js     11b0 <argval+0x70>
cmp    $0x100,%rax
jge    11b0 <argval+0x70>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@.str.1 = [8 x i8] c"(empty)\00"
@stderr = global i32 0
@.str.2 = [70 x i8] c"Value error: Value %s should be an integer in the range 0x00 to 0xff\0A\00"
define i32 @argval(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 10, i32* %4
%6 = load i8*, i8** %2
%7 = call i64 @strncasecmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
store i32 16, i32* %4
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 2
store i8* %11, i8** %2
br label %25
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 48
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 8, i32* %4
br label %24
18: ; preds = %12
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %23
23: ; preds = %22, %18
br label %24
24: ; preds = %23, %17
br label %25
25: ; preds = %24, %9
%26 = load i8*, i8** %2
%27 = load i32, i32* %4
%28 = call i64 @strtol(i8* %26, i8** %5, i32 %27)
store i64 %28, i64* %3
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %25
%34 = load i64, i64* %3
%35 = icmp slt i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i64, i64* %3
%38 = icmp sgt i64 %37, 255
br i1 %38, label %39, label %44
39: ; preds = %36, %33, %25
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %2
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %36
%45 = load i64, i64* %3
%46 = trunc i64 %45 to i32
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.1 = [8 x i8] c"(empty)\00"
@stderr = global i32 0
@.str.2 = [70 x i8] c"Value error: Value %s should be an integer in the range 0x00 to 0xff\0A\00"
define i32 @argval(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 2
br label %14
8: ; preds = %1
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 48
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = icmp eq i8 %9, 0
%13 = select i1 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0
br label %14
14: ; preds = %8, %11, %6
%15 = phi i8* [ %7, %6 ], [ %13, %11 ], [ %0, %8 ]
%16 = phi i32 [ 16, %6 ], [ 10, %11 ], [ 8, %8 ]
%17 = call i64 @strtol(i8* %15, i8** %2, i32 %16)
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
%21 = icmp slt i64 %17, 0
%22 = select i1 %20, i1 true, i1 %21
%23 = icmp sgt i64 %17, 255
%24 = select i1 %22, i1 true, i1 %23
br i1 %24, label %25, label %29
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %14
%30 = trunc i64 %17 to i32
ret i32 %30
}