#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 CHAR_BIT;
int /*<<< orphan*/ memset(unsigned long *, int /*<<< orphan*/, int);
int /*<<< orphan*/ set_bit(unsigned long *, unsigned char);
int test_bit(unsigned long *, unsigned char);
size_t strxspn(const char *s, const char *map, int parity) {
  unsigned long matchmap[((1 << CHAR_BIT) + (CHAR_BIT * sizeof(long)) - 1) /
                         (CHAR_BIT * sizeof(long))];
  size_t n = 0;
  memset(matchmap, 0, sizeof matchmap);
  while (*map)
    set_bit(matchmap, (unsigned char)*map++);
  if (parity)
    set_bit(matchmap, 0);
  while (test_bit(matchmap, (unsigned char)*s++) ^ parity)
    n++;
  return n;
}


x86 assembly (clang, -O0):
<strxspn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e96(%rip),%rax
movslq (%rax),%rdx
mov    %dl,%cl
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    %rdx,%rcx
shl    $0x3,%rcx
lea    -0x1(%rax,%rdx,8),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    %rcx,%rax
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
lea    0xf(,%rcx,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d5 <strxspn+0xa5>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%esi
call   1040 <set_bit@plt>
jmp    11a8 <strxspn+0x78>
cmpl   $0x0,-0x14(%rbp)
je     11ea <strxspn+0xba>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1040 <set_bit@plt>
jmp    11ef <strxspn+0xbf>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%esi
call   1050 <test_bit@plt>
xor    -0x14(%rbp),%eax
cmp    $0x0,%eax
je     1227 <strxspn+0xf7>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11ef <strxspn+0xbf>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strxspn>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e95(%rip),%rax
movslq (%rax),%rcx
mov    $0x1,%eax
shl    %cl,%eax
cltq
lea    (%rax,%rcx,8),%rax
add    $0xffffffffffffffff,%rax
shl    $0x3,%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1176 <strxspn+0x46>
xor    %edx,%edx
div    %rcx
jmp    117a <strxspn+0x4a>
xor    %edx,%edx
div    %ecx
mov    %rsp,%r12
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r12
mov    %r12,%rsp
shl    $0x3,%eax
mov    %r12,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1030 <memset@plt>
mov    (%rbx),%al
test   %al,%al
je     11c6 <strxspn+0x96>
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movzbl %al,%esi
mov    %r12,%rdi
call   1040 <set_bit@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11b0 <strxspn+0x80>
test   %r15d,%r15d
je     11d5 <strxspn+0xa5>
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <set_bit@plt>
movzbl (%r14),%esi
mov    %r12,%rdi
call   1050 <test_bit@plt>
xor    %ebx,%ebx
cmp    %r15d,%eax
je     1207 <strxspn+0xd7>
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%r14,%rbx,1),%esi
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <test_bit@plt>
cmp    %r15d,%eax
jne    11f0 <strxspn+0xc0>
mov    %rbx,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
define i64 @strxspn(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i32, i32* @CHAR_BIT
%11 = shl i32 1, %10
%12 = sext i32 %11 to i64
%13 = load i32, i32* @CHAR_BIT
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = add i64 %12, %15
%17 = sub i64 %16, 1
%18 = load i32, i32* @CHAR_BIT
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = udiv i64 %17, %20
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %7
%23 = alloca i64, i64 %21
store i64 %21, i64* %8
store i64 0, i64* %9
%24 = mul nuw i64 8, %21
%25 = trunc i64 %24 to i32
%26 = call i32 @memset(i64* %23, i32 0, i32 %25)
br label %27
27: ; preds = %31, %3
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
%34 = load i8, i8* %32
%35 = call i32 @set_bit(i64* %23, i8 zeroext %34)
br label %27
36: ; preds = %27
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @set_bit(i64* %23, i8 zeroext 0)
br label %41
41: ; preds = %39, %36
br label %42
42: ; preds = %50, %41
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %4
%45 = load i8, i8* %43
%46 = call i32 @test_bit(i64* %23, i8 zeroext %45)
%47 = load i32, i32* %6
%48 = xor i32 %46, %47
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %42
%51 = load i64, i64* %9
%52 = add i64 %51, 1
store i64 %52, i64* %9
br label %42
53: ; preds = %42
%54 = load i64, i64* %9
%55 = load i8*, i8** %7
ret i64 %54
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
define i64 @strxspn(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = load i32, i32* @CHAR_BIT
%5 = shl nuw i32 1, %4
%6 = sext i32 %5 to i64
%7 = sext i32 %4 to i64
%8 = shl nsw i64 %7, 3
%9 = add nsw i64 %6, -1
%10 = add nsw i64 %9, %8
%11 = udiv i64 %10, %8
%12 = alloca i64, i64 %11
%13 = trunc i64 %11 to i32
%14 = shl i32 %13, 3
%15 = call i32 @memset(i64* %12, i32 0, i32 %14)
%16 = load i8, i8* %1
%17 = icmp eq i8 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %3, %18
%19 = phi i8 [ %23, %18 ], [ %16, %3 ]
%20 = phi i8* [ %21, %18 ], [ %1, %3 ]
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i32 @set_bit(i64* %12, i8 zeroext %19)
%23 = load i8, i8* %21
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %18
25: ; preds = %18, %3
%26 = icmp eq i32 %2, 0
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = call i32 @set_bit(i64* %12, i8 zeroext 0)
br label %29
29: ; preds = %27, %25
%30 = load i8, i8* %0
%31 = call i32 @test_bit(i64* %12, i8 zeroext %30)
%32 = icmp eq i32 %31, %2
br i1 %32, label %41, label %33
33: ; preds = %29, %33
%34 = phi i64 [ %37, %33 ], [ 0, %29 ]
%35 = phi i8* [ %36, %33 ], [ %0, %29 ]
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = add i64 %34, 1
%38 = load i8, i8* %36
%39 = call i32 @test_bit(i64* %12, i8 zeroext %38)
%40 = icmp eq i32 %39, %2
br i1 %40, label %41, label %33
41: ; preds = %33, %29
%42 = phi i64 [ 0, %29 ], [ %37, %33 ]
ret i64 %42
}