#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*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strstr(char *, char const *);
int main() {
  const char bad[] = "naughty";
  char input[64];
  char *r;
  int x;
  printf("Command: ");
  fgets(input, 64, stdin);
  r = strstr(input, bad);
  if (r != NULL) {
    printf("Unallowed command detected\n");
    exit(1);
  }
  for (x = 0; x < 64; x++) {
    if (input[x] == '\n') {
      input[x] = '\0';
      break;
    }
  }
  printf("The command is '%s'\n", input);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0xc(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1040 <fgets@plt>
lea    -0x50(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     11b3 <main+0x73>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x5c(%rbp)
cmpl   $0x40,-0x5c(%rbp)
jge    11f7 <main+0xb7>
movslq -0x5c(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11e4 <main+0xa4>
movslq -0x5c(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
jmp    11f7 <main+0xb7>
jmp    11e9 <main+0xa9>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11ba <main+0x7a>
lea    -0x50(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1050 <fgets@plt>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
jne    11f6 <main+0xa6>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0xa,(%rsp,%rax,1)
je     11d7 <main+0x87>
cmpb   $0xa,0x1(%rsp,%rax,1)
je     11c7 <main+0x77>
cmpb   $0xa,0x2(%rsp,%rax,1)
je     11cd <main+0x7d>
cmpb   $0xa,0x3(%rsp,%rax,1)
je     11d3 <main+0x83>
add    $0x4,%rax
cmp    $0x40,%rax
jne    11a0 <main+0x50>
jmp    11dd <main+0x8d>
add    $0x1,%rax
jmp    11d7 <main+0x87>
add    $0x2,%rax
jmp    11d7 <main+0x87>
add    $0x3,%rax
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe2e(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret
lea    0xe2a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.main.bad = [8 x i8] c"naughty\00"
@.str = [10 x i8] c"Command: \00"
@stdin = global i32 0
@.str.1 = [28 x i8] c"Unallowed command detected\0A\00"
@.str.2 = [21 x i8] c"The command is '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca [64 x i8]
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [8 x i8]* %2 to i8*
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 64, i32 %9)
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%13 = call i8* @strstr(i8* %11, i8* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
store i32 0, i32* %5
br label %20
20: ; preds = %35, %19
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 64
br i1 %22, label %23, label %38
23: ; preds = %20
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %32
store i8 0, i8* %33
br label %38
34: ; preds = %23
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %20
38: ; preds = %30, %20
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %39)
ret i32 0
}

LLVM IR (-O2):
@__const.main.bad = [8 x i8] c"naughty\00"
@.str = [10 x i8] c"Command: \00"
@stdin = global i32 0
@.str.2 = [21 x i8] c"The command is '%s'\0A\00"
@str = [27 x i8] c"Unallowed command detected\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 64, i32 %4)
%6 = call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @__const.main.bad, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0, %35
%12 = phi i64 [ %36, %35 ], [ 0, %0 ]
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %20
16: ; preds = %30, %25, %20, %11
%17 = phi i64 [ %12, %11 ], [ %21, %20 ], [ %26, %25 ], [ %31, %30 ]
%18 = and i64 %17, 4294967295
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %18
store i8 0, i8* %19
br label %38
20: ; preds = %11
%21 = or i64 %12, 1
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 10
br i1 %24, label %16, label %25
25: ; preds = %20
%26 = or i64 %12, 2
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 10
br i1 %29, label %16, label %30
30: ; preds = %25
%31 = or i64 %12, 3
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 10
br i1 %34, label %16, label %35
35: ; preds = %30
%36 = add nuw nsw i64 %12, 4
%37 = icmp eq i64 %36, 64
br i1 %37, label %38, label %11
38: ; preds = %35, %16
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret i32 0
}