#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 */
typedef int /*<<< orphan*/ mbstate_t;

/* Variables and functions */
int /*<<< orphan*/ assert(char const *);
size_t mbrlen__(const char *s, size_t n, mbstate_t *ps) {
  int c;
  assert(s);
  c = *(const unsigned char *)s;
  if (c == 0)
    return 0;
  else if (6 == 1)
    return 1;
  else if (c <= 0x7F)
    return 1;
  else if (c <= 0xBF)
    return (size_t)-1;
  else if (c <= 0xDF)
    return 2;
  else if (c <= 0xEF)
    return 3;
  else if (c <= 0xF7)
    return 4;
  else if (c <= 0xFB)
    return 5;
  else if (c <= 0xFD)
    return 6;
  else
    return (size_t)-1;
}


x86 assembly (clang, -O0):
<mbrlen__>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    114e <mbrlen__+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    1209 <mbrlen__+0xf9>
cmpl   $0x7f,-0x24(%rbp)
jg     1165 <mbrlen__+0x55>
movq   $0x1,-0x8(%rbp)
jmp    1209 <mbrlen__+0xf9>
cmpl   $0xbf,-0x24(%rbp)
jg     117f <mbrlen__+0x6f>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1209 <mbrlen__+0xf9>
cmpl   $0xdf,-0x24(%rbp)
jg     1199 <mbrlen__+0x89>
movq   $0x2,-0x8(%rbp)
jmp    1209 <mbrlen__+0xf9>
cmpl   $0xef,-0x24(%rbp)
jg     11b3 <mbrlen__+0xa3>
movq   $0x3,-0x8(%rbp)
jmp    1209 <mbrlen__+0xf9>
cmpl   $0xf7,-0x24(%rbp)
jg     11cd <mbrlen__+0xbd>
movq   $0x4,-0x8(%rbp)
jmp    1209 <mbrlen__+0xf9>
cmpl   $0xfb,-0x24(%rbp)
jg     11e7 <mbrlen__+0xd7>
movq   $0x5,-0x8(%rbp)
jmp    1209 <mbrlen__+0xf9>
cmpl   $0xfd,-0x24(%rbp)
jg     1201 <mbrlen__+0xf1>
movq   $0x6,-0x8(%rbp)
jmp    1209 <mbrlen__+0xf9>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mbrlen__>:
push   %rbx
mov    %rdi,%rbx
call   1030 <assert@plt>
mov    (%rbx),%cl
test   %cl,%cl
je     1128 <mbrlen__+0x18>
mov    $0x1,%eax
js     112c <mbrlen__+0x1c>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0xffffffffffffffff,%rax
cmp    $0xc0,%cl
jb     1126 <mbrlen__+0x16>
mov    $0x2,%eax
cmp    $0xe0,%cl
jb     1126 <mbrlen__+0x16>
mov    $0x3,%eax
cmp    $0xf0,%cl
jb     1126 <mbrlen__+0x16>
mov    $0x4,%eax
cmp    $0xf8,%cl
jb     1126 <mbrlen__+0x16>
mov    $0x5,%eax
cmp    $0xfc,%cl
jb     1126 <mbrlen__+0x16>
cmp    $0xfe,%cl
mov    $0x6,%ecx
mov    $0xffffffffffffffff,%rax
cmovb  %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @mbrlen__(i8* %0, i64 %1, i32* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = call i32 @assert(i8* %9)
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i64 0, i64* %4
br label %46
17: ; preds = %3
%18 = load i32, i32* %8
%19 = icmp sle i32 %18, 127
br i1 %19, label %20, label %21
20: ; preds = %17
store i64 1, i64* %4
br label %46
21: ; preds = %17
%22 = load i32, i32* %8
%23 = icmp sle i32 %22, 191
br i1 %23, label %24, label %25
24: ; preds = %21
store i64 -1, i64* %4
br label %46
25: ; preds = %21
%26 = load i32, i32* %8
%27 = icmp sle i32 %26, 223
br i1 %27, label %28, label %29
28: ; preds = %25
store i64 2, i64* %4
br label %46
29: ; preds = %25
%30 = load i32, i32* %8
%31 = icmp sle i32 %30, 239
br i1 %31, label %32, label %33
32: ; preds = %29
store i64 3, i64* %4
br label %46
33: ; preds = %29
%34 = load i32, i32* %8
%35 = icmp sle i32 %34, 247
br i1 %35, label %36, label %37
36: ; preds = %33
store i64 4, i64* %4
br label %46
37: ; preds = %33
%38 = load i32, i32* %8
%39 = icmp sle i32 %38, 251
br i1 %39, label %40, label %41
40: ; preds = %37
store i64 5, i64* %4
br label %46
41: ; preds = %37
%42 = load i32, i32* %8
%43 = icmp sle i32 %42, 253
br i1 %43, label %44, label %45
44: ; preds = %41
store i64 6, i64* %4
br label %46
45: ; preds = %41
store i64 -1, i64* %4
br label %46
46: ; preds = %45, %44, %40, %36, %32, %28, %24, %20, %16
%47 = load i64, i64* %4
ret i64 %47
}

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