#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 */
int atoi(char const *);
int strtoul(char const *, int /*<<< orphan*/ *, int);
scalar_t__ verify_hex(char const *);
scalar_t__ verify_int(char const *);
int verify_u8(const char *buffer) {
  int retval = -1;
  if (verify_hex(buffer)) {
    retval = strtoul(buffer + 2, NULL, 16);
  } else if (verify_int(buffer)) {
    retval = atoi(buffer);
  }
  return (retval >= 0x0 && retval <= 0xff);
}


x86 assembly (clang, -O0):
<verify_u8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <verify_hex@plt>
cmp    $0x0,%rax
je     1184 <verify_u8+0x44>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0xc(%rbp)
jmp    11a8 <verify_u8+0x68>
mov    -0x8(%rbp),%rdi
call   1030 <verify_int@plt>
cmp    $0x0,%rax
je     11a3 <verify_u8+0x63>
mov    -0x8(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0xc(%rbp)
jmp    11a8 <verify_u8+0x68>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jl     11c4 <verify_u8+0x84>
cmpl   $0xff,-0xc(%rbp)
setle  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_u8>:
push   %rbx
mov    %rdi,%rbx
call   1040 <verify_hex@plt>
test   %rax,%rax
je     1163 <verify_u8+0x23>
add    $0x2,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
jmp    117f <verify_u8+0x3f>
mov    %rbx,%rdi
call   1030 <verify_int@plt>
test   %rax,%rax
je     117a <verify_u8+0x3a>
mov    %rbx,%rdi
call   1060 <atoi@plt>
jmp    117f <verify_u8+0x3f>
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x100,%eax
setb   %cl
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @verify_u8(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
%4 = load i8*, i8** %2
%5 = call i64 @verify_hex(i8* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 2
%10 = call i32 @strtoul(i8* %9, i32* null, i32 16)
store i32 %10, i32* %3
br label %19
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i64 @verify_int(i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %3
br label %18
18: ; preds = %15, %11
br label %19
19: ; preds = %18, %7
%20 = load i32, i32* %3
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %3
%24 = icmp sle i32 %23, 255
br label %25
25: ; preds = %22, %19
%26 = phi i1 [ false, %19 ], [ %24, %22 ]
%27 = zext i1 %26 to i32
ret i32 %27
}

LLVM IR (-O2):
define i32 @verify_u8(i8* %0) {
%2 = tail call i64 @verify_hex(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 2
%6 = tail call i32 @strtoul(i8* nocapture %5, i32* null, i32 16)
br label %12
7: ; preds = %1
%8 = tail call i64 @verify_int(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @atoi(i8* %0)
br label %12
12: ; preds = %7, %10, %4
%13 = phi i32 [ %6, %4 ], [ %11, %10 ], [ -1, %7 ]
%14 = icmp ult i32 %13, 256
%15 = zext i1 %14 to i32
ret i32 %15
}