#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*/ assert(char const *);
int utf8_encoded_expected_len(const char *str) {
  unsigned char c;
  assert(str);
  c = (unsigned char)str[0];
  if (c < 0x80)
    return 1;
  if ((c & 0xe0) == 0xc0)
    return 2;
  if ((c & 0xf0) == 0xe0)
    return 3;
  if ((c & 0xf8) == 0xf0)
    return 4;
  if ((c & 0xfc) == 0xf8)
    return 5;
  if ((c & 0xfe) == 0xfc)
    return 6;
  return 0;
}


x86 assembly (clang, -O0):
<utf8_encoded_expected_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x80,%eax
jge    1149 <utf8_encoded_expected_len+0x39>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <utf8_encoded_expected_len+0xe0>
movzbl -0x11(%rbp),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    1169 <utf8_encoded_expected_len+0x59>
movl   $0x2,-0x4(%rbp)
jmp    11f0 <utf8_encoded_expected_len+0xe0>
movzbl -0x11(%rbp),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    1189 <utf8_encoded_expected_len+0x79>
movl   $0x3,-0x4(%rbp)
jmp    11f0 <utf8_encoded_expected_len+0xe0>
movzbl -0x11(%rbp),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    11a9 <utf8_encoded_expected_len+0x99>
movl   $0x4,-0x4(%rbp)
jmp    11f0 <utf8_encoded_expected_len+0xe0>
movzbl -0x11(%rbp),%eax
and    $0xfc,%eax
cmp    $0xf8,%eax
jne    11c9 <utf8_encoded_expected_len+0xb9>
movl   $0x5,-0x4(%rbp)
jmp    11f0 <utf8_encoded_expected_len+0xe0>
movzbl -0x11(%rbp),%eax
and    $0xfe,%eax
cmp    $0xfc,%eax
jne    11e9 <utf8_encoded_expected_len+0xd9>
movl   $0x6,-0x4(%rbp)
jmp    11f0 <utf8_encoded_expected_len+0xe0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_encoded_expected_len>:
push   %rbx
mov    %rdi,%rbx
call   1030 <assert@plt>
movzbl (%rbx),%ecx
mov    $0x1,%eax
test   %cl,%cl
js     1127 <utf8_encoded_expected_len+0x17>
pop    %rbx
ret
mov    %ecx,%edx
and    $0xffffffe0,%edx
mov    $0x2,%eax
cmp    $0xc0,%edx
je     1125 <utf8_encoded_expected_len+0x15>
mov    %ecx,%edx
and    $0xfffffff0,%edx
mov    $0x3,%eax
cmp    $0xe0,%edx
je     1125 <utf8_encoded_expected_len+0x15>
mov    %ecx,%edx
and    $0xfffffff8,%edx
mov    $0x4,%eax
cmp    $0xf0,%edx
je     1125 <utf8_encoded_expected_len+0x15>
mov    %ecx,%edx
and    $0xfffffffc,%edx
mov    $0x5,%eax
cmp    $0xf8,%edx
je     1125 <utf8_encoded_expected_len+0x15>
and    $0xfffffffe,%ecx
xor    %edx,%edx
cmp    $0xfc,%ecx
mov    $0x6,%eax
cmovne %edx,%eax
pop    %rbx
ret

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

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