#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;
typedef int uint32_t;

/* Variables and functions */
uint32_t utf8_num_bytes(const uint8_t c) {
  if ((c & 0x80) == 0) {
    return 1;
  }
  if ((c & 0xE0) == 0xC0) {
    return 2;
  }
  if ((c & 0xF0) == 0xE0) {
    return 3;
  }
  if ((c & 0xF8) == 0xF0) {
    return 4;
  }
  return 0;
}


x86 assembly (clang, -O0):
<utf8_num_bytes>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1124 <utf8_num_bytes+0x24>
movl   $0x1,-0x4(%rbp)
jmp    1188 <utf8_num_bytes+0x88>
mov    -0x8(%rbp),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    1143 <utf8_num_bytes+0x43>
movl   $0x2,-0x4(%rbp)
jmp    1188 <utf8_num_bytes+0x88>
mov    -0x8(%rbp),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    1162 <utf8_num_bytes+0x62>
movl   $0x3,-0x4(%rbp)
jmp    1188 <utf8_num_bytes+0x88>
mov    -0x8(%rbp),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    1181 <utf8_num_bytes+0x81>
movl   $0x4,-0x4(%rbp)
jmp    1188 <utf8_num_bytes+0x88>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_num_bytes>:
mov    $0x1,%eax
test   $0x80,%dil
je     1149 <utf8_num_bytes+0x49>
mov    %edi,%ecx
and    $0xe0,%ecx
mov    $0x2,%eax
cmp    $0xc0,%ecx
je     1149 <utf8_num_bytes+0x49>
mov    %edi,%ecx
and    $0xf0,%ecx
mov    $0x3,%eax
cmp    $0xe0,%ecx
je     1149 <utf8_num_bytes+0x49>
and    $0xf8,%edi
xor    %eax,%eax
cmp    $0xf0,%edi
sete   %al
shl    $0x2,%eax
ret

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

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