#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 /*<<< orphan*/ clearerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putchar(char);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  char ch;
  if ((in = fopen(argv[1], "rb")) == NULL) {
    perror("Error");
    exit(1);
  }
  while (!feof(in)) {
    ch = getc(in);
    if (ferror(in)) {
      perror("Error");
      clearerr(in);
      break;
    }
    putchar(ch);
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11de <main+0x4e>
lea    0xe34(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11e3 <main+0x53>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1201 <main+0x71>
jmp    1248 <main+0xb8>
mov    -0x18(%rbp),%rdi
call   10b0 <getc@plt>
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     123a <main+0xaa>
lea    0xddc(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1070 <clearerr@plt>
jmp    1248 <main+0xb8>
movsbl -0x21(%rbp),%edi
call   1030 <putchar@plt>
jmp    11e3 <main+0x53>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
lea    0xe61(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1203 <main+0x73>
mov    %rax,%r14
nopl   0x0(%rax)
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11f1 <main+0x61>
mov    %r14,%rdi
call   10b0 <getc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    11dd <main+0x4d>
movsbl %bl,%edi
call   1030 <putchar@plt>
jmp    11b0 <main+0x20>
lea    0xe1f(%rip),%rdi
call   1090 <perror@plt>
mov    %r14,%rdi
call   1070 <clearerr@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdf9(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [6 x i8] c"Error\00"
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 i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %33, %17
%19 = load i32*, i32** %6
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %36
23: ; preds = %18
%24 = load i32*, i32** %6
%25 = call signext i8 @getc(i32* %24)
store i8 %25, i8* %8
%26 = load i32*, i32** %6
%27 = call i64 @ferror(i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32*, i32** %6
%32 = call i32 @clearerr(i32* %31)
br label %36
33: ; preds = %23
%34 = load i8, i8* %8
%35 = call i32 @putchar(i8 signext %34)
br label %18
36: ; preds = %29, %18
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
ret i32 0
}

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