#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 font_utf8_size(const char *c) {
  unsigned char first_c = *c;
  if (first_c < 0x80)
    return 1;
  size_t res = 0;
  while (first_c & 0x80) {
    res++;
    first_c <<= 1;
  }
  if (res > 4)
    res = 1;
  return res;
}


x86 assembly (clang, -O0):
<font_utf8_size>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x80,%eax
jge    112d <font_utf8_size+0x2d>
movq   $0x1,-0x8(%rbp)
jmp    117d <font_utf8_size+0x7d>
movq   $0x0,-0x20(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1162 <font_utf8_size+0x62>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movzbl -0x11(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x11(%rbp)
jmp    1135 <font_utf8_size+0x35>
cmpq   $0x4,-0x20(%rbp)
jbe    1175 <font_utf8_size+0x75>
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<font_utf8_size>:
mov    (%rdi),%cl
mov    $0x1,%eax
test   %cl,%cl
js     110c <font_utf8_size+0xc>
ret
mov    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %cl,%cl
add    $0x1,%rax
test   %cl,%cl
js     1120 <font_utf8_size+0x20>
lea    0x1(%rax),%rcx
cmp    $0x4,%rax
mov    $0x1,%eax
cmovb  %rcx,%rax
ret

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

LLVM IR (-O2):
define i64 @font_utf8_size(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp sgt i8 %2, -1
br i1 %3, label %13, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %7, %4 ], [ 0, %1 ]
%6 = phi i8 [ %8, %4 ], [ %2, %1 ]
%7 = add nuw nsw i64 %5, 1
%8 = shl i8 %6, 1
%9 = icmp sgt i8 %8, -1
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = icmp ugt i64 %5, 3
%12 = select i1 %11, i64 1, i64 %7
br label %13
13: ; preds = %1, %10
%14 = phi i64 [ %12, %10 ], [ 1, %1 ]
ret i64 %14
}