#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 */
int is_correct_utf8(const char *par_buf, size_t size) {
  unsigned int w32 = 0;
  const unsigned char *buf = (const unsigned char *)par_buf;
  if (!size)
    return 0;
  if (buf[0] <= 0x7F)
    return 1;
  if ((buf[0] & 0xE0) == 0xC0) {
    if (size < 2)
      return -7;
    if ((buf[1] & 0xC0) != 0x80)
      return -2;
    w32 |= buf[1] & 0x3F;
    w32 |= (buf[0] & 0x1F) << 6;
    if (w32 <= 0x7F)
      return -2;
    return 2;
  }
  if ((buf[0] & 0xF0) == 0xE0) {
    if (size < 3)
      return -7;
    if ((buf[1] & 0xC0) != 0x80)
      return -3;
    if ((buf[2] & 0xC0) != 0x80)
      return -3;
    w32 |= buf[2] & 0x3F;
    w32 |= (buf[1] & 0x3F) << 6;
    w32 |= (buf[0] & 0x0F) << 12;
    if (w32 <= 0x7FF)
      return -3;
    return 3;
  }
  if ((buf[0] & 0xF8) == 0xF0) {
    if (size < 4)
      return -7;
    if ((buf[1] & 0xC0) != 0x80)
      return -4;
    if ((buf[2] & 0xC0) != 0x80)
      return -4;
    if ((buf[3] & 0xC0) != 0x80)
      return -4;
    w32 |= buf[3] & 0x3F;
    w32 |= (buf[2] & 0x3F) << 6;
    w32 |= (buf[1] & 0x3F) << 12;
    w32 |= (buf[0] & 0x07) << 18;
    if (w32 <= 0xFFFF)
      return -4;
    return 4;
  }
  if ((buf[0] & 0xFC) == 0xF8) {
    if (size < 5)
      return -7;
    if ((buf[1] & 0xC0) != 0x80)
      return -5;
    if ((buf[2] & 0xC0) != 0x80)
      return -5;
    if ((buf[3] & 0xC0) != 0x80)
      return -5;
    if ((buf[4] & 0xC0) != 0x80)
      return -5;
    w32 |= buf[4] & 0x3F;
    w32 |= (buf[3] & 0x3F) << 6;
    w32 |= (buf[2] & 0x3F) << 12;
    w32 |= (buf[1] & 0x3F) << 18;
    w32 |= (buf[0] & 0x03) << 24;
    if (w32 <= 0x1FFFFF)
      return -5;
    return 5;
  }
  if ((buf[0] & 0xFE) == 0xFC) {
    if (size < 6)
      return -7;
    if ((buf[1] & 0xC0) != 0x80)
      return -6;
    if ((buf[2] & 0xC0) != 0x80)
      return -6;
    if ((buf[3] & 0xC0) != 0x80)
      return -6;
    if ((buf[4] & 0xC0) != 0x80)
      return -6;
    if ((buf[5] & 0xC0) != 0x80)
      return -6;
    w32 |= buf[5] & 0x3F;
    w32 |= (buf[4] & 0x3F) << 6;
    w32 |= (buf[3] & 0x3F) << 12;
    w32 |= (buf[2] & 0x3F) << 18;
    w32 |= (buf[1] & 0x3F) << 24;
    w32 |= (buf[0] & 0x01) << 30;
    if (w32 <= 0x3FFFFFF)
      return -6;
    return 6;
  }
  return -1;
}


x86 assembly (clang, -O0):
<is_correct_utf8>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1132 <is_correct_utf8+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jg     114e <is_correct_utf8+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    11e6 <is_correct_utf8+0xe6>
cmpq   $0x2,-0x18(%rbp)
jae    117c <is_correct_utf8+0x7c>
movl   $0xfffffff9,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     11a0 <is_correct_utf8+0xa0>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x3f,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0x1f,%eax
shl    $0x6,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x7f,-0x1c(%rbp)
ja     11da <is_correct_utf8+0xda>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
movl   $0x2,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    12b9 <is_correct_utf8+0x1b9>
cmpq   $0x3,-0x18(%rbp)
jae    1214 <is_correct_utf8+0x114>
movl   $0xfffffff9,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     1238 <is_correct_utf8+0x138>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     125c <is_correct_utf8+0x15c>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x3f,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x3f,%eax
shl    $0x6,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0xf,%eax
shl    $0xc,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x7ff,-0x1c(%rbp)
ja     12ad <is_correct_utf8+0x1ad>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
movl   $0x3,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    13c4 <is_correct_utf8+0x2c4>
cmpq   $0x4,-0x18(%rbp)
jae    12e7 <is_correct_utf8+0x1e7>
movl   $0xfffffff9,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     130b <is_correct_utf8+0x20b>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     132f <is_correct_utf8+0x22f>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     1353 <is_correct_utf8+0x253>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0x3f,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x3f,%eax
shl    $0x6,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x3f,%eax
shl    $0xc,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0x7,%eax
shl    $0x12,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xffff,-0x1c(%rbp)
ja     13b8 <is_correct_utf8+0x2b8>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
movl   $0x4,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0xfc,%eax
cmp    $0xf8,%eax
jne    1507 <is_correct_utf8+0x407>
cmpq   $0x5,-0x18(%rbp)
jae    13f2 <is_correct_utf8+0x2f2>
movl   $0xfffffff9,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     1416 <is_correct_utf8+0x316>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     143a <is_correct_utf8+0x33a>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     145e <is_correct_utf8+0x35e>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     1482 <is_correct_utf8+0x382>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0x3f,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0x3f,%eax
shl    $0x6,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x3f,%eax
shl    $0xc,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x3f,%eax
shl    $0x12,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0x3,%eax
shl    $0x18,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1fffff,-0x1c(%rbp)
ja     14fb <is_correct_utf8+0x3fb>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
movl   $0x5,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0xfe,%eax
cmp    $0xfc,%eax
jne    1682 <is_correct_utf8+0x582>
cmpq   $0x6,-0x18(%rbp)
jae    1535 <is_correct_utf8+0x435>
movl   $0xfffffff9,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     1559 <is_correct_utf8+0x459>
movl   $0xfffffffa,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     157d <is_correct_utf8+0x47d>
movl   $0xfffffffa,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     15a1 <is_correct_utf8+0x4a1>
movl   $0xfffffffa,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     15c5 <is_correct_utf8+0x4c5>
movl   $0xfffffffa,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x5(%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     15e9 <is_correct_utf8+0x4e9>
movl   $0xfffffffa,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
mov    -0x28(%rbp),%rax
movzbl 0x5(%rax),%eax
and    $0x3f,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x4(%rax),%eax
and    $0x3f,%eax
shl    $0x6,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0x3f,%eax
shl    $0xc,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x3f,%eax
shl    $0x12,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x3f,%eax
shl    $0x18,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0x1,%eax
shl    $0x1e,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x3ffffff,-0x1c(%rbp)
ja     1676 <is_correct_utf8+0x576>
movl   $0xfffffffa,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
movl   $0x6,-0x4(%rbp)
jmp    1689 <is_correct_utf8+0x589>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_correct_utf8>:
test   %rsi,%rsi
je     1112 <is_correct_utf8+0x12>
movzbl (%rdi),%ecx
mov    $0x1,%eax
test   %cl,%cl
js     1115 <is_correct_utf8+0x15>
ret
xor    %eax,%eax
ret
mov    %ecx,%eax
and    $0xffffffe0,%eax
cmp    $0xc0,%eax
jne    114c <is_correct_utf8+0x4c>
mov    $0xfffffff9,%eax
cmp    $0x2,%rsi
jb     1111 <is_correct_utf8+0x11>
mov    0x1(%rdi),%dl
and    $0xc0,%dl
mov    $0xfffffffe,%eax
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
xor    %eax,%eax
test   $0x1e,%cl
setne  %al
lea    -0x2(,%rax,4),%eax
ret
mov    %ecx,%eax
and    $0xfffffff0,%eax
cmp    $0xe0,%eax
jne    11a5 <is_correct_utf8+0xa5>
mov    $0xfffffff9,%eax
cmp    $0x3,%rsi
jb     1111 <is_correct_utf8+0x11>
movzbl 0x1(%rdi),%r8d
mov    %r8d,%esi
and    $0xffffffc0,%esi
mov    $0xfffffffd,%eax
cmp    $0x80,%esi
jne    1111 <is_correct_utf8+0x11>
mov    0x2(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
and    $0x20,%r8d
shl    $0x6,%r8d
shl    $0xc,%ecx
movzwl %cx,%eax
or     %r8d,%eax
mov    $0xfffffffd,%ecx
mov    $0x3,%eax
cmove  %ecx,%eax
ret
mov    %ecx,%eax
and    $0xfffffff8,%eax
cmp    $0xf0,%eax
jne    1218 <is_correct_utf8+0x118>
mov    $0xfffffff9,%eax
cmp    $0x4,%rsi
jb     1111 <is_correct_utf8+0x11>
movzbl 0x1(%rdi),%r8d
mov    %r8d,%esi
and    $0xffffffc0,%esi
mov    $0xfffffffc,%eax
cmp    $0x80,%esi
jne    1111 <is_correct_utf8+0x11>
mov    0x2(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
mov    0x3(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
and    $0x30,%r8d
shl    $0xc,%r8d
and    $0x7,%ecx
shl    $0x12,%ecx
xor    %eax,%eax
or     %r8d,%ecx
setne  %al
lea    -0x4(,%rax,8),%eax
ret
mov    %ecx,%eax
and    $0xfffffffc,%eax
cmp    $0xf8,%eax
jne    129b <is_correct_utf8+0x19b>
mov    $0xfffffff9,%eax
cmp    $0x5,%rsi
jb     1111 <is_correct_utf8+0x11>
movzbl 0x1(%rdi),%r8d
mov    %r8d,%esi
and    $0xffffffc0,%esi
mov    $0xfffffffb,%eax
cmp    $0x80,%esi
jne    1111 <is_correct_utf8+0x11>
mov    0x2(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
mov    0x3(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
mov    0x4(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
and    $0x38,%r8d
shl    $0x12,%r8d
and    $0x3,%ecx
shl    $0x18,%ecx
or     %r8d,%ecx
mov    $0xfffffffb,%ecx
mov    $0x5,%eax
cmove  %ecx,%eax
ret
mov    %ecx,%edx
and    $0xfffffffe,%edx
mov    $0xffffffff,%eax
cmp    $0xfc,%edx
jne    1111 <is_correct_utf8+0x11>
mov    $0xfffffff9,%eax
cmp    $0x6,%rsi
jb     1111 <is_correct_utf8+0x11>
movzbl 0x1(%rdi),%r8d
mov    %r8d,%esi
and    $0xffffffc0,%esi
mov    $0xfffffffa,%eax
cmp    $0x80,%esi
jne    1111 <is_correct_utf8+0x11>
mov    0x2(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
mov    0x3(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
mov    0x4(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
mov    0x5(%rdi),%dl
and    $0xc0,%dl
cmp    $0x80,%dl
jne    1111 <is_correct_utf8+0x11>
and    $0x3c,%r8d
shl    $0x18,%r8d
and    $0x1,%ecx
shl    $0x1e,%ecx
or     %r8d,%ecx
mov    $0xfffffffa,%ecx
mov    $0x6,%eax
cmove  %ecx,%eax
ret

LLVM IR (-O0):
define i32 @is_correct_utf8(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 0, i32* %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
%9 = load i64, i64* %5
%10 = icmp ne i64 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %375
12: ; preds = %2
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp sle i32 %16, 127
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 1, i32* %3
br label %375
19: ; preds = %12
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = and i32 %23, 224
%25 = icmp eq i32 %24, 192
br i1 %25, label %26, label %58
26: ; preds = %19
%27 = load i64, i64* %5
%28 = icmp ult i64 %27, 2
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 -7, i32* %3
br label %375
30: ; preds = %26
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = and i32 %34, 192
%36 = icmp ne i32 %35, 128
br i1 %36, label %37, label %38
37: ; preds = %30
store i32 -2, i32* %3
br label %375
38: ; preds = %30
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = and i32 %42, 63
%44 = load i32, i32* %6
%45 = or i32 %44, %43
store i32 %45, i32* %6
%46 = load i8*, i8** %7
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = and i32 %49, 31
%51 = shl i32 %50, 6
%52 = load i32, i32* %6
%53 = or i32 %52, %51
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = icmp ule i32 %54, 127
br i1 %55, label %56, label %57
56: ; preds = %38
store i32 -2, i32* %3
br label %375
57: ; preds = %38
store i32 2, i32* %3
br label %375
58: ; preds = %19
%59 = load i8*, i8** %7
%60 = getelementptr inbounds i8, i8* %59, i64 0
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = and i32 %62, 240
%64 = icmp eq i32 %63, 224
br i1 %64, label %65, label %113
65: ; preds = %58
%66 = load i64, i64* %5
%67 = icmp ult i64 %66, 3
br i1 %67, label %68, label %69
68: ; preds = %65
store i32 -7, i32* %3
br label %375
69: ; preds = %65
%70 = load i8*, i8** %7
%71 = getelementptr inbounds i8, i8* %70, i64 1
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = and i32 %73, 192
%75 = icmp ne i32 %74, 128
br i1 %75, label %76, label %77
76: ; preds = %69
store i32 -3, i32* %3
br label %375
77: ; preds = %69
%78 = load i8*, i8** %7
%79 = getelementptr inbounds i8, i8* %78, i64 2
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = and i32 %81, 192
%83 = icmp ne i32 %82, 128
br i1 %83, label %84, label %85
84: ; preds = %77
store i32 -3, i32* %3
br label %375
85: ; preds = %77
%86 = load i8*, i8** %7
%87 = getelementptr inbounds i8, i8* %86, i64 2
%88 = load i8, i8* %87
%89 = zext i8 %88 to i32
%90 = and i32 %89, 63
%91 = load i32, i32* %6
%92 = or i32 %91, %90
store i32 %92, i32* %6
%93 = load i8*, i8** %7
%94 = getelementptr inbounds i8, i8* %93, i64 1
%95 = load i8, i8* %94
%96 = zext i8 %95 to i32
%97 = and i32 %96, 63
%98 = shl i32 %97, 6
%99 = load i32, i32* %6
%100 = or i32 %99, %98
store i32 %100, i32* %6
%101 = load i8*, i8** %7
%102 = getelementptr inbounds i8, i8* %101, i64 0
%103 = load i8, i8* %102
%104 = zext i8 %103 to i32
%105 = and i32 %104, 15
%106 = shl i32 %105, 12
%107 = load i32, i32* %6
%108 = or i32 %107, %106
store i32 %108, i32* %6
%109 = load i32, i32* %6
%110 = icmp ule i32 %109, 2047
br i1 %110, label %111, label %112
111: ; preds = %85
store i32 -3, i32* %3
br label %375
112: ; preds = %85
store i32 3, i32* %3
br label %375
113: ; preds = %58
%114 = load i8*, i8** %7
%115 = getelementptr inbounds i8, i8* %114, i64 0
%116 = load i8, i8* %115
%117 = zext i8 %116 to i32
%118 = and i32 %117, 248
%119 = icmp eq i32 %118, 240
br i1 %119, label %120, label %184
120: ; preds = %113
%121 = load i64, i64* %5
%122 = icmp ult i64 %121, 4
br i1 %122, label %123, label %124
123: ; preds = %120
store i32 -7, i32* %3
br label %375
124: ; preds = %120
%125 = load i8*, i8** %7
%126 = getelementptr inbounds i8, i8* %125, i64 1
%127 = load i8, i8* %126
%128 = zext i8 %127 to i32
%129 = and i32 %128, 192
%130 = icmp ne i32 %129, 128
br i1 %130, label %131, label %132
131: ; preds = %124
store i32 -4, i32* %3
br label %375
132: ; preds = %124
%133 = load i8*, i8** %7
%134 = getelementptr inbounds i8, i8* %133, i64 2
%135 = load i8, i8* %134
%136 = zext i8 %135 to i32
%137 = and i32 %136, 192
%138 = icmp ne i32 %137, 128
br i1 %138, label %139, label %140
139: ; preds = %132
store i32 -4, i32* %3
br label %375
140: ; preds = %132
%141 = load i8*, i8** %7
%142 = getelementptr inbounds i8, i8* %141, i64 3
%143 = load i8, i8* %142
%144 = zext i8 %143 to i32
%145 = and i32 %144, 192
%146 = icmp ne i32 %145, 128
br i1 %146, label %147, label %148
147: ; preds = %140
store i32 -4, i32* %3
br label %375
148: ; preds = %140
%149 = load i8*, i8** %7
%150 = getelementptr inbounds i8, i8* %149, i64 3
%151 = load i8, i8* %150
%152 = zext i8 %151 to i32
%153 = and i32 %152, 63
%154 = load i32, i32* %6
%155 = or i32 %154, %153
store i32 %155, i32* %6
%156 = load i8*, i8** %7
%157 = getelementptr inbounds i8, i8* %156, i64 2
%158 = load i8, i8* %157
%159 = zext i8 %158 to i32
%160 = and i32 %159, 63
%161 = shl i32 %160, 6
%162 = load i32, i32* %6
%163 = or i32 %162, %161
store i32 %163, i32* %6
%164 = load i8*, i8** %7
%165 = getelementptr inbounds i8, i8* %164, i64 1
%166 = load i8, i8* %165
%167 = zext i8 %166 to i32
%168 = and i32 %167, 63
%169 = shl i32 %168, 12
%170 = load i32, i32* %6
%171 = or i32 %170, %169
store i32 %171, i32* %6
%172 = load i8*, i8** %7
%173 = getelementptr inbounds i8, i8* %172, i64 0
%174 = load i8, i8* %173
%175 = zext i8 %174 to i32
%176 = and i32 %175, 7
%177 = shl i32 %176, 18
%178 = load i32, i32* %6
%179 = or i32 %178, %177
store i32 %179, i32* %6
%180 = load i32, i32* %6
%181 = icmp ule i32 %180, 65535
br i1 %181, label %182, label %183
182: ; preds = %148
store i32 -4, i32* %3
br label %375
183: ; preds = %148
store i32 4, i32* %3
br label %375
184: ; preds = %113
%185 = load i8*, i8** %7
%186 = getelementptr inbounds i8, i8* %185, i64 0
%187 = load i8, i8* %186
%188 = zext i8 %187 to i32
%189 = and i32 %188, 252
%190 = icmp eq i32 %189, 248
br i1 %190, label %191, label %271
191: ; preds = %184
%192 = load i64, i64* %5
%193 = icmp ult i64 %192, 5
br i1 %193, label %194, label %195
194: ; preds = %191
store i32 -7, i32* %3
br label %375
195: ; preds = %191
%196 = load i8*, i8** %7
%197 = getelementptr inbounds i8, i8* %196, i64 1
%198 = load i8, i8* %197
%199 = zext i8 %198 to i32
%200 = and i32 %199, 192
%201 = icmp ne i32 %200, 128
br i1 %201, label %202, label %203
202: ; preds = %195
store i32 -5, i32* %3
br label %375
203: ; preds = %195
%204 = load i8*, i8** %7
%205 = getelementptr inbounds i8, i8* %204, i64 2
%206 = load i8, i8* %205
%207 = zext i8 %206 to i32
%208 = and i32 %207, 192
%209 = icmp ne i32 %208, 128
br i1 %209, label %210, label %211
210: ; preds = %203
store i32 -5, i32* %3
br label %375
211: ; preds = %203
%212 = load i8*, i8** %7
%213 = getelementptr inbounds i8, i8* %212, i64 3
%214 = load i8, i8* %213
%215 = zext i8 %214 to i32
%216 = and i32 %215, 192
%217 = icmp ne i32 %216, 128
br i1 %217, label %218, label %219
218: ; preds = %211
store i32 -5, i32* %3
br label %375
219: ; preds = %211
%220 = load i8*, i8** %7
%221 = getelementptr inbounds i8, i8* %220, i64 4
%222 = load i8, i8* %221
%223 = zext i8 %222 to i32
%224 = and i32 %223, 192
%225 = icmp ne i32 %224, 128
br i1 %225, label %226, label %227
226: ; preds = %219
store i32 -5, i32* %3
br label %375
227: ; preds = %219
%228 = load i8*, i8** %7
%229 = getelementptr inbounds i8, i8* %228, i64 4
%230 = load i8, i8* %229
%231 = zext i8 %230 to i32
%232 = and i32 %231, 63
%233 = load i32, i32* %6
%234 = or i32 %233, %232
store i32 %234, i32* %6
%235 = load i8*, i8** %7
%236 = getelementptr inbounds i8, i8* %235, i64 3
%237 = load i8, i8* %236
%238 = zext i8 %237 to i32
%239 = and i32 %238, 63
%240 = shl i32 %239, 6
%241 = load i32, i32* %6
%242 = or i32 %241, %240
store i32 %242, i32* %6
%243 = load i8*, i8** %7
%244 = getelementptr inbounds i8, i8* %243, i64 2
%245 = load i8, i8* %244
%246 = zext i8 %245 to i32
%247 = and i32 %246, 63
%248 = shl i32 %247, 12
%249 = load i32, i32* %6
%250 = or i32 %249, %248
store i32 %250, i32* %6
%251 = load i8*, i8** %7
%252 = getelementptr inbounds i8, i8* %251, i64 1
%253 = load i8, i8* %252
%254 = zext i8 %253 to i32
%255 = and i32 %254, 63
%256 = shl i32 %255, 18
%257 = load i32, i32* %6
%258 = or i32 %257, %256
store i32 %258, i32* %6
%259 = load i8*, i8** %7
%260 = getelementptr inbounds i8, i8* %259, i64 0
%261 = load i8, i8* %260
%262 = zext i8 %261 to i32
%263 = and i32 %262, 3
%264 = shl i32 %263, 24
%265 = load i32, i32* %6
%266 = or i32 %265, %264
store i32 %266, i32* %6
%267 = load i32, i32* %6
%268 = icmp ule i32 %267, 2097151
br i1 %268, label %269, label %270
269: ; preds = %227
store i32 -5, i32* %3
br label %375
270: ; preds = %227
store i32 5, i32* %3
br label %375
271: ; preds = %184
%272 = load i8*, i8** %7
%273 = getelementptr inbounds i8, i8* %272, i64 0
%274 = load i8, i8* %273
%275 = zext i8 %274 to i32
%276 = and i32 %275, 254
%277 = icmp eq i32 %276, 252
br i1 %277, label %278, label %374
278: ; preds = %271
%279 = load i64, i64* %5
%280 = icmp ult i64 %279, 6
br i1 %280, label %281, label %282
281: ; preds = %278
store i32 -7, i32* %3
br label %375
282: ; preds = %278
%283 = load i8*, i8** %7
%284 = getelementptr inbounds i8, i8* %283, i64 1
%285 = load i8, i8* %284
%286 = zext i8 %285 to i32
%287 = and i32 %286, 192
%288 = icmp ne i32 %287, 128
br i1 %288, label %289, label %290
289: ; preds = %282
store i32 -6, i32* %3
br label %375
290: ; preds = %282
%291 = load i8*, i8** %7
%292 = getelementptr inbounds i8, i8* %291, i64 2
%293 = load i8, i8* %292
%294 = zext i8 %293 to i32
%295 = and i32 %294, 192
%296 = icmp ne i32 %295, 128
br i1 %296, label %297, label %298
297: ; preds = %290
store i32 -6, i32* %3
br label %375
298: ; preds = %290
%299 = load i8*, i8** %7
%300 = getelementptr inbounds i8, i8* %299, i64 3
%301 = load i8, i8* %300
%302 = zext i8 %301 to i32
%303 = and i32 %302, 192
%304 = icmp ne i32 %303, 128
br i1 %304, label %305, label %306
305: ; preds = %298
store i32 -6, i32* %3
br label %375
306: ; preds = %298
%307 = load i8*, i8** %7
%308 = getelementptr inbounds i8, i8* %307, i64 4
%309 = load i8, i8* %308
%310 = zext i8 %309 to i32
%311 = and i32 %310, 192
%312 = icmp ne i32 %311, 128
br i1 %312, label %313, label %314
313: ; preds = %306
store i32 -6, i32* %3
br label %375
314: ; preds = %306
%315 = load i8*, i8** %7
%316 = getelementptr inbounds i8, i8* %315, i64 5
%317 = load i8, i8* %316
%318 = zext i8 %317 to i32
%319 = and i32 %318, 192
%320 = icmp ne i32 %319, 128
br i1 %320, label %321, label %322
321: ; preds = %314
store i32 -6, i32* %3
br label %375
322: ; preds = %314
%323 = load i8*, i8** %7
%324 = getelementptr inbounds i8, i8* %323, i64 5
%325 = load i8, i8* %324
%326 = zext i8 %325 to i32
%327 = and i32 %326, 63
%328 = load i32, i32* %6
%329 = or i32 %328, %327
store i32 %329, i32* %6
%330 = load i8*, i8** %7
%331 = getelementptr inbounds i8, i8* %330, i64 4
%332 = load i8, i8* %331
%333 = zext i8 %332 to i32
%334 = and i32 %333, 63
%335 = shl i32 %334, 6
%336 = load i32, i32* %6
%337 = or i32 %336, %335
store i32 %337, i32* %6
%338 = load i8*, i8** %7
%339 = getelementptr inbounds i8, i8* %338, i64 3
%340 = load i8, i8* %339
%341 = zext i8 %340 to i32
%342 = and i32 %341, 63
%343 = shl i32 %342, 12
%344 = load i32, i32* %6
%345 = or i32 %344, %343
store i32 %345, i32* %6
%346 = load i8*, i8** %7
%347 = getelementptr inbounds i8, i8* %346, i64 2
%348 = load i8, i8* %347
%349 = zext i8 %348 to i32
%350 = and i32 %349, 63
%351 = shl i32 %350, 18
%352 = load i32, i32* %6
%353 = or i32 %352, %351
store i32 %353, i32* %6
%354 = load i8*, i8** %7
%355 = getelementptr inbounds i8, i8* %354, i64 1
%356 = load i8, i8* %355
%357 = zext i8 %356 to i32
%358 = and i32 %357, 63
%359 = shl i32 %358, 24
%360 = load i32, i32* %6
%361 = or i32 %360, %359
store i32 %361, i32* %6
%362 = load i8*, i8** %7
%363 = getelementptr inbounds i8, i8* %362, i64 0
%364 = load i8, i8* %363
%365 = zext i8 %364 to i32
%366 = and i32 %365, 1
%367 = shl i32 %366, 30
%368 = load i32, i32* %6
%369 = or i32 %368, %367
store i32 %369, i32* %6
%370 = load i32, i32* %6
%371 = icmp ule i32 %370, 67108863
br i1 %371, label %372, label %373
372: ; preds = %322
store i32 -6, i32* %3
br label %375
373: ; preds = %322
store i32 6, i32* %3
br label %375
374: ; preds = %271
store i32 -1, i32* %3
br label %375
375: ; preds = %374, %373, %372, %321, %313, %305, %297, %289, %281, %270, %269, %226, %218, %210, %202, %194, %183, %182, %147, %139, %131, %123, %112, %111, %84, %76, %68, %57, %56, %37, %29, %18, %11
%376 = load i32, i32* %3
ret i32 %376
}

LLVM IR (-O2):
define i32 @is_correct_utf8(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %148, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = zext i8 %5 to i32
%7 = icmp sgt i8 %5, -1
br i1 %7, label %148, label %8
8: ; preds = %4
%9 = and i32 %6, 224
%10 = icmp eq i32 %9, 192
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = icmp ult i64 %1, 2
br i1 %12, label %148, label %13
13: ; preds = %11
%14 = getelementptr inbounds i8, i8* %0, i64 1
%15 = load i8, i8* %14
%16 = and i8 %15, -64
%17 = icmp eq i8 %16, -128
br i1 %17, label %18, label %148
18: ; preds = %13
%19 = and i32 %6, 30
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 -2, i32 2
br label %148
22: ; preds = %8
%23 = and i32 %6, 240
%24 = icmp eq i32 %23, 224
br i1 %24, label %25, label %46
25: ; preds = %22
%26 = icmp ult i64 %1, 3
br i1 %26, label %148, label %27
27: ; preds = %25
%28 = getelementptr inbounds i8, i8* %0, i64 1
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = and i32 %30, 192
%32 = icmp eq i32 %31, 128
br i1 %32, label %33, label %148
33: ; preds = %27
%34 = getelementptr inbounds i8, i8* %0, i64 2
%35 = load i8, i8* %34
%36 = and i8 %35, -64
%37 = icmp eq i8 %36, -128
br i1 %37, label %38, label %148
38: ; preds = %33
%39 = shl nuw nsw i32 %30, 6
%40 = and i32 %39, 2048
%41 = shl nuw nsw i32 %6, 12
%42 = and i32 %41, 61440
%43 = or i32 %40, %42
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 -3, i32 3
br label %148
46: ; preds = %22
%47 = and i32 %6, 248
%48 = icmp eq i32 %47, 240
br i1 %48, label %49, label %75
49: ; preds = %46
%50 = icmp ult i64 %1, 4
br i1 %50, label %148, label %51
51: ; preds = %49
%52 = getelementptr inbounds i8, i8* %0, i64 1
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = and i32 %54, 192
%56 = icmp eq i32 %55, 128
br i1 %56, label %57, label %148
57: ; preds = %51
%58 = getelementptr inbounds i8, i8* %0, i64 2
%59 = load i8, i8* %58
%60 = and i8 %59, -64
%61 = icmp eq i8 %60, -128
br i1 %61, label %62, label %148
62: ; preds = %57
%63 = getelementptr inbounds i8, i8* %0, i64 3
%64 = load i8, i8* %63
%65 = and i8 %64, -64
%66 = icmp eq i8 %65, -128
br i1 %66, label %67, label %148
67: ; preds = %62
%68 = shl nuw nsw i32 %54, 12
%69 = and i32 %68, 196608
%70 = shl nuw nsw i32 %6, 18
%71 = and i32 %70, 1835008
%72 = or i32 %69, %71
%73 = icmp eq i32 %72, 0
%74 = select i1 %73, i32 -4, i32 4
br label %148
75: ; preds = %46
%76 = and i32 %6, 252
%77 = icmp eq i32 %76, 248
br i1 %77, label %78, label %109
78: ; preds = %75
%79 = icmp ult i64 %1, 5
br i1 %79, label %148, label %80
80: ; preds = %78
%81 = getelementptr inbounds i8, i8* %0, i64 1
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = and i32 %83, 192
%85 = icmp eq i32 %84, 128
br i1 %85, label %86, label %148
86: ; preds = %80
%87 = getelementptr inbounds i8, i8* %0, i64 2
%88 = load i8, i8* %87
%89 = and i8 %88, -64
%90 = icmp eq i8 %89, -128
br i1 %90, label %91, label %148
91: ; preds = %86
%92 = getelementptr inbounds i8, i8* %0, i64 3
%93 = load i8, i8* %92
%94 = and i8 %93, -64
%95 = icmp eq i8 %94, -128
br i1 %95, label %96, label %148
96: ; preds = %91
%97 = getelementptr inbounds i8, i8* %0, i64 4
%98 = load i8, i8* %97
%99 = and i8 %98, -64
%100 = icmp eq i8 %99, -128
br i1 %100, label %101, label %148
101: ; preds = %96
%102 = shl nuw nsw i32 %83, 18
%103 = and i32 %102, 14680064
%104 = shl nuw i32 %6, 24
%105 = and i32 %104, 50331648
%106 = or i32 %103, %105
%107 = icmp eq i32 %106, 0
%108 = select i1 %107, i32 -5, i32 5
br label %148
109: ; preds = %75
%110 = and i32 %6, 254
%111 = icmp eq i32 %110, 252
br i1 %111, label %112, label %148
112: ; preds = %109
%113 = icmp ult i64 %1, 6
br i1 %113, label %148, label %114
114: ; preds = %112
%115 = getelementptr inbounds i8, i8* %0, i64 1
%116 = load i8, i8* %115
%117 = zext i8 %116 to i32
%118 = and i32 %117, 192
%119 = icmp eq i32 %118, 128
br i1 %119, label %120, label %148
120: ; preds = %114
%121 = getelementptr inbounds i8, i8* %0, i64 2
%122 = load i8, i8* %121
%123 = and i8 %122, -64
%124 = icmp eq i8 %123, -128
br i1 %124, label %125, label %148
125: ; preds = %120
%126 = getelementptr inbounds i8, i8* %0, i64 3
%127 = load i8, i8* %126
%128 = and i8 %127, -64
%129 = icmp eq i8 %128, -128
br i1 %129, label %130, label %148
130: ; preds = %125
%131 = getelementptr inbounds i8, i8* %0, i64 4
%132 = load i8, i8* %131
%133 = and i8 %132, -64
%134 = icmp eq i8 %133, -128
br i1 %134, label %135, label %148
135: ; preds = %130
%136 = getelementptr inbounds i8, i8* %0, i64 5
%137 = load i8, i8* %136
%138 = and i8 %137, -64
%139 = icmp eq i8 %138, -128
br i1 %139, label %140, label %148
140: ; preds = %135
%141 = shl nuw i32 %117, 24
%142 = and i32 %141, 1006632960
%143 = shl i32 %6, 30
%144 = and i32 %143, 1073741824
%145 = or i32 %142, %144
%146 = icmp eq i32 %145, 0
%147 = select i1 %146, i32 -6, i32 6
br label %148
148: ; preds = %109, %140, %135, %130, %125, %120, %114, %112, %101, %96, %91, %86, %80, %78, %67, %62, %57, %51, %49, %38, %33, %27, %25, %18, %13, %11, %4, %2
%149 = phi i32 [ 0, %2 ], [ 1, %4 ], [ -7, %11 ], [ -2, %13 ], [ %21, %18 ], [ -7, %25 ], [ -3, %27 ], [ -3, %33 ], [ %45, %38 ], [ -7, %49 ], [ -4, %51 ], [ -4, %57 ], [ -4, %62 ], [ %74, %67 ], [ -7, %78 ], [ -5, %80 ], [ -5, %86 ], [ -5, %91 ], [ -5, %96 ], [ %108, %101 ], [ -7, %112 ], [ -6, %114 ], [ -6, %120 ], [ -6, %125 ], [ -6, %130 ], [ -6, %135 ], [ %147, %140 ], [ -1, %109 ]
ret i32 %149
}