#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*/ string;

/* Variables and functions */
char *utf8_next_char(const char *string) {
  if (!string)
    return NULL;
  if (((unsigned char)(string[0]) & 0xE0) == 0xC0) {
    if (!string[1])
      return (char *)string + 1;
    return (char *)string + 2;
  } else if (((unsigned char)(string[0]) & 0xF0) == 0xE0) {
    if (!string[1])
      return (char *)string + 1;
    if (!string[2])
      return (char *)string + 2;
    return (char *)string + 3;
  } else if (((unsigned char)(string[0]) & 0xF8) == 0xF0) {
    if (!string[1])
      return (char *)string + 1;
    if (!string[2])
      return (char *)string + 2;
    if (!string[3])
      return (char *)string + 3;
    return (char *)string + 4;
  }
  return (char *)string + 1;
}


x86 assembly (clang, -O0):
<utf8_next_char>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1120 <utf8_next_char+0x20>
movq   $0x0,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    1167 <utf8_next_char+0x67>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    1156 <utf8_next_char+0x56>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    11cd <utf8_next_char+0xcd>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    119d <utf8_next_char+0x9d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x2(%rax)
jne    11bc <utf8_next_char+0xbc>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    1252 <utf8_next_char+0x152>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    1203 <utf8_next_char+0x103>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x2(%rax)
jne    1222 <utf8_next_char+0x122>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x3(%rax)
jne    1241 <utf8_next_char+0x141>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    1268 <utf8_next_char+0x168>
jmp    1257 <utf8_next_char+0x157>
jmp    125c <utf8_next_char+0x15c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_next_char>:
test   %rdi,%rdi
je     1120 <utf8_next_char+0x20>
movzbl (%rdi),%ecx
mov    %ecx,%eax
and    $0xffffffe0,%eax
cmp    $0xc0,%eax
jne    1123 <utf8_next_char+0x23>
mov    $0x2,%eax
mov    $0x1,%ecx
jmp    1165 <utf8_next_char+0x65>
xor    %eax,%eax
ret
mov    %ecx,%eax
and    $0xfffffff0,%eax
cmp    $0xe0,%eax
jne    1141 <utf8_next_char+0x41>
cmpb   $0x0,0x1(%rdi)
je     1175 <utf8_next_char+0x75>
mov    $0x3,%eax
mov    $0x2,%ecx
jmp    1165 <utf8_next_char+0x65>
and    $0xfffffff8,%ecx
lea    0x1(%rdi),%rax
cmp    $0xf0,%ecx
jne    1174 <utf8_next_char+0x74>
cmpb   $0x0,(%rax)
je     1174 <utf8_next_char+0x74>
cmpb   $0x0,0x2(%rdi)
je     117d <utf8_next_char+0x7d>
mov    $0x4,%eax
mov    $0x3,%ecx
lea    (%rdi,%rcx,1),%rdx
add    %rdi,%rax
cmpb   $0x0,(%rdi,%rcx,1)
cmove  %rdx,%rax
ret
add    $0x1,%rdi
mov    %rdi,%rax
ret
add    $0x2,%rdi
mov    %rdi,%rax
ret

LLVM IR (-O0):
define i8* @utf8_next_char(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store i8* null, i8** %2
br label %90
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = and i32 %11, 224
%13 = icmp eq i32 %12, 192
br i1 %13, label %14, label %25
14: ; preds = %7
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %2
br label %90
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 2
store i8* %24, i8** %2
br label %90
25: ; preds = %7
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = and i32 %29, 240
%31 = icmp eq i32 %30, 224
br i1 %31, label %32, label %51
32: ; preds = %25
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %32
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8* %39, i8** %2
br label %90
40: ; preds = %32
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %40
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 2
store i8* %47, i8** %2
br label %90
48: ; preds = %40
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i64 3
store i8* %50, i8** %2
br label %90
51: ; preds = %25
%52 = load i8*, i8** %3
%53 = getelementptr inbounds i8, i8* %52, i64 0
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = and i32 %55, 248
%57 = icmp eq i32 %56, 240
br i1 %57, label %58, label %85
58: ; preds = %51
%59 = load i8*, i8** %3
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = load i8, i8* %60
%62 = icmp ne i8 %61, 0
br i1 %62, label %66, label %63
63: ; preds = %58
%64 = load i8*, i8** %3
%65 = getelementptr inbounds i8, i8* %64, i64 1
store i8* %65, i8** %2
br label %90
66: ; preds = %58
%67 = load i8*, i8** %3
%68 = getelementptr inbounds i8, i8* %67, i64 2
%69 = load i8, i8* %68
%70 = icmp ne i8 %69, 0
br i1 %70, label %74, label %71
71: ; preds = %66
%72 = load i8*, i8** %3
%73 = getelementptr inbounds i8, i8* %72, i64 2
store i8* %73, i8** %2
br label %90
74: ; preds = %66
%75 = load i8*, i8** %3
%76 = getelementptr inbounds i8, i8* %75, i64 3
%77 = load i8, i8* %76
%78 = icmp ne i8 %77, 0
br i1 %78, label %82, label %79
79: ; preds = %74
%80 = load i8*, i8** %3
%81 = getelementptr inbounds i8, i8* %80, i64 3
store i8* %81, i8** %2
br label %90
82: ; preds = %74
%83 = load i8*, i8** %3
%84 = getelementptr inbounds i8, i8* %83, i64 4
store i8* %84, i8** %2
br label %90
85: ; preds = %51
br label %86
86: ; preds = %85
br label %87
87: ; preds = %86
%88 = load i8*, i8** %3
%89 = getelementptr inbounds i8, i8* %88, i64 1
store i8* %89, i8** %2
br label %90
90: ; preds = %87, %82, %79, %71, %63, %48, %45, %37, %22, %19, %6
%91 = load i8*, i8** %2
ret i8* %91
}

LLVM IR (-O2):
define i8* @utf8_next_char(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %34, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = zext i8 %4 to i32
%6 = and i32 %5, 224
%7 = icmp eq i32 %6, 192
br i1 %7, label %26, label %8
8: ; preds = %3
%9 = and i32 %5, 240
%10 = icmp eq i32 %9, 224
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %34, label %26
15: ; preds = %8
%16 = and i32 %5, 248
%17 = icmp eq i32 %16, 240
%18 = getelementptr inbounds i8, i8* %0, i64 1
br i1 %17, label %19, label %34
19: ; preds = %15
%20 = load i8, i8* %18
%21 = icmp eq i8 %20, 0
br i1 %21, label %34, label %22
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %0, i64 2
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %22, %11, %3
%27 = phi i64 [ 1, %3 ], [ 2, %11 ], [ 3, %22 ]
%28 = phi i64 [ 2, %3 ], [ 3, %11 ], [ 4, %22 ]
%29 = getelementptr inbounds i8, i8* %0, i64 %27
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
%32 = getelementptr inbounds i8, i8* %0, i64 %28
%33 = select i1 %31, i8* %29, i8* %32
br label %34
34: ; preds = %26, %15, %22, %19, %11, %1
%35 = phi i8* [ null, %1 ], [ %12, %11 ], [ %18, %19 ], [ %23, %22 ], [ %18, %15 ], [ %33, %26 ]
ret i8* %35
}