#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*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putc(char);
scalar_t__ read(int, char *, int);
int main(int argc, char *argv[]) {
  char c, lc = 0;
  int fd;
  if (argc == 1) {
    fd = 0;
  } else {
    fd = open(argv[1], 00);
  }
  if (fd < 0) {
    printf("Cat couldn't find the asked for file.\n");
    return -1;
  }
  while (read(fd, &c, 1) > 0) {
    putc(c);
    if (fd == 0) {
      if (c == '\n' && (lc != '\n' && lc != '\r'))
        putc('\r');
    } else {
      if (c == '\r' && (lc != '\n' && lc != '\r')) {
        putc('\n');
        putc('\r');
      }
    }
    lc = c;
  }
  printf("\n");
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x12(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1190 <main+0x30>
movl   $0x0,-0x18(%rbp)
jmp    11a2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11c3 <main+0x63>
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    11c8 <main+0x68>
mov    -0x18(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    1277 <main+0x117>
movsbl -0x11(%rbp),%edi
call   1060 <putc@plt>
cmpl   $0x0,-0x18(%rbp)
jne    122c <main+0xcc>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    1227 <main+0xc7>
movsbl -0x12(%rbp),%eax
cmp    $0xa,%eax
je     1227 <main+0xc7>
movsbl -0x12(%rbp),%eax
cmp    $0xd,%eax
je     1227 <main+0xc7>
mov    $0xd,%edi
call   1060 <putc@plt>
jmp    126c <main+0x10c>
movsbl -0x11(%rbp),%eax
cmp    $0xd,%eax
jne    1267 <main+0x107>
movsbl -0x12(%rbp),%eax
cmp    $0xa,%eax
je     1267 <main+0x107>
movsbl -0x12(%rbp),%eax
cmp    $0xd,%eax
je     1267 <main+0x107>
mov    $0xa,%edi
call   1060 <putc@plt>
mov    $0xd,%edi
call   1060 <putc@plt>
jmp    126c <main+0x10c>
mov    -0x11(%rbp),%al
mov    %al,-0x12(%rbp)
jmp    11c8 <main+0x68>
lea    0xda7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
je     11a7 <main+0x37>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
call   1080 <open@plt>
test   %eax,%eax
jns    11ac <main+0x3c>
lea    0xe6e(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r15d,%r15d
jmp    11af <main+0x3f>
mov    %eax,%r15d
lea    0x7(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    1242 <main+0xd2>
xor    %ebp,%ebp
lea    0x7(%rsp),%r14
jmp    11f5 <main+0x85>
mov    $0xd,%edi
call   1070 <putc@plt>
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    1242 <main+0xd2>
mov    %ebp,%ebx
movzbl 0x7(%rsp),%ebp
movsbl %bpl,%edi
call   1070 <putc@plt>
test   %r15d,%r15d
je     1230 <main+0xc0>
cmp    $0xd,%bpl
jne    11e0 <main+0x70>
cmp    $0xa,%bl
je     11e0 <main+0x70>
cmp    $0xd,%bl
je     11e0 <main+0x70>
mov    $0xa,%edi
call   1070 <putc@plt>
jmp    11cf <main+0x5f>
cs nopw 0x0(%rax,%rax,1)
cmp    $0xa,%bpl
jne    11e0 <main+0x70>
cmp    $0xa,%bl
je     11e0 <main+0x70>
cmp    $0xd,%bl
je     11e0 <main+0x70>
jmp    11cf <main+0x5f>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"Cat couldn't find the asked for file.\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %7
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %8
br label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @open(i8* %15, i32 0)
store i32 %16, i32* %8
br label %17
17: ; preds = %12, %11
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
ret i32 -1
22: ; preds = %17
br label %23
23: ; preds = %63, %22
%24 = load i32, i32* %8
%25 = call i64 @read(i32 %24, i8* %6, i32 1)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %65
27: ; preds = %23
%28 = load i8, i8* %6
%29 = call i32 @putc(i8 signext %28)
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %47
32: ; preds = %27
%33 = load i8, i8* %6
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 10
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load i8, i8* %7
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 10
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load i8, i8* %7
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 13
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @putc(i8 signext 13)
br label %46
46: ; preds = %44, %40, %36, %32
br label %63
47: ; preds = %27
%48 = load i8, i8* %6
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 13
br i1 %50, label %51, label %62
51: ; preds = %47
%52 = load i8, i8* %7
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 10
br i1 %54, label %55, label %62
55: ; preds = %51
%56 = load i8, i8* %7
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 13
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = call i32 @putc(i8 signext 10)
%61 = call i32 @putc(i8 signext 13)
br label %62
62: ; preds = %59, %55, %51, %47
br label %63
63: ; preds = %62, %46
%64 = load i8, i8* %6
store i8 %64, i8* %7
br label %23
65: ; preds = %23
%66 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%67 = load i32, i32* %8
%68 = call i32 @close(i32 %67)
%69 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@str = [38 x i8] c"Cat couldn't find the asked for file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 1
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @open(i8* %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2, %5
%11 = phi i32 [ %8, %5 ], [ 0, %2 ]
%12 = call i64 @read(i32 %11, i8* %3, i32 1)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %10
%15 = icmp eq i32 %11, 0
br label %18
16: ; preds = %5
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
ret i32 -1
18: ; preds = %14, %32
%19 = phi i8 [ 0, %14 ], [ %20, %32 ]
%20 = load i8, i8* %3
%21 = tail call i32 @putc(i8 signext %20)
br i1 %15, label %22, label %25
22: ; preds = %18
%23 = icmp eq i8 %20, 10
br i1 %23, label %24, label %32
24: ; preds = %22
switch i8 %19, label %30 [
i8 13, label %32
i8 10, label %32
]
25: ; preds = %18
%26 = icmp eq i8 %20, 13
br i1 %26, label %27, label %32
27: ; preds = %25
switch i8 %19, label %28 [
i8 13, label %32
i8 10, label %32
]
28: ; preds = %27
%29 = tail call i32 @putc(i8 signext 10)
br label %30
30: ; preds = %24, %28
%31 = tail call i32 @putc(i8 signext 13)
br label %32
32: ; preds = %30, %27, %27, %25, %24, %24, %22
%33 = call i64 @read(i32 %11, i8* %3, i32 1)
%34 = icmp sgt i64 %33, 0
br i1 %34, label %18, label %35
35: ; preds = %32, %10
%36 = tail call i32 @putchar(i32 10)
%37 = tail call i32 @close(i32 %11)
%38 = tail call i32 @exit(i32 0)
unreachable
}