#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_strspn(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) = g_utf8_next_char(((cset))))) {
      if (*cset == '\0') {
        return cstr - str;
      }
      if (g_utf8_get_char(cstr) == g_utf8_get_char(cset)) {
        break;
      }
    }
  }
  return cstr - str;
}


x86 assembly (clang, -O0):
<ldap_utf8_strspn>:
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     11cd <ldap_utf8_strspn+0xad>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1174 <ldap_utf8_strspn+0x54>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <ldap_utf8_strspn+0xbc>
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    119f <ldap_utf8_strspn+0x7f>
jmp    11b6 <ldap_utf8_strspn+0x96>
jmp    11a4 <ldap_utf8_strspn+0x84>
mov    -0x28(%rbp),%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,-0x28(%rbp)
jmp    1150 <ldap_utf8_strspn+0x30>
jmp    11bb <ldap_utf8_strspn+0x9b>
mov    -0x20(%rbp),%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,-0x20(%rbp)
jmp    1138 <ldap_utf8_strspn+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_strspn>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
mov    %rdi,%r12
je     1190 <ldap_utf8_strspn+0x70>
mov    %rsi,%r15
mov    %r14,%r12
cmpb   $0x0,(%r15)
je     1190 <ldap_utf8_strspn+0x70>
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%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     1180 <ldap_utf8_strspn+0x60>
mov    %rbx,%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    1150 <ldap_utf8_strspn+0x30>
jmp    1190 <ldap_utf8_strspn+0x70>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <g_utf8_next_char@plt>
mov    %rax,%r12
cmpb   $0x0,(%rax)
jne    113a <ldap_utf8_strspn+0x1a>
sub    %r14,%r12
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @ldap_utf8_strspn(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 %22, 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 %18, 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 %22, label %9
18: ; preds = %9
%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, %5, %14, %2
%23 = phi i8* [ %0, %2 ], [ %6, %14 ], [ %6, %5 ], [ %19, %18 ]
%24 = ptrtoint i8* %23 to i64
%25 = ptrtoint i8* %0 to i64
%26 = sub i64 %24, %25
ret i64 %26
}