#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 *fcitx_utf8_get_char(char const *, int *);
scalar_t__ fcitx_utf8_get_char_validated(char const *, int);
__attribute__((visibility("default"))) int
fcitx_utf8_check_string(const char *s) {
  while (*s) {
    int chr;
    if (fcitx_utf8_get_char_validated(s, 6) < 0)
      return 0;
    s = fcitx_utf8_get_char(s, &chr);
  }
  return 1;
}


x86 assembly (clang, -O0):
<fcitx_utf8_check_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1173 <fcitx_utf8_check_string+0x53>
mov    -0x10(%rbp),%rdi
mov    $0x6,%esi
call   1040 <fcitx_utf8_get_char_validated@plt>
cmp    $0x0,%rax
jge    115d <fcitx_utf8_check_string+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    117a <fcitx_utf8_check_string+0x5a>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <fcitx_utf8_get_char@plt>
mov    %rax,-0x10(%rbp)
jmp    112c <fcitx_utf8_check_string+0xc>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utf8_check_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%r14d
cmpb   $0x0,(%rdi)
je     116a <fcitx_utf8_check_string+0x4a>
mov    %rdi,%rbx
lea    0xc(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x6,%esi
call   1040 <fcitx_utf8_get_char_validated@plt>
test   %rax,%rax
js     1167 <fcitx_utf8_check_string+0x47>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <fcitx_utf8_get_char@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    1140 <fcitx_utf8_check_string+0x20>
jmp    116a <fcitx_utf8_check_string+0x4a>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fcitx_utf8_check_string(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
br label %5
5: ; preds = %14, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = call i64 @fcitx_utf8_get_char_validated(i8* %10, i32 6)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 0, i32* %2
br label %18
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i8* @fcitx_utf8_get_char(i8* %15, i32* %4)
store i8* %16, i8** %3
br label %5
17: ; preds = %5
store i32 1, i32* %2
br label %18
18: ; preds = %17, %13
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
define i32 @fcitx_utf8_check_string(i8* %0) {
%2 = alloca i32
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
br label %7
7: ; preds = %5, %12
%8 = phi i8* [ %0, %5 ], [ %13, %12 ]
%9 = call i64 @fcitx_utf8_get_char_validated(i8* %8, i32 6)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7
br label %16
12: ; preds = %7
%13 = call i8* @fcitx_utf8_get_char(i8* %8, i32* %2)
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %7
16: ; preds = %12, %1, %11
%17 = phi i32 [ 0, %11 ], [ 1, %1 ], [ 1, %12 ]
ret i32 %17
}