#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);
int utf8seqlen(const int c) {
  assert(c >= 0);
  if (c < 0x80)
    return 1;
  if (c < 0x800)
    return 2;
  if (c < 0x10000)
    return 3;
  if (c < 0x200000)
    return 4;
  if (c < 0x4000000)
    return 5;
  return 6;
}


x86 assembly (clang, -O0):
<utf8seqlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x80,-0x8(%rbp)
jge    1145 <utf8seqlen+0x35>
movl   $0x1,-0x4(%rbp)
jmp    11b0 <utf8seqlen+0xa0>
cmpl   $0x800,-0x8(%rbp)
jge    115e <utf8seqlen+0x4e>
movl   $0x2,-0x4(%rbp)
jmp    11b0 <utf8seqlen+0xa0>
cmpl   $0x10000,-0x8(%rbp)
jge    1177 <utf8seqlen+0x67>
movl   $0x3,-0x4(%rbp)
jmp    11b0 <utf8seqlen+0xa0>
cmpl   $0x200000,-0x8(%rbp)
jge    1190 <utf8seqlen+0x80>
movl   $0x4,-0x4(%rbp)
jmp    11b0 <utf8seqlen+0xa0>
cmpl   $0x4000000,-0x8(%rbp)
jge    11a9 <utf8seqlen+0x99>
movl   $0x5,-0x4(%rbp)
jmp    11b0 <utf8seqlen+0xa0>
movl   $0x6,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8seqlen>:
push   %rbx
mov    %edi,%ebx
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
mov    $0x1,%eax
cmp    $0x80,%ebx
jl     115f <utf8seqlen+0x4f>
mov    $0x2,%eax
cmp    $0x800,%ebx
jb     115f <utf8seqlen+0x4f>
mov    $0x3,%eax
cmp    $0x10000,%ebx
jb     115f <utf8seqlen+0x4f>
mov    $0x4,%eax
cmp    $0x200000,%ebx
jb     115f <utf8seqlen+0x4f>
cmp    $0x4000000,%ebx
mov    $0x6,%eax
sbb    $0x0,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @utf8seqlen(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sge i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 128
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %2
br label %28
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 2048
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 2, i32* %2
br label %28
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 65536
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 3, i32* %2
br label %28
19: ; preds = %15
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 2097152
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 4, i32* %2
br label %28
23: ; preds = %19
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 67108864
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 5, i32* %2
br label %28
27: ; preds = %23
store i32 6, i32* %2
br label %28
28: ; preds = %27, %26, %22, %18, %14, %10
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @utf8seqlen(i32 %0) {
%2 = xor i32 %0, -1
%3 = lshr i32 %2, 31
%4 = tail call i32 @assert(i32 %3)
%5 = icmp slt i32 %0, 128
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = icmp ult i32 %0, 2048
br i1 %7, label %15, label %8
8: ; preds = %6
%9 = icmp ult i32 %0, 65536
br i1 %9, label %15, label %10
10: ; preds = %8
%11 = icmp ult i32 %0, 2097152
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = icmp ult i32 %0, 67108864
%14 = select i1 %13, i32 5, i32 6
br label %15
15: ; preds = %12, %10, %8, %6, %1
%16 = phi i32 [ 1, %1 ], [ 2, %6 ], [ 3, %8 ], [ 4, %10 ], [ %14, %12 ]
ret i32 %16
}