#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 wchar_t;
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int *get_utf8_value(int *, int *);
int /*<<< orphan*/ stdout;
void utf8_parse(const char *msg, unsigned int len) {
  uint8_t *pend = NULL;
  uint8_t *p;
  uint8_t *pre;
  wchar_t val;
  int page;
  pend = (uint8_t *)msg + len;
  for (pre = (uint8_t *)msg; pre < pend;) {
    val = 0;
    p = get_utf8_value(pre, &val);
    if (NULL == p)
      break;
    page = val / 128;
    if (val >= 256) {
      fprintf(stdout, "%d %d ", page, (val % 128));
      for (; pre < p; pre++)
        fprintf(stdout, "%c", *pre);
      fprintf(stdout, "\n");
    }
    pre = p;
  }
}


x86 assembly (clang, -O0):
<utf8_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1230 <utf8_parse+0x110>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <get_utf8_value@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1188 <utf8_parse+0x68>
jmp    1230 <utf8_parse+0x110>
mov    -0x2c(%rbp),%eax
mov    $0x80,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
cmpl   $0x100,-0x2c(%rbp)
jl     1223 <utf8_parse+0x103>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x80,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x34(%rbp),%edx
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    120c <utf8_parse+0xec>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
jmp    11d0 <utf8_parse+0xb0>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1151 <utf8_parse+0x31>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%eax
lea    (%rdi,%rax,4),%r14
cmp    %rdi,%r14
jbe    11db <utf8_parse+0xbb>
mov    %rdi,%rbx
lea    0x4(%rsp),%r15
mov    0x2e97(%rip),%r13
lea    0xeb7(%rip),%r12
jmp    117a <utf8_parse+0x5a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%edi
lea    0xe9f(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rbp,%rbx
cmp    %r14,%rbp
jae    11db <utf8_parse+0xbb>
movl   $0x0,0x4(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <get_utf8_value@plt>
test   %rax,%rax
je     11db <utf8_parse+0xbb>
mov    %rax,%rbp
mov    0x4(%rsp),%ecx
cmp    $0x100,%ecx
jl     1172 <utf8_parse+0x52>
mov    %ecx,%edx
shr    $0x7,%edx
mov    0x0(%r13),%edi
and    $0x7f,%ecx
lea    0xe4c(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    %rbp,%rbx
jae    1160 <utf8_parse+0x40>
mov    0x0(%r13),%edi
mov    (%rbx),%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x4,%rbx
cmp    %rbp,%rbx
jb     11c0 <utf8_parse+0xa0>
jmp    1160 <utf8_parse+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [7 x i8] c"%d %d \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @utf8_parse(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32* null, i32** %5
%10 = load i8*, i8** %3
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
store i32* %14, i32** %5
%15 = load i8*, i8** %3
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %7
br label %17
17: ; preds = %53, %2
%18 = load i32*, i32** %7
%19 = load i32*, i32** %5
%20 = icmp ult i32* %18, %19
br i1 %20, label %21, label %55
21: ; preds = %17
store i32 0, i32* %8
%22 = load i32*, i32** %7
%23 = call i32* @get_utf8_value(i32* %22, i32* %8)
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* null, %24
br i1 %25, label %26, label %27
26: ; preds = %21
br label %55
27: ; preds = %21
%28 = load i32, i32* %8
%29 = sdiv i32 %28, 128
store i32 %29, i32* %9
%30 = load i32, i32* %8
%31 = icmp sge i32 %30, 256
br i1 %31, label %32, label %53
32: ; preds = %27
%33 = load i32, i32* @stdout
%34 = load i32, i32* %9
%35 = load i32, i32* %8
%36 = srem i32 %35, 128
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %36)
br label %38
38: ; preds = %47, %32
%39 = load i32*, i32** %7
%40 = load i32*, i32** %6
%41 = icmp ult i32* %39, %40
br i1 %41, label %42, label %50
42: ; preds = %38
%43 = load i32, i32* @stdout
%44 = load i32*, i32** %7
%45 = load i32, i32* %44
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %42
%48 = load i32*, i32** %7
%49 = getelementptr inbounds i32, i32* %48, i32 1
store i32* %49, i32** %7
br label %38
50: ; preds = %38
%51 = load i32, i32* @stdout
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %53
53: ; preds = %50, %27
%54 = load i32*, i32** %6
store i32* %54, i32** %7
br label %17
55: ; preds = %26, %17
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [7 x i8] c"%d %d \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @utf8_parse(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = bitcast i8* %0 to i32*
%6 = zext i32 %1 to i64
%7 = getelementptr inbounds i32, i32* %5, i64 %6
%8 = icmp ugt i32* %7, %5
br i1 %8, label %9, label %34
9: ; preds = %2, %32
%10 = phi i32* [ %11, %32 ], [ %5, %2 ]
store i32 0, i32* %3
%11 = call i32* @get_utf8_value(i32* %10, i32* %3)
%12 = icmp eq i32* %11, null
br i1 %12, label %34, label %13
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 255
br i1 %15, label %16, label %32
16: ; preds = %13
%17 = lshr i32 %14, 7
%18 = load i32, i32* @stdout
%19 = and i32 %14, 127
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19)
%21 = icmp ult i32* %10, %11
br i1 %21, label %22, label %29
22: ; preds = %16, %22
%23 = phi i32* [ %27, %22 ], [ %10, %16 ]
%24 = load i32, i32* @stdout
%25 = load i32, i32* %23
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds i32, i32* %23, i64 1
%28 = icmp ult i32* %27, %11
br i1 %28, label %22, label %29
29: ; preds = %22, %16
%30 = load i32, i32* @stdout
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %29, %13
%33 = icmp ult i32* %11, %7
br i1 %33, label %9, label %34
34: ; preds = %32, %9, %2
ret void
}