#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 utf8_surrogate_len(const char *character) {
  size_t result = 0;
  char test_char;
  if (!character)
    return 0;
  test_char = character[0];
  if ((test_char & 0x80) == 0)
    return 1;
  while (test_char & 0x80) {
    test_char <<= 1;
    result++;
  }
  return result;
}


x86 assembly (clang, -O0):
<utf8_surrogate_len>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1128 <utf8_surrogate_len+0x28>
movq   $0x0,-0x8(%rbp)
jmp    118a <utf8_surrogate_len+0x8a>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1150 <utf8_surrogate_len+0x50>
movq   $0x1,-0x8(%rbp)
jmp    118a <utf8_surrogate_len+0x8a>
jmp    1155 <utf8_surrogate_len+0x55>
movsbl -0x19(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1182 <utf8_surrogate_len+0x82>
movsbl -0x19(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <utf8_surrogate_len+0x55>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_surrogate_len>:
test   %rdi,%rdi
je     112b <utf8_surrogate_len+0x2b>
mov    (%rdi),%cl
mov    $0x1,%eax
test   %cl,%cl
jns    112a <utf8_surrogate_len+0x2a>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %cl,%cl
add    $0x1,%rax
test   %cl,%cl
js     1120 <utf8_surrogate_len+0x20>
ret
xor    %eax,%eax
ret

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

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