#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 uint8_t;

/* Variables and functions */
int gtxt_unicode_len(const char chr) {
  uint8_t c = (uint8_t)chr;
  if ((c & 0x80) == 0) {
    return 1;
  } else if ((c & 0xe0) == 0xc0) {
    return 2;
  } else if ((c & 0xf0) == 0xe0) {
    return 3;
  } else if ((c & 0xf8) == 0xf0) {
    return 4;
  } else if ((c & 0xfc) == 0xf8) {
    return 5;
  } else {
    return 6;
  }
}


x86 assembly (clang, -O0):
<gtxt_unicode_len>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    112e <gtxt_unicode_len+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    11b1 <gtxt_unicode_len+0xb1>
mov    -0xc(%rbp),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    114d <gtxt_unicode_len+0x4d>
movl   $0x2,-0x4(%rbp)
jmp    11b1 <gtxt_unicode_len+0xb1>
mov    -0xc(%rbp),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    116c <gtxt_unicode_len+0x6c>
movl   $0x3,-0x4(%rbp)
jmp    11b1 <gtxt_unicode_len+0xb1>
mov    -0xc(%rbp),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    118b <gtxt_unicode_len+0x8b>
movl   $0x4,-0x4(%rbp)
jmp    11b1 <gtxt_unicode_len+0xb1>
mov    -0xc(%rbp),%eax
and    $0xfc,%eax
cmp    $0xf8,%eax
jne    11aa <gtxt_unicode_len+0xaa>
movl   $0x5,-0x4(%rbp)
jmp    11b1 <gtxt_unicode_len+0xb1>
movl   $0x6,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtxt_unicode_len>:
mov    $0x1,%eax
test   $0x80,%dil
je     115a <gtxt_unicode_len+0x5a>
movzbl %dil,%ecx
mov    %ecx,%edx
and    $0xffffffe0,%edx
mov    $0x2,%eax
cmp    $0xc0,%edx
je     115a <gtxt_unicode_len+0x5a>
mov    %ecx,%edx
and    $0xfffffff0,%edx
mov    $0x3,%eax
cmp    $0xe0,%edx
je     115a <gtxt_unicode_len+0x5a>
mov    %ecx,%edx
and    $0xfffffff8,%edx
mov    $0x4,%eax
cmp    $0xf0,%edx
je     115a <gtxt_unicode_len+0x5a>
and    $0xfffffffc,%ecx
xor    %edx,%edx
cmp    $0xf8,%ecx
sete   %dl
mov    $0x6,%eax
sub    %edx,%eax
ret

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

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