#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__ g_utf8_get_char(char const *);
char *g_utf8_next_char(char const *);
char *ldap_utf8_strchr(const char *str, const char *chr) {
  for (; *str != '\0'; ((str) = g_utf8_next_char(((str))))) {
    if (g_utf8_get_char(str) == g_utf8_get_char(chr)) {
      return (char *)str;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<ldap_utf8_strchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118a <ldap_utf8_strchr+0x6a>
mov    -0x10(%rbp),%rdi
call   1040 <g_utf8_get_char@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <g_utf8_get_char@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jne    1173 <ldap_utf8_strchr+0x53>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1192 <ldap_utf8_strchr+0x72>
jmp    1178 <ldap_utf8_strchr+0x58>
mov    -0x10(%rbp),%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,-0x10(%rbp)
jmp    1130 <ldap_utf8_strchr+0x10>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldap_utf8_strchr>:
push   %r15
push   %r14
push   %rbx
cmpb   $0x0,(%rdi)
je     1158 <ldap_utf8_strchr+0x38>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rbx,%rdi
call   1040 <g_utf8_get_char@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <g_utf8_get_char@plt>
cmp    %rax,%r15
je     115a <ldap_utf8_strchr+0x3a>
mov    %rbx,%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    1130 <ldap_utf8_strchr+0x10>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ldap_utf8_strchr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %6
6: ; preds = %20, %2
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %6
%12 = load i8*, i8** %4
%13 = call i64 @g_utf8_get_char(i8* %12)
%14 = load i8*, i8** %5
%15 = call i64 @g_utf8_get_char(i8* %14)
%16 = icmp eq i64 %13, %15
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i8*, i8** %4
store i8* %18, i8** %3
br label %24
19: ; preds = %11
br label %20
20: ; preds = %19
%21 = load i8*, i8** %4
%22 = call i8* @g_utf8_next_char(i8* %21)
store i8* %22, i8** %4
br label %6
23: ; preds = %6
store i8* null, i8** %3
br label %24
24: ; preds = %23, %17
%25 = load i8*, i8** %3
ret i8* %25
}

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