#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*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strchr(char const *, int);
int main() {
  enum {
    NORMAL = 0,
    ESC = 1,
    CSI = 2,
  } mode = NORMAL;
  const char *allowed_control_codes = "\r\n\t\b";
  while (!feof(stdin)) {
    int ch = fgetc(stdin);
    switch (mode) {
    case CSI:
      if (64 <= ch && ch <= 126)
        mode = NORMAL;
      break;
    case ESC:
      if (ch == '[')
        mode = CSI;
      else if (64 <= ch && ch <= 95)
        mode = NORMAL;
      break;
    case NORMAL:
      if (ch == 27)
        mode = ESC;
      else if (ch > 0x1f)
        fputc(ch, stdout);
      else if (strchr(allowed_control_codes, ch))
        fputc(ch, stdout);
    }
    fflush(stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1194 <main+0x44>
jmp    12bb <main+0x16b>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     123d <main+0xed>
jmp    11b8 <main+0x68>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     11fe <main+0xae>
jmp    11c9 <main+0x79>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
jne    12a8 <main+0x158>
jmp    11da <main+0x8a>
mov    $0x40,%eax
cmp    -0x14(%rbp),%eax
jg     11f9 <main+0xa9>
cmpl   $0x7e,-0x14(%rbp)
jg     11f9 <main+0xa9>
movl   $0x0,-0x8(%rbp)
jmp    12a8 <main+0x158>
cmpl   $0x5b,-0x14(%rbp)
jne    1214 <main+0xc4>
movl   $0x2,-0x8(%rbp)
jmp    1238 <main+0xe8>
mov    $0x40,%eax
cmp    -0x14(%rbp),%eax
jg     1233 <main+0xe3>
cmpl   $0x5f,-0x14(%rbp)
jg     1233 <main+0xe3>
movl   $0x0,-0x8(%rbp)
jmp    1238 <main+0xe8>
jmp    12a8 <main+0x158>
cmpl   $0x1b,-0x14(%rbp)
jne    1253 <main+0x103>
movl   $0x1,-0x8(%rbp)
jmp    12a3 <main+0x153>
cmpl   $0x1f,-0x14(%rbp)
jle    1273 <main+0x123>
mov    -0x14(%rbp),%edi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
call   1050 <fputc@plt>
jmp    129e <main+0x14e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <strchr@plt>
cmp    $0x0,%eax
je     1299 <main+0x149>
mov    -0x14(%rbp),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
call   1050 <fputc@plt>
jmp    129e <main+0x14e>
jmp    12a3 <main+0x153>
jmp    12a8 <main+0x158>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    1171 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e89(%rip),%r12
mov    (%r12),%edi
call   1060 <feof@plt>
test   %eax,%eax
je     1177 <main+0x27>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
mov    0x2e58(%rip),%r15
lea    0xe79(%rip),%r14
jmp    11b5 <main+0x65>
mov    (%r15),%esi
mov    %ebp,%edi
call   1050 <fputc@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%edi
call   1070 <fflush@plt>
mov    (%r12),%edi
call   1060 <feof@plt>
test   %eax,%eax
jne    116c <main+0x1c>
mov    (%r12),%edi
call   1040 <fgetc@plt>
mov    %eax,%ebp
test   %ebx,%ebx
je     1200 <main+0xb0>
cmp    $0x1,%ebx
je     11e0 <main+0x90>
cmp    $0x2,%ebx
jne    11a0 <main+0x50>
add    $0xffffffc0,%ebp
xor    %ebx,%ebx
cmp    $0x3f,%ebp
setae  %bl
add    %ebx,%ebx
jmp    11a0 <main+0x50>
nopl   (%rax)
mov    $0x2,%ebx
cmp    $0x5b,%ebp
je     11a0 <main+0x50>
and    $0xffffffe0,%ebp
xor    %ebx,%ebx
cmp    $0x40,%ebp
setne  %bl
jmp    11a0 <main+0x50>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%ebx
cmp    $0x1b,%ebp
je     11a0 <main+0x50>
cmp    $0x20,%ebp
jge    1189 <main+0x39>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     11a0 <main+0x50>
mov    (%r15),%esi
mov    %ebp,%edi
call   1050 <fputc@plt>
jmp    11a0 <main+0x50>

LLVM IR (-O0):
@.str = [5 x i8] c"\0D\0A\09\08\00"
@stdin = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
br label %5
5: ; preds = %58, %0
%6 = load i32, i32* @stdin
%7 = call i32 @feof(i32 %6)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %61
10: ; preds = %5
%11 = load i32, i32* @stdin
%12 = call i32 @fgetc(i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %2
switch i32 %13, label %58 [
i32 2, label %14
i32 1, label %22
i32 0, label %35
]
14: ; preds = %10
%15 = load i32, i32* %4
%16 = icmp sle i32 64, %15
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %4
%19 = icmp sle i32 %18, 126
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %2
br label %21
21: ; preds = %20, %17, %14
br label %58
22: ; preds = %10
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 91
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 2, i32* %2
br label %34
26: ; preds = %22
%27 = load i32, i32* %4
%28 = icmp sle i32 64, %27
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %4
%31 = icmp sle i32 %30, 95
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 0, i32* %2
br label %33
33: ; preds = %32, %29, %26
br label %34
34: ; preds = %33, %25
br label %58
35: ; preds = %10
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 27
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 1, i32* %2
br label %57
39: ; preds = %35
%40 = load i32, i32* %4
%41 = icmp sgt i32 %40, 31
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32, i32* %4
%44 = load i32, i32* @stdout
%45 = call i32 @fputc(i32 %43, i32 %44)
br label %56
46: ; preds = %39
%47 = load i8*, i8** %3
%48 = load i32, i32* %4
%49 = call i32 @strchr(i8* %47, i32 %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = load i32, i32* %4
%53 = load i32, i32* @stdout
%54 = call i32 @fputc(i32 %52, i32 %53)
br label %55
55: ; preds = %51, %46
br label %56
56: ; preds = %55, %42
br label %57
57: ; preds = %56, %38
br label %58
58: ; preds = %57, %10, %34, %21
%59 = load i32, i32* @stdout
%60 = call i32 @fflush(i32 %59)
br label %5
61: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"\0D\0A\09\08\00"
@stdin = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = load i32, i32* @stdin
%2 = tail call i32 @feof(i32 %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %38
4: ; preds = %0, %31
%5 = phi i32 [ %32, %31 ], [ 0, %0 ]
%6 = load i32, i32* @stdin
%7 = tail call i32 @fgetc(i32 %6)
switch i32 %5, label %31 [
i32 2, label %8
i32 1, label %12
i32 0, label %18
]
8: ; preds = %4
%9 = add i32 %7, -64
%10 = icmp ult i32 %9, 63
%11 = select i1 %10, i32 0, i32 2
br label %31
12: ; preds = %4
%13 = icmp eq i32 %7, 91
br i1 %13, label %31, label %14
14: ; preds = %12
%15 = and i32 %7, -32
%16 = icmp ne i32 %15, 64
%17 = zext i1 %16 to i32
br label %31
18: ; preds = %4
%19 = icmp eq i32 %7, 27
br i1 %19, label %31, label %20
20: ; preds = %18
%21 = icmp sgt i32 %7, 31
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = load i32, i32* @stdout
%24 = tail call i32 @fputc(i32 %7, i32 %23)
br label %31
25: ; preds = %20
%26 = tail call i32 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%27 = icmp eq i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i32, i32* @stdout
%30 = tail call i32 @fputc(i32 %7, i32 %29)
br label %31
31: ; preds = %14, %8, %18, %12, %25, %28, %22, %4
%32 = phi i32 [ %5, %4 ], [ 0, %22 ], [ 0, %28 ], [ 0, %25 ], [ %11, %8 ], [ 2, %12 ], [ %17, %14 ], [ 1, %18 ]
%33 = load i32, i32* @stdout
%34 = tail call i32 @fflush(i32 %33)
%35 = load i32, i32* @stdin
%36 = tail call i32 @feof(i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %4, label %38
38: ; preds = %31, %0
ret i32 0
}