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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ ismaxortrailingjunk(char const *, char *, unsigned long);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char const *, char **, int);
int parse_uint8_base(const char *arg, uint8_t *ret, int base) {
  unsigned long ldata;
  char *end;
  ldata = strtoul(arg, &end, base);
  if (ismaxortrailingjunk(arg, end, ldata))
    return -1;
  if (ldata > 0xff) {
    fprintf(stderr, "%s: won't fit in a byte\n", arg);
    return -1;
  }
  *ret = (uint8_t)ldata;
  return 0;
}


x86 assembly (clang, -O0):
<parse_uint8_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x30(%rbp),%rsi
call   1050 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <ismaxortrailingjunk@plt>
cmp    $0x0,%rax
je     117e <parse_uint8_base+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <parse_uint8_base+0x93>
cmpq   $0xff,-0x28(%rbp)
jbe    11b1 <parse_uint8_base+0x81>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe60(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <parse_uint8_base+0x93>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_uint8_base>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <strtoul@plt>
mov    %rax,%rbp
mov    (%rsp),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1030 <ismaxortrailingjunk@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
jne    118b <parse_uint8_base+0x5b>
cmp    $0x100,%rbp
jb     1185 <parse_uint8_base+0x55>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
jmp    118b <parse_uint8_base+0x5b>
mov    %rbp,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"%s: won't fit in a byte\0A\00"
define i32 @parse_uint8_base(i8* %0, i64* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i64* %1, i64** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i32, i32* %7
%12 = call i64 @strtoul(i8* %10, i8** %9, i32 %11)
store i64 %12, i64* %8
%13 = load i8*, i8** %5
%14 = load i8*, i8** %9
%15 = load i64, i64* %8
%16 = call i64 @ismaxortrailingjunk(i8* %13, i8* %14, i64 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 -1, i32* %4
br label %29
19: ; preds = %3
%20 = load i64, i64* %8
%21 = icmp ugt i64 %20, 255
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %5
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 -1, i32* %4
br label %29
26: ; preds = %19
%27 = load i64, i64* %8
%28 = load i64*, i64** %6
store i64 %27, i64* %28
store i32 0, i32* %4
br label %29
29: ; preds = %26, %22, %18
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"%s: won't fit in a byte\0A\00"
define i32 @parse_uint8_base(i8* %0, i64* nocapture writeonly %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i64 @strtoul(i8* %0, i8** %4, i32 %2)
%7 = load i8*, i8** %4
%8 = tail call i64 @ismaxortrailingjunk(i8* %0, i8* %7, i64 %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = icmp ugt i64 %6, 255
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %16
15: ; preds = %10
store i64 %6, i64* %1
br label %16
16: ; preds = %3, %15, %12
%17 = phi i32 [ -1, %12 ], [ 0, %15 ], [ -1, %3 ]
ret i32 %17
}