#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__ strchr(char *, char);
int strspn(char *string, char *control) {
  register int count = 0;
  register char ch;
  while (ch = *string) {
    if (strchr(control, ch))
      ++count;
    else
      break;
    ++string;
  }
  return count;
}


x86 assembly (clang, -O0):
<strspn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
cmp    $0x0,%al
je     1173 <strspn+0x63>
mov    -0x10(%rbp),%rdi
movsbl -0x15(%rbp),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     115d <strspn+0x4d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1162 <strspn+0x52>
jmp    1173 <strspn+0x63>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1127 <strspn+0x17>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strspn>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1150 <strspn+0x40>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1152 <strspn+0x42>
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <strspn+0x20>
jmp    1152 <strspn+0x42>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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