#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 s_utf8_width(const char *p) {
  if (*p == '\0')
    return 0;
  if ((unsigned char)*p <= 0x7F)
    return 1;
  if ((0xC2 <= (unsigned char)*p && (unsigned char)*p <= 0xDF))
    return 2;
  if ((0xE0 <= (unsigned char)*p && (unsigned char)*p <= 0xEF))
    return 3;
  if ((0xF0 <= (unsigned char)*p && (unsigned char)*p <= 0xF7))
    return 4;
  if ((0xF8 <= (unsigned char)*p && (unsigned char)*p <= 0xFB))
    return 5;
  if ((0xFC <= (unsigned char)*p && (unsigned char)*p <= 0xFD))
    return 6;
  return 1;
}


x86 assembly (clang, -O0):
<s_utf8_width>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1125 <s_utf8_width+0x25>
movq   $0x0,-0x8(%rbp)
jmp    1249 <s_utf8_width+0x149>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jg     1142 <s_utf8_width+0x42>
movq   $0x1,-0x8(%rbp)
jmp    1249 <s_utf8_width+0x149>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
mov    $0xc2,%eax
cmp    %ecx,%eax
jg     1175 <s_utf8_width+0x75>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xdf,%eax
jg     1175 <s_utf8_width+0x75>
movq   $0x2,-0x8(%rbp)
jmp    1249 <s_utf8_width+0x149>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
mov    $0xe0,%eax
cmp    %ecx,%eax
jg     11a8 <s_utf8_width+0xa8>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xef,%eax
jg     11a8 <s_utf8_width+0xa8>
movq   $0x3,-0x8(%rbp)
jmp    1249 <s_utf8_width+0x149>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
mov    $0xf0,%eax
cmp    %ecx,%eax
jg     11db <s_utf8_width+0xdb>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xf7,%eax
jg     11db <s_utf8_width+0xdb>
movq   $0x4,-0x8(%rbp)
jmp    1249 <s_utf8_width+0x149>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
mov    $0xf8,%eax
cmp    %ecx,%eax
jg     120e <s_utf8_width+0x10e>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xfb,%eax
jg     120e <s_utf8_width+0x10e>
movq   $0x5,-0x8(%rbp)
jmp    1249 <s_utf8_width+0x149>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
mov    $0xfc,%eax
cmp    %ecx,%eax
jg     1241 <s_utf8_width+0x141>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xfd,%eax
jg     1241 <s_utf8_width+0x141>
movq   $0x6,-0x8(%rbp)
jmp    1249 <s_utf8_width+0x149>
movq   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_utf8_width>:
mov    (%rdi),%cl
test   %cl,%cl
je     110e <s_utf8_width+0xe>
mov    $0x1,%eax
js     1111 <s_utf8_width+0x11>
ret
xor    %eax,%eax
ret
lea    0x3e(%rcx),%edx
mov    $0x2,%eax
cmp    $0x1e,%dl
jb     110d <s_utf8_width+0xd>
mov    %ecx,%edx
and    $0xf0,%dl
mov    $0x3,%eax
cmp    $0xe0,%dl
je     110d <s_utf8_width+0xd>
mov    %ecx,%edx
and    $0xf8,%dl
mov    $0x4,%eax
cmp    $0xf0,%dl
je     110d <s_utf8_width+0xd>
mov    %ecx,%edx
and    $0xfc,%dl
mov    $0x5,%eax
cmp    $0xf8,%dl
je     110d <s_utf8_width+0xd>
and    $0xfe,%cl
xor    %eax,%eax
cmp    $0xfc,%cl
sete   %al
lea    (%rax,%rax,4),%rax
add    $0x1,%rax
ret

LLVM IR (-O0):
define i64 @s_utf8_width(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 0, i64* %2
br label %71
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = icmp sle i32 %12, 127
br i1 %13, label %14, label %15
14: ; preds = %9
store i64 1, i64* %2
br label %71
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = icmp sle i32 194, %18
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = icmp sle i32 %23, 223
br i1 %24, label %25, label %26
25: ; preds = %20
store i64 2, i64* %2
br label %71
26: ; preds = %20, %15
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp sle i32 224, %29
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = icmp sle i32 %34, 239
br i1 %35, label %36, label %37
36: ; preds = %31
store i64 3, i64* %2
br label %71
37: ; preds = %31, %26
%38 = load i8*, i8** %3
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = icmp sle i32 240, %40
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = load i8*, i8** %3
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp sle i32 %45, 247
br i1 %46, label %47, label %48
47: ; preds = %42
store i64 4, i64* %2
br label %71
48: ; preds = %42, %37
%49 = load i8*, i8** %3
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = icmp sle i32 248, %51
br i1 %52, label %53, label %59
53: ; preds = %48
%54 = load i8*, i8** %3
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = icmp sle i32 %56, 251
br i1 %57, label %58, label %59
58: ; preds = %53
store i64 5, i64* %2
br label %71
59: ; preds = %53, %48
%60 = load i8*, i8** %3
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp sle i32 252, %62
br i1 %63, label %64, label %70
64: ; preds = %59
%65 = load i8*, i8** %3
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = icmp sle i32 %67, 253
br i1 %68, label %69, label %70
69: ; preds = %64
store i64 6, i64* %2
br label %71
70: ; preds = %64, %59
store i64 1, i64* %2
br label %71
71: ; preds = %70, %69, %58, %47, %36, %25, %14, %8
%72 = load i64, i64* %2
ret i64 %72
}

LLVM IR (-O2):
define i64 @s_utf8_width(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = icmp sgt i8 %2, -1
br i1 %5, label %22, label %6
6: ; preds = %4
%7 = add nsw i8 %2, 62
%8 = icmp ult i8 %7, 30
br i1 %8, label %22, label %9
9: ; preds = %6
%10 = and i8 %2, -16
%11 = icmp eq i8 %10, -32
br i1 %11, label %22, label %12
12: ; preds = %9
%13 = and i8 %2, -8
%14 = icmp eq i8 %13, -16
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = and i8 %2, -4
%17 = icmp eq i8 %16, -8
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = and i8 %2, -2
%20 = icmp eq i8 %19, -4
%21 = select i1 %20, i64 6, i64 1
br label %22
22: ; preds = %18, %15, %12, %9, %6, %4, %1
%23 = phi i64 [ 0, %1 ], [ 1, %4 ], [ 2, %6 ], [ 3, %9 ], [ 4, %12 ], [ 5, %15 ], [ %21, %18 ]
ret i64 %23
}