#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*/ SEEK_END;
scalar_t__ calloc(long, int);
int /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *loadinstrs(FILE *file) {
  long filesize;
  char *buff;
  char *buffptr;
  char ch;
  fseek(file, 0, SEEK_END);
  filesize = ftell(file);
  rewind(file);
  buff = (char *)calloc(filesize + 1, sizeof(char));
  if (!buff) {
    fprintf(stderr, "Failed to allocate the instruction buffer.\n");
    exit(1);
  }
  buffptr = buff;
  while ((ch = fgetc(file)) != EOF)
    *buffptr++ = ch;
  return buff;
}


x86 assembly (clang, -O0):
<loadinstrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e6 <loadinstrs+0x76>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2ddc(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1228 <loadinstrs+0xb8>
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11ee <loadinstrs+0x7e>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadinstrs>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r12,%rdi
call   1070 <ftell@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1030 <rewind@plt>
add    $0x1,%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11f2 <loadinstrs+0x82>
mov    %rax,%r14
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    0x2e1a(%rip),%r15
cmp    (%r15),%al
je     11e3 <loadinstrs+0x73>
mov    %r14,%rbx
xchg   %ax,%ax
mov    %al,(%rbx)
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%al
jne    11d0 <loadinstrs+0x60>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@SEEK_END = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Failed to allocate the instruction buffer.\0A\00"
@EOF = global i8 0
define i8* @loadinstrs(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = load i32, i32* @SEEK_END
%9 = call i32 @fseek(i32* %7, i32 0, i32 %8)
%10 = load i32*, i32** %2
%11 = call i64 @ftell(i32* %10)
store i64 %11, i64* %3
%12 = load i32*, i32** %2
%13 = call i32 @rewind(i32* %12)
%14 = load i64, i64* %3
%15 = add nsw i64 %14, 1
%16 = call i64 @calloc(i64 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %24, label %20
20: ; preds = %1
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %1
%25 = load i8*, i8** %4
store i8* %25, i8** %5
br label %26
26: ; preds = %33, %24
%27 = load i32*, i32** %2
%28 = call signext i8 @fgetc(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 %37
33: ; preds = %26
%34 = load i8, i8* %6
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %5
store i8 %34, i8* %35
br label %26
37: ; preds = %26
%38 = load i8*, i8** %4
ret i8* %38
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Failed to allocate the instruction buffer.\0A\00"
@EOF = global i8 0
define i8* @loadinstrs(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i32 @fseek(i32* %0, i32 0, i32 %2)
%4 = tail call i64 @ftell(i32* %0)
%5 = tail call i32 @rewind(i32* %0)
%6 = add nsw i64 %4, 1
%7 = tail call i64 @calloc(i64 %6, i32 1)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = tail call signext i8 @fgetc(i32* %0)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %25, label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10, %18
%19 = phi i8 [ %22, %18 ], [ %11, %10 ]
%20 = phi i8* [ %21, %18 ], [ %8, %10 ]
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8 %19, i8* %20
%22 = tail call signext i8 @fgetc(i32* %0)
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %22, %23
br i1 %24, label %25, label %18
25: ; preds = %18, %10
ret i8* %8
}