#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 _chartorune(unsigned short *, char const *);
char *strchr(char const *, unsigned short);
char *_utfrune(const char *s, unsigned short c) {
  long c1;
  unsigned short r;
  int n;
  if (c < 0x80)
    return strchr(s, c);
  for (;;) {
    c1 = *(unsigned char *)s;
    if (c1 < 0x80) {
      if (c1 == 0)
        return 0;
      if (c1 == c)
        return (char *)s;
      s++;
      continue;
    }
    n = _chartorune(&r, s);
    if (r == c)
      return (char *)s;
    s += n;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_utfrune>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
cmp    $0x80,%eax
jge    1158 <_utfrune+0x38>
mov    -0x10(%rbp),%rdi
movzwl -0x12(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
jmp    1200 <_utfrune+0xe0>
jmp    115d <_utfrune+0x3d>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %rax,-0x20(%rbp)
cmpq   $0x80,-0x20(%rbp)
jge    11bd <_utfrune+0x9d>
cmpq   $0x0,-0x20(%rbp)
jne    118e <_utfrune+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    1200 <_utfrune+0xe0>
mov    -0x20(%rbp),%rax
movzwl -0x12(%rbp),%ecx
cmp    %rcx,%rax
jne    11ac <_utfrune+0x8c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1200 <_utfrune+0xe0>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115d <_utfrune+0x3d>
mov    -0x10(%rbp),%rsi
lea    -0x22(%rbp),%rdi
call   1040 <_chartorune@plt>
mov    %eax,-0x28(%rbp)
movzwl -0x22(%rbp),%eax
movzwl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jne    11ea <_utfrune+0xca>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1200 <_utfrune+0xe0>
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    115d <_utfrune+0x3d>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_utfrune>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
cmp    $0x80,%esi
jae    1148 <_utfrune+0x28>
movzwl %bp,%esi
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strchr@plt>
lea    0xe(%rsp),%r14
nopl   (%rax)
movzbl (%rbx),%eax
test   %al,%al
js     1170 <_utfrune+0x50>
test   %al,%al
je     118a <_utfrune+0x6a>
mov    $0x1,%ecx
cmp    %bp,%ax
je     118c <_utfrune+0x6c>
add    %rcx,%rbx
jmp    1150 <_utfrune+0x30>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <_chartorune@plt>
cmp    %bp,0xe(%rsp)
je     118c <_utfrune+0x6c>
movslq %eax,%rcx
add    %rcx,%rbx
jmp    1150 <_utfrune+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @_utfrune(i8* %0, i16 zeroext %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
%5 = icmp ult i16 %1, 128
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i16 zeroext %1)
br label %26
8: ; preds = %2, %17
%9 = phi i8* [ %19, %17 ], [ %0, %2 ]
%10 = load i8, i8* %9
%11 = icmp sgt i8 %10, -1
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = icmp eq i8 %10, 0
br i1 %13, label %26, label %14
14: ; preds = %12
%15 = zext i8 %10 to i16
%16 = icmp eq i16 %15, %1
br i1 %16, label %26, label %17
17: ; preds = %14, %24
%18 = phi i64 [ %25, %24 ], [ 1, %14 ]
%19 = getelementptr inbounds i8, i8* %9, i64 %18
br label %8
20: ; preds = %8
%21 = call i32 @_chartorune(i16* %3, i8* %9)
%22 = load i16, i16* %3
%23 = icmp eq i16 %22, %1
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = sext i32 %21 to i64
br label %17
26: ; preds = %20, %14, %12, %6
%27 = phi i8* [ %7, %6 ], [ %9, %20 ], [ %9, %14 ], [ null, %12 ]
ret i8* %27
}