#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 */
scalar_t__ ishexnumber(char const);
char toupper(char const);
int hex2byte(const char c[2]) {
  if (!(ishexnumber(c[0]) && ishexnumber(c[1])))
    return -1;
  return ((c[0] <= '9' ? c[0] - '0' : toupper(c[0]) - 'A' + 10) << 4) +
         (c[1] <= '9' ? c[1] - '0' : toupper(c[1]) - 'A' + 10);
}


x86 assembly (clang, -O0):
<hex2byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <ishexnumber@plt>
cmp    $0x0,%rax
je     1159 <hex2byte+0x39>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <ishexnumber@plt>
cmp    $0x0,%rax
jne    1165 <hex2byte+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <hex2byte+0xd0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     1187 <hex2byte+0x67>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    119f <hex2byte+0x7f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x39,%eax
jg     11cc <hex2byte+0xac>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e5 <hex2byte+0xc5>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2byte>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1040 <ishexnumber@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1193 <hex2byte+0x73>
movsbl 0x1(%rbx),%edi
call   1040 <ishexnumber@plt>
test   %rax,%rax
je     1193 <hex2byte+0x73>
mov    (%rbx),%al
mov    $0xffffffd0,%r14d
cmp    $0x3a,%al
jge    115d <hex2byte+0x3d>
mov    $0xffffffd0,%ecx
jmp    116a <hex2byte+0x4a>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    $0xffffffc9,%ecx
movsbl %al,%r15d
add    %ecx,%r15d
shl    $0x4,%r15d
mov    0x1(%rbx),%al
cmp    $0x3a,%al
jl     118a <hex2byte+0x6a>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    $0xffffffc9,%r14d
movsbl %al,%ebp
add    %r14d,%ebp
add    %r15d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hex2byte(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = call i64 @ishexnumber(i8 signext %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = call i64 @ishexnumber(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %9, %1
store i32 -1, i32* %2
br label %61
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp sle i32 %20, 57
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 48
br label %36
28: ; preds = %16
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = call signext i8 @toupper(i8 signext %31)
%33 = sext i8 %32 to i32
%34 = sub nsw i32 %33, 65
%35 = add nsw i32 %34, 10
br label %36
36: ; preds = %28, %22
%37 = phi i32 [ %27, %22 ], [ %35, %28 ]
%38 = shl i32 %37, 4
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp sle i32 %42, 57
br i1 %43, label %44, label %50
44: ; preds = %36
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = sub nsw i32 %48, 48
br label %58
50: ; preds = %36
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = call signext i8 @toupper(i8 signext %53)
%55 = sext i8 %54 to i32
%56 = sub nsw i32 %55, 65
%57 = add nsw i32 %56, 10
br label %58
58: ; preds = %50, %44
%59 = phi i32 [ %49, %44 ], [ %57, %50 ]
%60 = add nsw i32 %38, %59
store i32 %60, i32* %2
br label %61
61: ; preds = %58, %15
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
define i32 @hex2byte(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i64 @ishexnumber(i8 signext %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %31, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = tail call i64 @ishexnumber(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %31, label %10
10: ; preds = %5
%11 = load i8, i8* %0
%12 = icmp slt i8 %11, 58
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call signext i8 @toupper(i8 signext %11)
br label %15
15: ; preds = %10, %13
%16 = phi i8 [ %14, %13 ], [ %11, %10 ]
%17 = phi i32 [ -55, %13 ], [ -48, %10 ]
%18 = sext i8 %16 to i32
%19 = add nsw i32 %17, %18
%20 = shl nsw i32 %19, 4
%21 = load i8, i8* %6
%22 = icmp slt i8 %21, 58
br i1 %22, label %25, label %23
23: ; preds = %15
%24 = tail call signext i8 @toupper(i8 signext %21)
br label %25
25: ; preds = %15, %23
%26 = phi i8 [ %24, %23 ], [ %21, %15 ]
%27 = phi i32 [ -55, %23 ], [ -48, %15 ]
%28 = sext i8 %26 to i32
%29 = add nsw i32 %27, %28
%30 = add nsw i32 %29, %20
br label %31
31: ; preds = %1, %5, %25
%32 = phi i32 [ %30, %25 ], [ -1, %5 ], [ -1, %1 ]
ret i32 %32
}