#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 /*<<< orphan*/ print_err(char *, char const *);
long strtol(char const *, char **, int /*<<< orphan*/);
int safe_atob(const char *s) {
  char *endptr;
  long res = strtol(s, &endptr, 0);
  if (res >= 0 && res <= 255 && !*endptr)
    return res;
  print_err("bad byte value \"%s\"", s);
  return -1;
}


x86 assembly (clang, -O0):
<safe_atob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     1171 <safe_atob+0x51>
cmpq   $0xff,-0x20(%rbp)
jg     1171 <safe_atob+0x51>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1171 <safe_atob+0x51>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1188 <safe_atob+0x68>
mov    -0x10(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1030 <print_err@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_atob>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
cmp    $0xff,%rax
ja     1146 <safe_atob+0x26>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     115a <safe_atob+0x3a>
lea    0xeb3(%rip),%rdi
mov    %rbx,%rsi
call   1030 <print_err@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"bad byte value \22%s\22\00"
define i32 @safe_atob(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strtol(i8* %6, i8** %4, i32 0)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp sge i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %1
%11 = load i64, i64* %5
%12 = icmp sle i64 %11, 255
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i64, i64* %5
%19 = trunc i64 %18 to i32
store i32 %19, i32* %2
br label %23
20: ; preds = %13, %10, %1
%21 = load i8*, i8** %3
%22 = call i32 @print_err(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 -1, i32* %2
br label %23
23: ; preds = %20, %17
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [20 x i8] c"bad byte value \22%s\22\00"
define i32 @safe_atob(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = icmp ult i64 %4, 256
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = trunc i64 %4 to i32
br label %14
12: ; preds = %6, %1
%13 = tail call i32 @print_err(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ -1, %12 ], [ %11, %10 ]
ret i32 %15
}