#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 */
size_t smtp_utf8_charlen(char c) {
  unsigned char uc;
  uc = (unsigned char)c;
  if ((uc & 0x80) == 0) {
    return 1;
  } else if ((uc & 0xE0) == 0xC0) {
    return 2;
  } else if ((uc & 0xF0) == 0xE0) {
    return 3;
  } else if ((uc & 0xF8) == 0xF0) {
    return 4;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<smtp_utf8_charlen>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0xa(%rbp)
movzbl -0xa(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    112f <smtp_utf8_charlen+0x2f>
movq   $0x1,-0x8(%rbp)
jmp    119a <smtp_utf8_charlen+0x9a>
movzbl -0xa(%rbp),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    1150 <smtp_utf8_charlen+0x50>
movq   $0x2,-0x8(%rbp)
jmp    119a <smtp_utf8_charlen+0x9a>
movzbl -0xa(%rbp),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    1171 <smtp_utf8_charlen+0x71>
movq   $0x3,-0x8(%rbp)
jmp    119a <smtp_utf8_charlen+0x9a>
movzbl -0xa(%rbp),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    1192 <smtp_utf8_charlen+0x92>
movq   $0x4,-0x8(%rbp)
jmp    119a <smtp_utf8_charlen+0x9a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<smtp_utf8_charlen>:
mov    $0x1,%eax
test   $0x80,%dil
je     1145 <smtp_utf8_charlen+0x45>
movzbl %dil,%ecx
mov    %ecx,%edx
and    $0xffffffe0,%edx
mov    $0x2,%eax
cmp    $0xc0,%edx
je     1145 <smtp_utf8_charlen+0x45>
mov    %ecx,%edx
and    $0xfffffff0,%edx
mov    $0x3,%eax
cmp    $0xe0,%edx
je     1145 <smtp_utf8_charlen+0x45>
and    $0xfffffff8,%ecx
xor    %eax,%eax
cmp    $0xf0,%ecx
sete   %al
shl    $0x2,%rax
ret

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

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