#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  char buf[1024];
  size_t nread;
  FILE *file;
  file = fopen(argv[1], "r");
  if (file) {
    while ((nread = fread(buf, 1, sizeof buf, file)) > 0) {
      fwrite(buf, 1, nread, stdout);
    }
    if (ferror(file)) {
      printf("error.\n");
    }
    fclose(file);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     1229 <main+0xc9>
jmp    11a7 <main+0x47>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
jbe    11fb <main+0x9b>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    0x2df6(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1080 <fwrite@plt>
jmp    11a7 <main+0x47>
mov    -0x420(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     121d <main+0xbd>
lea    0xdea(%rip),%rdi
call   1060 <printf@plt>
mov    -0x420(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    0x8(%rsi),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11fe <main+0x9e>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     11dd <main+0x7d>
mov    0x2e3b(%rip),%r15
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11f6 <main+0x96>
lea    0xe11(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.1 = [8 x i8] c"error.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i64
%8 = alloca i32*
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 ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %35
15: ; preds = %2
br label %16
16: ; preds = %21, %15
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %8
%19 = call i64 @fread(i8* %17, i32 1, i32 1024, i32* %18)
store i64 %19, i64* %7
%20 = icmp ugt i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = load i64, i64* %7
%24 = load i32, i32* @stdout
%25 = call i32 @fwrite(i8* %22, i32 1, i64 %23, i32 %24)
br label %16
26: ; preds = %16
%27 = load i32*, i32** %8
%28 = call i64 @ferror(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = load i32*, i32** %8
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %32, %2
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
@str = [7 x i8] c"error.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %25, label %9
9: ; preds = %2
%10 = call i64 @fread(i8* %4, i32 1, i32 1024, i32* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9, %12
%13 = phi i64 [ %16, %12 ], [ %10, %9 ]
%14 = load i32, i32* @stdout
%15 = call i32 @fwrite(i8* %4, i32 1, i64 %13, i32 %14)
%16 = call i64 @fread(i8* %4, i32 1, i32 1024, i32* %7)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %12
18: ; preds = %12, %9
%19 = call i64 @ferror(i32* %7)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = call i32 @fclose(i32* %7)
br label %25
25: ; preds = %23, %2
ret i32 0
}