#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__ isdigit(char);
unsigned char hex_value(char c) {
  if (isdigit(c))
    return c - '0';
  switch (c) {
  case 'a':
  case 'A':
    return 0x0A;
  case 'b':
  case 'B':
    return 0x0B;
  case 'c':
  case 'C':
    return 0x0C;
  case 'd':
  case 'D':
    return 0x0D;
  case 'e':
  case 'E':
    return 0x0E;
  case 'f':
  case 'F':
    return 0x0F;
  default:
    return 0xFF;
  }
}


x86 assembly (clang, -O0):
<hex_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1140 <hex_value+0x30>
movsbl -0x2(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x1(%rbp)
jmp    11a4 <hex_value+0x94>
movsbl -0x2(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x25,%eax
ja     11a0 <hex_value+0x90>
mov    -0x10(%rbp),%rax
lea    0xe9f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0xa,-0x1(%rbp)
jmp    11a4 <hex_value+0x94>
movb   $0xb,-0x1(%rbp)
jmp    11a4 <hex_value+0x94>
movb   $0xc,-0x1(%rbp)
jmp    11a4 <hex_value+0x94>
movb   $0xd,-0x1(%rbp)
jmp    11a4 <hex_value+0x94>
movb   $0xe,-0x1(%rbp)
jmp    11a4 <hex_value+0x94>
movb   $0xf,-0x1(%rbp)
jmp    11a4 <hex_value+0x94>
movb   $0xff,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_value>:
push   %rbx
mov    %edi,%ebx
call   1030 <isdigit@plt>
test   %rax,%rax
je     1122 <hex_value+0x12>
lea    -0x30(%rbx),%eax
pop    %rbx
ret
movsbl %bl,%ecx
add    $0xffffffbf,%ecx
cmp    $0x25,%ecx
ja     1153 <hex_value+0x43>
mov    $0xa,%al
lea    0xeca(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0xb,%al
pop    %rbx
ret
mov    $0xc,%al
pop    %rbx
ret
mov    $0xd,%al
pop    %rbx
ret
mov    $0xe,%al
pop    %rbx
ret
mov    $0xf,%al
pop    %rbx
ret
mov    $0xff,%al
pop    %rbx
ret

LLVM IR (-O0):
define zeroext i8 @hex_value(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = call i64 @isdigit(i8 signext %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
%10 = sub nsw i32 %9, 48
%11 = trunc i32 %10 to i8
store i8 %11, i8* %2
br label %22
12: ; preds = %1
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
switch i32 %14, label %21 [
i32 97, label %15
i32 65, label %15
i32 98, label %16
i32 66, label %16
i32 99, label %17
i32 67, label %17
i32 100, label %18
i32 68, label %18
i32 101, label %19
i32 69, label %19
i32 102, label %20
i32 70, label %20
]
15: ; preds = %12, %12
store i8 10, i8* %2
br label %22
16: ; preds = %12, %12
store i8 11, i8* %2
br label %22
17: ; preds = %12, %12
store i8 12, i8* %2
br label %22
18: ; preds = %12, %12
store i8 13, i8* %2
br label %22
19: ; preds = %12, %12
store i8 14, i8* %2
br label %22
20: ; preds = %12, %12
store i8 15, i8* %2
br label %22
21: ; preds = %12
store i8 -1, i8* %2
br label %22
22: ; preds = %21, %20, %19, %18, %17, %16, %15, %7
%23 = load i8, i8* %2
ret i8 %23
}

LLVM IR (-O2):
define zeroext i8 @hex_value(i8 signext %0) {
%2 = tail call i64 @isdigit(i8 signext %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = add i8 %0, -48
br label %14
6: ; preds = %1
%7 = sext i8 %0 to i32
switch i32 %7, label %13 [
i32 97, label %14
i32 65, label %14
i32 98, label %8
i32 66, label %8
i32 99, label %9
i32 67, label %9
i32 100, label %10
i32 68, label %10
i32 101, label %11
i32 69, label %11
i32 102, label %12
i32 70, label %12
]
8: ; preds = %6, %6
br label %14
9: ; preds = %6, %6
br label %14
10: ; preds = %6, %6
br label %14
11: ; preds = %6, %6
br label %14
12: ; preds = %6, %6
br label %14
13: ; preds = %6
br label %14
14: ; preds = %6, %6, %13, %12, %11, %10, %9, %8, %4
%15 = phi i8 [ %5, %4 ], [ -1, %13 ], [ 15, %12 ], [ 14, %11 ], [ 13, %10 ], [ 12, %9 ], [ 11, %8 ], [ 10, %6 ], [ 10, %6 ]
ret i8 %15
}