#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*/);
scalar_t__ putchar(int);
int /*<<< orphan*/ stdout;
void do_cat(FILE *f, int escape) {
  int c;
  if (escape) {
    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;
      }
    }
  } else {
    while ((c = fgetc(f)) != EOF) {
      if (putchar(c) < 0)
        exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<do_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     122f <do_cat+0xef>
jmp    115e <do_cat+0x1e>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e77(%rip),%rcx
cmp    (%rcx),%eax
je     122a <do_cat+0xea>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x9,%eax
je     119e <do_cat+0x5e>
jmp    118d <do_cat+0x4d>
mov    -0x14(%rbp),%eax
sub    $0xa,%eax
je     11d1 <do_cat+0x91>
jmp    1204 <do_cat+0xc4>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    0xe52(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%eax
jne    11cc <do_cat+0x8c>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1225 <do_cat+0xe5>
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
lea    0xe22(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%eax
jne    11ff <do_cat+0xbf>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1225 <do_cat+0xe5>
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
cmp    $0x0,%rax
jge    1220 <do_cat+0xe0>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1225 <do_cat+0xe5>
jmp    115e <do_cat+0x1e>
jmp    1275 <do_cat+0x135>
jmp    1234 <do_cat+0xf4>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x10(%rbp)
mov    0x2da1(%rip),%rcx
cmp    (%rcx),%eax
je     1270 <do_cat+0x130>
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
cmp    $0x0,%rax
jge    126b <do_cat+0x12b>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1234 <do_cat+0xf4>
jmp    1275 <do_cat+0x135>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_cat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%rbx
test   %esi,%esi
je     116f <do_cat+0x2f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e89(%rip),%r12
cmp    (%r12),%eax
jne    119b <do_cat+0x5b>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2e72(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%eax
je     1165 <do_cat+0x25>
mov    %eax,%edi
call   1030 <putchar@plt>
test   %rax,%rax
jns    1180 <do_cat+0x40>
jmp    1202 <do_cat+0xc2>
mov    0x2e36(%rip),%r13
lea    0xe5a(%rip),%r14
lea    0xe50(%rip),%r15
jmp    11da <do_cat+0x9a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
test   %rax,%rax
js     1202 <do_cat+0xc2>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r12),%eax
je     1165 <do_cat+0x25>
cmp    $0xa,%eax
je     11f0 <do_cat+0xb0>
cmp    $0x9,%eax
jne    11c0 <do_cat+0x80>
mov    0x0(%r13),%esi
mov    %r15,%rdi
jmp    11f7 <do_cat+0xb7>
nopl   (%rax)
mov    0x0(%r13),%esi
mov    %r14,%rdi
call   1040 <fputs@plt>
cmp    (%r12),%eax
jne    11cc <do_cat+0x8c>
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, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %41
8: ; preds = %2
br label %9
9: ; preds = %39, %8
%10 = load i32*, i32** %3
%11 = call i32 @fgetc(i32* %10)
store i32 %11, i32* %5
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %40
14: ; preds = %9
%15 = load i32, i32* %5
switch i32 %15, label %32 [
i32 9, label %16
i32 10, label %24
]
16: ; preds = %14
%17 = load i32, i32* @stdout
%18 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
br label %39
24: ; preds = %14
%25 = load i32, i32* @stdout
%26 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %24
br label %39
32: ; preds = %14
%33 = load i32, i32* %5
%34 = call i64 @putchar(i32 %33)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %32
br label %39
39: ; preds = %38, %31, %23
br label %9
40: ; preds = %9
br label %55
41: ; preds = %2
br label %42
42: ; preds = %53, %41
%43 = load i32*, i32** %3
%44 = call i32 @fgetc(i32* %43)
store i32 %44, i32* %5
%45 = load i32, i32* @EOF
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %54
47: ; preds = %42
%48 = load i32, i32* %5
%49 = call i64 @putchar(i32 %48)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %47
br label %42
54: ; preds = %42
br label %55
55: ; preds = %54, %40
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, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %33, label %4
4: ; preds = %2
%5 = tail call i32 @fgetc(i32* %0)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %42, label %8
8: ; preds = %4, %29
%9 = phi i32 [ %30, %29 ], [ %5, %4 ]
switch i32 %9, label %24 [
i32 9, label %10
i32 10, label %17
]
10: ; preds = %8
%11 = load i32, i32* @stdout
%12 = tail call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %10
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = load i32, i32* @stdout
%19 = tail call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %8
%25 = tail call i64 @putchar(i32 %9)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %24, %17, %10
%30 = tail call i32 @fgetc(i32* %0)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %42, label %8
33: ; preds = %2, %37
%34 = tail call i32 @fgetc(i32* %0)
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %42, label %37
37: ; preds = %33
%38 = tail call i64 @putchar(i32 %34)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %33
40: ; preds = %37
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %29, %33, %4
ret void
}