#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 int uint32_t;

/* Variables and functions */
int extract_utf8(int /*<<< orphan*/ const **, int, int, int);
uint32_t next_char_from_utf8(const uint8_t **io_utf8) {
  uint32_t c = *(*io_utf8)++;
  if (c < 0x80)
    return c;
  if (c < 0xC0)
    return 0xFFFFFFFF;
  if (c < 0xE0)
    return extract_utf8(io_utf8, c & 0x1F, 1, 0x80);
  if (c < 0xF0)
    return extract_utf8(io_utf8, c & 0x0F, 2, 0x800);
  if (c < 0xF8)
    return extract_utf8(io_utf8, c & 0x07, 3, 0x10000);
  return 0xFFFFFFFF;
}


x86 assembly (clang, -O0):
<next_char_from_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,(%rcx)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    114a <next_char_from_utf8+0x3a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <next_char_from_utf8+0xe4>
cmpl   $0xc0,-0x14(%rbp)
jge    1163 <next_char_from_utf8+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <next_char_from_utf8+0xe4>
cmpl   $0xe0,-0x14(%rbp)
jge    1191 <next_char_from_utf8+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
and    $0x1f,%esi
mov    $0x1,%edx
mov    $0x80,%ecx
call   1030 <extract_utf8@plt>
mov    %eax,-0x4(%rbp)
jmp    11f4 <next_char_from_utf8+0xe4>
cmpl   $0xf0,-0x14(%rbp)
jge    11bf <next_char_from_utf8+0xaf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
and    $0xf,%esi
mov    $0x2,%edx
mov    $0x800,%ecx
call   1030 <extract_utf8@plt>
mov    %eax,-0x4(%rbp)
jmp    11f4 <next_char_from_utf8+0xe4>
cmpl   $0xf8,-0x14(%rbp)
jge    11ed <next_char_from_utf8+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
and    $0x7,%esi
mov    $0x3,%edx
mov    $0x10000,%ecx
call   1030 <extract_utf8@plt>
mov    %eax,-0x4(%rbp)
jmp    11f4 <next_char_from_utf8+0xe4>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_char_from_utf8>:
mov    (%rdi),%rax
lea    0x4(%rax),%rcx
mov    %rcx,(%rdi)
mov    (%rax),%esi
cmp    $0x80,%esi
jge    1127 <next_char_from_utf8+0x17>
mov    %esi,%eax
ret
mov    $0xffffffff,%eax
cmp    $0xc0,%esi
jae    1135 <next_char_from_utf8+0x25>
ret
cmp    $0xdf,%esi
ja     114f <next_char_from_utf8+0x3f>
and    $0x1f,%esi
mov    $0x1,%edx
mov    $0x80,%ecx
jmp    1030 <extract_utf8@plt>
cmp    $0xef,%esi
ja     1169 <next_char_from_utf8+0x59>
and    $0xf,%esi
mov    $0x2,%edx
mov    $0x800,%ecx
jmp    1030 <extract_utf8@plt>
cmp    $0xf7,%esi
ja     1134 <next_char_from_utf8+0x24>
and    $0x7,%esi
mov    $0x3,%edx
mov    $0x10000,%ecx
jmp    1030 <extract_utf8@plt>

LLVM IR (-O0):
define i32 @next_char_from_utf8(i32** %0) {
%2 = alloca i32
%3 = alloca i32**
%4 = alloca i32
store i32** %0, i32*** %3
%5 = load i32**, i32*** %3
%6 = load i32*, i32** %5
%7 = getelementptr inbounds i32, i32* %6, i32 1
store i32* %7, i32** %5
%8 = load i32, i32* %6
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 128
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %42
13: ; preds = %1
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 192
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 -1, i32* %2
br label %42
17: ; preds = %13
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 224
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32**, i32*** %3
%22 = load i32, i32* %4
%23 = and i32 %22, 31
%24 = call i32 @extract_utf8(i32** %21, i32 %23, i32 1, i32 128)
store i32 %24, i32* %2
br label %42
25: ; preds = %17
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 240
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32**, i32*** %3
%30 = load i32, i32* %4
%31 = and i32 %30, 15
%32 = call i32 @extract_utf8(i32** %29, i32 %31, i32 2, i32 2048)
store i32 %32, i32* %2
br label %42
33: ; preds = %25
%34 = load i32, i32* %4
%35 = icmp slt i32 %34, 248
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i32**, i32*** %3
%38 = load i32, i32* %4
%39 = and i32 %38, 7
%40 = call i32 @extract_utf8(i32** %37, i32 %39, i32 3, i32 65536)
store i32 %40, i32* %2
br label %42
41: ; preds = %33
store i32 -1, i32* %2
br label %42
42: ; preds = %41, %36, %28, %20, %16, %11
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
define i32 @next_char_from_utf8(i32** %0) {
%2 = load i32*, i32** %0
%3 = getelementptr inbounds i32, i32* %2, i64 1
store i32* %3, i32** %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 128
br i1 %5, label %23, label %6
6: ; preds = %1
%7 = icmp ult i32 %4, 192
br i1 %7, label %23, label %8
8: ; preds = %6
%9 = icmp ult i32 %4, 224
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = and i32 %4, 31
%12 = tail call i32 @extract_utf8(i32** %0, i32 %11, i32 1, i32 128)
br label %23
13: ; preds = %8
%14 = icmp ult i32 %4, 240
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = and i32 %4, 15
%17 = tail call i32 @extract_utf8(i32** %0, i32 %16, i32 2, i32 2048)
br label %23
18: ; preds = %13
%19 = icmp ult i32 %4, 248
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = and i32 %4, 7
%22 = tail call i32 @extract_utf8(i32** %0, i32 %21, i32 3, i32 65536)
br label %23
23: ; preds = %18, %6, %1, %20, %15, %10
%24 = phi i32 [ %12, %10 ], [ %17, %15 ], [ %22, %20 ], [ %4, %1 ], [ -1, %6 ], [ -1, %18 ]
ret i32 %24
}