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

/* Variables and functions */
uint8_t hexstr_todecnum(char *hexliteral) {
  uint8_t value;
  if (hexliteral[1] >= 'A' && hexliteral[1] <= 'F')
    value = (hexliteral[1] - 55);
  else
    value = (hexliteral[1] - 48);
  if (hexliteral[0] >= 'A' && hexliteral[0] <= 'F')
    value |= ((hexliteral[0] - 55) << 4);
  else
    value |= ((hexliteral[0] - 48) << 4);
  return value;
}


x86 assembly (clang, -O0):
<hexstr_todecnum>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x41,%eax
jl     113d <hexstr_todecnum+0x3d>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x46,%eax
jg     113d <hexstr_todecnum+0x3d>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x37,%eax
mov    %al,-0x9(%rbp)
jmp    114b <hexstr_todecnum+0x4b>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
jl     1186 <hexstr_todecnum+0x86>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x46,%eax
jg     1186 <hexstr_todecnum+0x86>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
sub    $0x37,%ecx
shl    $0x4,%ecx
movsbl -0x9(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x9(%rbp)
jmp    119c <hexstr_todecnum+0x9c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
sub    $0x30,%ecx
shl    $0x4,%ecx
movsbl -0x9(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexstr_todecnum>:
mov    (%rdi),%al
mov    0x1(%rdi),%cl
lea    -0x41(%rcx),%edx
cmp    $0x6,%dl
mov    $0xc9,%edx
mov    $0xd0,%esi
cmovb  %edx,%esi
add    %cl,%sil
lea    -0x41(%rax),%ecx
shl    $0x4,%al
lea    -0x70(%rax),%edx
cmp    $0x6,%cl
movzbl %al,%ecx
movzbl %dl,%eax
cmovae %ecx,%eax
or     %sil,%al
ret

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

LLVM IR (-O2):
define signext i8 @hexstr_todecnum(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %2
%4 = add i8 %3, -65
%5 = icmp ult i8 %4, 6
%6 = select i1 %5, i8 -55, i8 -48
%7 = add i8 %6, %3
%8 = load i8, i8* %0
%9 = add i8 %8, -65
%10 = icmp ult i8 %9, 6
%11 = shl i8 %8, 4
%12 = add nuw nsw i8 %11, -112
%13 = select i1 %10, i8 %12, i8 %11
%14 = or i8 %13, %7
ret i8 %14
}