int digitValue(char c) {
  int value = 0;
  switch (c) {
  case 'I':
    value = 1;
    break;
  case 'V':
    value = 5;
    break;
  case 'X':
    value = 10;
    break;
  case 'L':
    value = 50;
    break;
  case 'C':
    value = 100;
    break;
  case 'D':
    value = 500;
    break;
  case 'M':
    value = 1000;
    break;
  case '\0':
    value = 0;
    break;
  default:
    value = -1;
  }
  return value;
}


x86 assembly (clang, -O0):
<digitValue>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,-0xc(%rbp)
test   %eax,%eax
je     11f0 <digitValue+0xf0>
jmp    1125 <digitValue+0x25>
mov    -0xc(%rbp),%eax
sub    $0x43,%eax
je     11cc <digitValue+0xcc>
jmp    1136 <digitValue+0x36>
mov    -0xc(%rbp),%eax
sub    $0x44,%eax
je     11d8 <digitValue+0xd8>
jmp    1147 <digitValue+0x47>
mov    -0xc(%rbp),%eax
sub    $0x49,%eax
je     119c <digitValue+0x9c>
jmp    1158 <digitValue+0x58>
mov    -0xc(%rbp),%eax
sub    $0x4c,%eax
je     11c0 <digitValue+0xc0>
jmp    1169 <digitValue+0x69>
mov    -0xc(%rbp),%eax
sub    $0x4d,%eax
je     11e4 <digitValue+0xe4>
jmp    117a <digitValue+0x7a>
mov    -0xc(%rbp),%eax
sub    $0x56,%eax
je     11a8 <digitValue+0xa8>
jmp    118b <digitValue+0x8b>
mov    -0xc(%rbp),%eax
sub    $0x58,%eax
je     11b4 <digitValue+0xb4>
jmp    11fc <digitValue+0xfc>
movl   $0x1,-0x8(%rbp)
jmp    1203 <digitValue+0x103>
movl   $0x5,-0x8(%rbp)
jmp    1203 <digitValue+0x103>
movl   $0xa,-0x8(%rbp)
jmp    1203 <digitValue+0x103>
movl   $0x32,-0x8(%rbp)
jmp    1203 <digitValue+0x103>
movl   $0x64,-0x8(%rbp)
jmp    1203 <digitValue+0x103>
movl   $0x1f4,-0x8(%rbp)
jmp    1203 <digitValue+0x103>
movl   $0x3e8,-0x8(%rbp)
jmp    1203 <digitValue+0x103>
movl   $0x0,-0x8(%rbp)
jmp    1203 <digitValue+0x103>
movl   $0xffffffff,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<digitValue>:
lea    -0x43(%rdi),%ecx
cmp    $0x15,%ecx
ja     1123 <digitValue+0x23>
mov    $0x1,%eax
lea    0xeec(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x64,%eax
ret
test   %edi,%edi
jne    112a <digitValue+0x2a>
xor    %eax,%eax
ret
mov    $0xffffffff,%eax
ret
mov    $0x1f4,%eax
ret
mov    $0x32,%eax
ret
mov    $0x3e8,%eax
ret
mov    $0x5,%eax
ret
mov    $0xa,%eax
ret

LLVM IR (-O0):
define i32 @digitValue(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 = sext i8 %4 to i32
switch i32 %5, label %14 [
i32 73, label %6
i32 86, label %7
i32 88, label %8
i32 76, label %9
i32 67, label %10
i32 68, label %11
i32 77, label %12
i32 0, label %13
]
6: ; preds = %1
store i32 1, i32* %3
br label %15
7: ; preds = %1
store i32 5, i32* %3
br label %15
8: ; preds = %1
store i32 10, i32* %3
br label %15
9: ; preds = %1
store i32 50, i32* %3
br label %15
10: ; preds = %1
store i32 100, i32* %3
br label %15
11: ; preds = %1
store i32 500, i32* %3
br label %15
12: ; preds = %1
store i32 1000, i32* %3
br label %15
13: ; preds = %1
store i32 0, i32* %3
br label %15
14: ; preds = %1
store i32 -1, i32* %3
br label %15
15: ; preds = %14, %13, %12, %11, %10, %9, %8, %7, %6
%16 = load i32, i32* %3
ret i32 %16
}

LLVM IR (-O2):
define i32 @digitValue(i8 signext %0) {
%2 = sext i8 %0 to i32
switch i32 %2, label %10 [
i32 73, label %11
i32 86, label %3
i32 88, label %4
i32 76, label %5
i32 67, label %6
i32 68, label %7
i32 77, label %8
i32 0, label %9
]
3: ; preds = %1
br label %11
4: ; preds = %1
br label %11
5: ; preds = %1
br label %11
6: ; preds = %1
br label %11
7: ; preds = %1
br label %11
8: ; preds = %1
br label %11
9: ; preds = %1
br label %11
10: ; preds = %1
br label %11
11: ; preds = %1, %10, %9, %8, %7, %6, %5, %4, %3
%12 = phi i32 [ -1, %10 ], [ 0, %9 ], [ 1000, %8 ], [ 500, %7 ], [ 100, %6 ], [ 50, %5 ], [ 10, %4 ], [ 5, %3 ], [ 1, %1 ]
ret i32 %12
}