#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 */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ assert(char const *);
__attribute__((unused)) int utf8_char_bytewidth(const char *s) {
  assert(s);
  if ((*s & 0x80) == 0x00)
    return 1;
  else if ((*s & 0xe0) == 0xc0)
    return 2;
  else if ((*s & 0xf0) == 0xe0)
    return 3;
  else if ((*s & 0xf8) == 0xf0)
    return 4;
  else
    abort();
}


x86 assembly (clang, -O0):
<utf8_char_bytewidth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1156 <utf8_char_bytewidth+0x36>
movl   $0x1,-0x4(%rbp)
jmp    11c6 <utf8_char_bytewidth+0xa6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    1179 <utf8_char_bytewidth+0x59>
movl   $0x2,-0x4(%rbp)
jmp    11c6 <utf8_char_bytewidth+0xa6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    119c <utf8_char_bytewidth+0x7c>
movl   $0x3,-0x4(%rbp)
jmp    11c6 <utf8_char_bytewidth+0xa6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    11bf <utf8_char_bytewidth+0x9f>
movl   $0x4,-0x4(%rbp)
jmp    11c6 <utf8_char_bytewidth+0xa6>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_char_bytewidth>:
push   %rbx
mov    %rdi,%rbx
call   1040 <assert@plt>
movzbl (%rbx),%ecx
mov    $0x1,%eax
test   $0x80,%cl
je     116a <utf8_char_bytewidth+0x4a>
mov    %ecx,%edx
and    $0xffffffe0,%edx
mov    $0x2,%eax
cmp    $0xc0,%edx
je     116a <utf8_char_bytewidth+0x4a>
mov    %ecx,%edx
and    $0xfffffff0,%edx
mov    $0x3,%eax
cmp    $0xe0,%edx
je     116a <utf8_char_bytewidth+0x4a>
and    $0xfffffff8,%ecx
mov    $0x4,%eax
cmp    $0xf0,%ecx
jne    116c <utf8_char_bytewidth+0x4c>
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @utf8_char_bytewidth(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @assert(i8* %4)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = and i32 %8, 128
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %35
12: ; preds = %1
%13 = load i8*, i8** %3
%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 %19
18: ; preds = %12
store i32 2, i32* %2
br label %35
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = and i32 %22, 240
%24 = icmp eq i32 %23, 224
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 3, i32* %2
br label %35
26: ; preds = %19
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = and i32 %29, 248
%31 = icmp eq i32 %30, 240
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 4, i32* %2
br label %35
33: ; preds = %26
%34 = call i32 (...) @abort()
unreachable
35: ; preds = %32, %25, %18, %11
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @utf8_char_bytewidth(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
%3 = load i8, i8* %0
%4 = zext i8 %3 to i32
%5 = and i32 %4, 128
%6 = icmp eq i32 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = and i32 %4, 224
%9 = icmp eq i32 %8, 192
br i1 %9, label %18, label %10
10: ; preds = %7
%11 = and i32 %4, 240
%12 = icmp eq i32 %11, 224
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = and i32 %4, 248
%15 = icmp eq i32 %14, 240
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 (...) @abort()
unreachable
18: ; preds = %13, %10, %7, %1
%19 = phi i32 [ 1, %1 ], [ 2, %7 ], [ 3, %10 ], [ 4, %13 ]
ret i32 %19
}