int utf8_sequence_length(const char c) {
  static const unsigned char byte[] = {0x00, 0x80, 0xC2, 0xE0, 0xF0};
  static const int len[] = {1, 0, 2, 3, 4};
  unsigned i;
  for (i = 1; i < (sizeof(byte) / sizeof(*byte)); i++)
    if (c >= byte[i - 1] && c < byte[i])
      break;
  return len[i - 1];
}


x86 assembly (clang, -O0):
<utf8_sequence_length>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    $0x5,%rax
jae    1173 <utf8_sequence_length+0x73>
movsbl -0x1(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    %ecx,%edx
lea    0xecd(%rip),%rcx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jl     1160 <utf8_sequence_length+0x60>
movsbl -0x1(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    %ecx,%edx
lea    0xeb1(%rip),%rcx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jge    1160 <utf8_sequence_length+0x60>
jmp    1173 <utf8_sequence_length+0x73>
jmp    1165 <utf8_sequence_length+0x65>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1111 <utf8_sequence_length+0x11>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0xe8c(%rip),%rax
mov    (%rax,%rcx,4),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_sequence_length>:
shr    $0x5,%dil
and    $0x4,%dil
movzbl %dil,%eax
lea    0xeed(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
@utf8_sequence_length.byte = internal constant [5 x i8] c"\00\80\C2\E0\F0"
@utf8_sequence_length.len = internal constant [5 x i32] [i32 1, i32 0, i32 2, i32 3, i32 4]
define i32 @utf8_sequence_length(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
store i32 1, i32* %3
br label %4
4: ; preds = %29, %1
%5 = load i32, i32* %3
%6 = zext i32 %5 to i64
%7 = icmp ult i64 %6, 5
br i1 %7, label %8, label %32
8: ; preds = %4
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = load i32, i32* %3
%12 = sub i32 %11, 1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [5 x i8], [5 x i8]* @utf8_sequence_length.byte, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp sge i32 %10, %16
br i1 %17, label %18, label %28
18: ; preds = %8
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = load i32, i32* %3
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [5 x i8], [5 x i8]* @utf8_sequence_length.byte, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = icmp slt i32 %20, %25
br i1 %26, label %27, label %28
27: ; preds = %18
br label %32
28: ; preds = %18, %8
br label %29
29: ; preds = %28
%30 = load i32, i32* %3
%31 = add i32 %30, 1
store i32 %31, i32* %3
br label %4
32: ; preds = %27, %4
%33 = load i32, i32* %3
%34 = sub i32 %33, 1
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [5 x i32], [5 x i32]* @utf8_sequence_length.len, i64 0, i64 %35
%37 = load i32, i32* %36
ret i32 %37
}

LLVM IR (-O2):
@utf8_sequence_length.len = internal unnamed_addr constant [5 x i32] [i32 1, i32 0, i32 2, i32 3, i32 4]
define i32 @utf8_sequence_length(i8 signext %0) {
%2 = lshr i8 %0, 5
%3 = and i8 %2, 4
%4 = zext i8 %3 to i64
%5 = getelementptr inbounds [5 x i32], [5 x i32]* @utf8_sequence_length.len, i64 0, i64 %4
%6 = load i32, i32* %5
ret i32 %6
}