#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 *, int /*<<< orphan*/);
int /*<<< orphan*/ vassert(int /*<<< orphan*/, char *);
size_t strspn(const char *str1, const char *str2) {
  size_t count = 0;
  vassert(str1 != NULL, "str1 == NULL");
  vassert(str2 != NULL, "str2 == NULL");
  while (*str1) {
    if (strchr(str2, *str1++) == NULL)
      return count;
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<strspn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xeb4(%rip),%rsi
call   1040 <vassert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xea8(%rip),%rsi
call   1040 <vassert@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ba <strspn+0x9a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    11a9 <strspn+0x89>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <strspn+0xa2>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116a <strspn+0x4a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%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
xor    %edi,%edi
test   %r15,%r15
setne  %dil
lea    0xec5(%rip),%rsi
call   1040 <vassert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
lea    0xebd(%rip),%rsi
call   1040 <vassert@plt>
mov    (%r15),%al
xor    %ebx,%ebx
test   %al,%al
je     117e <strspn+0x5e>
xchg   %ax,%ax
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     117e <strspn+0x5e>
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <strspn+0x40>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"str1 == NULL\00"
@.str.1 = [13 x i8] c"str2 == NULL\00"
define i64 @strspn(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 0, i64* %6
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @vassert(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @vassert(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %29, %2
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
%23 = load i8, i8* %21
%24 = sext i8 %23 to i32
%25 = call i32* @strchr(i8* %20, i32 %24)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = load i64, i64* %6
store i64 %28, i64* %3
br label %34
29: ; preds = %19
%30 = load i64, i64* %6
%31 = add i64 %30, 1
store i64 %31, i64* %6
br label %15
32: ; preds = %15
%33 = load i64, i64* %6
store i64 %33, i64* %3
br label %34
34: ; preds = %32, %27
%35 = load i64, i64* %3
ret i64 %35
}

LLVM IR (-O2):
@.str = [13 x i8] c"str1 == NULL\00"
@.str.1 = [13 x i8] c"str2 == NULL\00"
define i64 @strspn(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @vassert(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i8* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @vassert(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %2, %18
%12 = phi i8 [ %21, %18 ], [ %9, %2 ]
%13 = phi i64 [ %20, %18 ], [ 0, %2 ]
%14 = phi i8* [ %19, %18 ], [ %0, %2 ]
%15 = sext i8 %12 to i32
%16 = tail call i32* @strchr(i8* %1, i32 %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %11
%19 = getelementptr inbounds i8, i8* %14, i64 1
%20 = add i64 %13, 1
%21 = load i8, i8* %19
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %11
23: ; preds = %11, %18, %2
%24 = phi i64 [ 0, %2 ], [ %20, %18 ], [ %13, %11 ]
ret i64 %24
}