int checkhex(char s) {
  int ret;
  switch (s) {
  case 'A':
    ret = 10;
    break;
  case 'a':
    ret = 10;
    break;
  case 'B':
    ret = 11;
    break;
  case 'b':
    ret = 11;
    break;
  case 'C':
    ret = 12;
    break;
  case 'c':
    ret = 12;
    break;
  case 'D':
    ret = 13;
    break;
  case 'd':
    ret = 13;
    break;
  case 'e':
    ret = 14;
    break;
  case 'E':
    ret = 14;
    break;
  case 'f':
    ret = 15;
    break;
  case 'F':
    ret = 16;
    break;
  default:
    ret = (int)s - 48;
  }
  return ret;
}


x86 assembly (clang, -O0):
<checkhex>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x25,%eax
ja     11c4 <checkhex+0xc4>
mov    -0x10(%rbp),%rax
lea    0xed5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xa,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xa,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xb,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xb,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xc,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xc,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xd,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xd,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xe,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xe,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0xf,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movl   $0x10,-0x8(%rbp)
jmp    11ce <checkhex+0xce>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkhex>:
lea    -0x41(%rdi),%ecx
cmp    $0x25,%ecx
ja     113b <checkhex+0x3b>
mov    $0xa,%eax
lea    0xeec(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0xe,%eax
ret
mov    $0xb,%eax
ret
mov    $0xc,%eax
ret
mov    $0xd,%eax
ret
mov    $0x10,%eax
ret
add    $0xffffffd0,%edi
mov    %edi,%eax
ret
mov    $0xf,%eax
ret

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

LLVM IR (-O2):
define i32 @checkhex(i8 signext %0) {
%2 = sext i8 %0 to i32
switch i32 %2, label %13 [
i32 65, label %15
i32 97, label %15
i32 66, label %3
i32 98, label %4
i32 67, label %5
i32 99, label %6
i32 68, label %7
i32 100, label %8
i32 101, label %9
i32 69, label %10
i32 102, label %11
i32 70, label %12
]
3: ; preds = %1
br label %15
4: ; preds = %1
br label %15
5: ; preds = %1
br label %15
6: ; preds = %1
br label %15
7: ; preds = %1
br label %15
8: ; preds = %1
br label %15
9: ; preds = %1
br label %15
10: ; preds = %1
br label %15
11: ; preds = %1
br label %15
12: ; preds = %1
br label %15
13: ; preds = %1
%14 = add nsw i32 %2, -48
br label %15
15: ; preds = %1, %1, %13, %12, %11, %10, %9, %8, %7, %6, %5, %4, %3
%16 = phi i32 [ %14, %13 ], [ 16, %12 ], [ 15, %11 ], [ 14, %10 ], [ 14, %9 ], [ 13, %8 ], [ 13, %7 ], [ 12, %6 ], [ 12, %5 ], [ 11, %4 ], [ 11, %3 ], [ 10, %1 ], [ 10, %1 ]
ret i32 %16
}