#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int c;
  FILE *fd;
  if (argc > 2) {
    fprintf(stderr, "usage: %s [file]\n", argv[0]);
    return -1;
  }
  if (argc == 1)
    fd = stdin;
  else if (!(fd = fopen(argv[1], "r"))) {
    fprintf(stderr, "%s: unable to open file %s\n", argv[0], argv[1]);
    return -2;
  }
  while ((c = fgetc(fd)) != EOF)
    if (c == '\r')
      continue;
    else if (c == '\n')
      fputc('\r', stdout);
    else
      fputc(c, stdout);
  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   $0x2,-0x8(%rbp)
jle    118a <main+0x4a>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <main+0x133>
cmpl   $0x1,-0x8(%rbp)
jne    11a7 <main+0x67>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1200 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11fb <main+0xbb>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1273 <main+0x133>
jmp    1200 <main+0xc0>
jmp    1205 <main+0xc5>
mov    -0x20(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dc8(%rip),%rcx
cmp    (%rcx),%eax
je     126c <main+0x12c>
cmpl   $0xd,-0x14(%rbp)
jne    122f <main+0xef>
jmp    1205 <main+0xc5>
cmpl   $0xa,-0x14(%rbp)
jne    1251 <main+0x111>
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
mov    $0xd,%edi
call   1040 <fputc@plt>
jmp    1262 <main+0x122>
mov    -0x14(%rbp),%edi
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
call   1040 <fputc@plt>
jmp    1267 <main+0x127>
jmp    1205 <main+0xc5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
jl     1175 <main+0x35>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe9d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    120d <main+0xcd>
cmp    $0x1,%edi
jne    1186 <main+0x46>
mov    0x2e67(%rip),%rax
mov    (%rax),%rbx
jmp    119e <main+0x5e>
mov    0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e8 <main+0xa8>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    0x2e33(%rip),%rbp
xor    %r14d,%r14d
cmp    0x0(%rbp),%eax
je     120d <main+0xcd>
mov    0x2e0c(%rip),%r15
jmp    11dc <main+0x9c>
xchg   %ax,%ax
mov    $0xd,%eax
mov    (%r15),%esi
mov    %eax,%edi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%rbp),%eax
je     120d <main+0xcd>
cmp    $0xa,%eax
je     11c0 <main+0x80>
cmp    $0xd,%eax
je     11cf <main+0x8f>
jmp    11c5 <main+0x85>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
mov    0x8(%rbp),%rcx
lea    0xe14(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xfffffffe,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s [file]\0A\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"%s: unable to open file %s\0A\00"
@EOF = global i32 0
@stdout = 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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %60
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i32*, i32** @stdin
store i32* %20, i32** %7
br label %37
21: ; preds = %16
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %7
%26 = icmp ne i32* %25, null
br i1 %26, label %36, label %27
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %34)
store i32 -2, i32* %3
br label %60
36: ; preds = %21
br label %37
37: ; preds = %36, %19
br label %38
38: ; preds = %58, %46, %37
%39 = load i32*, i32** %7
%40 = call i32 @fgetc(i32* %39)
store i32 %40, i32* %6
%41 = load i32, i32* @EOF
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %59
43: ; preds = %38
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, 13
br i1 %45, label %46, label %47
46: ; preds = %43
br label %38
47: ; preds = %43
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 10
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* @stdout
%52 = call i32 @fputc(i32 13, i32 %51)
br label %57
53: ; preds = %47
%54 = load i32, i32* %6
%55 = load i32, i32* @stdout
%56 = call i32 @fputc(i32 %54, i32 %55)
br label %57
57: ; preds = %53, %50
br label %58
58: ; preds = %57
br label %38
59: ; preds = %38
store i32 0, i32* %3
br label %60
60: ; preds = %59, %27, %10
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s [file]\0A\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"%s: unable to open file %s\0A\00"
@EOF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %38
8: ; preds = %2
%9 = icmp eq i32 %0, 1
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = load i32*, i32** @stdin
br label %22
12: ; preds = %8
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = load i8*, i8** %13
%21 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %20)
br label %38
22: ; preds = %12, %10
%23 = phi i32* [ %11, %10 ], [ %15, %12 ]
%24 = tail call i32 @fgetc(i32* %23)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %38, label %27
27: ; preds = %22, %34
%28 = phi i32 [ %35, %34 ], [ %24, %22 ]
switch i32 %28, label %29 [
i32 13, label %34
i32 10, label %30
]
29: ; preds = %27
br label %30
30: ; preds = %27, %29
%31 = phi i32 [ %28, %29 ], [ 13, %27 ]
%32 = load i32, i32* @stdout
%33 = tail call i32 @fputc(i32 %31, i32 %32)
br label %34
34: ; preds = %30, %27
%35 = tail call i32 @fgetc(i32* %23)
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %27
38: ; preds = %34, %22, %17, %4
%39 = phi i32 [ -1, %4 ], [ -2, %17 ], [ 0, %22 ], [ 0, %34 ]
ret i32 %39
}