#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
size_t utf8_seqlen(unsigned char ch) {
  if (ch <= 0x7f)
    return 1;
  if ((ch & 0xe0) == 0xc0)
    return 2;
  if ((ch & 0xf0) == 0xe0)
    return 3;
  if ((ch & 0xf8) == 0xf0)
    return 4;
  if ((ch & 0xfc) == 0xf8)
    return 5;
  if ((ch & 0xfe) == 0xfc)
    return 6;
  return 0;
}


x86 assembly (clang, -O0):
<utf8_seqlen>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x7f,%eax
jg     1124 <utf8_seqlen+0x24>
movq   $0x1,-0x8(%rbp)
jmp    11d1 <utf8_seqlen+0xd1>
movzbl -0x9(%rbp),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    1145 <utf8_seqlen+0x45>
movq   $0x2,-0x8(%rbp)
jmp    11d1 <utf8_seqlen+0xd1>
movzbl -0x9(%rbp),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    1166 <utf8_seqlen+0x66>
movq   $0x3,-0x8(%rbp)
jmp    11d1 <utf8_seqlen+0xd1>
movzbl -0x9(%rbp),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    1187 <utf8_seqlen+0x87>
movq   $0x4,-0x8(%rbp)
jmp    11d1 <utf8_seqlen+0xd1>
movzbl -0x9(%rbp),%eax
and    $0xfc,%eax
cmp    $0xf8,%eax
jne    11a8 <utf8_seqlen+0xa8>
movq   $0x5,-0x8(%rbp)
jmp    11d1 <utf8_seqlen+0xd1>
movzbl -0x9(%rbp),%eax
and    $0xfe,%eax
cmp    $0xfc,%eax
jne    11c9 <utf8_seqlen+0xc9>
movq   $0x6,-0x8(%rbp)
jmp    11d1 <utf8_seqlen+0xd1>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_seqlen>:
mov    $0x1,%eax
test   %dil,%dil
js     110b <utf8_seqlen+0xb>
ret
mov    %edi,%ecx
and    $0xffffffe0,%ecx
mov    $0x2,%eax
cmp    $0xc0,%ecx
je     110a <utf8_seqlen+0xa>
mov    %edi,%ecx
and    $0xfffffff0,%ecx
mov    $0x3,%eax
cmp    $0xe0,%ecx
je     110a <utf8_seqlen+0xa>
mov    %edi,%ecx
and    $0xfffffff8,%ecx
mov    $0x4,%eax
cmp    $0xf0,%ecx
je     110a <utf8_seqlen+0xa>
mov    %edi,%ecx
and    $0xfffffffc,%ecx
mov    $0x5,%eax
cmp    $0xf8,%ecx
je     110a <utf8_seqlen+0xa>
and    $0xfffffffe,%edi
xor    %ecx,%ecx
cmp    $0xfc,%edi
mov    $0x6,%eax
cmovne %rcx,%rax
ret

LLVM IR (-O0):
define i64 @utf8_seqlen(i8 zeroext %0) {
%2 = alloca i64
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = zext i8 %4 to i32
%6 = icmp sle i32 %5, 127
br i1 %6, label %7, label %8
7: ; preds = %1
store i64 1, i64* %2
br label %39
8: ; preds = %1
%9 = load i8, i8* %3
%10 = zext i8 %9 to i32
%11 = and i32 %10, 224
%12 = icmp eq i32 %11, 192
br i1 %12, label %13, label %14
13: ; preds = %8
store i64 2, i64* %2
br label %39
14: ; preds = %8
%15 = load i8, i8* %3
%16 = zext i8 %15 to i32
%17 = and i32 %16, 240
%18 = icmp eq i32 %17, 224
br i1 %18, label %19, label %20
19: ; preds = %14
store i64 3, i64* %2
br label %39
20: ; preds = %14
%21 = load i8, i8* %3
%22 = zext i8 %21 to i32
%23 = and i32 %22, 248
%24 = icmp eq i32 %23, 240
br i1 %24, label %25, label %26
25: ; preds = %20
store i64 4, i64* %2
br label %39
26: ; preds = %20
%27 = load i8, i8* %3
%28 = zext i8 %27 to i32
%29 = and i32 %28, 252
%30 = icmp eq i32 %29, 248
br i1 %30, label %31, label %32
31: ; preds = %26
store i64 5, i64* %2
br label %39
32: ; preds = %26
%33 = load i8, i8* %3
%34 = zext i8 %33 to i32
%35 = and i32 %34, 254
%36 = icmp eq i32 %35, 252
br i1 %36, label %37, label %38
37: ; preds = %32
store i64 6, i64* %2
br label %39
38: ; preds = %32
store i64 0, i64* %2
br label %39
39: ; preds = %38, %37, %31, %25, %19, %13, %7
%40 = load i64, i64* %2
ret i64 %40
}

LLVM IR (-O2):
define i64 @utf8_seqlen(i8 zeroext %0) {
%2 = zext i8 %0 to i32
%3 = icmp sgt i8 %0, -1
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = and i32 %2, 224
%6 = icmp eq i32 %5, 192
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = and i32 %2, 240
%9 = icmp eq i32 %8, 224
br i1 %9, label %20, label %10
10: ; preds = %7
%11 = and i32 %2, 248
%12 = icmp eq i32 %11, 240
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = and i32 %2, 252
%15 = icmp eq i32 %14, 248
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = and i32 %2, 254
%18 = icmp eq i32 %17, 252
%19 = select i1 %18, i64 6, i64 0
br label %20
20: ; preds = %16, %13, %10, %7, %4, %1
%21 = phi i64 [ 1, %1 ], [ 2, %4 ], [ 3, %7 ], [ 4, %10 ], [ 5, %13 ], [ %19, %16 ]
ret i64 %21
}