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


x86 assembly (clang, -O0):
<sl_hex2byte>:
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)
movsbl (%rax),%edi
call   1030 <sl_hex2num@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    114c <sl_hex2byte+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <sl_hex2byte+0x78>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <sl_hex2num@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    117c <sl_hex2byte+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <sl_hex2byte+0x78>
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sl_hex2byte>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <sl_hex2num@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     1140 <sl_hex2byte+0x30>
mov    %eax,%ebp
movsbl 0x1(%rbx),%edi
call   1030 <sl_hex2num@plt>
test   %eax,%eax
js     1140 <sl_hex2byte+0x30>
shl    $0x4,%ebp
or     %ebp,%eax
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sl_hex2byte(i8* %0) {
%2 = alloca i32
%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 = sext i8 %8 to i32
%10 = call i32 @sl_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 i32 -1, i32* %2
br label %28
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 = sext i8 %17 to i32
%19 = call i32 @sl_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 i32 -1, i32* %2
br label %28
23: ; preds = %14
%24 = load i32, i32* %4
%25 = shl i32 %24, 4
%26 = load i32, i32* %5
%27 = or i32 %25, %26
store i32 %27, i32* %2
br label %28
28: ; preds = %23, %22, %13
%29 = load i32, i32* %2
ret i32 %29
}

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