__attribute__((visibility("default"))) int fcitx_utf8_char_len(const char *in) {
  if (!(in[0] & 0x80))
    return 1;
  if ((in[0] & 0xe0) == 0xc0 && (((in[1]) & 0xc0) == 0x80))
    return 2;
  if ((in[0] & 0xf0) == 0xe0 && (((in[1]) & 0xc0) == 0x80) &&
      (((in[2]) & 0xc0) == 0x80))
    return 3;
  if ((in[0] & 0xf8) == 0xf0 && (((in[1]) & 0xc0) == 0x80) &&
      (((in[2]) & 0xc0) == 0x80) && (((in[3]) & 0xc0) == 0x80))
    return 4;
  if ((in[0] & 0xfc) == 0xf8 && (((in[1]) & 0xc0) == 0x80) &&
      (((in[2]) & 0xc0) == 0x80) && (((in[3]) & 0xc0) == 0x80) &&
      (((in[4]) & 0xc0) == 0x80))
    return 5;
  if ((in[0] & 0xfe) == 0xfc && (((in[1]) & 0xc0) == 0x80) &&
      (((in[2]) & 0xc0) == 0x80) && (((in[3]) & 0xc0) == 0x80) &&
      (((in[4]) & 0xc0) == 0x80) && (((in[5]) & 0xc0) == 0x80))
    return 6;
  return 1;
}


x86 assembly (clang, -O0):
<fcitx_utf8_char_len>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1129 <fcitx_utf8_char_len+0x29>
movl   $0x1,-0x4(%rbp)
jmp    1347 <fcitx_utf8_char_len+0x247>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    1164 <fcitx_utf8_char_len+0x64>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1164 <fcitx_utf8_char_len+0x64>
movl   $0x2,-0x4(%rbp)
jmp    1347 <fcitx_utf8_char_len+0x247>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    11b7 <fcitx_utf8_char_len+0xb7>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    11b7 <fcitx_utf8_char_len+0xb7>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    11b7 <fcitx_utf8_char_len+0xb7>
movl   $0x3,-0x4(%rbp)
jmp    1347 <fcitx_utf8_char_len+0x247>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    1222 <fcitx_utf8_char_len+0x122>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1222 <fcitx_utf8_char_len+0x122>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1222 <fcitx_utf8_char_len+0x122>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1222 <fcitx_utf8_char_len+0x122>
movl   $0x4,-0x4(%rbp)
jmp    1347 <fcitx_utf8_char_len+0x247>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xfc,%eax
cmp    $0xf8,%eax
jne    12a5 <fcitx_utf8_char_len+0x1a5>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    12a5 <fcitx_utf8_char_len+0x1a5>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    12a5 <fcitx_utf8_char_len+0x1a5>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    12a5 <fcitx_utf8_char_len+0x1a5>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    12a5 <fcitx_utf8_char_len+0x1a5>
movl   $0x5,-0x4(%rbp)
jmp    1347 <fcitx_utf8_char_len+0x247>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xfe,%eax
cmp    $0xfc,%eax
jne    1340 <fcitx_utf8_char_len+0x240>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1340 <fcitx_utf8_char_len+0x240>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1340 <fcitx_utf8_char_len+0x240>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1340 <fcitx_utf8_char_len+0x240>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1340 <fcitx_utf8_char_len+0x240>
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1340 <fcitx_utf8_char_len+0x240>
movl   $0x6,-0x4(%rbp)
jmp    1347 <fcitx_utf8_char_len+0x247>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utf8_char_len>:
movzbl (%rdi),%ecx
mov    $0x1,%eax
test   $0x80,%cl
je     11f4 <fcitx_utf8_char_len+0xf4>
mov    %ecx,%eax
and    $0xffffffe0,%eax
cmp    $0xc0,%eax
jne    1131 <fcitx_utf8_char_len+0x31>
mov    0x1(%rdi),%dl
and    $0xc0,%dl
mov    $0x2,%eax
cmp    $0x80,%dl
je     11f4 <fcitx_utf8_char_len+0xf4>
mov    %ecx,%eax
and    $0xf0,%al
cmp    $0xe0,%al
jne    1156 <fcitx_utf8_char_len+0x56>
mov    0x1(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    1156 <fcitx_utf8_char_len+0x56>
mov    0x2(%rdi),%dl
and    $0xc0,%dl
mov    $0x3,%eax
cmp    $0x80,%dl
je     11f4 <fcitx_utf8_char_len+0xf4>
mov    %ecx,%eax
and    $0xf8,%al
cmp    $0xf0,%al
jne    1180 <fcitx_utf8_char_len+0x80>
mov    0x1(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    1180 <fcitx_utf8_char_len+0x80>
mov    0x2(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    1180 <fcitx_utf8_char_len+0x80>
mov    0x3(%rdi),%dl
and    $0xc0,%dl
mov    $0x4,%eax
cmp    $0x80,%dl
je     11f4 <fcitx_utf8_char_len+0xf4>
mov    %ecx,%eax
and    $0xfc,%al
cmp    $0xf8,%al
jne    11b3 <fcitx_utf8_char_len+0xb3>
mov    0x1(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    11b3 <fcitx_utf8_char_len+0xb3>
mov    0x2(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    11b3 <fcitx_utf8_char_len+0xb3>
mov    0x3(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    11b3 <fcitx_utf8_char_len+0xb3>
mov    0x4(%rdi),%dl
and    $0xc0,%dl
mov    $0x5,%eax
cmp    $0x80,%dl
je     11f4 <fcitx_utf8_char_len+0xf4>
and    $0xfe,%cl
cmp    $0xfc,%cl
jne    11ef <fcitx_utf8_char_len+0xef>
mov    0x1(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    11ef <fcitx_utf8_char_len+0xef>
mov    0x2(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    11ef <fcitx_utf8_char_len+0xef>
mov    0x3(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    11ef <fcitx_utf8_char_len+0xef>
mov    0x4(%rdi),%al
and    $0xc0,%al
cmp    $0x80,%al
jne    11ef <fcitx_utf8_char_len+0xef>
mov    0x5(%rdi),%cl
and    $0xc0,%cl
mov    $0x6,%eax
cmp    $0x80,%cl
je     11f4 <fcitx_utf8_char_len+0xf4>
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i32 @fcitx_utf8_char_len(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = and i32 %7, 128
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 1, i32* %2
br label %157
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = and i32 %15, 224
%17 = icmp eq i32 %16, 192
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = and i32 %22, 192
%24 = icmp eq i32 %23, 128
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 2, i32* %2
br label %157
26: ; preds = %18, %11
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = and i32 %30, 240
%32 = icmp eq i32 %31, 224
br i1 %32, label %33, label %48
33: ; preds = %26
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = and i32 %37, 192
%39 = icmp eq i32 %38, 128
br i1 %39, label %40, label %48
40: ; preds = %33
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = and i32 %44, 192
%46 = icmp eq i32 %45, 128
br i1 %46, label %47, label %48
47: ; preds = %40
store i32 3, i32* %2
br label %157
48: ; preds = %40, %33, %26
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = and i32 %52, 248
%54 = icmp eq i32 %53, 240
br i1 %54, label %55, label %77
55: ; preds = %48
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = and i32 %59, 192
%61 = icmp eq i32 %60, 128
br i1 %61, label %62, label %77
62: ; preds = %55
%63 = load i8*, i8** %3
%64 = getelementptr inbounds i8, i8* %63, i64 2
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = and i32 %66, 192
%68 = icmp eq i32 %67, 128
br i1 %68, label %69, label %77
69: ; preds = %62
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i64 3
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = and i32 %73, 192
%75 = icmp eq i32 %74, 128
br i1 %75, label %76, label %77
76: ; preds = %69
store i32 4, i32* %2
br label %157
77: ; preds = %69, %62, %55, %48
%78 = load i8*, i8** %3
%79 = getelementptr inbounds i8, i8* %78, i64 0
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = and i32 %81, 252
%83 = icmp eq i32 %82, 248
br i1 %83, label %84, label %113
84: ; preds = %77
%85 = load i8*, i8** %3
%86 = getelementptr inbounds i8, i8* %85, i64 1
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = and i32 %88, 192
%90 = icmp eq i32 %89, 128
br i1 %90, label %91, label %113
91: ; preds = %84
%92 = load i8*, i8** %3
%93 = getelementptr inbounds i8, i8* %92, i64 2
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = and i32 %95, 192
%97 = icmp eq i32 %96, 128
br i1 %97, label %98, label %113
98: ; preds = %91
%99 = load i8*, i8** %3
%100 = getelementptr inbounds i8, i8* %99, i64 3
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = and i32 %102, 192
%104 = icmp eq i32 %103, 128
br i1 %104, label %105, label %113
105: ; preds = %98
%106 = load i8*, i8** %3
%107 = getelementptr inbounds i8, i8* %106, i64 4
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = and i32 %109, 192
%111 = icmp eq i32 %110, 128
br i1 %111, label %112, label %113
112: ; preds = %105
store i32 5, i32* %2
br label %157
113: ; preds = %105, %98, %91, %84, %77
%114 = load i8*, i8** %3
%115 = getelementptr inbounds i8, i8* %114, i64 0
%116 = load i8, i8* %115
%117 = sext i8 %116 to i32
%118 = and i32 %117, 254
%119 = icmp eq i32 %118, 252
br i1 %119, label %120, label %156
120: ; preds = %113
%121 = load i8*, i8** %3
%122 = getelementptr inbounds i8, i8* %121, i64 1
%123 = load i8, i8* %122
%124 = sext i8 %123 to i32
%125 = and i32 %124, 192
%126 = icmp eq i32 %125, 128
br i1 %126, label %127, label %156
127: ; preds = %120
%128 = load i8*, i8** %3
%129 = getelementptr inbounds i8, i8* %128, i64 2
%130 = load i8, i8* %129
%131 = sext i8 %130 to i32
%132 = and i32 %131, 192
%133 = icmp eq i32 %132, 128
br i1 %133, label %134, label %156
134: ; preds = %127
%135 = load i8*, i8** %3
%136 = getelementptr inbounds i8, i8* %135, i64 3
%137 = load i8, i8* %136
%138 = sext i8 %137 to i32
%139 = and i32 %138, 192
%140 = icmp eq i32 %139, 128
br i1 %140, label %141, label %156
141: ; preds = %134
%142 = load i8*, i8** %3
%143 = getelementptr inbounds i8, i8* %142, i64 4
%144 = load i8, i8* %143
%145 = sext i8 %144 to i32
%146 = and i32 %145, 192
%147 = icmp eq i32 %146, 128
br i1 %147, label %148, label %156
148: ; preds = %141
%149 = load i8*, i8** %3
%150 = getelementptr inbounds i8, i8* %149, i64 5
%151 = load i8, i8* %150
%152 = sext i8 %151 to i32
%153 = and i32 %152, 192
%154 = icmp eq i32 %153, 128
br i1 %154, label %155, label %156
155: ; preds = %148
store i32 6, i32* %2
br label %157
156: ; preds = %148, %141, %134, %127, %120, %113
store i32 1, i32* %2
br label %157
157: ; preds = %156, %155, %112, %76, %47, %25, %10
%158 = load i32, i32* %2
ret i32 %158
}

LLVM IR (-O2):
define i32 @fcitx_utf8_char_len(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = zext i8 %2 to i32
%4 = and i32 %3, 128
%5 = icmp eq i32 %4, 0
br i1 %5, label %97, label %6
6: ; preds = %1
%7 = and i32 %3, 224
%8 = icmp eq i32 %7, 192
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = and i8 %11, -64
%13 = icmp eq i8 %12, -128
br i1 %13, label %97, label %14
14: ; preds = %9, %6
%15 = and i8 %2, -16
%16 = icmp eq i8 %15, -32
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %0, i64 1
%19 = load i8, i8* %18
%20 = and i8 %19, -64
%21 = icmp eq i8 %20, -128
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = getelementptr inbounds i8, i8* %0, i64 2
%24 = load i8, i8* %23
%25 = and i8 %24, -64
%26 = icmp eq i8 %25, -128
br i1 %26, label %97, label %27
27: ; preds = %22, %17, %14
%28 = and i8 %2, -8
%29 = icmp eq i8 %28, -16
br i1 %29, label %30, label %45
30: ; preds = %27
%31 = getelementptr inbounds i8, i8* %0, i64 1
%32 = load i8, i8* %31
%33 = and i8 %32, -64
%34 = icmp eq i8 %33, -128
br i1 %34, label %35, label %45
35: ; preds = %30
%36 = getelementptr inbounds i8, i8* %0, i64 2
%37 = load i8, i8* %36
%38 = and i8 %37, -64
%39 = icmp eq i8 %38, -128
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = getelementptr inbounds i8, i8* %0, i64 3
%42 = load i8, i8* %41
%43 = and i8 %42, -64
%44 = icmp eq i8 %43, -128
br i1 %44, label %97, label %45
45: ; preds = %40, %35, %30, %27
%46 = and i8 %2, -4
%47 = icmp eq i8 %46, -8
br i1 %47, label %48, label %68
48: ; preds = %45
%49 = getelementptr inbounds i8, i8* %0, i64 1
%50 = load i8, i8* %49
%51 = and i8 %50, -64
%52 = icmp eq i8 %51, -128
br i1 %52, label %53, label %68
53: ; preds = %48
%54 = getelementptr inbounds i8, i8* %0, i64 2
%55 = load i8, i8* %54
%56 = and i8 %55, -64
%57 = icmp eq i8 %56, -128
br i1 %57, label %58, label %68
58: ; preds = %53
%59 = getelementptr inbounds i8, i8* %0, i64 3
%60 = load i8, i8* %59
%61 = and i8 %60, -64
%62 = icmp eq i8 %61, -128
br i1 %62, label %63, label %68
63: ; preds = %58
%64 = getelementptr inbounds i8, i8* %0, i64 4
%65 = load i8, i8* %64
%66 = and i8 %65, -64
%67 = icmp eq i8 %66, -128
br i1 %67, label %97, label %68
68: ; preds = %63, %58, %53, %48, %45
%69 = and i8 %2, -2
%70 = icmp eq i8 %69, -4
br i1 %70, label %71, label %96
71: ; preds = %68
%72 = getelementptr inbounds i8, i8* %0, i64 1
%73 = load i8, i8* %72
%74 = and i8 %73, -64
%75 = icmp eq i8 %74, -128
br i1 %75, label %76, label %96
76: ; preds = %71
%77 = getelementptr inbounds i8, i8* %0, i64 2
%78 = load i8, i8* %77
%79 = and i8 %78, -64
%80 = icmp eq i8 %79, -128
br i1 %80, label %81, label %96
81: ; preds = %76
%82 = getelementptr inbounds i8, i8* %0, i64 3
%83 = load i8, i8* %82
%84 = and i8 %83, -64
%85 = icmp eq i8 %84, -128
br i1 %85, label %86, label %96
86: ; preds = %81
%87 = getelementptr inbounds i8, i8* %0, i64 4
%88 = load i8, i8* %87
%89 = and i8 %88, -64
%90 = icmp eq i8 %89, -128
br i1 %90, label %91, label %96
91: ; preds = %86
%92 = getelementptr inbounds i8, i8* %0, i64 5
%93 = load i8, i8* %92
%94 = and i8 %93, -64
%95 = icmp eq i8 %94, -128
br i1 %95, label %97, label %96
96: ; preds = %91, %86, %81, %76, %71, %68
br label %97
97: ; preds = %91, %63, %40, %22, %9, %1, %96
%98 = phi i32 [ 1, %96 ], [ 1, %1 ], [ 2, %9 ], [ 3, %22 ], [ 4, %40 ], [ 5, %63 ], [ 6, %91 ]
ret i32 %98
}