#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 */
typedef int /*<<< orphan*/ src;

/* Variables and functions */
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strtok_r(char *, char *, char **);
int mc_path_valid(const char *filename) {
  char *token;
  char *last_buf = NULL;
  char seps[] = "/\\";
  char src[256] = {0};
  int i, len, depth = 0;
  strncpy(src, filename, sizeof(src));
  token = strtok_r(src, seps, &last_buf);
  while (token) {
    len = (int)strlen(token);
    if (!len) {
      return 0;
    }
    for (i = 0; i < len; ++i) {
      if (':' == token[i]) {
        return 0;
      }
      if (('\\' == token[i]) || ('/' == token[i]) || ('*' == token[i]) ||
          ('?' == token[i]) || ('"' == token[i]) || ('<' == token[i]) ||
          ('>' == token[i]) || ('|' == token[i]) || ('\t' == token[i])) {
        return 0;
      }
    }
    ++depth;
    token = strtok_r(0, seps, &last_buf);
  }
  return 1;
}


x86 assembly (clang, -O0):
<mc_path_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0xea2(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xe9a(%rip),%al
mov    %al,-0x21(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
movl   $0x0,-0x13c(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x130(%rbp),%rdi
lea    -0x23(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1376 <mc_path_valid+0x236>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x138(%rbp)
cmpl   $0x0,-0x138(%rbp)
jne    11e8 <mc_path_valid+0xa8>
movl   $0x0,-0x4(%rbp)
jmp    137d <mc_path_valid+0x23d>
movl   $0x0,-0x134(%rbp)
mov    -0x134(%rbp),%eax
cmp    -0x138(%rbp),%eax
jge    134d <mc_path_valid+0x20d>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x3a,%eax
cmp    %ecx,%eax
jne    122c <mc_path_valid+0xec>
movl   $0x0,-0x4(%rbp)
jmp    137d <mc_path_valid+0x23d>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x5c,%eax
cmp    %ecx,%eax
je     1328 <mc_path_valid+0x1e8>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2f,%eax
cmp    %ecx,%eax
je     1328 <mc_path_valid+0x1e8>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2a,%eax
cmp    %ecx,%eax
je     1328 <mc_path_valid+0x1e8>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x3f,%eax
cmp    %ecx,%eax
je     1328 <mc_path_valid+0x1e8>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x22,%eax
cmp    %ecx,%eax
je     1328 <mc_path_valid+0x1e8>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x3c,%eax
cmp    %ecx,%eax
je     1328 <mc_path_valid+0x1e8>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x3e,%eax
cmp    %ecx,%eax
je     1328 <mc_path_valid+0x1e8>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x7c,%eax
cmp    %ecx,%eax
je     1328 <mc_path_valid+0x1e8>
mov    -0x18(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x9,%eax
cmp    %ecx,%eax
jne    1334 <mc_path_valid+0x1f4>
movl   $0x0,-0x4(%rbp)
jmp    137d <mc_path_valid+0x23d>
jmp    1339 <mc_path_valid+0x1f9>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    11f2 <mc_path_valid+0xb2>
mov    -0x13c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13c(%rbp)
lea    -0x23(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
jmp    11b5 <mc_path_valid+0x75>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mc_path_valid>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%rsi
movq   $0x0,0x8(%rsp)
movb   $0x0,0x6(%rsp)
movw   $0x5c2f,0x4(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     1265 <mc_path_valid+0x135>
mov    %rax,%rbx
xor    %r15d,%r15d
lea    0xe04(%rip),%r13
lea    0x4(%rsp),%r14
lea    0x8(%rsp),%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     126b <mc_path_valid+0x13b>
jle    1250 <mc_path_valid+0x120>
mov    %eax,%eax
xor    %ecx,%ecx
jmp    122e <mc_path_valid+0xfe>
nopw   0x0(%rax,%rax,1)
cmp    $0x7c,%dl
je     126b <mc_path_valid+0x13b>
add    $0x1,%rcx
cmp    %rcx,%rax
je     1250 <mc_path_valid+0x120>
movzbl (%rbx,%rcx,1),%edx
lea    -0x9(%rdx),%esi
cmp    $0x53,%sil
ja     1220 <mc_path_valid+0xf0>
movzbl %sil,%edx
movslq 0x0(%r13,%rdx,4),%rdx
add    %r13,%rdx
jmp    *%rdx
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1206 <mc_path_valid+0xd6>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.mc_path_valid.seps = [3 x i8] c"/\\\00"
define i32 @mc_path_valid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [3 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %5
%11 = bitcast [3 x i8]* %6 to i8*
%12 = bitcast [256 x i8]* %7 to i8*
store i32 0, i32* %10
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 256)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%18 = call i8* @strtok_r(i8* %16, i8* %17, i8** %5)
store i8* %18, i8** %4
br label %19
19: ; preds = %120, %1
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %125
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i64 @strlen(i8* %23)
%25 = trunc i64 %24 to i32
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %22
store i32 0, i32* %2
br label %126
29: ; preds = %22
store i32 0, i32* %8
br label %30
30: ; preds = %117, %29
%31 = load i32, i32* %8
%32 = load i32, i32* %9
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %120
34: ; preds = %30
%35 = load i8*, i8** %4
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 58, %40
br i1 %41, label %42, label %43
42: ; preds = %34
store i32 0, i32* %2
br label %126
43: ; preds = %34
%44 = load i8*, i8** %4
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 92, %49
br i1 %50, label %115, label %51
51: ; preds = %43
%52 = load i8*, i8** %4
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 47, %57
br i1 %58, label %115, label %59
59: ; preds = %51
%60 = load i8*, i8** %4
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 42, %65
br i1 %66, label %115, label %67
67: ; preds = %59
%68 = load i8*, i8** %4
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 63, %73
br i1 %74, label %115, label %75
75: ; preds = %67
%76 = load i8*, i8** %4
%77 = load i32, i32* %8
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp eq i32 34, %81
br i1 %82, label %115, label %83
83: ; preds = %75
%84 = load i8*, i8** %4
%85 = load i32, i32* %8
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = icmp eq i32 60, %89
br i1 %90, label %115, label %91
91: ; preds = %83
%92 = load i8*, i8** %4
%93 = load i32, i32* %8
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = icmp eq i32 62, %97
br i1 %98, label %115, label %99
99: ; preds = %91
%100 = load i8*, i8** %4
%101 = load i32, i32* %8
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %100, i64 %102
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp eq i32 124, %105
br i1 %106, label %115, label %107
107: ; preds = %99
%108 = load i8*, i8** %4
%109 = load i32, i32* %8
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8, i8* %108, i64 %110
%112 = load i8, i8* %111
%113 = sext i8 %112 to i32
%114 = icmp eq i32 9, %113
br i1 %114, label %115, label %116
115: ; preds = %107, %99, %91, %83, %75, %67, %59, %51, %43
store i32 0, i32* %2
br label %126
116: ; preds = %107
br label %117
117: ; preds = %116
%118 = load i32, i32* %8
%119 = add nsw i32 %118, 1
store i32 %119, i32* %8
br label %30
120: ; preds = %30
%121 = load i32, i32* %10
%122 = add nsw i32 %121, 1
store i32 %122, i32* %10
%123 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%124 = call i8* @strtok_r(i8* null, i8* %123, i8** %5)
store i8* %124, i8** %4
br label %19
125: ; preds = %19
store i32 1, i32* %2
br label %126
126: ; preds = %125, %115, %42, %28
%127 = load i32, i32* %2
ret i32 %127
}

LLVM IR (-O2):
@__const.mc_path_valid.seps = [3 x i8] c"/\\\00"
define i32 @mc_path_valid(i8* %0) {
%2 = alloca i8*
%3 = alloca [3 x i8]
%4 = alloca [256 x i8]
%5 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = call i32 @strncpy(i8* %7, i8* %0, i32 256)
%9 = call i8* @strtok_r(i8* %7, i8* %6, i8** %2)
%10 = icmp eq i8* %9, null
br i1 %10, label %30, label %11
11: ; preds = %1, %27
%12 = phi i8* [ %28, %27 ], [ %9, %1 ]
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %11
%17 = icmp sgt i32 %14, 0
br i1 %17, label %18, label %27
18: ; preds = %16
%19 = and i64 %13, 4294967295
br label %20
20: ; preds = %18, %24
%21 = phi i64 [ 0, %18 ], [ %25, %24 ]
%22 = getelementptr inbounds i8, i8* %12, i64 %21
%23 = load i8, i8* %22
switch i8 %23, label %24 [
i8 58, label %30
i8 92, label %30
i8 47, label %30
i8 42, label %30
i8 63, label %30
i8 34, label %30
i8 60, label %30
i8 62, label %30
i8 124, label %30
i8 9, label %30
]
24: ; preds = %20
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %19
br i1 %26, label %27, label %20
27: ; preds = %24, %16
%28 = call i8* @strtok_r(i8* null, i8* %6, i8** %2)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %11
30: ; preds = %11, %27, %20, %20, %20, %20, %20, %20, %20, %20, %20, %20, %1
%31 = phi i32 [ 1, %1 ], [ 0, %20 ], [ 0, %20 ], [ 0, %20 ], [ 0, %20 ], [ 0, %20 ], [ 0, %20 ], [ 0, %20 ], [ 0, %20 ], [ 0, %20 ], [ 0, %20 ], [ 0, %11 ], [ 1, %27 ]
ret i32 %31
}