#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 c_tolower(unsigned char const);
unsigned char hexdec(const char *s) {
  int a = c_tolower(*(const unsigned char *)s);
  int b = c_tolower(*(const unsigned char *)(s + 1));
  return ((a >= '0' && a <= '9' ? a - '0' : a - 'W') << 4) |
         (b >= '0' && b <= '9' ? b - '0' : b - 'W');
}


x86 assembly (clang, -O0):
<hexdec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <c_tolower@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <c_tolower@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x30,-0xc(%rbp)
jl     115d <hexdec+0x4d>
cmpl   $0x39,-0xc(%rbp)
jg     115d <hexdec+0x4d>
mov    -0xc(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <hexdec+0x56>
mov    -0xc(%rbp),%eax
sub    $0x57,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x30,-0x10(%rbp)
jl     1191 <hexdec+0x81>
cmpl   $0x39,-0x10(%rbp)
jg     1191 <hexdec+0x81>
mov    -0x10(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x1c(%rbp)
jmp    119a <hexdec+0x8a>
mov    -0x10(%rbp),%eax
sub    $0x57,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
or     %ecx,%eax
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdec>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movzbl (%rdi),%edi
call   1030 <c_tolower@plt>
mov    %eax,%r14d
movzbl 0x1(%rbx),%edi
call   1030 <c_tolower@plt>
lea    -0x30(%r14),%ecx
xor    %edx,%edx
cmp    $0xa,%ecx
setae  %dl
lea    (%rdx,%rdx,8),%ecx
add    %r14d,%ecx
shl    $0x4,%ecx
lea    -0x30(%rax),%edx
lea    0xa9(%rax),%esi
add    $0xd0,%eax
cmp    $0xa,%edx
cmovae %esi,%eax
or     %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define zeroext i8 @hexdec(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = call i32 @c_tolower(i8 zeroext %6)
store i32 %7, i32* %3
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = call i32 @c_tolower(i8 zeroext %10)
store i32 %11, i32* %4
%12 = load i32, i32* %3
%13 = icmp sge i32 %12, 48
br i1 %13, label %14, label %20
14: ; preds = %1
%15 = load i32, i32* %3
%16 = icmp sle i32 %15, 57
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 48
br label %23
20: ; preds = %14, %1
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 87
br label %23
23: ; preds = %20, %17
%24 = phi i32 [ %19, %17 ], [ %22, %20 ]
%25 = shl i32 %24, 4
%26 = load i32, i32* %4
%27 = icmp sge i32 %26, 48
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load i32, i32* %4
%30 = icmp sle i32 %29, 57
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 48
br label %37
34: ; preds = %28, %23
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 87
br label %37
37: ; preds = %34, %31
%38 = phi i32 [ %33, %31 ], [ %36, %34 ]
%39 = or i32 %25, %38
%40 = trunc i32 %39 to i8
ret i8 %40
}

LLVM IR (-O2):
define zeroext i8 @hexdec(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @c_tolower(i8 zeroext %2)
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = tail call i32 @c_tolower(i8 zeroext %5)
%7 = add i32 %3, -48
%8 = icmp ult i32 %7, 10
%9 = select i1 %8, i32 0, i32 9
%10 = add i32 %9, %3
%11 = shl i32 %10, 4
%12 = add i32 %6, -48
%13 = icmp ult i32 %12, 10
%14 = select i1 %13, i32 208, i32 169
%15 = add i32 %14, %6
%16 = or i32 %15, %11
%17 = trunc i32 %16 to i8
ret i8 %17
}