#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char const *, char *, int /*<<< orphan*/);
char *strtok(char *, char *);
int fsfilter(const char *fs, const char *filter, int nm) {
  int ret = 0;
  char *stropt;
  char *strtmp;
  if ((strtmp = strdup(filter)) == NULL) {
    (void)fputs("Cannot duplicate filter\n", stderr);
    exit(EXIT_FAILURE);
  }
  stropt = strtok(strtmp, ",");
  while (stropt != NULL) {
    if (strncmp(fs, stropt, strlen(stropt)) == 0) {
      ret = 1;
      break;
    }
    stropt = strtok(NULL, ",");
  }
  free(strtmp);
  return nm ? !ret : ret;
}


x86 assembly (clang, -O0):
<fsfilter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11c4 <fsfilter+0x54>
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    0xe4f(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     123a <fsfilter+0xca>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1221 <fsfilter+0xb1>
movl   $0x1,-0x18(%rbp)
jmp    123a <fsfilter+0xca>
xor    %eax,%eax
mov    %eax,%edi
lea    0xded(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11d8 <fsfilter+0x68>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x14(%rbp)
je     1263 <fsfilter+0xf3>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
jmp    1269 <fsfilter+0xf9>
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsfilter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1090 <strdup@plt>
test   %rax,%rax
je     1230 <fsfilter+0xc0>
mov    %rax,%r15
lea    0xe7e(%rip),%rsi
mov    %rax,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     11f4 <fsfilter+0x84>
mov    %rax,%rbp
mov    %ebx,0x4(%rsp)
lea    0xe63(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11fe <fsfilter+0x8e>
xor    %r14d,%r14d
xor    %edi,%edi
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11c0 <fsfilter+0x50>
jmp    1204 <fsfilter+0x94>
xor    %r14d,%r14d
mov    $0x1,%ebp
jmp    1211 <fsfilter+0xa1>
mov    $0x1,%r14d
xor    %ebp,%ebp
test   %rbx,%rbx
setne  %bpl
mov    0x4(%rsp),%ebx
mov    %r15,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
cmove  %r14d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
lea    0xdc0(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Cannot duplicate filter\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c",\00"
define i32 @fsfilter(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%10 = load i8*, i8** %5
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %9
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = call i32 @fputs(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %3
%19 = load i8*, i8** %9
%20 = call i8* @strtok(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %8
br label %21
21: ; preds = %32, %18
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i8*, i8** %4
%26 = load i8*, i8** %8
%27 = load i8*, i8** %8
%28 = call i32 @strlen(i8* %27)
%29 = call i64 @strncmp(i8* %25, i8* %26, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %7
br label %34
32: ; preds = %24
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %33, i8** %8
br label %21
34: ; preds = %31, %21
%35 = load i8*, i8** %9
%36 = call i32 @free(i8* %35)
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32, i32* %7
%41 = icmp ne i32 %40, 0
%42 = xor i1 %41, true
%43 = zext i1 %42 to i32
br label %46
44: ; preds = %34
%45 = load i32, i32* %7
br label %46
46: ; preds = %44, %39
%47 = phi i32 [ %43, %39 ], [ %45, %44 ]
ret i32 %47
}

LLVM IR (-O2):
@.str = [25 x i8] c"Cannot duplicate filter\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c",\00"
define i32 @fsfilter(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i8* @strdup(i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fputs(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3
%12 = tail call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %26, label %14
14: ; preds = %11, %19
%15 = phi i8* [ %20, %19 ], [ %12, %11 ]
%16 = tail call i32 @strlen(i8* %15)
%17 = tail call i64 @strncmp(i8* %0, i8* %15, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %14
22: ; preds = %14, %19
%23 = phi i32 [ 0, %19 ], [ 1, %14 ]
%24 = xor i1 %18, true
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %22, %11
%27 = phi i32 [ 1, %11 ], [ %25, %22 ]
%28 = phi i32 [ 0, %11 ], [ %23, %22 ]
%29 = tail call i32 @free(i8* %4)
%30 = icmp eq i32 %2, 0
%31 = select i1 %30, i32 %28, i32 %27
ret i32 %31
}