#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*/ SEEK_END;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void output(char *file) {
  FILE *fd = fopen(file, "r");
  long size;
  char *buffer;
  size_t result_size;
  if (NULL == fd) {
    fprintf(stderr, "error: Failed to open usage file '%s'\n", file);
    fprintf(stderr, "error: Set 'TODO_COMPLETION_FILE' environment variable\n");
    exit(1);
  }
  fseek(fd, 0, SEEK_END);
  size = ftell(fd);
  rewind(fd);
  buffer = (char *)malloc(sizeof(char) * size);
  if (NULL == buffer) {
    fprintf(stderr, "error: Memory allocation error\n");
    exit(2);
  }
  result_size = fread(buffer, 1, size, fd);
  if (size != (int)result_size) {
    fprintf(stderr, "error: Error reading file '%s'\n", file);
    exit(3);
  }
  printf("%s\n", buffer);
  fclose(fd);
  free(buffer);
  exit(0);
}


x86 assembly (clang, -O0):
<output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1218 <output+0x68>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1282 <output+0xd2>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movslq %ecx,%rcx
cmp    %rcx,%rax
je     12d5 <output+0x125>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    0xdc1(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<output>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe3e(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
jne    1200 <output+0x50>
mov    0x2e05(%rip),%rbx
mov    (%rbx),%edi
lea    0xe26(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %rax,%rbx
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1070 <rewind@plt>
mov    %r12d,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
jne    1257 <output+0xa7>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
cltq
cmp    %rax,%r12
jne    129a <output+0xea>
lea    0xe26(%rip),%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"error: Failed to open usage file '%s'\0A\00"
@.str.2 = [56 x i8] c"error: Set 'TODO_COMPLETION_FILE' environment variable\0A\00"
@SEEK_END = global i32 0
@.str.3 = [32 x i8] c"error: Memory allocation error\0A\00"
@.str.4 = [32 x i8] c"error: Error reading file '%s'\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define void @output(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* null, %9
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %2
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
%19 = load i32*, i32** %3
%20 = load i32, i32* @SEEK_END
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32*, i32** %3
%23 = call i64 @ftell(i32* %22)
store i64 %23, i64* %4
%24 = load i32*, i32** %3
%25 = call i32 @rewind(i32* %24)
%26 = load i64, i64* %4
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = icmp eq i8* null, %31
br i1 %32, label %33, label %37
33: ; preds = %18
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 2)
unreachable
37: ; preds = %18
%38 = load i8*, i8** %5
%39 = load i64, i64* %4
%40 = load i32*, i32** %3
%41 = call i64 @fread(i8* %38, i32 1, i64 %39, i32* %40)
store i64 %41, i64* %6
%42 = load i64, i64* %4
%43 = load i64, i64* %6
%44 = trunc i64 %43 to i32
%45 = sext i32 %44 to i64
%46 = icmp ne i64 %42, %45
br i1 %46, label %47, label %52
47: ; preds = %37
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %2
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = call i32 @exit(i32 3)
unreachable
52: ; preds = %37
%53 = load i8*, i8** %5
%54 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = load i32*, i32** %3
%56 = call i32 @fclose(i32* %55)
%57 = load i8*, i8** %5
%58 = call i32 @free(i8* %57)
%59 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"error: Failed to open usage file '%s'\0A\00"
@.str.2 = [56 x i8] c"error: Set 'TODO_COMPLETION_FILE' environment variable\0A\00"
@SEEK_END = global i32 0
@.str.3 = [32 x i8] c"error: Memory allocation error\0A\00"
@.str.4 = [32 x i8] c"error: Error reading file '%s'\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define void @output(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %2, i32 0, i32 %11)
%13 = tail call i64 @ftell(i32* %2)
%14 = tail call i32 @rewind(i32* %2)
%15 = trunc i64 %13 to i32
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %23
19: ; preds = %10
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%22 = tail call i32 @exit(i32 2)
unreachable
23: ; preds = %10
%24 = tail call i64 @fread(i8* %17, i32 1, i64 %13, i32* %2)
%25 = shl i64 %24, 32
%26 = ashr exact i64 %25, 32
%27 = icmp eq i64 %13, %26
br i1 %27, label %32, label %28
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%31 = tail call i32 @exit(i32 3)
unreachable
32: ; preds = %23
%33 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %17)
%34 = tail call i32 @fclose(i32* %2)
%35 = tail call i32 @free(i8* %17)
%36 = tail call i32 @exit(i32 0)
unreachable
}