int fcitx_utf8_type(char c) {
  if (!(c & 0x80))
    return 1;
  if (!(c & 0x40))
    return 0;
  if (!(c & 0x20))
    return 2;
  if (!(c & 0x10))
    return 3;
  if (!(c & 0x08))
    return 4;
  if (!(c & 0x04))
    return 5;
  if (!(c & 0x02))
    return 6;
  return -1;
}


x86 assembly (clang, -O0):
<fcitx_utf8_type>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1128 <fcitx_utf8_type+0x28>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <fcitx_utf8_type+0xd7>
movsbl -0x5(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
jne    1144 <fcitx_utf8_type+0x44>
movl   $0x0,-0x4(%rbp)
jmp    11d7 <fcitx_utf8_type+0xd7>
movsbl -0x5(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
jne    1160 <fcitx_utf8_type+0x60>
movl   $0x2,-0x4(%rbp)
jmp    11d7 <fcitx_utf8_type+0xd7>
movsbl -0x5(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
jne    117c <fcitx_utf8_type+0x7c>
movl   $0x3,-0x4(%rbp)
jmp    11d7 <fcitx_utf8_type+0xd7>
movsbl -0x5(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
jne    1198 <fcitx_utf8_type+0x98>
movl   $0x4,-0x4(%rbp)
jmp    11d7 <fcitx_utf8_type+0xd7>
movsbl -0x5(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    11b4 <fcitx_utf8_type+0xb4>
movl   $0x5,-0x4(%rbp)
jmp    11d7 <fcitx_utf8_type+0xd7>
movsbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    11d0 <fcitx_utf8_type+0xd0>
movl   $0x6,-0x4(%rbp)
jmp    11d7 <fcitx_utf8_type+0xd7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utf8_type>:
mov    $0x1,%eax
test   $0x80,%dil
je     114d <fcitx_utf8_type+0x4d>
xor    %eax,%eax
test   $0x40,%dil
je     114d <fcitx_utf8_type+0x4d>
mov    $0x2,%eax
test   $0x20,%dil
je     114d <fcitx_utf8_type+0x4d>
mov    $0x3,%eax
test   $0x10,%dil
je     114d <fcitx_utf8_type+0x4d>
mov    $0x4,%eax
test   $0x8,%dil
je     114d <fcitx_utf8_type+0x4d>
mov    $0x5,%eax
test   $0x4,%dil
je     114d <fcitx_utf8_type+0x4d>
movzbl %dil,%eax
and    $0x2,%eax
neg    %eax
sbb    %eax,%eax
or     $0x6,%eax
ret

LLVM IR (-O0):
define i32 @fcitx_utf8_type(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = and i32 %5, 128
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 1, i32* %2
br label %46
9: ; preds = %1
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = and i32 %11, 64
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %9
store i32 0, i32* %2
br label %46
15: ; preds = %9
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = and i32 %17, 32
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %15
store i32 2, i32* %2
br label %46
21: ; preds = %15
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = and i32 %23, 16
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %21
store i32 3, i32* %2
br label %46
27: ; preds = %21
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = and i32 %29, 8
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %27
store i32 4, i32* %2
br label %46
33: ; preds = %27
%34 = load i8, i8* %3
%35 = sext i8 %34 to i32
%36 = and i32 %35, 4
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %33
store i32 5, i32* %2
br label %46
39: ; preds = %33
%40 = load i8, i8* %3
%41 = sext i8 %40 to i32
%42 = and i32 %41, 2
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %39
store i32 6, i32* %2
br label %46
45: ; preds = %39
store i32 -1, i32* %2
br label %46
46: ; preds = %45, %44, %38, %32, %26, %20, %14, %8
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
define i32 @fcitx_utf8_type(i8 signext %0) {
%2 = zext i8 %0 to i32
%3 = and i32 %2, 128
%4 = icmp eq i32 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = and i32 %2, 64
%7 = icmp eq i32 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %5
%9 = and i32 %2, 32
%10 = icmp eq i32 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %8
%12 = and i32 %2, 16
%13 = icmp eq i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %11
%15 = and i32 %2, 8
%16 = icmp eq i32 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %14
%18 = and i32 %2, 4
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = and i32 %2, 2
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i32 6, i32 -1
br label %24
24: ; preds = %20, %17, %14, %11, %8, %5, %1
%25 = phi i32 [ 1, %1 ], [ 0, %5 ], [ 2, %8 ], [ 3, %11 ], [ 4, %14 ], [ 5, %17 ], [ %23, %20 ]
ret i32 %25
}