#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(int /*<<< orphan*/);
int utf8_following_bytes(const char c) {
  if ((c & 0x80) == 0) {
    return 0;
  } else if ((c & 0xE0) == 0xC0) {
    return 1;
  } else if ((c & 0xF0) == 0xE0) {
    return 2;
  } else if ((c & 0xF8) == 0xF0) {
    return 3;
  } else if ((c & 0xC0) == 0x80) {
    return -1;
  }
  assert(false && "Invalid UTF-8 byte");
}


x86 assembly (clang, -O0):
<utf8_following_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    113c <utf8_following_bytes+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    11d7 <utf8_following_bytes+0xc7>
movsbl -0x5(%rbp),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    115c <utf8_following_bytes+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <utf8_following_bytes+0xc7>
movsbl -0x5(%rbp),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    117c <utf8_following_bytes+0x6c>
movl   $0x2,-0x4(%rbp)
jmp    11d7 <utf8_following_bytes+0xc7>
movsbl -0x5(%rbp),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    119c <utf8_following_bytes+0x8c>
movl   $0x3,-0x4(%rbp)
jmp    11d7 <utf8_following_bytes+0xc7>
movsbl -0x5(%rbp),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    11bc <utf8_following_bytes+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <utf8_following_bytes+0xc7>
jmp    11c1 <utf8_following_bytes+0xb1>
jmp    11c6 <utf8_following_bytes+0xb6>
jmp    11cb <utf8_following_bytes+0xbb>
jmp    11d0 <utf8_following_bytes+0xc0>
xor    %edi,%edi
call   1030 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_following_bytes>:
xor    %eax,%eax
test   $0x80,%dil
je     116e <utf8_following_bytes+0x5e>
movzbl %dil,%ecx
mov    %ecx,%edx
and    $0xffffffe0,%edx
mov    $0x1,%eax
cmp    $0xc0,%edx
je     116e <utf8_following_bytes+0x5e>
mov    %ecx,%edx
and    $0xfffffff0,%edx
mov    $0x2,%eax
cmp    $0xe0,%edx
je     116e <utf8_following_bytes+0x5e>
mov    %ecx,%edx
and    $0xfffffff8,%edx
mov    $0x3,%eax
cmp    $0xf0,%edx
je     116e <utf8_following_bytes+0x5e>
and    $0xffffffc0,%ecx
mov    $0xffffffff,%eax
cmp    $0x80,%ecx
je     116e <utf8_following_bytes+0x5e>
push   %rax
xor    %edi,%edi
call   1030 <assert@plt>
add    $0x8,%rsp
ret

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

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