#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 hex_digit(char const, char const *);
int hex_byte(const char *s, const char *path) {
  int hi, lo;
  hi = hex_digit(s[0], path);
  if (hi < 0)
    return -1;
  lo = hex_digit(s[1], path);
  if (lo < 0)
    return -1;
  return hi << 4 | lo;
}


x86 assembly (clang, -O0):
<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    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1030 <hex_digit@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    114b <hex_byte+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <hex_byte+0x73>
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1030 <hex_digit@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1177 <hex_byte+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <hex_byte+0x73>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_byte>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <hex_digit@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     1149 <hex_byte+0x39>
mov    %eax,%ebp
movsbl 0x1(%rbx),%edi
mov    %r15,%rsi
call   1030 <hex_digit@plt>
test   %eax,%eax
js     1149 <hex_byte+0x39>
shl    $0x4,%ebp
or     %ebp,%eax
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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