#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 utf8codepointcalcsize(const void *str) {
  const char *s = (const char *)str;
  if (0xf0 == (0xf8 & s[0])) {
    return 4;
  } else if (0xe0 == (0xf0 & s[0])) {
    return 3;
  } else if (0xc0 == (0xe0 & s[0])) {
    return 2;
  }
  return 1;
}


x86 assembly (clang, -O0):
<utf8codepointcalcsize>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
and    $0xf8,%ecx
mov    $0xf0,%eax
cmp    %ecx,%eax
jne    1137 <utf8codepointcalcsize+0x37>
movq   $0x4,-0x8(%rbp)
jmp    1197 <utf8codepointcalcsize+0x97>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
and    $0xf0,%ecx
mov    $0xe0,%eax
cmp    %ecx,%eax
jne    115e <utf8codepointcalcsize+0x5e>
movq   $0x3,-0x8(%rbp)
jmp    1197 <utf8codepointcalcsize+0x97>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
and    $0xe0,%ecx
mov    $0xc0,%eax
cmp    %ecx,%eax
jne    1185 <utf8codepointcalcsize+0x85>
movq   $0x2,-0x8(%rbp)
jmp    1197 <utf8codepointcalcsize+0x97>
jmp    118a <utf8codepointcalcsize+0x8a>
jmp    118f <utf8codepointcalcsize+0x8f>
movq   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8codepointcalcsize>:
movzbl (%rdi),%ecx
mov    %ecx,%edx
and    $0xfffffff8,%edx
mov    $0x4,%eax
cmp    $0xf0,%edx
je     1139 <utf8codepointcalcsize+0x39>
mov    %ecx,%edx
and    $0xfffffff0,%edx
mov    $0x3,%eax
cmp    $0xe0,%edx
je     1139 <utf8codepointcalcsize+0x39>
and    $0xffffffe0,%ecx
xor    %eax,%eax
cmp    $0xc0,%ecx
sete   %al
add    $0x1,%rax
ret

LLVM IR (-O0):
define i64 @utf8codepointcalcsize(i8* %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 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = and i32 248, %9
%11 = icmp eq i32 240, %10
br i1 %11, label %12, label %13
12: ; preds = %1
store i64 4, i64* %2
br label %32
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = and i32 240, %17
%19 = icmp eq i32 224, %18
br i1 %19, label %20, label %21
20: ; preds = %13
store i64 3, i64* %2
br label %32
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = and i32 224, %25
%27 = icmp eq i32 192, %26
br i1 %27, label %28, label %29
28: ; preds = %21
store i64 2, i64* %2
br label %32
29: ; preds = %21
br label %30
30: ; preds = %29
br label %31
31: ; preds = %30
store i64 1, i64* %2
br label %32
32: ; preds = %31, %28, %20, %12
%33 = load i64, i64* %2
ret i64 %33
}

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