#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 */
char *sr_strndup(char const *, size_t);
size_t strspn(char const *, char const *);
int sr_parse_char_span(const char **input, const char *accept, char **result) {
  size_t count = strspn(*input, accept);
  if (count == 0)
    return 0;
  *result = sr_strndup(*input, count);
  *input += count;
  return count;
}


x86 assembly (clang, -O0):
<sr_parse_char_span>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strspn@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    115f <sr_parse_char_span+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    118e <sr_parse_char_span+0x6e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <sr_strndup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sr_parse_char_span>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%r15
mov    (%rdi),%r12
mov    %r12,%rdi
call   1040 <strspn@plt>
test   %rax,%rax
je     1154 <sr_parse_char_span+0x34>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <sr_strndup@plt>
mov    %rax,(%r14)
add    %rbx,(%r15)
jmp    1156 <sr_parse_char_span+0x36>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @sr_parse_char_span(i8** nocapture %0, i8* nocapture %1, i8** nocapture writeonly %2) {
%4 = load i8*, i8** %0
%5 = tail call i64 @strspn(i8* %4, i8* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = tail call i8* @sr_strndup(i8* %4, i64 %5)
store i8* %8, i8** %2
%9 = load i8*, i8** %0
%10 = getelementptr inbounds i8, i8* %9, i64 %5
store i8* %10, i8** %0
%11 = trunc i64 %5 to i32
br label %12
12: ; preds = %3, %7
%13 = phi i32 [ %11, %7 ], [ 0, %3 ]
ret i32 %13
}