#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 O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int getchar();
int open(char *, int, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int cin, fout;
  char c;
  if (argc > 1)
    fout = open(argv[1], O_WRONLY | O_CREAT, 0644);
  else
    fout = 1;
  while ((cin = getchar()) != EOF) {
    c = cin;
    if (c == '\n')
      c = '\r';
    if (c == '\t')
      c = ' ';
    c |= 0x80;
    write(fout, &c, 1);
  }
  close(fout);
  return (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)
cmpl   $0x1,-0x8(%rbp)
jle    118c <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e80(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
jmp    1193 <main+0x53>
movl   $0x1,-0x18(%rbp)
jmp    1198 <main+0x58>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%eax
je     11fb <main+0xbb>
mov    -0x14(%rbp),%eax
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    11c8 <main+0x88>
movb   $0xd,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x9,%eax
jne    11d9 <main+0x99>
movb   $0x20,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
or     $0x80,%eax
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1198 <main+0x58>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     1178 <main+0x38>
mov    0x8(%rsi),%rdi
mov    0x2e67(%rip),%rax
mov    0x2e90(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e5a(%rip),%r15
cmp    (%r15),%eax
je     11d2 <main+0x92>
mov    $0xd,%r12d
mov    $0xa0,%ebp
lea    0xf(%rsp),%r14
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%al
cmove  %r12d,%eax
mov    %eax,%ecx
or     $0x80,%cl
cmp    $0x9,%al
movzbl %cl,%eax
cmove  %ebp,%eax
mov    %al,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%eax
jne    11a0 <main+0x60>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %14, i32 %17, i32 420)
store i32 %18, i32* %7
br label %20
19: ; preds = %2
store i32 1, i32* %7
br label %20
20: ; preds = %19, %11
br label %21
21: ; preds = %37, %20
%22 = call i32 (...) @getchar()
store i32 %22, i32* %6
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %44
25: ; preds = %21
%26 = load i32, i32* %6
%27 = trunc i32 %26 to i8
store i8 %27, i8* %8
%28 = load i8, i8* %8
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br i1 %30, label %31, label %32
31: ; preds = %25
store i8 13, i8* %8
br label %32
32: ; preds = %31, %25
%33 = load i8, i8* %8
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 9
br i1 %35, label %36, label %37
36: ; preds = %32
store i8 32, i8* %8
br label %37
37: ; preds = %36, %32
%38 = load i8, i8* %8
%39 = sext i8 %38 to i32
%40 = or i32 %39, 128
%41 = trunc i32 %40 to i8
store i8 %41, i8* %8
%42 = load i32, i32* %7
%43 = call i32 @write(i32 %42, i8* %8, i32 1)
br label %21
44: ; preds = %21
%45 = load i32, i32* %7
%46 = call i32 @close(i32 %45)
ret i32 0
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* %7, i32 %10, i32 420)
br label %12
12: ; preds = %2, %5
%13 = phi i32 [ %11, %5 ], [ 1, %2 ]
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %30, label %17
17: ; preds = %12, %17
%18 = phi i32 [ %27, %17 ], [ %14, %12 ]
%19 = trunc i32 %18 to i8
%20 = and i32 %18, 255
%21 = icmp eq i32 %20, 10
%22 = select i1 %21, i8 13, i8 %19
%23 = icmp eq i8 %22, 9
%24 = or i8 %22, -128
%25 = select i1 %23, i8 -96, i8 %24
store i8 %25, i8* %3
%26 = call i32 @write(i32 %13, i8* %3, i32 1)
%27 = tail call i32 (...) @getchar()
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %17
30: ; preds = %17, %12
%31 = tail call i32 @close(i32 %13)
ret i32 0
}