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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getegid();
int /*<<< orphan*/ setregid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  char cmdbuf[128] = "export IFS=' \t\n'; /usr/bin/file ";
  char *input = cmdbuf + strlen(cmdbuf);
  int len = sizeof(cmdbuf) - (strlen(cmdbuf) + 1);
  gid_t egid = getegid();
  setregid(egid, egid);
  fprintf(stdout, "Please enter a filename: ");
  fgets(input, len, stdin);
  for (; *input != '\0'; ++input) {
    switch (*input) {
    case '|':
    case '&':
    case '<':
    case '>':
    case '!':
    case '$':
    case ';':
      *input = ' ';
      break;
    }
  }
  system(cmdbuf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe69(%rip),%rsi
mov    $0x80,%edx
call   1070 <memcpy@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rcx
mov    $0x80,%eax
sub    %rcx,%rax
mov    %eax,-0x9c(%rbp)
mov    $0x0,%al
call   1080 <getegid@plt>
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%edi
mov    -0xa0(%rbp),%esi
call   1090 <setregid@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x98(%rbp),%rdi
mov    -0x9c(%rbp),%esi
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    -0x98(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12fd <main+0x18d>
mov    -0x98(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0xac(%rbp)
sub    $0x21,%eax
je     12d7 <main+0x167>
jmp    1270 <main+0x100>
mov    -0xac(%rbp),%eax
sub    $0x24,%eax
je     12d7 <main+0x167>
jmp    1284 <main+0x114>
mov    -0xac(%rbp),%eax
sub    $0x26,%eax
je     12d7 <main+0x167>
jmp    1298 <main+0x128>
mov    -0xac(%rbp),%eax
add    $0xffffffc5,%eax
sub    $0x2,%eax
jb     12d7 <main+0x167>
jmp    12af <main+0x13f>
mov    -0xac(%rbp),%eax
sub    $0x3e,%eax
je     12d7 <main+0x167>
jmp    12c3 <main+0x153>
mov    -0xac(%rbp),%eax
sub    $0x7c,%eax
jne    12e1 <main+0x171>
jmp    12d7 <main+0x167>
mov    -0x98(%rbp),%rax
movb   $0x20,(%rax)
jmp    12e6 <main+0x176>
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
jmp    123f <main+0xcf>
lea    -0x90(%rbp),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
movaps 0xefc(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xee0(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xea8(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe8c(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe70(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe54(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe38(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
lea    (%rsp,%rbx,1),%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    $0x7f,%ebp
sub    %eax,%ebp
xor    %eax,%eax
call   1070 <getegid@plt>
mov    %eax,%edi
mov    %eax,%esi
call   1080 <setregid@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <fgets@plt>
mov    (%rsp,%rbx,1),%dl
test   %dl,%dl
je     1264 <main+0x104>
lea    (%rbx,%r14,1),%rax
add    $0x1,%rax
movabs $0x5800005200000000,%rcx
jmp    1255 <main+0xf5>
bt     %rdx,%rcx
jae    125d <main+0xfd>
movb   $0x20,-0x1(%rax)
movzbl (%rax),%edx
add    $0x1,%rax
test   %dl,%dl
je     1264 <main+0x104>
movsbl %dl,%edx
cmp    $0x3e,%edx
jbe    1240 <main+0xe0>
cmp    $0x7c,%edx
je     1246 <main+0xe6>
jmp    124a <main+0xea>
mov    %rsp,%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.cmdbuf = [128 x i8] c"export IFS=' \09\0A'; /usr/bin/file \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stdout = global i32 0
@.str = [26 x i8] c"Please enter a filename: \00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [128 x i8]* %6 to i8*
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
store i8* %15, i8** %7
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = sub i64 128, %19
%21 = trunc i64 %20 to i32
store i32 %21, i32* %8
%22 = call i32 (...) @getegid()
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = load i32, i32* %9
%25 = call i32 @setregid(i32 %23, i32 %24)
%26 = load i32, i32* @stdout
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%28 = load i8*, i8** %7
%29 = load i32, i32* %8
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %28, i32 %29, i32 %30)
br label %32
32: ; preds = %44, %2
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
switch i32 %40, label %43 [
i32 124, label %41
i32 38, label %41
i32 60, label %41
i32 62, label %41
i32 33, label %41
i32 36, label %41
i32 59, label %41
]
41: ; preds = %37, %37, %37, %37, %37, %37, %37
%42 = load i8*, i8** %7
store i8 32, i8* %42
br label %43
43: ; preds = %37, %41
br label %44
44: ; preds = %43
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %7
br label %32
47: ; preds = %32
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%49 = call i32 @system(i8* %48)
ret i32 0
}

LLVM IR (-O2):
@__const.main.cmdbuf = [128 x i8] c"export IFS=' \09\0A'; /usr/bin/file \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stdout = global i32 0
@.str = [26 x i8] c"Please enter a filename: \00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %6
%8 = call i32 @strlen(i8* %4)
%9 = sub i32 127, %8
%10 = call i32 (...) @getegid()
%11 = call i32 @setregid(i32 %10, i32 %10)
%12 = load i32, i32* @stdout
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %7, i32 %9, i32 %14)
%16 = load i8, i8* %7
%17 = icmp eq i8 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %2, %23
%19 = phi i8 [ %25, %23 ], [ %16, %2 ]
%20 = phi i8* [ %24, %23 ], [ %7, %2 ]
%21 = sext i8 %19 to i32
switch i32 %21, label %23 [
i32 124, label %22
i32 38, label %22
i32 60, label %22
i32 62, label %22
i32 33, label %22
i32 36, label %22
i32 59, label %22
]
22: ; preds = %18, %18, %18, %18, %18, %18, %18
store i8 32, i8* %20
br label %23
23: ; preds = %22, %18
%24 = getelementptr inbounds i8, i8* %20, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %18
27: ; preds = %23, %2
%28 = call i32 @system(i8* %4)
ret i32 0
}