#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 */
typedef int uint8_t;

/* Variables and functions */
size_t utf8_charlen(uint8_t c) {
  if (c < 0x80)
    return 1;
  if ((c & 0xe0) == 0xc0)
    return 2;
  if ((c & 0xf0) == 0xe0)
    return 3;
  if ((c & 0xf8) == 0xf0 && (c <= 0xf4))
    return 4;
  else
    return 0;
}


x86 assembly (clang, -O0):
<utf8_charlen>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    1121 <utf8_charlen+0x21>
movq   $0x1,-0x8(%rbp)
jmp    1196 <utf8_charlen+0x96>
mov    -0xc(%rbp),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    1141 <utf8_charlen+0x41>
movq   $0x2,-0x8(%rbp)
jmp    1196 <utf8_charlen+0x96>
mov    -0xc(%rbp),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    1161 <utf8_charlen+0x61>
movq   $0x3,-0x8(%rbp)
jmp    1196 <utf8_charlen+0x96>
mov    -0xc(%rbp),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    118e <utf8_charlen+0x8e>
cmpl   $0xf4,-0xc(%rbp)
jg     118e <utf8_charlen+0x8e>
movq   $0x4,-0x8(%rbp)
jmp    1196 <utf8_charlen+0x96>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_charlen>:
mov    $0x1,%eax
cmp    $0x80,%edi
jl     1158 <utf8_charlen+0x58>
mov    %edi,%ecx
and    $0xe0,%ecx
mov    $0x2,%eax
cmp    $0xc0,%ecx
je     1158 <utf8_charlen+0x58>
mov    %edi,%ecx
and    $0xf0,%ecx
mov    $0x3,%eax
cmp    $0xe0,%ecx
je     1158 <utf8_charlen+0x58>
mov    %edi,%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
sete   %al
cmp    $0xf5,%edi
setb   %cl
and    %al,%cl
movzbl %cl,%eax
shl    $0x2,%rax
ret

LLVM IR (-O0):
define i64 @utf8_charlen(i32 %0) {
%2 = alloca i64
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 128
br i1 %5, label %6, label %7
6: ; preds = %1
store i64 1, i64* %2
br label %26
7: ; preds = %1
%8 = load i32, i32* %3
%9 = and i32 %8, 224
%10 = icmp eq i32 %9, 192
br i1 %10, label %11, label %12
11: ; preds = %7
store i64 2, i64* %2
br label %26
12: ; preds = %7
%13 = load i32, i32* %3
%14 = and i32 %13, 240
%15 = icmp eq i32 %14, 224
br i1 %15, label %16, label %17
16: ; preds = %12
store i64 3, i64* %2
br label %26
17: ; preds = %12
%18 = load i32, i32* %3
%19 = and i32 %18, 248
%20 = icmp eq i32 %19, 240
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* %3
%23 = icmp sle i32 %22, 244
br i1 %23, label %24, label %25
24: ; preds = %21
store i64 4, i64* %2
br label %26
25: ; preds = %21, %17
store i64 0, i64* %2
br label %26
26: ; preds = %25, %24, %16, %11, %6
%27 = load i64, i64* %2
ret i64 %27
}

LLVM IR (-O2):
define i64 @utf8_charlen(i32 %0) {
%2 = icmp slt i32 %0, 128
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = and i32 %0, 224
%5 = icmp eq i32 %4, 192
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = and i32 %0, 240
%8 = icmp eq i32 %7, 224
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = and i32 %0, 248
%11 = icmp eq i32 %10, 240
%12 = icmp ult i32 %0, 245
%13 = and i1 %12, %11
%14 = select i1 %13, i64 4, i64 0
br label %15
15: ; preds = %9, %6, %3, %1
%16 = phi i64 [ 1, %1 ], [ 2, %3 ], [ 3, %6 ], [ %14, %9 ]
ret i64 %16
}