#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__ is_letter(char);
int transform_hex(char symbol) {
  if (is_letter(symbol)) {
    switch (symbol) {
    case 'a':
      return 10;
    case 'b':
      return 11;
    case 'c':
      return 12;
    case 'd':
      return 13;
    case 'e':
      return 14;
    case 'f':
      return 15;
    }
  }
  return symbol - '0';
}


x86 assembly (clang, -O0):
<transform_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <is_letter@plt>
cmp    $0x0,%rax
je     11a8 <transform_hex+0x98>
movsbl -0x5(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x5,%eax
ja     11a3 <transform_hex+0x93>
mov    -0x10(%rbp),%rax
lea    0xeae(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xa,-0x4(%rbp)
jmp    11b2 <transform_hex+0xa2>
movl   $0xb,-0x4(%rbp)
jmp    11b2 <transform_hex+0xa2>
movl   $0xc,-0x4(%rbp)
jmp    11b2 <transform_hex+0xa2>
movl   $0xd,-0x4(%rbp)
jmp    11b2 <transform_hex+0xa2>
movl   $0xe,-0x4(%rbp)
jmp    11b2 <transform_hex+0xa2>
movl   $0xf,-0x4(%rbp)
jmp    11b2 <transform_hex+0xa2>
jmp    11a8 <transform_hex+0x98>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transform_hex>:
push   %rbx
mov    %edi,%ebx
call   1030 <is_letter@plt>
lea    -0x61(%rbx),%ecx
cmp    $0x6,%ecx
mov    $0xffffffa9,%ecx
mov    $0xffffffd0,%edx
cmovae %edx,%ecx
test   %rax,%rax
cmove  %edx,%ecx
add    %ebx,%ecx
mov    %ecx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @transform_hex(i8 signext %0) {
%2 = tail call i64 @is_letter(i8 signext %0)
%3 = icmp ne i64 %2, 0
%4 = sext i8 %0 to i32
%5 = add nsw i32 %4, -97
%6 = icmp ult i32 %5, 6
%7 = select i1 %3, i1 %6, i1 false
%8 = add nsw i32 %4, -48
%9 = add nsw i32 %4, -87
%10 = select i1 %7, i32 %9, i32 %8
ret i32 %10
}