#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(unsigned int);
int hexDecodeChar(unsigned int ch) {
  int digit;
  if (isdigit(ch)) {
    digit = ch - '0';
  } else {
    if (ch >= 'A' || ch <= 'F') {
      digit = ch - 'A' + 10;
    } else if (ch >= 'a' || ch <= 'f') {
      digit = ch - 'a' + 10;
    } else {
      return -1;
    }
  }
  return digit;
}


x86 assembly (clang, -O0):
<hexDecodeChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     113b <hexDecodeChar+0x2b>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
jmp    119b <hexDecodeChar+0x8b>
cmpl   $0x41,-0x8(%rbp)
jae    114f <hexDecodeChar+0x3f>
cmpl   $0x46,-0x8(%rbp)
ja     1160 <hexDecodeChar+0x50>
mov    -0x8(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    1196 <hexDecodeChar+0x86>
cmpl   $0x61,-0x8(%rbp)
jae    1174 <hexDecodeChar+0x64>
cmpl   $0x66,-0x8(%rbp)
ja     1185 <hexDecodeChar+0x75>
mov    -0x8(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    1191 <hexDecodeChar+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <hexDecodeChar+0x91>
jmp    1196 <hexDecodeChar+0x86>
jmp    119b <hexDecodeChar+0x8b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexDecodeChar>:
push   %rbx
mov    %edi,%ebx
call   1030 <isdigit@plt>
lea    -0x30(%rbx),%ecx
add    $0xffffffc9,%ebx
test   %rax,%rax
cmovne %ecx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @hexDecodeChar(i32 %0) {
%2 = tail call i64 @isdigit(i32 %0)
%3 = icmp eq i64 %2, 0
%4 = select i1 %3, i32 -55, i32 -48
%5 = add i32 %4, %0
ret i32 %5
}