#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 /*<<< orphan*/ *strchr(char const *, char const);
size_t strspn(const char *s, const char *charset) {
  size_t i;
  for (i = 0; strchr(charset, s[i]) != NULL && s[i] != '\0'; i++)
    ;
  return i;
}


x86 assembly (clang, -O0):
<strspn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1164 <strspn+0x54>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1174 <strspn+0x64>
jmp    118a <strspn+0x7a>
jmp    1179 <strspn+0x69>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <strspn+0x18>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strspn>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
movsbl (%rdi),%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     114e <strspn+0x3e>
nopl   (%rax)
cmpb   $0x0,(%r15,%rbx,1)
je     114e <strspn+0x3e>
movsbl 0x1(%r15,%rbx,1),%esi
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1130 <strspn+0x20>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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