#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 /*<<< orphan*/ uint8_t;
typedef unsigned int uint32_t;

/* Variables and functions */
unsigned int parse_counted_utf8_char(int /*<<< orphan*/ const *, size_t);
size_t utf8_num_bytes(int /*<<< orphan*/ const);
uint32_t parse_utf8_char(const uint8_t *utf8, size_t *size) {
  switch (*size = utf8_num_bytes(utf8[0])) {
  case 1:
  case 2:
  case 3:
  case 4:
    return parse_counted_utf8_char(utf8, *size);
  default:
    *size = 0;
    return 0u;
  }
}


x86 assembly (clang, -O0):
<parse_utf8_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <utf8_num_bytes@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
add    $0xffffffffffffffff,%rax
sub    $0x3,%rax
ja     116d <parse_utf8_char+0x4d>
jmp    1155 <parse_utf8_char+0x35>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1030 <parse_counted_utf8_char@plt>
mov    %eax,-0x4(%rbp)
jmp    117f <parse_utf8_char+0x5f>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_utf8_char>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1040 <utf8_num_bytes@plt>
mov    %rax,(%r14)
lea    -0x1(%rax),%rcx
cmp    $0x3,%rcx
ja     1150 <parse_utf8_char+0x30>
mov    %rbx,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <parse_counted_utf8_char@plt>
movq   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @parse_utf8_char(i32* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64*
store i32* %0, i32** %4
store i64* %1, i64** %5
%6 = load i32*, i32** %4
%7 = getelementptr inbounds i32, i32* %6, i64 0
%8 = load i32, i32* %7
%9 = call i64 @utf8_num_bytes(i32 %8)
%10 = load i64*, i64** %5
store i64 %9, i64* %10
switch i64 %9, label %16 [
i64 1, label %11
i64 2, label %11
i64 3, label %11
i64 4, label %11
]
11: ; preds = %2, %2, %2, %2
%12 = load i32*, i32** %4
%13 = load i64*, i64** %5
%14 = load i64, i64* %13
%15 = call i32 @parse_counted_utf8_char(i32* %12, i64 %14)
store i32 %15, i32* %3
br label %18
16: ; preds = %2
%17 = load i64*, i64** %5
store i64 0, i64* %17
store i32 0, i32* %3
br label %18
18: ; preds = %16, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
define i32 @parse_utf8_char(i32* %0, i64* nocapture %1) {
%3 = load i32, i32* %0
%4 = tail call i64 @utf8_num_bytes(i32 %3)
store i64 %4, i64* %1
%5 = add i64 %4, -1
%6 = icmp ult i64 %5, 4
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @parse_counted_utf8_char(i32* %0, i64 %4)
br label %10
9: ; preds = %2
store i64 0, i64* %1
br label %10
10: ; preds = %9, %7
%11 = phi i32 [ 0, %9 ], [ %8, %7 ]
ret i32 %11
}