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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int hex_value(char const);
int /*<<< orphan*/ is_hex(char const);
int /*<<< orphan*/ stderr;
uint8_t get_byte(const char *p) {
  if (!is_hex(p[0]) || !is_hex(p[1])) {
    fprintf(stderr, "syntax error: missing or invalid hex digit\n");
    exit(1);
  }
  return (hex_value(p[0]) << 4) | hex_value(p[1]);
}


x86 assembly (clang, -O0):
<get_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <is_hex@plt>
cmp    $0x0,%eax
je     1177 <get_byte+0x37>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <is_hex@plt>
cmp    $0x0,%eax
jne    1196 <get_byte+0x56>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <hex_value@plt>
shl    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <hex_value@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
or     %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_byte>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1040 <is_hex@plt>
test   %eax,%eax
je     117e <get_byte+0x3e>
movsbl 0x1(%rbx),%edi
call   1040 <is_hex@plt>
test   %eax,%eax
je     117e <get_byte+0x3e>
movsbl (%rbx),%edi
call   1030 <hex_value@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x1(%rbx),%edi
call   1030 <hex_value@plt>
or     %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"syntax error: missing or invalid hex digit\0A\00"
define i32 @get_byte(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = getelementptr inbounds i8, i8* %3, i64 0
%5 = load i8, i8* %4
%6 = call i32 @is_hex(i8 signext %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
%12 = call i32 @is_hex(i8 signext %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %8, %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %8
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = call i32 @hex_value(i8 signext %21)
%23 = shl i32 %22, 4
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = call i32 @hex_value(i8 signext %26)
%28 = or i32 %23, %27
ret i32 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"syntax error: missing or invalid hex digit\0A\00"
define i32 @get_byte(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @is_hex(i8 signext %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = tail call i32 @is_hex(i8 signext %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %5, %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = load i8, i8* %0
%16 = tail call i32 @hex_value(i8 signext %15)
%17 = shl i32 %16, 4
%18 = load i8, i8* %6
%19 = tail call i32 @hex_value(i8 signext %18)
%20 = or i32 %19, %17
ret i32 %20
}