#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 EOF;
int getchar();
scalar_t__ isascii(int);
scalar_t__ isprint(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(int);
int main() {
  int c;
  while ((c = getchar()) != EOF) {
    if (isascii(c) && (isprint(c) || c == '\n' || c == '\t' || c == ' ')) {
      if (c == '\t') {
        printf("\\t");
      } else if (c == '\\') {
        printf("\\\\");
      } else {
        if (c == ' ') {
          int d = 1;
          while ((c = getchar()) == ' ') {
            d++;
          }
          for (int i = 0; i < d; i++) {
            if (c == '\n') {
              putchar('~');
            } else {
              putchar(' ');
            }
          }
        }
        if (c == '\n') {
          putchar('$');
        }
        putchar(c);
      }
    } else {
      printf("\\%03o", c);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e78(%rip),%rcx
cmp    (%rcx),%eax
je     12b0 <main+0x160>
mov    -0x8(%rbp),%edi
call   1070 <isascii@plt>
cmp    $0x0,%rax
je     129a <main+0x14a>
mov    -0x8(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
jne    11ba <main+0x6a>
cmpl   $0xa,-0x8(%rbp)
je     11ba <main+0x6a>
cmpl   $0x9,-0x8(%rbp)
je     11ba <main+0x6a>
cmpl   $0x20,-0x8(%rbp)
jne    129a <main+0x14a>
cmpl   $0x9,-0x8(%rbp)
jne    11d7 <main+0x87>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1295 <main+0x145>
cmpl   $0x5c,-0x8(%rbp)
jne    11f4 <main+0xa4>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1290 <main+0x140>
cmpl   $0x20,-0x8(%rbp)
jne    1274 <main+0x124>
movl   $0x1,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x20,%eax
jne    1226 <main+0xd6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1205 <main+0xb5>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126f <main+0x11f>
cmpl   $0xa,-0x8(%rbp)
jne    1252 <main+0x102>
mov    $0x7e,%edi
call   1030 <putchar@plt>
jmp    125c <main+0x10c>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1261 <main+0x111>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122d <main+0xdd>
jmp    1274 <main+0x124>
cmpl   $0xa,-0x8(%rbp)
jne    1288 <main+0x138>
mov    $0x24,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    1295 <main+0x145>
jmp    12ab <main+0x15b>
mov    -0x8(%rbp),%esi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    115f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e7f(%rip),%r13
cmp    0x0(%r13),%eax
jne    1180 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xe7d(%rip),%r12
mov    $0x7e,%r15d
jmp    11bb <main+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     116f <main+0x1f>
mov    %ebp,%edi
call   1070 <isascii@plt>
test   %rax,%rax
je     11a0 <main+0x50>
mov    %ebp,%edi
call   1060 <isprint@plt>
test   %rax,%rax
je     11f0 <main+0xa0>
cmp    $0x9,%ebp
je     126d <main+0x11d>
cmp    $0x5c,%ebp
je     1276 <main+0x126>
cmp    $0x20,%ebp
je     11ff <main+0xaf>
jmp    124d <main+0xfd>
nopl   0x0(%rax)
cmp    $0x9,%ebp
je     126d <main+0x11d>
cmp    $0xa,%ebp
je     1252 <main+0x102>
cmp    $0x20,%ebp
jne    11a0 <main+0x50>
xor    %ebx,%ebx
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%r14d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
add    $0x1,%ebx
lea    0x1(%r14),%eax
cmp    $0x20,%ebp
je     1210 <main+0xc0>
cmp    $0xa,%ebp
mov    $0x20,%ebx
cmove  %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%r14d
jne    1240 <main+0xf0>
cmp    $0xa,%ebp
jne    1261 <main+0x111>
mov    $0x24,%edi
call   1030 <putchar@plt>
mov    $0xa,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
jmp    11ac <main+0x5c>
lea    0xd8c(%rip),%rdi
jmp    127d <main+0x12d>
lea    0xd86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ac <main+0x5c>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [3 x i8] c"\\t\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [6 x i8] c"\\%03o\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %76, %0
%6 = call i32 (...) @getchar()
store i32 %6, i32* %2
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %77
9: ; preds = %5
%10 = load i32, i32* %2
%11 = call i64 @isascii(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %73
13: ; preds = %9
%14 = load i32, i32* %2
%15 = call i64 @isprint(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %13
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 10
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 9
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 32
br i1 %25, label %26, label %73
26: ; preds = %23, %20, %17, %13
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 9
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %72
31: ; preds = %26
%32 = load i32, i32* %2
%33 = icmp eq i32 %32, 92
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %71
36: ; preds = %31
%37 = load i32, i32* %2
%38 = icmp eq i32 %37, 32
br i1 %38, label %39, label %63
39: ; preds = %36
store i32 1, i32* %3
br label %40
40: ; preds = %43, %39
%41 = call i32 (...) @getchar()
store i32 %41, i32* %2
%42 = icmp eq i32 %41, 32
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %40
46: ; preds = %40
store i32 0, i32* %4
br label %47
47: ; preds = %59, %46
%48 = load i32, i32* %4
%49 = load i32, i32* %3
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %62
51: ; preds = %47
%52 = load i32, i32* %2
%53 = icmp eq i32 %52, 10
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @putchar(i32 126)
br label %58
56: ; preds = %51
%57 = call i32 @putchar(i32 32)
br label %58
58: ; preds = %56, %54
br label %59
59: ; preds = %58
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %47
62: ; preds = %47
br label %63
63: ; preds = %62, %36
%64 = load i32, i32* %2
%65 = icmp eq i32 %64, 10
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 @putchar(i32 36)
br label %68
68: ; preds = %66, %63
%69 = load i32, i32* %2
%70 = call i32 @putchar(i32 %69)
br label %71
71: ; preds = %68, %34
br label %72
72: ; preds = %71, %29
br label %76
73: ; preds = %23, %9
%74 = load i32, i32* %2
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %73, %72
br label %5
77: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [3 x i8] c"\\t\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [6 x i8] c"\\%03o\00"
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %46, label %4
4: ; preds = %0, %42
%5 = phi i32 [ %43, %42 ], [ %1, %0 ]
%6 = tail call i64 @isascii(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %40, label %8
8: ; preds = %4
%9 = tail call i64 @isprint(i32 %5)
%10 = freeze i64 %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
switch i32 %5, label %40 [
i32 9, label %15
i32 32, label %14
i32 10, label %35
]
13: ; preds = %8
switch i32 %5, label %32 [
i32 9, label %15
i32 92, label %17
i32 32, label %14
]
14: ; preds = %12, %13
br label %19
15: ; preds = %12, %13
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %42
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %42
19: ; preds = %14, %19
%20 = phi i32 [ %23, %19 ], [ 1, %14 ]
%21 = tail call i32 (...) @getchar()
%22 = icmp eq i32 %21, 32
%23 = add nuw nsw i32 %20, 1
br i1 %22, label %19, label %24
24: ; preds = %19
%25 = icmp eq i32 %21, 10
%26 = select i1 %25, i32 126, i32 32
br label %27
27: ; preds = %24, %27
%28 = phi i32 [ 0, %24 ], [ %30, %27 ]
%29 = tail call i32 @putchar(i32 %26)
%30 = add nuw nsw i32 %28, 1
%31 = icmp eq i32 %30, %20
br i1 %31, label %32, label %27
32: ; preds = %27, %13
%33 = phi i32 [ %5, %13 ], [ %21, %27 ]
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %37
35: ; preds = %12, %32
%36 = tail call i32 @putchar(i32 36)
br label %37
37: ; preds = %35, %32
%38 = phi i32 [ 10, %35 ], [ %33, %32 ]
%39 = tail call i32 @putchar(i32 %38)
br label %42
40: ; preds = %12, %4
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %42
42: ; preds = %15, %37, %17, %40
%43 = tail call i32 (...) @getchar()
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %4
46: ; preds = %42, %0
ret i32 0
}