#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 */
char *g_utf8_find_next_char(const char *p, const char *end) {
  if (*p) {
    if (end)
      for (++p; p < end && (*p & 0xc0) == 0x80; ++p)
        ;
    else
      for (++p; (*p & 0xc0) == 0x80; ++p)
        ;
  }
  return (p == end) ? NULL : (char *)p;
}


x86 assembly (clang, -O0):
<g_utf8_find_next_char>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c8 <g_utf8_find_next_char+0xc8>
cmpq   $0x0,-0x10(%rbp)
je     1185 <g_utf8_find_next_char+0x85>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x11(%rbp)
jae    115a <g_utf8_find_next_char+0x5a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    116a <g_utf8_find_next_char+0x6a>
jmp    1180 <g_utf8_find_next_char+0x80>
jmp    116f <g_utf8_find_next_char+0x6f>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1130 <g_utf8_find_next_char+0x30>
jmp    11c3 <g_utf8_find_next_char+0xc3>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    11be <g_utf8_find_next_char+0xbe>
jmp    11ad <g_utf8_find_next_char+0xad>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1191 <g_utf8_find_next_char+0x91>
jmp    11c3 <g_utf8_find_next_char+0xc3>
jmp    11c8 <g_utf8_find_next_char+0xc8>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11e1 <g_utf8_find_next_char+0xe1>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    11e9 <g_utf8_find_next_char+0xe9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<g_utf8_find_next_char>:
cmpb   $0x0,(%rdi)
je     114e <g_utf8_find_next_char+0x4e>
test   %rsi,%rsi
je     1140 <g_utf8_find_next_char+0x40>
add    $0x1,%rdi
mov    %rdi,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
cmp    %rsi,%rax
jae    114e <g_utf8_find_next_char+0x4e>
movzbl (%rdi),%ecx
and    $0xc0,%cl
lea    0x1(%rdi),%rax
cmp    $0x80,%cl
je     1120 <g_utf8_find_next_char+0x20>
jmp    114e <g_utf8_find_next_char+0x4e>
nopl   0x0(%rax)
movzbl 0x1(%rdi),%eax
add    $0x1,%rdi
and    $0xc0,%al
cmp    $0x80,%al
je     1140 <g_utf8_find_next_char+0x40>
xor    %eax,%eax
cmp    %rsi,%rdi
cmovne %rdi,%rax
ret

LLVM IR (-O0):
define i8* @g_utf8_find_next_char(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %46
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %31
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
br label %14
14: ; preds = %27, %11
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = icmp ult i8* %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = and i32 %21, 192
%23 = icmp eq i32 %22, 128
br label %24
24: ; preds = %18, %14
%25 = phi i1 [ false, %14 ], [ %23, %18 ]
br i1 %25, label %26, label %30
26: ; preds = %24
br label %27
27: ; preds = %26
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
br label %14
30: ; preds = %24
br label %45
31: ; preds = %8
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
br label %34
34: ; preds = %41, %31
%35 = load i8*, i8** %3
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = and i32 %37, 192
%39 = icmp eq i32 %38, 128
br i1 %39, label %40, label %44
40: ; preds = %34
br label %41
41: ; preds = %40
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %3
br label %34
44: ; preds = %34
br label %45
45: ; preds = %44, %30
br label %46
46: ; preds = %45, %2
%47 = load i8*, i8** %3
%48 = load i8*, i8** %4
%49 = icmp eq i8* %47, %48
br i1 %49, label %50, label %51
50: ; preds = %46
br label %53
51: ; preds = %46
%52 = load i8*, i8** %3
br label %53
53: ; preds = %51, %50
%54 = phi i8* [ null, %50 ], [ %52, %51 ]
ret i8* %54
}

LLVM IR (-O2):
define i8* @g_utf8_find_next_char(i8* %0, i8* readnone %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = icmp eq i8* %1, null
br i1 %6, label %15, label %7
7: ; preds = %5, %11
%8 = phi i8* [ %9, %11 ], [ %0, %5 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = icmp ult i8* %9, %1
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i8, i8* %9
%13 = and i8 %12, -64
%14 = icmp eq i8 %13, -128
br i1 %14, label %7, label %21
15: ; preds = %5, %15
%16 = phi i8* [ %17, %15 ], [ %0, %5 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = and i8 %18, -64
%20 = icmp eq i8 %19, -128
br i1 %20, label %15, label %21
21: ; preds = %7, %11, %15, %2
%22 = phi i8* [ %0, %2 ], [ %17, %15 ], [ %9, %11 ], [ %9, %7 ]
%23 = icmp eq i8* %22, %1
%24 = select i1 %23, i8* null, i8* %22
ret i8* %24
}