#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__ isalpha(char);
scalar_t__ isdigit(char);
char toupper(char);
unsigned long CheatDatabase_GetHexDigit(char ch) {
  if (isdigit(ch)) {
    return ch - '0';
  }
  if (isalpha(ch)) {
    return toupper(ch) - 'A' + 10;
  }
  return 0;
}


x86 assembly (clang, -O0):
<CheatDatabase_GetHexDigit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1163 <CheatDatabase_GetHexDigit+0x33>
movsbl -0x9(%rbp),%eax
sub    $0x30,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    119b <CheatDatabase_GetHexDigit+0x6b>
movsbl -0x9(%rbp),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     1193 <CheatDatabase_GetHexDigit+0x63>
movsbl -0x9(%rbp),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
add    $0xa,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    119b <CheatDatabase_GetHexDigit+0x6b>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheatDatabase_GetHexDigit>:
push   %rbx
mov    %edi,%ebx
call   1030 <isdigit@plt>
test   %rax,%rax
je     1147 <CheatDatabase_GetHexDigit+0x17>
movsbq %bl,%rax
add    $0xffffffffffffffd0,%rax
pop    %rbx
ret
movsbl %bl,%ebx
mov    %ebx,%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     1167 <CheatDatabase_GetHexDigit+0x37>
mov    %ebx,%edi
call   1040 <toupper@plt>
movsbq %al,%rax
add    $0xffffffffffffffc9,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @CheatDatabase_GetHexDigit(i8 signext %0) {
%2 = alloca i64
%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 = sext i32 %10 to i64
store i64 %11, i64* %2
br label %24
12: ; preds = %1
%13 = load i8, i8* %3
%14 = call i64 @isalpha(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i8, i8* %3
%18 = call signext i8 @toupper(i8 signext %17)
%19 = sext i8 %18 to i32
%20 = sub nsw i32 %19, 65
%21 = add nsw i32 %20, 10
%22 = sext i32 %21 to i64
store i64 %22, i64* %2
br label %24
23: ; preds = %12
store i64 0, i64* %2
br label %24
24: ; preds = %23, %16, %7
%25 = load i64, i64* %2
ret i64 %25
}

LLVM IR (-O2):
define i64 @CheatDatabase_GetHexDigit(i8 signext %0) {
%2 = tail call i64 @isdigit(i8 signext %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = sext i8 %0 to i64
%6 = add nsw i64 %5, -48
br label %14
7: ; preds = %1
%8 = tail call i64 @isalpha(i8 signext %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call signext i8 @toupper(i8 signext %0)
%12 = sext i8 %11 to i64
%13 = add nsw i64 %12, -55
br label %14
14: ; preds = %7, %10, %4
%15 = phi i64 [ %6, %4 ], [ %13, %10 ], [ 0, %7 ]
ret i64 %15
}