#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 EINVAL;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const);
int /*<<< orphan*/ stderr;
int bad_filename(const char *filename) {
  const char *c;
  c = filename;
  if (*c == '-') {
    fprintf(stderr, "Bad character '%c' found in filename\n", *c);
    return EINVAL;
  }
  for (; *c; c++) {
    if (*c < 32 || *c == '<' || *c == '>' || *c == '|') {
      fprintf(stderr, "Bad character '%c' found in filename\n", *c);
      return EINVAL;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<bad_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1161 <bad_filename+0x51>
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
lea    0xeb8(%rip),%rsi
movsbl (%rax),%edx
call   1030 <fprintf@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <bad_filename+0xed>
jmp    1166 <bad_filename+0x56>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f6 <bad_filename+0xe6>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jl     11b3 <bad_filename+0xa3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3c,%eax
je     11b3 <bad_filename+0xa3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3e,%eax
je     11b3 <bad_filename+0xa3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7c,%eax
jne    11e0 <bad_filename+0xd0>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
lea    0xe39(%rip),%rsi
movsbl (%rax),%edx
call   1030 <fprintf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <bad_filename+0xed>
jmp    11e5 <bad_filename+0xd5>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1166 <bad_filename+0x56>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bad_filename>:
push   %rax
mov    (%rdi),%cl
xor    %eax,%eax
test   %cl,%cl
je     113f <bad_filename+0x2f>
cmp    $0x2d,%cl
jne    1141 <bad_filename+0x31>
mov    0x2ebb(%rip),%rax
mov    (%rax),%edi
movsbl %cl,%edx
lea    0xecf(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
add    $0x1,%rdi
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x20,%cl
jl     111e <bad_filename+0xe>
cmp    $0x3c,%cl
je     111e <bad_filename+0xe>
cmp    $0x3e,%cl
je     111e <bad_filename+0xe>
cmp    $0x7c,%cl
je     111e <bad_filename+0xe>
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
jne    1150 <bad_filename+0x40>
jmp    113f <bad_filename+0x2f>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"Bad character '%c' found in filename\0A\00"
@EINVAL = global i32 0
define i32 @bad_filename(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 45
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8 signext %13)
%15 = load i32, i32* @EINVAL
store i32 %15, i32* %2
br label %52
16: ; preds = %1
br label %17
17: ; preds = %48, %16
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %51
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp slt i32 %24, 32
br i1 %25, label %41, label %26
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 60
br i1 %30, label %41, label %31
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 62
br i1 %35, label %41, label %36
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 124
br i1 %40, label %41, label %47
41: ; preds = %36, %31, %26, %21
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %4
%44 = load i8, i8* %43
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8 signext %44)
%46 = load i32, i32* @EINVAL
store i32 %46, i32* %2
br label %52
47: ; preds = %36
br label %48
48: ; preds = %47
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %4
br label %17
51: ; preds = %17
store i32 0, i32* %2
br label %52
52: ; preds = %51, %41, %10
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"Bad character '%c' found in filename\0A\00"
@EINVAL = global i32 0
define i32 @bad_filename(i8* nocapture %0) {
%2 = load i8, i8* %0
switch i8 %2, label %3 [
i8 45, label %15
i8 0, label %20
]
3: ; preds = %1, %9
%4 = phi i8* [ %10, %9 ], [ %0, %1 ]
%5 = phi i8 [ %11, %9 ], [ %2, %1 ]
%6 = freeze i8 %5
%7 = icmp slt i8 %6, 32
br i1 %7, label %13, label %8
8: ; preds = %3
switch i8 %6, label %9 [
i8 124, label %13
i8 62, label %13
i8 60, label %13
]
9: ; preds = %8
%10 = getelementptr inbounds i8, i8* %4, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %20, label %3
13: ; preds = %8, %8, %8, %3
%14 = freeze i8 %5
br label %15
15: ; preds = %13, %1
%16 = phi i8 [ %2, %1 ], [ %14, %13 ]
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8 signext %16)
%19 = load i32, i32* @EINVAL
br label %20
20: ; preds = %9, %15, %1
%21 = phi i32 [ 0, %1 ], [ %19, %15 ], [ 0, %9 ]
ret i32 %21
}