#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 */
uint32_t extract_utf8(const uint8_t **u, uint32_t c, int n, uint32_t m) {
  if (n == 0)
    return c >= m ? c : 0xFFFFFFFF;
  uint32_t c2 = *(*u)++;
  if (c2 < 0x80)
    return 0xFFFFFFFF;
  if (c2 < 0xC0)
    return extract_utf8(u, (c << 6) | (c2 & 0x3F), n - 1, m);
  return 0xFFFFFFFF;
}


x86 assembly (clang, -O0):
<extract_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    115e <extract_utf8+0x4e>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1146 <extract_utf8+0x36>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <extract_utf8+0x43>
mov    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <extract_utf8+0x43>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c9 <extract_utf8+0xb9>
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,(%rcx)
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x80,-0x20(%rbp)
jge    118d <extract_utf8+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <extract_utf8+0xb9>
cmpl   $0xc0,-0x20(%rbp)
jge    11c2 <extract_utf8+0xb2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
shl    $0x6,%esi
mov    -0x20(%rbp),%eax
and    $0x3f,%eax
or     %eax,%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
mov    -0x1c(%rbp),%ecx
call   1030 <extract_utf8@plt>
mov    %eax,-0x4(%rbp)
jmp    11c9 <extract_utf8+0xb9>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_utf8>:
test   %edx,%edx
je     1140 <extract_utf8+0x40>
mov    (%rdi),%r9
mov    %edx,%r8d
xor    %r11d,%r11d
xor    %r10d,%r10d
mov    (%r9,%r11,4),%eax
mov    %eax,%edx
and    $0xffffffc0,%edx
cmp    $0x80,%edx
jne    114b <extract_utf8+0x4b>
mov    %esi,%edx
shl    $0x6,%edx
and    $0x3f,%eax
mov    %eax,%esi
or     %edx,%esi
add    $0xfffffffffffffffc,%r10
add    $0x1,%r11
cmp    %r11d,%r8d
jne    1110 <extract_utf8+0x10>
sub    %r10,%r9
mov    %r9,(%rdi)
cmp    %ecx,%esi
mov    $0xffffffff,%eax
cmovge %esi,%eax
ret
sub    %r10,%r9
add    $0x4,%r9
mov    %r9,(%rdi)
mov    $0xffffffff,%eax
ret

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

LLVM IR (-O2):
define i32 @extract_utf8(i32** nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = load i32*, i32** %0
br label %13
8: ; preds = %21
store i32* %17, i32** %0
br label %9
9: ; preds = %8, %4
%10 = phi i32 [ %24, %8 ], [ %1, %4 ]
%11 = icmp slt i32 %10, %3
%12 = select i1 %11, i32 -1, i32 %10
br label %28
13: ; preds = %6, %21
%14 = phi i32* [ %7, %6 ], [ %17, %21 ]
%15 = phi i32 [ %2, %6 ], [ %25, %21 ]
%16 = phi i32 [ %1, %6 ], [ %24, %21 ]
%17 = getelementptr inbounds i32, i32* %14, i64 1
%18 = load i32, i32* %14
%19 = and i32 %18, -64
%20 = icmp eq i32 %19, 128
br i1 %20, label %21, label %27
21: ; preds = %13
%22 = shl i32 %16, 6
%23 = and i32 %18, 63
%24 = or i32 %23, %22
%25 = add nsw i32 %15, -1
%26 = icmp eq i32 %25, 0
br i1 %26, label %8, label %13
27: ; preds = %13
store i32* %17, i32** %0
br label %28
28: ; preds = %27, %9
%29 = phi i32 [ %12, %9 ], [ -1, %27 ]
ret i32 %29
}