#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*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int strspn(char *, char *);
char *strstr(char *, char *);
int mcf_CheckValidCat(char *category, int dotDotDot) {
  static char validChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw"
                             "xyz1234567890/~!@#$%^&*()_+=-`\"\'\t?><,. ";
  char *strDots, *error = NULL;
  int len;
  if (category == NULL)
    return 1;
  len = strlen(category);
  strDots = strstr(category, "...");
  if (len >= 255)
    error = "is too long";
  else if (strspn(category, validChars) != len)
    error = "contains invalid characters";
  else if (strstr(category, "//") != NULL)
    error = "contains \"//\"";
  else if (category[0] == '/')
    error = "contains leading slash";
  else if (category[len - 1] == '/')
    error = "contains trailing slash";
  else if ((dotDotDot == 0 && strDots != NULL) ||
           (dotDotDot != 0 && strDots != NULL && strDots != category + len - 3))
    error = "contains invalid \"...\"";
  if (error != NULL) {
    fprintf(stderr, "Error in declared category %s: %s\n", error, category);
    return 0;
  } else {
    return (strDots == NULL ? 1 : -1);
  }
}


x86 assembly (clang, -O0):
<mcf_CheckValidCat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116e <mcf_CheckValidCat+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    12fe <mcf_CheckValidCat+0x1be>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0xff,-0x2c(%rbp)
jl     11ab <mcf_CheckValidCat+0x6b>
lea    0xe62(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12b2 <mcf_CheckValidCat+0x172>
mov    -0x10(%rbp),%rdi
lea    0x2e9a(%rip),%rsi
call   1040 <strspn@plt>
cmp    -0x2c(%rbp),%eax
je     11d4 <mcf_CheckValidCat+0x94>
lea    0xe45(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12ad <mcf_CheckValidCat+0x16d>
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11fe <mcf_CheckValidCat+0xbe>
lea    0xe3a(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12a8 <mcf_CheckValidCat+0x168>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    121e <mcf_CheckValidCat+0xde>
lea    0xe28(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12a3 <mcf_CheckValidCat+0x163>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1248 <mcf_CheckValidCat+0x108>
lea    0xe15(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    129e <mcf_CheckValidCat+0x15e>
cmpl   $0x0,-0x14(%rbp)
jne    125d <mcf_CheckValidCat+0x11d>
cmpq   $0x0,-0x20(%rbp)
jne    128e <mcf_CheckValidCat+0x14e>
cmpl   $0x0,-0x14(%rbp)
je     1299 <mcf_CheckValidCat+0x159>
cmpq   $0x0,-0x20(%rbp)
je     1299 <mcf_CheckValidCat+0x159>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
add    %rdx,%rcx
add    $0xfffffffffffffffd,%rcx
cmp    %rcx,%rax
je     1299 <mcf_CheckValidCat+0x159>
lea    0xdd7(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    129e <mcf_CheckValidCat+0x15e>
jmp    12a3 <mcf_CheckValidCat+0x163>
jmp    12a8 <mcf_CheckValidCat+0x168>
jmp    12ad <mcf_CheckValidCat+0x16d>
jmp    12b2 <mcf_CheckValidCat+0x172>
cmpq   $0x0,-0x28(%rbp)
je     12e6 <mcf_CheckValidCat+0x1a6>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdae(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12fe <mcf_CheckValidCat+0x1be>
mov    -0x20(%rbp),%rdx
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcf_CheckValidCat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1179 <mcf_CheckValidCat+0x39>
mov    %esi,%r15d
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
cmp    $0xfe,%ebp
jle    1180 <mcf_CheckValidCat+0x40>
lea    0xe8d(%rip),%rdx
jmp    11ba <mcf_CheckValidCat+0x7a>
mov    $0x1,%eax
jmp    11d4 <mcf_CheckValidCat+0x94>
mov    %rax,%r14
lea    0x2ec6(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strspn@plt>
cmp    %ebp,%eax
jne    11b3 <mcf_CheckValidCat+0x73>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     11df <mcf_CheckValidCat+0x9f>
lea    0xe7e(%rip),%rdx
jmp    11ba <mcf_CheckValidCat+0x7a>
lea    0xe56(%rip),%rdx
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xeb9(%rip),%rsi
mov    %rbx,%rcx
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmpb   $0x2f,(%rbx)
jne    11ed <mcf_CheckValidCat+0xad>
lea    0xe52(%rip),%rdx
jmp    11ba <mcf_CheckValidCat+0x7a>
movslq %ebp,%rax
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1200 <mcf_CheckValidCat+0xc0>
lea    0xe56(%rip),%rdx
jmp    11ba <mcf_CheckValidCat+0x7a>
lea    0xe65(%rip),%rdx
test   %r15d,%r15d
jne    1211 <mcf_CheckValidCat+0xd1>
test   %r14,%r14
jne    11ba <mcf_CheckValidCat+0x7a>
test   %r15d,%r15d
je     1227 <mcf_CheckValidCat+0xe7>
test   %r14,%r14
je     1227 <mcf_CheckValidCat+0xe7>
add    %rbx,%rax
add    $0xfffffffffffffffd,%rax
cmp    %rax,%r14
jne    11ba <mcf_CheckValidCat+0x7a>
neg    %r14
sbb    %eax,%eax
or     $0x1,%eax
jmp    11d4 <mcf_CheckValidCat+0x94>

LLVM IR (-O0):
@mcf_CheckValidCat.validChars = internal global [89 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/~!@#$%^&*()_+=-`\22'\09?><,. \00"
@.str = [4 x i8] c"...\00"
@.str.1 = [12 x i8] c"is too long\00"
@.str.2 = [28 x i8] c"contains invalid characters\00"
@.str.3 = [3 x i8] c"//\00"
@.str.4 = [14 x i8] c"contains \22//\22\00"
@.str.5 = [23 x i8] c"contains leading slash\00"
@.str.6 = [24 x i8] c"contains trailing slash\00"
@.str.7 = [23 x i8] c"contains invalid \22...\22\00"
@stderr = global i32 0
@.str.8 = [35 x i8] c"Error in declared category %s: %s\0A\00"
define i32 @mcf_CheckValidCat(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* null, i8** %7
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %87
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %8
%15 = load i8*, i8** %4
%16 = call i8* @strstr(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %6
%17 = load i32, i32* %8
%18 = icmp sge i32 %17, 255
br i1 %18, label %19, label %20
19: ; preds = %12
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %74
20: ; preds = %12
%21 = load i8*, i8** %4
%22 = call i32 @strspn(i8* %21, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @mcf_CheckValidCat.validChars, i64 0, i64 0))
%23 = load i32, i32* %8
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %20
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %73
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = call i8* @strstr(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %26
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %72
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 47
br i1 %36, label %37, label %38
37: ; preds = %31
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %71
38: ; preds = %31
%39 = load i8*, i8** %4
%40 = load i32, i32* %8
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 47
br i1 %46, label %47, label %48
47: ; preds = %38
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8** %7
br label %70
48: ; preds = %38
%49 = load i32, i32* %5
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i8*, i8** %6
%53 = icmp ne i8* %52, null
br i1 %53, label %68, label %54
54: ; preds = %51, %48
%55 = load i32, i32* %5
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %69
57: ; preds = %54
%58 = load i8*, i8** %6
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %69
60: ; preds = %57
%61 = load i8*, i8** %6
%62 = load i8*, i8** %4
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = getelementptr inbounds i8, i8* %65, i64 -3
%67 = icmp ne i8* %61, %66
br i1 %67, label %68, label %69
68: ; preds = %60, %51
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %69
69: ; preds = %68, %60, %57, %54
br label %70
70: ; preds = %69, %47
br label %71
71: ; preds = %70, %37
br label %72
72: ; preds = %71, %30
br label %73
73: ; preds = %72, %25
br label %74
74: ; preds = %73, %19
%75 = load i8*, i8** %7
%76 = icmp ne i8* %75, null
br i1 %76, label %77, label %82
77: ; preds = %74
%78 = load i32, i32* @stderr
%79 = load i8*, i8** %7
%80 = load i8*, i8** %4
%81 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %79, i8* %80)
store i32 0, i32* %3
br label %87
82: ; preds = %74
%83 = load i8*, i8** %6
%84 = icmp eq i8* %83, null
%85 = zext i1 %84 to i64
%86 = select i1 %84, i32 1, i32 -1
store i32 %86, i32* %3
br label %87
87: ; preds = %82, %77, %11
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@mcf_CheckValidCat.validChars = internal global [89 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/~!@#$%^&*()_+=-`\22'\09?><,. \00"
@.str = [4 x i8] c"...\00"
@.str.1 = [12 x i8] c"is too long\00"
@.str.2 = [28 x i8] c"contains invalid characters\00"
@.str.3 = [3 x i8] c"//\00"
@.str.4 = [14 x i8] c"contains \22//\22\00"
@.str.5 = [23 x i8] c"contains leading slash\00"
@.str.6 = [24 x i8] c"contains trailing slash\00"
@.str.7 = [23 x i8] c"contains invalid \22...\22\00"
@stderr = global i32 0
@.str.8 = [35 x i8] c"Error in declared category %s: %s\0A\00"
define i32 @mcf_CheckValidCat(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %43, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i32 %5, 254
br i1 %7, label %36, label %8
8: ; preds = %4
%9 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @mcf_CheckValidCat.validChars, i64 0, i64 0))
%10 = icmp eq i32 %9, %5
br i1 %10, label %11, label %36
11: ; preds = %8
%12 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %36
14: ; preds = %11
%15 = load i8, i8* %0
%16 = icmp eq i8 %15, 47
br i1 %16, label %36, label %17
17: ; preds = %14
%18 = add nsw i32 %5, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 47
br i1 %22, label %36, label %23
23: ; preds = %17
%24 = icmp eq i32 %1, 0
%25 = icmp ne i8* %6, null
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %36, label %27
27: ; preds = %23
%28 = icmp ne i32 %1, 0
%29 = select i1 %28, i1 %25, i1 false
%30 = xor i1 %29, true
%31 = sext i32 %5 to i64
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = getelementptr inbounds i8, i8* %32, i64 -3
%34 = icmp eq i8* %6, %33
%35 = select i1 %30, i1 true, i1 %34
br i1 %35, label %40, label %36
36: ; preds = %23, %27, %4, %8, %11, %14, %17
%37 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), %17 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), %14 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %11 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), %27 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), %23 ]
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %37, i8* %0)
br label %43
40: ; preds = %27
%41 = icmp eq i8* %6, null
%42 = select i1 %41, i32 1, i32 -1
br label %43
43: ; preds = %2, %40, %36
%44 = phi i32 [ 0, %36 ], [ %42, %40 ], [ 1, %2 ]
ret i32 %44
}