#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 *);
size_t ldap_utf8_strcspn(const char *str, const char *set) {
  const char *cstr;
  const char *cset;
  for (cstr = str; *cstr != '\0'; ((cstr) = g_utf8_next_char(((cstr))))) {
    for (cset = set; *cset != '\0'; ((cset) = g_utf8_next_char(((cset))))) {
      if (g_utf8_get_char(cstr) == g_utf8_get_char(cset)) {
        return cstr - str;
      }
    }
  }
  return cstr - str;
}


x86 assembly (clang, -O0):
<ldap_utf8_strcspn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c8 <ldap_utf8_strcspn+0xa8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b1 <ldap_utf8_strcspn+0x91>
mov    -0x20(%rbp),%rdi
call   1040 <g_utf8_get_char@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <g_utf8_get_char@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jne    119a <ldap_utf8_strcspn+0x7a>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <ldap_utf8_strcspn+0xb7>
jmp    119f <ldap_utf8_strcspn+0x7f>
mov    -0x28(%rbp),%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,-0x28(%rbp)
jmp    1150 <ldap_utf8_strcspn+0x30>
jmp    11b6 <ldap_utf8_strcspn+0x96>
mov    -0x20(%rbp),%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,-0x20(%rbp)
jmp    1138 <ldap_utf8_strcspn+0x18>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldap_utf8_strcspn>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
cmpb   $0x0,(%rdi)
mov    %rdi,%r12
je     118a <ldap_utf8_strcspn+0x6a>
mov    %rsi,%r14
mov    %r15,%r12
jmp    1150 <ldap_utf8_strcspn+0x30>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,%r12
cmpb   $0x0,(%rax)
je     118a <ldap_utf8_strcspn+0x6a>
cmpb   $0x0,(%r14)
je     1140 <ldap_utf8_strcspn+0x20>
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %r12,%rdi
call   1040 <g_utf8_get_char@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <g_utf8_get_char@plt>
cmp    %rax,%r13
je     118a <ldap_utf8_strcspn+0x6a>
mov    %rbx,%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    1160 <ldap_utf8_strcspn+0x40>
jmp    1140 <ldap_utf8_strcspn+0x20>
sub    %r15,%r12
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @ldap_utf8_strcspn(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
store i8* %8, i8** %6
br label %9
9: ; preds = %38, %2
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %41
14: ; preds = %9
%15 = load i8*, i8** %5
store i8* %15, i8** %7
br label %16
16: ; preds = %34, %14
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %16
%22 = load i8*, i8** %6
%23 = call i64 @g_utf8_get_char(i8* %22)
%24 = load i8*, i8** %7
%25 = call i64 @g_utf8_get_char(i8* %24)
%26 = icmp eq i64 %23, %25
br i1 %26, label %27, label %33
27: ; preds = %21
%28 = load i8*, i8** %6
%29 = load i8*, i8** %4
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
store i64 %32, i64* %3
br label %47
33: ; preds = %21
br label %34
34: ; preds = %33
%35 = load i8*, i8** %7
%36 = call i8* @g_utf8_next_char(i8* %35)
store i8* %36, i8** %7
br label %16
37: ; preds = %16
br label %38
38: ; preds = %37
%39 = load i8*, i8** %6
%40 = call i8* @g_utf8_next_char(i8* %39)
store i8* %40, i8** %6
br label %9
41: ; preds = %9
%42 = load i8*, i8** %6
%43 = load i8*, i8** %4
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
store i64 %46, i64* %3
br label %47
47: ; preds = %41, %27
%48 = load i64, i64* %3
ret i64 %48
}

LLVM IR (-O2):
define i64 @ldap_utf8_strcspn(i8* %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %2, %18
%6 = phi i8* [ %19, %18 ], [ %0, %2 ]
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %5, %14
%10 = phi i8* [ %15, %14 ], [ %1, %5 ]
%11 = tail call i64 @g_utf8_get_char(i8* %6)
%12 = tail call i64 @g_utf8_get_char(i8* %10)
%13 = icmp eq i64 %11, %12
br i1 %13, label %22, label %14
14: ; preds = %9
%15 = tail call i8* @g_utf8_next_char(i8* %10)
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %9
18: ; preds = %14, %5
%19 = tail call i8* @g_utf8_next_char(i8* %6)
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %5
22: ; preds = %18, %9, %2
%23 = phi i8* [ %0, %2 ], [ %6, %9 ], [ %19, %18 ]
%24 = ptrtoint i8* %23 to i64
%25 = ptrtoint i8* %0 to i64
%26 = sub i64 %24, %25
ret i64 %26
}