#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*/ isxdigit(unsigned char);
scalar_t__ strtoul(char *, int /*<<< orphan*/ *, int);
bool get_hex_byte(const char *str, uint8_t *byte) {
  char buf[] = {str[0], str[1], '\0'};
  if (!isxdigit((unsigned char)str[0]) || !isxdigit((unsigned char)str[1]))
    return false;
  *byte = (uint8_t)strtoul(buf, NULL, 16);
  return true;
}


x86 assembly (clang, -O0):
<get_hex_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1b(%rbp)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x1a(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%eax
je     1172 <get_hex_byte+0x52>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%eax
jne    117e <get_hex_byte+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    11a1 <get_hex_byte+0x81>
lea    -0x1b(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtoul@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hex_byte>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movzbl (%rdi),%edi
mov    %dil,0xd(%rsp)
mov    0x1(%rbx),%al
mov    %al,0xe(%rsp)
movb   $0x0,0xf(%rsp)
call   1040 <isxdigit@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1173 <get_hex_byte+0x53>
movzbl 0x1(%rbx),%edi
call   1040 <isxdigit@plt>
test   %eax,%eax
je     1173 <get_hex_byte+0x53>
lea    0xd(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtoul@plt>
mov    %rax,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_hex_byte(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca [3 x i8]
store i8* %0, i8** %4
store i64* %1, i64** %5
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
store i8 %10, i8* %7
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
store i8 %14, i8* %11
%15 = getelementptr inbounds i8, i8* %11, i64 1
store i8 0, i8* %15
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = call i32 @isxdigit(i8 zeroext %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8, i8* %23
%25 = call i32 @isxdigit(i8 zeroext %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %21, %2
store i32 0, i32* %3
br label %32
28: ; preds = %21
%29 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%30 = call i64 @strtoul(i8* %29, i32* null, i32 16)
%31 = load i64*, i64** %5
store i64 %30, i64* %31
store i32 1, i32* %3
br label %32
32: ; preds = %28, %27
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @get_hex_byte(i8* nocapture %0, i64* nocapture writeonly %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %0
store i8 %5, i8* %4
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
store i8 %8, i8* %6
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %9
%10 = tail call i32 @isxdigit(i8 zeroext %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %2
%13 = load i8, i8* %7
%14 = tail call i32 @isxdigit(i8 zeroext %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i64 @strtoul(i8* nocapture %4, i32* null, i32 16)
store i64 %17, i64* %1
br label %18
18: ; preds = %2, %12, %16
%19 = phi i32 [ 1, %16 ], [ 0, %12 ], [ 0, %2 ]
ret i32 %19
}