int hexCharToInt(unsigned char c) {
  static int table_created = 0;
  static int table[256];
  int i;
  if (table_created == 0) {
    for (i = 0; i < 256; i++) {
      switch ((unsigned char)i) {
      case '0':
        table[i] = 0;
        break;
      case '1':
        table[i] = 1;
        break;
      case '2':
        table[i] = 2;
        break;
      case '3':
        table[i] = 3;
        break;
      case '4':
        table[i] = 4;
        break;
      case '5':
        table[i] = 5;
        break;
      case '6':
        table[i] = 6;
        break;
      case '7':
        table[i] = 7;
        break;
      case '8':
        table[i] = 8;
        break;
      case '9':
        table[i] = 9;
        break;
      case 'A':
      case 'a':
        table[i] = 10;
        break;
      case 'B':
      case 'b':
        table[i] = 11;
        break;
      case 'C':
      case 'c':
        table[i] = 12;
        break;
      case 'D':
      case 'd':
        table[i] = 13;
        break;
      case 'E':
      case 'e':
        table[i] = 14;
        break;
      case 'F':
      case 'f':
        table[i] = 15;
        break;
      default:
        table[i] = -1;
      }
    }
    table_created = 1;
  }
  return table[c];
}


x86 assembly (clang, -O0):
<hexCharToInt>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
cmpl   $0x0,0x2f1f(%rip)
jne    12f4 <hexCharToInt+0x1f4>
movl   $0x0,-0x8(%rbp)
cmpl   $0x100,-0x8(%rbp)
jge    12ea <hexCharToInt+0x1ea>
movzbl -0x8(%rbp),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x36,%eax
ja     12c5 <hexCharToInt+0x1c5>
mov    -0x10(%rbp),%rax
lea    0xeb4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movslq -0x8(%rbp),%rcx
lea    0x2ee0(%rip),%rax
movl   $0x0,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2ec9(%rip),%rax
movl   $0x1,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2eb2(%rip),%rax
movl   $0x2,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2e9b(%rip),%rax
movl   $0x3,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2e84(%rip),%rax
movl   $0x4,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2e6d(%rip),%rax
movl   $0x5,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2e56(%rip),%rax
movl   $0x6,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2e3f(%rip),%rax
movl   $0x7,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2e28(%rip),%rax
movl   $0x8,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2e11(%rip),%rax
movl   $0x9,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2dfa(%rip),%rax
movl   $0xa,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2de3(%rip),%rax
movl   $0xb,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2dcc(%rip),%rax
movl   $0xc,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2db5(%rip),%rax
movl   $0xd,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2d9e(%rip),%rax
movl   $0xe,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2d87(%rip),%rax
movl   $0xf,(%rax,%rcx,4)
jmp    12d7 <hexCharToInt+0x1d7>
movslq -0x8(%rbp),%rcx
lea    0x2d70(%rip),%rax
movl   $0xffffffff,(%rax,%rcx,4)
jmp    12dc <hexCharToInt+0x1dc>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    111e <hexCharToInt+0x1e>
movl   $0x1,0x2d3c(%rip)
movzbl -0x1(%rbp),%eax
mov    %eax,%ecx
lea    0x2d3f(%rip),%rax
mov    (%rax,%rcx,4),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexCharToInt>:
cmpb   $0x0,0x2f29(%rip)
jne    1170 <hexCharToInt+0x70>
xor    %eax,%eax
lea    0xeee(%rip),%r8
lea    0x2f27(%rip),%r9
jmp    1131 <hexCharToInt+0x31>
nopl   0x0(%rax,%rax,1)
mov    %esi,0x4(%r9,%rax,4)
add    $0x2,%rax
cmp    $0x100,%rax
je     1169 <hexCharToInt+0x69>
lea    0xd0(%rax),%rcx
mov    $0xffffffff,%esi
mov    $0xffffffff,%edx
cmp    $0x36,%cl
ja     114f <hexCharToInt+0x4f>
movsbq %cl,%rcx
mov    (%r8,%rcx,4),%edx
mov    %edx,(%r9,%rax,4)
lea    0xd1(%rax),%rcx
cmp    $0x36,%cl
ja     1120 <hexCharToInt+0x20>
movsbq %cl,%rcx
mov    (%r8,%rcx,4),%esi
jmp    1120 <hexCharToInt+0x20>
movb   $0x1,0x2ec0(%rip)
movzbl %dil,%eax
lea    0x2ec5(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
@hexCharToInt.table_created = internal global i32 0
@hexCharToInt.table = internal global [256 x i32] zeroinitializer
define i32 @hexCharToInt(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
%4 = load i32, i32* @hexCharToInt.table_created
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %87
6: ; preds = %1
store i32 0, i32* %3
br label %7
7: ; preds = %83, %6
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 256
br i1 %9, label %10, label %86
10: ; preds = %7
%11 = load i32, i32* %3
%12 = trunc i32 %11 to i8
%13 = zext i8 %12 to i32
switch i32 %13, label %78 [
i32 48, label %14
i32 49, label %18
i32 50, label %22
i32 51, label %26
i32 52, label %30
i32 53, label %34
i32 54, label %38
i32 55, label %42
i32 56, label %46
i32 57, label %50
i32 65, label %54
i32 97, label %54
i32 66, label %58
i32 98, label %58
i32 67, label %62
i32 99, label %62
i32 68, label %66
i32 100, label %66
i32 69, label %70
i32 101, label %70
i32 70, label %74
i32 102, label %74
]
14: ; preds = %10
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %16
store i32 0, i32* %17
br label %82
18: ; preds = %10
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %20
store i32 1, i32* %21
br label %82
22: ; preds = %10
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %24
store i32 2, i32* %25
br label %82
26: ; preds = %10
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %28
store i32 3, i32* %29
br label %82
30: ; preds = %10
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %32
store i32 4, i32* %33
br label %82
34: ; preds = %10
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %36
store i32 5, i32* %37
br label %82
38: ; preds = %10
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %40
store i32 6, i32* %41
br label %82
42: ; preds = %10
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %44
store i32 7, i32* %45
br label %82
46: ; preds = %10
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %48
store i32 8, i32* %49
br label %82
50: ; preds = %10
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %52
store i32 9, i32* %53
br label %82
54: ; preds = %10, %10
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %56
store i32 10, i32* %57
br label %82
58: ; preds = %10, %10
%59 = load i32, i32* %3
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %60
store i32 11, i32* %61
br label %82
62: ; preds = %10, %10
%63 = load i32, i32* %3
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %64
store i32 12, i32* %65
br label %82
66: ; preds = %10, %10
%67 = load i32, i32* %3
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %68
store i32 13, i32* %69
br label %82
70: ; preds = %10, %10
%71 = load i32, i32* %3
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %72
store i32 14, i32* %73
br label %82
74: ; preds = %10, %10
%75 = load i32, i32* %3
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %76
store i32 15, i32* %77
br label %82
78: ; preds = %10
%79 = load i32, i32* %3
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %80
store i32 -1, i32* %81
br label %82
82: ; preds = %78, %74, %70, %66, %62, %58, %54, %50, %46, %42, %38, %34, %30, %26, %22, %18, %14
br label %83
83: ; preds = %82
%84 = load i32, i32* %3
%85 = add nsw i32 %84, 1
store i32 %85, i32* %3
br label %7
86: ; preds = %7
store i32 1, i32* @hexCharToInt.table_created
br label %87
87: ; preds = %86, %1
%88 = load i8, i8* %2
%89 = zext i8 %88 to i64
%90 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %89
%91 = load i32, i32* %90
ret i32 %91
}

LLVM IR (-O2):
@hexCharToInt.table_created = internal unnamed_addr global i1 false
@hexCharToInt.table = internal unnamed_addr global [256 x i32] zeroinitializer
@switch.table.hexCharToInt = [55 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15]
define i32 @hexCharToInt(i8 zeroext %0) {
%2 = load i1, i1* @hexCharToInt.table_created
br i1 %2, label %29, label %3
3: ; preds = %1, %23
%4 = phi i64 [ %26, %23 ], [ 0, %1 ]
%5 = trunc i64 %4 to i8
%6 = add i8 %5, -48
%7 = icmp ult i8 %6, 55
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = sext i8 %6 to i64
%10 = getelementptr inbounds [55 x i32], [55 x i32]* @switch.table.hexCharToInt, i64 0, i64 %9
%11 = load i32, i32* %10
br label %12
12: ; preds = %3, %8
%13 = phi i32 [ %11, %8 ], [ -1, %3 ]
%14 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %4
store i32 %13, i32* %14
%15 = or i64 %4, 1
%16 = trunc i64 %15 to i8
%17 = add i8 %16, -48
%18 = icmp ult i8 %17, 55
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = sext i8 %17 to i64
%21 = getelementptr inbounds [55 x i32], [55 x i32]* @switch.table.hexCharToInt, i64 0, i64 %20
%22 = load i32, i32* %21
br label %23
23: ; preds = %19, %12
%24 = phi i32 [ %22, %19 ], [ -1, %12 ]
%25 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %15
store i32 %24, i32* %25
%26 = add nuw nsw i64 %4, 2
%27 = icmp eq i64 %26, 256
br i1 %27, label %28, label %3
28: ; preds = %23
store i1 true, i1* @hexCharToInt.table_created
br label %29
29: ; preds = %28, %1
%30 = zext i8 %0 to i64
%31 = getelementptr inbounds [256 x i32], [256 x i32]* @hexCharToInt.table, i64 0, i64 %30
%32 = load i32, i32* %31
ret i32 %32
}