#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 */
unsigned int strlen(char *);
unsigned strcspn(char a[], char b[]) {
  unsigned i, j, match;
  for (i = 0; i < strlen(a); i++) {
    match = 0;
    for (j = 0; j < strlen(b); j++) {
      if (a[i] == b[j]) {
        match = 1;
        break;
      }
    }
    if (match)
      return i;
  }
}


x86 assembly (clang, -O0):
<strcspn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jae    11d2 <strcspn+0xc2>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jae    11aa <strcspn+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1197 <strcspn+0x87>
movl   $0x1,-0x24(%rbp)
jmp    11aa <strcspn+0x9a>
jmp    119c <strcspn+0x8c>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1151 <strcspn+0x41>
cmpl   $0x0,-0x24(%rbp)
je     11bf <strcspn+0xaf>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d2 <strcspn+0xc2>
jmp    11c4 <strcspn+0xb4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <strcspn+0x17>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcspn>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
call   1030 <strlen@plt>
xor    %r14d,%r14d
test   %eax,%eax
jne    1153 <strcspn+0x43>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
nopl   0x0(%rax)
add    $0x1,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%r14
jae    112a <strcspn+0x1a>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1140 <strcspn+0x30>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%r14,1),%eax
cmp    (%r12,%rbx,1),%al
je     112a <strcspn+0x1a>
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1170 <strcspn+0x60>
jmp    1140 <strcspn+0x30>

LLVM IR (-O0):
define i32 @strcspn(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %9
9: ; preds = %45, %2
%10 = load i32, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = icmp ult i32 %10, %12
br i1 %13, label %14, label %48
14: ; preds = %9
store i32 0, i32* %8
store i32 0, i32* %7
br label %15
15: ; preds = %36, %14
%16 = load i32, i32* %7
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = icmp ult i32 %16, %18
br i1 %19, label %20, label %39
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i8*, i8** %5
%28 = load i32, i32* %7
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %26, %32
br i1 %33, label %34, label %35
34: ; preds = %20
store i32 1, i32* %8
br label %39
35: ; preds = %20
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add i32 %37, 1
store i32 %38, i32* %7
br label %15
39: ; preds = %34, %15
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = load i32, i32* %6
store i32 %43, i32* %3
br label %48
44: ; preds = %39
br label %45
45: ; preds = %44
%46 = load i32, i32* %6
%47 = add i32 %46, 1
store i32 %47, i32* %6
br label %9
48: ; preds = %42, %9
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
define i32 @strcspn(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %31, label %5
5: ; preds = %2, %22
%6 = phi i64 [ %23, %22 ], [ 0, %2 ]
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %0, i64 %6
br label %15
11: ; preds = %15
%12 = tail call i32 @strlen(i8* %1)
%13 = zext i32 %12 to i64
%14 = icmp ult i64 %21, %13
br i1 %14, label %15, label %22
15: ; preds = %9, %11
%16 = phi i64 [ 0, %9 ], [ %21, %11 ]
%17 = load i8, i8* %10
%18 = getelementptr inbounds i8, i8* %1, i64 %16
%19 = load i8, i8* %18
%20 = icmp eq i8 %17, %19
%21 = add nuw nsw i64 %16, 1
br i1 %20, label %27, label %11
22: ; preds = %11, %5
%23 = add nuw nsw i64 %6, 1
%24 = tail call i32 @strlen(i8* %0)
%25 = zext i32 %24 to i64
%26 = icmp ult i64 %23, %25
br i1 %26, label %5, label %29
27: ; preds = %15
%28 = trunc i64 %6 to i32
br label %31
29: ; preds = %22
%30 = trunc i64 %23 to i32
br label %31
31: ; preds = %29, %27, %2
%32 = phi i32 [ 0, %2 ], [ %28, %27 ], [ %30, %29 ]
ret i32 %32
}