#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main() {
  char input[64];
  char output[64];
  int a, b;
  printf("Command: ");
  fgets(input, 64, stdin);
  for (a = 0, b = 0; a < 64; a++, b++) {
    if (input[a] == '\\') {
      b--;
      continue;
    }
    if (input[a] == '\n') {
      output[b] = '\0';
      break;
    }
    output[b] = input[a];
  }
  printf("The filtered command is '%s'\n", output);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e9d(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1040 <fgets@plt>
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
cmpl   $0x40,-0x94(%rbp)
jge    1206 <main+0xe6>
movslq -0x94(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x5c,%eax
jne    11a1 <main+0x81>
mov    -0x98(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x98(%rbp)
jmp    11e3 <main+0xc3>
movslq -0x94(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11ca <main+0xaa>
movslq -0x98(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
jmp    1206 <main+0xe6>
movslq -0x94(%rbp),%rax
mov    -0x50(%rbp,%rax,1),%cl
movslq -0x98(%rbp),%rax
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    116b <main+0x4b>
lea    -0x90(%rbp),%rsi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0xed1(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2ea9(%rip),%rax
mov    (%rax),%edx
lea    0x40(%rsp),%rdi
mov    $0x40,%esi
call   1040 <fgets@plt>
xor    %eax,%eax
jmp    1170 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %cl,(%rsp,%rax,1)
add    $0x2,%rbx
add    $0x1,%eax
cmp    $0x40,%rbx
je     11ae <main+0x8e>
movzbl 0x40(%rsp,%rbx,1),%ecx
cmp    $0x5c,%cl
je     1190 <main+0x70>
cmp    $0xa,%cl
je     11a8 <main+0x88>
movslq %eax,%rdx
mov    %cl,(%rsp,%rdx,1)
jmp    1193 <main+0x73>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
movzbl 0x41(%rsp,%rbx,1),%ecx
cmp    $0x5c,%cl
je     1163 <main+0x43>
cltq
add    $0x1,%rax
cmp    $0xa,%cl
jne    1160 <main+0x40>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xe55(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Command: \00"
@stdin = global i32 0
@.str.1 = [30 x i8] c"The filtered command is '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca [64 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 64, i32 %8)
store i32 0, i32* %4
store i32 0, i32* %5
br label %10
10: ; preds = %42, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 64
br i1 %12, label %13, label %47
13: ; preds = %10
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 92
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* %5
%22 = add nsw i32 %21, -1
store i32 %22, i32* %5
br label %42
23: ; preds = %13
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %2, 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 %47
34: ; preds = %23
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %40
store i8 %38, i8* %41
br label %42
42: ; preds = %34, %20
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %10
47: ; preds = %30, %10
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %48)
ret i32 0
}

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