#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);
int xnum(char ch) {
  int n = 0;
  if (isdigit(ch))
    n = (ch - '0');
  if (ch >= 'a' && ch <= 'f')
    n = (ch - 'a' + 10);
  if (ch >= 'A' && ch <= 'F')
    n = (ch - 'A' + 10);
  return n;
}


x86 assembly (clang, -O0):
<xnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1142 <xnum+0x32>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x61,%eax
jl     1169 <xnum+0x59>
movsbl -0x1(%rbp),%eax
cmp    $0x66,%eax
jg     1169 <xnum+0x59>
movsbl -0x1(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x41,%eax
jl     1190 <xnum+0x80>
movsbl -0x1(%rbp),%eax
cmp    $0x46,%eax
jg     1190 <xnum+0x80>
movsbl -0x1(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xnum>:
push   %rbx
mov    %edi,%ebx
call   1030 <isdigit@plt>
lea    -0x30(%rbx),%ecx
xor    %edx,%edx
test   %rax,%rax
cmovne %ecx,%edx
lea    -0x61(%rbx),%eax
lea    -0x57(%rbx),%ecx
cmp    $0x6,%al
cmovae %edx,%ecx
lea    -0x41(%rbx),%eax
add    $0xffffffc9,%ebx
cmp    $0x6,%al
cmovae %ecx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @xnum(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
store i32 0, i32* %3
%4 = load i8, i8* %2
%5 = call i64 @isdigit(i8 signext %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = sub nsw i32 %9, 48
store i32 %10, i32* %3
br label %11
11: ; preds = %7, %1
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = icmp sge i32 %13, 97
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load i8, i8* %2
%17 = sext i8 %16 to i32
%18 = icmp sle i32 %17, 102
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8, i8* %2
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, 97
%23 = add nsw i32 %22, 10
store i32 %23, i32* %3
br label %24
24: ; preds = %19, %15, %11
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = icmp sge i32 %26, 65
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load i8, i8* %2
%30 = sext i8 %29 to i32
%31 = icmp sle i32 %30, 70
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i8, i8* %2
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 65
%36 = add nsw i32 %35, 10
store i32 %36, i32* %3
br label %37
37: ; preds = %32, %28, %24
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @xnum(i8 signext %0) {
%2 = tail call i64 @isdigit(i8 signext %0)
%3 = icmp eq i64 %2, 0
%4 = sext i8 %0 to i32
%5 = add nsw i32 %4, -48
%6 = select i1 %3, i32 0, i32 %5
%7 = add i8 %0, -97
%8 = icmp ult i8 %7, 6
%9 = add nsw i32 %4, -87
%10 = select i1 %8, i32 %9, i32 %6
%11 = add i8 %0, -65
%12 = icmp ult i8 %11, 6
%13 = add nsw i32 %4, -55
%14 = select i1 %12, i32 %13, i32 %10
ret i32 %14
}