#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*/ free(char *);
char *malloc(int);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char const *, char *);
char *strdup(char const *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char *, char const *, int);
char *strtok_r(char *, char *, char **);
int filter_has_val(const char *filter, const char *val) {
  char *x = NULL, *token = NULL;
  char *m_buffer = NULL, *buffer;
  int len = strlen(val);
  int ret = 0;
  if (!strcmp(filter, "*"))
    return 1;
  x = strdup(filter);
  if (!x)
    return 0;
  m_buffer = malloc(strlen(x));
  if (!m_buffer) {
    free(x);
    return 0;
  }
  buffer = m_buffer;
  token = strtok_r(x, ",", &buffer);
  while (token) {
    if (*val == '@')
      token = strchr(token, '@');
    if (token && !strncmp(token, val, len)) {
      ret = 1;
      break;
    }
    token = strtok_r(NULL, ",", &buffer);
  }
  free(m_buffer);
  free(x);
  return ret;
}


x86 assembly (clang, -O0):
<filter_has_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    11e0 <filter_has_val+0x60>
movl   $0x1,-0x4(%rbp)
jmp    12ea <filter_has_val+0x16a>
mov    -0x10(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1204 <filter_has_val+0x84>
movl   $0x0,-0x4(%rbp)
jmp    12ea <filter_has_val+0x16a>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1238 <filter_has_val+0xb8>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ea <filter_has_val+0x16a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdb7(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12d2 <filter_has_val+0x152>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    1285 <filter_has_val+0x105>
mov    -0x28(%rbp),%rdi
mov    $0x40,%esi
call   1060 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12b5 <filter_has_val+0x135>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12b5 <filter_has_val+0x135>
movl   $0x1,-0x40(%rbp)
jmp    12d2 <filter_has_val+0x152>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd42(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
jmp    1258 <filter_has_val+0xd8>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_has_val>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
lea    0xe5a(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
je     125f <filter_has_val+0xdf>
mov    %rbp,%rdi
call   10a0 <strdup@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1281 <filter_has_val+0x101>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1279 <filter_has_val+0xf9>
mov    %rax,%r15
mov    %rax,0x8(%rsp)
lea    0xe0f(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1070 <strtok_r@plt>
test   %rax,%rax
mov    %r15,0x10(%rsp)
je     1266 <filter_has_val+0xe6>
lea    0xdf1(%rip),%r13
lea    0x8(%rsp),%r15
jmp    1246 <filter_has_val+0xc6>
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     126a <filter_has_val+0xea>
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r13,%rsi
mov    %r15,%rdx
call   1070 <strtok_r@plt>
test   %rax,%rax
je     126f <filter_has_val+0xef>
cmpb   $0x40,(%rbx)
jne    1220 <filter_has_val+0xa0>
mov    %rax,%rdi
mov    $0x40,%esi
call   1060 <strchr@plt>
test   %rax,%rax
jne    1220 <filter_has_val+0xa0>
jmp    1232 <filter_has_val+0xb2>
mov    $0x1,%ebp
jmp    1281 <filter_has_val+0x101>
xor    %ebp,%ebp
jmp    126f <filter_has_val+0xef>
mov    $0x1,%ebp
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"*\00"
@.str.1 = [2 x i8] c",\00"
define i32 @filter_has_val(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %10
store i32 0, i32* %11
%14 = load i8*, i8** %4
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %2
store i32 1, i32* %3
br label %66
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %18
store i32 0, i32* %3
br label %66
24: ; preds = %18
%25 = load i8*, i8** %6
%26 = call i32 @strlen(i8* %25)
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %33, label %30
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = call i32 @free(i8* %31)
store i32 0, i32* %3
br label %66
33: ; preds = %24
%34 = load i8*, i8** %8
store i8* %34, i8** %9
%35 = load i8*, i8** %6
%36 = call i8* @strtok_r(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %9)
store i8* %36, i8** %7
br label %37
37: ; preds = %58, %33
%38 = load i8*, i8** %7
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %60
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 64
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i8*, i8** %7
%47 = call i8* @strchr(i8* %46, i8 signext 64)
store i8* %47, i8** %7
br label %48
48: ; preds = %45, %40
%49 = load i8*, i8** %7
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %58
51: ; preds = %48
%52 = load i8*, i8** %7
%53 = load i8*, i8** %5
%54 = load i32, i32* %10
%55 = call i32 @strncmp(i8* %52, i8* %53, i32 %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %51
store i32 1, i32* %11
br label %60
58: ; preds = %51, %48
%59 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %9)
store i8* %59, i8** %7
br label %37
60: ; preds = %57, %37
%61 = load i8*, i8** %8
%62 = call i32 @free(i8* %61)
%63 = load i8*, i8** %6
%64 = call i32 @free(i8* %63)
%65 = load i32, i32* %11
store i32 %65, i32* %3
br label %66
66: ; preds = %60, %30, %23, %17
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [2 x i8] c"*\00"
@.str.1 = [2 x i8] c",\00"
define i32 @filter_has_val(i8* nocapture %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %38, label %8
8: ; preds = %2
%9 = tail call i8* @strdup(i8* %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %38, label %11
11: ; preds = %8
%12 = tail call i32 @strlen(i8* %9)
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @free(i8* %9)
br label %38
17: ; preds = %11
store i8* %13, i8** %3
%18 = call i8* @strtok_r(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%19 = icmp eq i8* %18, null
br i1 %19, label %34, label %20
20: ; preds = %17, %31
%21 = phi i8* [ %32, %31 ], [ %18, %17 ]
%22 = load i8, i8* %1
%23 = icmp eq i8 %22, 64
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i8* @strchr(i8* %21, i8 signext 64)
%26 = icmp eq i8* %25, null
br i1 %26, label %31, label %27
27: ; preds = %20, %24
%28 = phi i8* [ %25, %24 ], [ %21, %20 ]
%29 = call i32 @strncmp(i8* %28, i8* %1, i32 %5)
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %27, %24
%32 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %20
34: ; preds = %31, %27, %17
%35 = phi i32 [ 0, %17 ], [ 1, %27 ], [ 0, %31 ]
%36 = call i32 @free(i8* %13)
%37 = call i32 @free(i8* %9)
br label %38
38: ; preds = %8, %2, %34, %15
%39 = phi i32 [ %35, %34 ], [ 0, %15 ], [ 1, %2 ], [ 0, %8 ]
ret i32 %39
}