#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
void output_file(const char *fn) {
  FILE *fp = fopen(fn, "r");
  if (!fp) {
    fprintf(stderr, "Cannot open %s (%s)\n", fn, strerror(errno));
    exit(EXIT_FAILURE);
  }
  size_t n;
  do {
    char buffer[4096];
    n = fread(buffer, 1, 4096, fp);
    fwrite(buffer, 1, n, stdout);
  } while (n != 0);
  fclose(fp);
}


x86 assembly (clang, -O0):
<output_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f0 <output_file+0x80>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x102c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x102c(%rbp),%edi
mov    -0x1028(%rbp),%rdx
mov    %rax,%rcx
lea    0xe25(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11f5 <output_file+0x85>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2da3(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1080 <fwrite@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11f5 <output_file+0x85>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%rbx
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e6 <output_file+0x76>
mov    %rax,%r14
mov    %rsp,%rbx
mov    0x2e2a(%rip),%r15
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %rax,%rbp
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1080 <fwrite@plt>
test   %rbp,%rbp
jne    11a0 <output_file+0x30>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df3(%rip),%rax
mov    (%rax),%ebp
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdfe(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Cannot open %s (%s)\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
define void @output_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca [4096 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %18, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %2
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %1
br label %19
19: ; preds = %27, %18
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%21 = load i32*, i32** %3
%22 = call i64 @fread(i8* %20, i32 1, i32 4096, i32* %21)
store i64 %22, i64* %4
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%24 = load i64, i64* %4
%25 = load i32, i32* @stdout
%26 = call i32 @fwrite(i8* %23, i32 1, i64 %24, i32 %25)
br label %27
27: ; preds = %19
%28 = load i64, i64* %4
%29 = icmp ne i64 %28, 0
br i1 %29, label %19, label %30
30: ; preds = %27
%31 = load i32*, i32** %3
%32 = call i32 @fclose(i32* %31)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Cannot open %s (%s)\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
define void @output_file(i8* %0) {
%2 = alloca [4096 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
br label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %5, %14
%15 = call i64 @fread(i8* %6, i32 1, i32 4096, i32* %3)
%16 = load i32, i32* @stdout
%17 = call i32 @fwrite(i8* %6, i32 1, i64 %15, i32 %16)
%18 = icmp eq i64 %15, 0
br i1 %18, label %19, label %14
19: ; preds = %14
%20 = call i32 @fclose(i32* %3)
ret void
}