#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 strlen(char const *);
size_t strcspn(const char *s, const char *charset) {
  size_t i;
  size_t len = strlen(s);
  for (i = 0; strchr(charset, s[i]) == NULL && i < len; i++)
    ;
  return i;
}


x86 assembly (clang, -O0):
<strcspn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    117a <strcspn+0x5a>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    118a <strcspn+0x6a>
jmp    11a0 <strcspn+0x80>
jmp    118f <strcspn+0x6f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1145 <strcspn+0x25>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcspn>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
mov    %rax,%rcx
lea    0x1(%rbx),%rax
test   %rcx,%rcx
jne    1161 <strcspn+0x41>
cmp    %r12,%rbx
mov    %rax,%rbx
jb     1140 <strcspn+0x20>
add    $0xffffffffffffffff,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @strcspn(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
store i64 0, i64* %5
br label %9
9: ; preds = %24, %2
%10 = load i8*, i8** %4
%11 = load i8*, i8** %3
%12 = load i64, i64* %5
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = load i8, i8* %13
%15 = call i32* @strchr(i8* %10, i8 signext %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = load i64, i64* %5
%19 = load i64, i64* %6
%20 = icmp ult i64 %18, %19
br label %21
21: ; preds = %17, %9
%22 = phi i1 [ false, %9 ], [ %20, %17 ]
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 %9
27: ; preds = %21
%28 = load i64, i64* %5
ret i64 %28
}

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