#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 hex2num(int /*<<< orphan*/);
unsigned char hexbyte(const unsigned char *hex) {
  int a, b;
  a = hex2num(*hex++);
  if (a < 0)
    return -1;
  b = hex2num(*hex++);
  if (b < 0)
    return -1;
  return (a << 4) | b;
}


x86 assembly (clang, -O0):
<hexbyte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%edi
call   1030 <hex2num@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1149 <hexbyte+0x39>
movb   $0xff,-0x1(%rbp)
jmp    1182 <hexbyte+0x72>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%edi
call   1030 <hex2num@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1176 <hexbyte+0x66>
movb   $0xff,-0x1(%rbp)
jmp    1182 <hexbyte+0x72>
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
or     -0x18(%rbp),%eax
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexbyte>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
movzbl (%rdi),%edi
call   1030 <hex2num@plt>
mov    $0xff,%r14b
test   %eax,%eax
js     113d <hexbyte+0x2d>
mov    %eax,%ebp
movzbl 0x1(%rbx),%edi
call   1030 <hex2num@plt>
test   %eax,%eax
js     113d <hexbyte+0x2d>
shl    $0x4,%ebp
or     %ebp,%eax
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @hexbyte(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %3
%8 = load i8, i8* %6
%9 = zext i8 %8 to i32
%10 = call i32 @hex2num(i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i8 -1, i8* %2
br label %29
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
%17 = load i8, i8* %15
%18 = zext i8 %17 to i32
%19 = call i32 @hex2num(i32 %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %14
store i8 -1, i8* %2
br label %29
23: ; preds = %14
%24 = load i32, i32* %4
%25 = shl i32 %24, 4
%26 = load i32, i32* %5
%27 = or i32 %25, %26
%28 = trunc i32 %27 to i8
store i8 %28, i8* %2
br label %29
29: ; preds = %23, %22, %13
%30 = load i8, i8* %2
ret i8 %30
}

LLVM IR (-O2):
define zeroext i8 @hexbyte(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = zext i8 %2 to i32
%4 = tail call i32 @hex2num(i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = tail call i32 @hex2num(i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = shl i32 %4, 4
%14 = or i32 %10, %13
%15 = trunc i32 %14 to i8
br label %16
16: ; preds = %6, %1, %12
%17 = phi i8 [ %15, %12 ], [ -1, %1 ], [ -1, %6 ]
ret i8 %17
}