#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 */
scalar_t__ snoopy_filterregistry_callByName(char *, char *, char *);
scalar_t__ snoopy_filterregistry_doesNameExist(char *);
int /*<<< orphan*/ snoopy_message_append(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strstr(char *, char *);
char *strtok_r(char *, char *, char **);
int snoopy_filtering_check_chain(char *logMessage, char *filterChain) {
  char filterChainCopy[4096];
  int filterChainCopySize;
  int j;
  char *str;
  char *rest;
  char *filterSpec;
  char *fcPos_filterSpecArg;
  filterChainCopySize = strlen(filterChain);
  if (filterChainCopySize > 4096 - 1) {
    filterChainCopySize = 4096 - 1;
  }
  strncpy(filterChainCopy, filterChain, filterChainCopySize);
  filterChainCopy[filterChainCopySize] = '\0';
  for (j = 1, str = filterChainCopy;; j++, str = NULL) {
    char filterName[1024];
    char *filterNamePtr;
    size_t filterNameSize;
    char filterArg[1024];
    char *filterArgPtr;
    filterSpec = strtok_r(str, ";", &rest);
    if (NULL == filterSpec) {
      break;
    }
    fcPos_filterSpecArg = strstr(filterSpec, ":");
    if (NULL == fcPos_filterSpecArg) {
      filterName[0] = '\0';
      filterNamePtr = filterSpec;
      filterArg[0] = '\0';
      filterArgPtr = filterArg;
    } else {
      filterNameSize = fcPos_filterSpecArg - filterSpec;
      filterName[0] = '\0';
      strncpy(filterName, filterSpec, filterNameSize);
      filterName[filterNameSize] = '\0';
      filterNamePtr = filterName;
      filterArgPtr = fcPos_filterSpecArg + 1;
    }
    if (0 == snoopy_filterregistry_doesNameExist(filterNamePtr)) {
      snoopy_message_append(logMessage, "ERROR(Filter not found - ");
      snoopy_message_append(logMessage, filterNamePtr);
      snoopy_message_append(logMessage, ")");
      break;
    }
    if (0 == snoopy_filterregistry_callByName(filterNamePtr, logMessage,
                                              filterArgPtr)) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<snoopy_filtering_check_chain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1870,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0xfff,-0x1024(%rbp)
jle    11ac <snoopy_filtering_check_chain+0x3c>
movl   $0xfff,-0x1024(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1024(%rbp),%rdx
call   1030 <strncpy@plt>
movslq -0x1024(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
movl   $0x1,-0x1028(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x1030(%rbp),%rdi
lea    0xe08(%rip),%rsi
lea    -0x1038(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x1040(%rbp)
xor    %eax,%eax
cmp    -0x1040(%rbp),%rax
jne    121f <snoopy_filtering_check_chain+0xaf>
jmp    1383 <snoopy_filtering_check_chain+0x213>
mov    -0x1040(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x1048(%rbp)
xor    %eax,%eax
cmp    -0x1048(%rbp),%rax
jne    1277 <snoopy_filtering_check_chain+0x107>
movb   $0x0,-0x1450(%rbp)
mov    -0x1040(%rbp),%rax
mov    %rax,-0x1458(%rbp)
movb   $0x0,-0x1860(%rbp)
lea    -0x1860(%rbp),%rax
mov    %rax,-0x1868(%rbp)
jmp    12df <snoopy_filtering_check_chain+0x16f>
mov    -0x1048(%rbp),%rax
mov    -0x1040(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x1460(%rbp)
movb   $0x0,-0x1450(%rbp)
lea    -0x1450(%rbp),%rdi
mov    -0x1040(%rbp),%rsi
mov    -0x1460(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x1460(%rbp),%rax
movb   $0x0,-0x1450(%rbp,%rax,1)
lea    -0x1450(%rbp),%rax
mov    %rax,-0x1458(%rbp)
mov    -0x1048(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1868(%rbp)
mov    -0x1458(%rbp),%rdi
call   1050 <snoopy_filterregistry_doesNameExist@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    132e <snoopy_filtering_check_chain+0x1be>
mov    -0x10(%rbp),%rdi
lea    0xd00(%rip),%rsi
call   1070 <snoopy_message_append@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1458(%rbp),%rsi
call   1070 <snoopy_message_append@plt>
mov    -0x10(%rbp),%rdi
lea    0xcfa(%rip),%rsi
call   1070 <snoopy_message_append@plt>
jmp    1383 <snoopy_filtering_check_chain+0x213>
mov    -0x1458(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1868(%rbp),%rdx
call   1080 <snoopy_filterregistry_callByName@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    135f <snoopy_filtering_check_chain+0x1ef>
movl   $0x0,-0x4(%rbp)
jmp    138a <snoopy_filtering_check_chain+0x21a>
jmp    1364 <snoopy_filtering_check_chain+0x1f4>
mov    -0x1028(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1028(%rbp)
movq   $0x0,-0x1030(%rbp)
jmp    11ea <snoopy_filtering_check_chain+0x7a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snoopy_filtering_check_chain>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1818,%rsp
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1040 <strlen@plt>
cmp    $0xfff,%eax
mov    $0xfff,%ecx
cmovl  %eax,%ecx
movslq %ecx,%rbp
lea    0x810(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
movb   $0x0,0x810(%rsp,%rbp,1)
lea    0xe3c(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1070 <strtok_r@plt>
test   %rax,%rax
je     12ad <snoopy_filtering_check_chain+0x13d>
mov    %rax,%rbx
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1230 <snoopy_filtering_check_chain+0xc0>
mov    %rax,%r14
mov    %rax,%rbp
sub    %rbx,%rbp
movb   $0x0,0x10(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
movb   $0x0,0x10(%rsp,%rbp,1)
add    $0x1,%r14
mov    %r12,%rbx
jmp    1245 <snoopy_filtering_check_chain+0xd5>
nopl   0x0(%rax)
movb   $0x0,0x10(%rsp)
movb   $0x0,0x410(%rsp)
lea    0x410(%rsp),%r14
mov    %rbx,%rdi
call   1060 <snoopy_filterregistry_doesNameExist@plt>
test   %rax,%rax
je     1284 <snoopy_filtering_check_chain+0x114>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1090 <snoopy_filterregistry_callByName@plt>
test   %rax,%rax
je     12b4 <snoopy_filtering_check_chain+0x144>
xor    %edi,%edi
lea    0xd92(%rip),%rsi
mov    %r15,%rdx
call   1070 <strtok_r@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11f0 <snoopy_filtering_check_chain+0x80>
jmp    12ad <snoopy_filtering_check_chain+0x13d>
lea    0xd77(%rip),%rsi
mov    %r13,%rdi
call   1080 <snoopy_message_append@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <snoopy_message_append@plt>
lea    0xd77(%rip),%rsi
mov    %r13,%rdi
call   1080 <snoopy_message_append@plt>
mov    $0x1,%eax
jmp    12b6 <snoopy_filtering_check_chain+0x146>
xor    %eax,%eax
add    $0x1818,%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"
@.str.2 = [26 x i8] c"ERROR(Filter not found - \00"
@.str.3 = [2 x i8] c")\00"
define i32 @snoopy_filtering_check_chain(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [1024 x i8]
%14 = alloca i8*
%15 = alloca i64
%16 = alloca [1024 x i8]
%17 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp sgt i32 %20, 4095
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 4095, i32* %7
br label %23
23: ; preds = %22, %2
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%25 = load i8*, i8** %5
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = call i32 @strncpy(i8* %24, i8* %25, i64 %27)
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %30
store i8 0, i8* %31
store i32 1, i32* %8
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
store i8* %32, i8** %9
br label %33
33: ; preds = %85, %23
%34 = load i8*, i8** %9
%35 = call i8* @strtok_r(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10)
store i8* %35, i8** %11
%36 = load i8*, i8** %11
%37 = icmp eq i8* null, %36
br i1 %37, label %38, label %39
38: ; preds = %33
br label %88
39: ; preds = %33
%40 = load i8*, i8** %11
%41 = call i8* @strstr(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %41, i8** %12
%42 = load i8*, i8** %12
%43 = icmp eq i8* null, %42
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
store i8 0, i8* %45
%46 = load i8*, i8** %11
store i8* %46, i8** %14
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
store i8 0, i8* %47
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
store i8* %48, i8** %17
br label %65
49: ; preds = %39
%50 = load i8*, i8** %12
%51 = load i8*, i8** %11
%52 = ptrtoint i8* %50 to i64
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %52, %53
store i64 %54, i64* %15
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
store i8 0, i8* %55
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%57 = load i8*, i8** %11
%58 = load i64, i64* %15
%59 = call i32 @strncpy(i8* %56, i8* %57, i64 %58)
%60 = load i64, i64* %15
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 %60
store i8 0, i8* %61
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
store i8* %62, i8** %14
%63 = load i8*, i8** %12
%64 = getelementptr inbounds i8, i8* %63, i64 1
store i8* %64, i8** %17
br label %65
65: ; preds = %49, %44
%66 = load i8*, i8** %14
%67 = call i64 @snoopy_filterregistry_doesNameExist(i8* %66)
%68 = icmp eq i64 0, %67
br i1 %68, label %69, label %77
69: ; preds = %65
%70 = load i8*, i8** %4
%71 = call i32 @snoopy_message_append(i8* %70, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%72 = load i8*, i8** %4
%73 = load i8*, i8** %14
%74 = call i32 @snoopy_message_append(i8* %72, i8* %73)
%75 = load i8*, i8** %4
%76 = call i32 @snoopy_message_append(i8* %75, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %88
77: ; preds = %65
%78 = load i8*, i8** %14
%79 = load i8*, i8** %4
%80 = load i8*, i8** %17
%81 = call i64 @snoopy_filterregistry_callByName(i8* %78, i8* %79, i8* %80)
%82 = icmp eq i64 0, %81
br i1 %82, label %83, label %84
83: ; preds = %77
store i32 0, i32* %3
br label %89
84: ; preds = %77
br label %85
85: ; preds = %84
%86 = load i32, i32* %8
%87 = add nsw i32 %86, 1
store i32 %87, i32* %8
store i8* null, i8** %9
br label %33
88: ; preds = %69, %38
store i32 1, i32* %3
br label %89
89: ; preds = %88, %83
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@.str = [2 x i8] c";\00"
@.str.2 = [26 x i8] c"ERROR(Filter not found - \00"
@.str.3 = [2 x i8] c")\00"
define i32 @snoopy_filtering_check_chain(i8* %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = bitcast i8** %4 to i8*
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp slt i32 %9, 4095
%11 = select i1 %10, i32 %9, i32 4095
%12 = sext i32 %11 to i64
%13 = call i32 @strncpy(i8* %7, i8* %1, i64 %12)
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %12
store i8 0, i8* %14
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = call i8* @strtok_r(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%18 = icmp eq i8* %17, null
br i1 %18, label %46, label %19
19: ; preds = %2, %43
%20 = phi i8* [ %44, %43 ], [ %17, %2 ]
%21 = call i8* @strchr(i8* %20, i32 58)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %19
store i8 0, i8* %15
store i8 0, i8* %16
br label %31
24: ; preds = %19
%25 = ptrtoint i8* %21 to i64
%26 = ptrtoint i8* %20 to i64
%27 = sub i64 %25, %26
store i8 0, i8* %15
%28 = call i32 @strncpy(i8* %15, i8* %20, i64 %27)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %27
store i8 0, i8* %29
%30 = getelementptr inbounds i8, i8* %21, i64 1
br label %31
31: ; preds = %24, %23
%32 = phi i8* [ %20, %23 ], [ %15, %24 ]
%33 = phi i8* [ %16, %23 ], [ %30, %24 ]
%34 = call i64 @snoopy_filterregistry_doesNameExist(i8* %32)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = call i32 @snoopy_message_append(i8* %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @snoopy_message_append(i8* %0, i8* %32)
%39 = call i32 @snoopy_message_append(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %46
40: ; preds = %31
%41 = call i64 @snoopy_filterregistry_callByName(i8* %32, i8* %0, i8* %33)
%42 = icmp eq i64 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %40
%44 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %19
46: ; preds = %43, %2, %36
br label %47
47: ; preds = %40, %46
%48 = phi i32 [ 1, %46 ], [ 0, %40 ]
ret i32 %48
}