int parse_extension(const char *extension, char **endptr) {
  int i;
  switch (extension[0]) {
  case '2':
  case '4':
  case '5':
  case '6':
  case '7':
  case '9':
    i = extension[0] - '0';
    break;
  case '1':
    switch (extension[1]) {
    case '1':
      i = 11;
      break;
    case '3':
      i = 13;
      break;
    default:
      i = 0;
      break;
    }
    break;
  default:
    i = 0;
    break;
  }
  *endptr = (char *)extension + (i > 9 ? 2 : (i > 0 ? 1 : 0));
  return i;
}


x86 assembly (clang, -O0):
<parse_extension>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
sub    $0x31,%eax
je     116c <parse_extension+0x6c>
jmp    1124 <parse_extension+0x24>
mov    -0x18(%rbp),%eax
sub    $0x32,%eax
je     115a <parse_extension+0x5a>
jmp    1135 <parse_extension+0x35>
mov    -0x18(%rbp),%eax
add    $0xffffffcc,%eax
sub    $0x4,%eax
jb     115a <parse_extension+0x5a>
jmp    1149 <parse_extension+0x49>
mov    -0x18(%rbp),%eax
sub    $0x39,%eax
jne    11ba <parse_extension+0xba>
jmp    115a <parse_extension+0x5a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    11c1 <parse_extension+0xc1>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x31,%eax
je     1196 <parse_extension+0x96>
jmp    1185 <parse_extension+0x85>
mov    -0x1c(%rbp),%eax
sub    $0x33,%eax
je     11a2 <parse_extension+0xa2>
jmp    11ae <parse_extension+0xae>
movl   $0xb,-0x14(%rbp)
jmp    11b5 <parse_extension+0xb5>
movl   $0xd,-0x14(%rbp)
jmp    11b5 <parse_extension+0xb5>
movl   $0x0,-0x14(%rbp)
jmp    11c1 <parse_extension+0xc1>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x9,-0x14(%rbp)
jle    11e0 <parse_extension+0xe0>
mov    $0x2,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f3 <parse_extension+0xf3>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovg  %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%eax
cltq
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_extension>:
movsbl (%rdi),%ecx
xor    %eax,%eax
cmp    $0x39,%ecx
ja     111f <parse_extension+0x1f>
movabs $0x2f4000000000000,%rdx
bt     %rcx,%rdx
jae    112d <parse_extension+0x2d>
add    $0xffffffd0,%ecx
mov    %ecx,%eax
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
add    %rcx,%rdi
mov    %rdi,(%rsi)
ret
cmp    $0x31,%rcx
jne    111f <parse_extension+0x1f>
mov    0x1(%rdi),%al
cmp    $0x31,%al
je     1145 <parse_extension+0x45>
cmp    $0x33,%al
jne    1151 <parse_extension+0x51>
mov    $0xd,%eax
jmp    114a <parse_extension+0x4a>
mov    $0xb,%eax
mov    $0x2,%ecx
jmp    1126 <parse_extension+0x26>
xor    %eax,%eax
xor    %ecx,%ecx
jmp    1126 <parse_extension+0x26>

LLVM IR (-O0):
define i32 @parse_extension(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %25 [
i32 50, label %10
i32 52, label %10
i32 53, label %10
i32 54, label %10
i32 55, label %10
i32 57, label %10
i32 49, label %16
]
10: ; preds = %2, %2, %2, %2, %2, %2
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = sub nsw i32 %14, 48
store i32 %15, i32* %5
br label %26
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
switch i32 %20, label %23 [
i32 49, label %21
i32 51, label %22
]
21: ; preds = %16
store i32 11, i32* %5
br label %24
22: ; preds = %16
store i32 13, i32* %5
br label %24
23: ; preds = %16
store i32 0, i32* %5
br label %24
24: ; preds = %23, %22, %21
br label %26
25: ; preds = %2
store i32 0, i32* %5
br label %26
26: ; preds = %25, %24, %10
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = icmp sgt i32 %28, 9
br i1 %29, label %30, label %31
30: ; preds = %26
br label %36
31: ; preds = %26
%32 = load i32, i32* %5
%33 = icmp sgt i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 1, i32 0
br label %36
36: ; preds = %31, %30
%37 = phi i32 [ 2, %30 ], [ %35, %31 ]
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %27, i64 %38
%40 = load i8**, i8*** %4
store i8* %39, i8** %40
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
define i32 @parse_extension(i8* %0, i8** nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = sext i8 %3 to i32
switch i32 %4, label %10 [
i32 50, label %5
i32 52, label %5
i32 53, label %5
i32 54, label %5
i32 55, label %5
i32 57, label %5
i32 49, label %7
]
5: ; preds = %2, %2, %2, %2, %2, %2
%6 = add nsw i32 %4, -48
br label %10
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
switch i8 %9, label %17 [
i8 49, label %15
i8 51, label %14
]
10: ; preds = %5, %2
%11 = phi i32 [ 0, %2 ], [ %6, %5 ]
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
br label %17
14: ; preds = %7
br label %15
15: ; preds = %7, %14
%16 = phi i32 [ 11, %7 ], [ 13, %14 ]
br label %17
17: ; preds = %7, %10, %15
%18 = phi i32 [ %16, %15 ], [ %11, %10 ], [ 0, %7 ]
%19 = phi i64 [ 2, %15 ], [ %13, %10 ], [ 0, %7 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8* %20, i8** %1
ret i32 %18
}