#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 */
size_t qhex_decode(char *str) {
  const char HEXMAPTBL[16 * 16] = {
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  1,  2,  3, 4, 5, 6, 7, 8, 9,  0,  0,
      0,  0,  0,  0, 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 10, 11, 12,
      13, 14, 15, 0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0,  0,  0,
      0,  0,  0,  0, 0, 0,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0};
  char *pEncPt, *pBinPt = str;
  for (pEncPt = str; *pEncPt != '\0'; pEncPt += 2) {
    *pBinPt++ = (HEXMAPTBL[(unsigned char)(*pEncPt)] << 4) +
                HEXMAPTBL[(unsigned char)(*(pEncPt + 1))];
  }
  *pBinPt = '\0';
  return (pBinPt - str);
}


x86 assembly (clang, -O0):
<qhex_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xed3(%rip),%rsi
mov    $0x100,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ba <qhex_decode+0xaa>
mov    -0x118(%rbp),%rax
movzbl (%rax),%eax
movsbl -0x110(%rbp,%rax,1),%eax
ff
shl    $0x4,%eax
mov    -0x118(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
movsbl -0x110(%rbp,%rcx,1),%ecx
ff
add    %ecx,%eax
mov    %al,%cl
mov    -0x120(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x120(%rbp)
mov    %cl,(%rax)
mov    -0x118(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x118(%rbp)
jmp    114d <qhex_decode+0x3d>
mov    -0x120(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x120(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qhex_decode>:
mov    (%rdi),%dl
mov    %rdi,%rax
test   %dl,%dl
je     1145 <qhex_decode+0x45>
xor    %eax,%eax
lea    0xeee(%rip),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl %dl,%edx
movzbl (%rdx,%rcx,1),%edx
shl    $0x4,%dl
movzbl 0x1(%rdi,%rax,2),%esi
add    (%rsi,%rcx,1),%dl
mov    %dl,(%rdi,%rax,1)
movzbl 0x2(%rdi,%rax,2),%edx
add    $0x1,%rax
test   %dl,%dl
jne    1120 <qhex_decode+0x20>
add    %rdi,%rax
movb   $0x0,(%rax)
sub    %rdi,%rax
ret

LLVM IR (-O0):
@__const.qhex_decode.HEXMAPTBL = <{ [103 x i8], [153 x i8] }> <{ [103 x i8] c"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01\02\03\04\05\06\07\08\09\00\00\00\00\00\00\00\0A\0B\0C\0D\0E\0F\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\0A\0B\0C\0D\0E\0F", [153 x i8] zeroinitializer }>
define i64 @qhex_decode(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = bitcast [256 x i8]* %3 to i8*
%7 = load i8*, i8** %2
store i8* %7, i8** %5
%8 = load i8*, i8** %2
store i8* %8, i8** %4
br label %9
9: ; preds = %33, %1
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %36
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = zext i8 %16 to i64
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = shl i32 %20, 4
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8, i8* %23
%25 = zext i8 %24 to i64
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = add nsw i32 %21, %28
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
store i8 %30, i8* %31
br label %33
33: ; preds = %14
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 2
store i8* %35, i8** %4
br label %9
36: ; preds = %9
%37 = load i8*, i8** %5
store i8 0, i8* %37
%38 = load i8*, i8** %5
%39 = load i8*, i8** %2
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
ret i64 %42
}

LLVM IR (-O2):
@__const.qhex_decode.HEXMAPTBL = <{ [103 x i8], [153 x i8] }> <{ [103 x i8] c"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01\02\03\04\05\06\07\08\09\00\00\00\00\00\00\00\0A\0B\0C\0D\0E\0F\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\0A\0B\0C\0D\0E\0F", [153 x i8] zeroinitializer }>
define i64 @qhex_decode(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %20, %4 ], [ %2, %1 ]
%6 = phi i8* [ %18, %4 ], [ %0, %1 ]
%7 = phi i8* [ %19, %4 ], [ %0, %1 ]
%8 = zext i8 %5 to i64
%9 = getelementptr inbounds [256 x i8], [256 x i8]* bitcast (<{ [103 x i8], [153 x i8] }>* @__const.qhex_decode.HEXMAPTBL to [256 x i8]*), i64 0, i64 %8
%10 = load i8, i8* %9
%11 = shl i8 %10, 4
%12 = getelementptr inbounds i8, i8* %7, i64 1
%13 = load i8, i8* %12
%14 = zext i8 %13 to i64
%15 = getelementptr inbounds [256 x i8], [256 x i8]* bitcast (<{ [103 x i8], [153 x i8] }>* @__const.qhex_decode.HEXMAPTBL to [256 x i8]*), i64 0, i64 %14
%16 = load i8, i8* %15
%17 = add i8 %16, %11
%18 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %17, i8* %6
%19 = getelementptr inbounds i8, i8* %7, i64 2
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %4
22: ; preds = %4, %1
%23 = phi i8* [ %0, %1 ], [ %18, %4 ]
store i8 0, i8* %23
%24 = ptrtoint i8* %23 to i64
%25 = ptrtoint i8* %0 to i64
%26 = sub i64 %24, %25
ret i64 %26
}