#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*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stdout;
void do_cat(FILE *f) {
  int c;
  while ((c = fgetc(f)) != EOF) {
    switch (c) {
    case '\t':
      if (fputs("\\t", stdout) == EOF)
        exit(1);
      break;
    case '\n':
      if (fputs("$\n", stdout) == EOF)
        exit(1);
      break;
    default:
      if (putchar(c) < 0)
        exit(1);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<do_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%eax
je     1217 <do_cat+0xd7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x9,%eax
je     118c <do_cat+0x4c>
jmp    117b <do_cat+0x3b>
mov    -0x10(%rbp),%eax
sub    $0xa,%eax
je     11bf <do_cat+0x7f>
jmp    11f2 <do_cat+0xb2>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%eax
jne    11ba <do_cat+0x7a>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1212 <do_cat+0xd2>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%eax
jne    11ed <do_cat+0xad>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1212 <do_cat+0xd2>
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
cmp    $0x0,%eax
jge    120d <do_cat+0xcd>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1212 <do_cat+0xd2>
jmp    114c <do_cat+0xc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_cat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%rbx
call   1050 <fgetc@plt>
mov    0x2e90(%rip),%r12
cmp    (%r12),%eax
jne    1168 <do_cat+0x28>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2e69(%rip),%r13
lea    0xe8d(%rip),%r14
lea    0xe83(%rip),%r15
jmp    1199 <do_cat+0x59>
nop
mov    %eax,%edi
call   1030 <putchar@plt>
test   %eax,%eax
js     11c2 <do_cat+0x82>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r12),%eax
je     115e <do_cat+0x1e>
cmp    $0xa,%eax
je     11b0 <do_cat+0x70>
cmp    $0x9,%eax
jne    1180 <do_cat+0x40>
mov    0x0(%r13),%esi
mov    %r15,%rdi
jmp    11b7 <do_cat+0x77>
nopl   0x0(%rax)
mov    0x0(%r13),%esi
mov    %r14,%rdi
call   1040 <fputs@plt>
cmp    (%r12),%eax
jne    118b <do_cat+0x4b>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [3 x i8] c"\\t\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"$\0A\00"
define void @do_cat(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
br label %4
4: ; preds = %34, %1
%5 = load i32*, i32** %2
%6 = call i32 @fgetc(i32* %5)
store i32 %6, i32* %3
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %35
9: ; preds = %4
%10 = load i32, i32* %3
switch i32 %10, label %27 [
i32 9, label %11
i32 10, label %19
]
11: ; preds = %9
%12 = load i32, i32* @stdout
%13 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
br label %34
19: ; preds = %9
%20 = load i32, i32* @stdout
%21 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
br label %34
27: ; preds = %9
%28 = load i32, i32* %3
%29 = call i32 @putchar(i32 %28)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %27
br label %34
34: ; preds = %33, %26, %18
br label %4
35: ; preds = %4
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [3 x i8] c"\\t\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"$\0A\00"
define void @do_cat(i32* nocapture %0) {
%2 = tail call i32 @fgetc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %30, label %5
5: ; preds = %1, %26
%6 = phi i32 [ %27, %26 ], [ %2, %1 ]
switch i32 %6, label %21 [
i32 9, label %7
i32 10, label %14
]
7: ; preds = %5
%8 = load i32, i32* @stdout
%9 = tail call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %26
12: ; preds = %7
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = load i32, i32* @stdout
%16 = tail call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %5
%22 = tail call i32 @putchar(i32 %6)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %21, %14, %7
%27 = tail call i32 @fgetc(i32* %0)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %5
30: ; preds = %26, %1
ret void
}