#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 */
scalar_t__ is_valid_ascii(char const);
__attribute__((visibility("default"))) char *
fcitx_utils_get_ascii_endn(const char *string, size_t len) {
  if (!string)
    return NULL;
  const char *end = string + len;
  for (; string < end && is_valid_ascii(*string); string++) {
  }
  return (char *)string;
}


x86 assembly (clang, -O0):
<fcitx_utils_get_ascii_endn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1138 <fcitx_utils_get_ascii_endn+0x28>
movq   $0x0,-0x8(%rbp)
jmp    119b <fcitx_utils_get_ascii_endn+0x8b>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x21(%rbp)
jae    116d <fcitx_utils_get_ascii_endn+0x5d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <is_valid_ascii@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117d <fcitx_utils_get_ascii_endn+0x6d>
jmp    1193 <fcitx_utils_get_ascii_endn+0x83>
jmp    1182 <fcitx_utils_get_ascii_endn+0x72>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <fcitx_utils_get_ascii_endn+0x34>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utils_get_ascii_endn>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1148 <fcitx_utils_get_ascii_endn+0x38>
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
jle    114a <fcitx_utils_get_ascii_endn+0x3a>
add    %rbx,%r14
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1030 <is_valid_ascii@plt>
test   %rax,%rax
je     114a <fcitx_utils_get_ascii_endn+0x3a>
add    $0x1,%rbx
cmp    %r14,%rbx
jb     1130 <fcitx_utils_get_ascii_endn+0x20>
jmp    114a <fcitx_utils_get_ascii_endn+0x3a>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @fcitx_utils_get_ascii_endn(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i8* null, i8** %3
br label %31
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i64, i64* %5
%13 = getelementptr inbounds i8, i8* %11, i64 %12
store i8* %13, i8** %6
br label %14
14: ; preds = %26, %10
%15 = load i8*, i8** %4
%16 = load i8*, i8** %6
%17 = icmp ult i8* %15, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = call i64 @is_valid_ascii(i8 signext %20)
%22 = icmp ne i64 %21, 0
br label %23
23: ; preds = %18, %14
%24 = phi i1 [ false, %14 ], [ %22, %18 ]
br i1 %24, label %25, label %29
25: ; preds = %23
br label %26
26: ; preds = %25
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
br label %14
29: ; preds = %23
%30 = load i8*, i8** %4
store i8* %30, i8** %3
br label %31
31: ; preds = %29, %9
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
define i8* @fcitx_utils_get_ascii_endn(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 %1
%6 = icmp sgt i64 %1, 0
br i1 %6, label %7, label %15
7: ; preds = %4, %12
%8 = phi i8* [ %13, %12 ], [ %0, %4 ]
%9 = load i8, i8* %8
%10 = tail call i64 @is_valid_ascii(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %8, i64 1
%14 = icmp ult i8* %13, %5
br i1 %14, label %7, label %15
15: ; preds = %12, %7, %4, %2
%16 = phi i8* [ null, %2 ], [ %0, %4 ], [ %13, %12 ], [ %8, %7 ]
ret i8* %16
}