#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 */
char EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int main(int argc, char *argv[]) {
  char c;
  FILE *fd;
  if (argc != 2) {
    printf("Usage: %s filename\n", argv[0]);
    exit(0);
  }
  if ((fd = fopen(argv[1], "r")) == NULL) {
    perror("fopen");
    exit(1);
  }
  while ((c = getc(fd)) != EOF)
    if (c != 13)
      putchar(c);
  fclose(fd);
}


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)
je     11aa <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e2 <main+0x72>
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11e7 <main+0x77>
mov    -0x20(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2deb(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1223 <main+0xb3>
movsbl -0x11(%rbp),%eax
cmp    $0xd,%eax
je     121e <main+0xae>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
jmp    11e7 <main+0x77>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11dd <main+0x6d>
mov    0x8(%rsi),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f3 <main+0x83>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <getc@plt>
mov    0x2e48(%rip),%r14
jmp    11b8 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    (%r14),%al
je     11cb <main+0x5b>
cmp    $0xd,%al
je     11b0 <main+0x40>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    11b0 <main+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rsi),%rsi
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe1c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%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 ne i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
br label %26
26: ; preds = %40, %25
%27 = load i32*, i32** %7
%28 = call signext i8 @getc(i32* %27)
store i8 %28, i8* %6
%29 = sext i8 %28 to i32
%30 = load i8, i8* @EOF
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %29, %31
br i1 %32, label %33, label %41
33: ; preds = %26
%34 = load i8, i8* %6
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 13
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i8, i8* %6
%39 = call i32 @putchar(i8 signext %38)
br label %40
40: ; preds = %37, %33
br label %26
41: ; preds = %26
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call signext i8 @getc(i32* %11)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %29, label %20
17: ; preds = %8
%18 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %13, %25
%21 = phi i8 [ %26, %25 ], [ %14, %13 ]
%22 = icmp eq i8 %21, 13
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @putchar(i8 signext %21)
br label %25
25: ; preds = %23, %20
%26 = tail call signext i8 @getc(i32* %11)
%27 = load i8, i8* @EOF
%28 = icmp eq i8 %26, %27
br i1 %28, label %29, label %20
29: ; preds = %25, %13
%30 = tail call i32 @fclose(i32* %11)
ret i32 0
}