#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;
char *calloc(int, int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *getFileContents(FILE *file) {
  rewind(file);
  char c;
  fseek(file, 0, SEEK_END);
  int size = ftell(file);
  char *contents = calloc(size + 1, 1);
  int i = 0;
  rewind(file);
  while ((c = fgetc(file)) != EOF) {
    contents[i++] = c;
  }
  rewind(file);
  return contents;
}


x86 assembly (clang, -O0):
<getFileContents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
mov    0x2e21(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11e7 <getFileContents+0x97>
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11a9 <getFileContents+0x59>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileContents>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1030 <rewind@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r12,%rdi
call   1060 <ftell@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1030 <rewind@plt>
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    0x2e3e(%rip),%r15
cmp    (%r15),%al
je     11c3 <getFileContents+0x73>
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
mov    %al,(%rbx)
mov    %r12,%rdi
call   1040 <fgetc@plt>
add    $0x1,%rbx
cmp    (%r15),%al
jne    11b0 <getFileContents+0x60>
mov    %r12,%rdi
call   1030 <rewind@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@EOF = global i8 0
define i8* @getFileContents(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = call i32 @rewind(i32* %7)
%9 = load i32*, i32** %2
%10 = load i32, i32* @SEEK_END
%11 = call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = load i32*, i32** %2
%13 = call i32 @ftell(i32* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
%16 = call i8* @calloc(i32 %15, i32 1)
store i8* %16, i8** %5
store i32 0, i32* %6
%17 = load i32*, i32** %2
%18 = call i32 @rewind(i32* %17)
br label %19
19: ; preds = %26, %1
%20 = load i32*, i32** %2
%21 = call signext i8 @fgetc(i32* %20)
store i8 %21, i8* %3
%22 = sext i8 %21 to i32
%23 = load i8, i8* @EOF
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %33
26: ; preds = %19
%27 = load i8, i8* %3
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 %27, i8* %32
br label %19
33: ; preds = %19
%34 = load i32*, i32** %2
%35 = call i32 @rewind(i32* %34)
%36 = load i8*, i8** %5
ret i8* %36
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@EOF = global i8 0
define noalias i8* @getFileContents(i32* nocapture %0) {
%2 = tail call i32 @rewind(i32* %0)
%3 = load i32, i32* @SEEK_END
%4 = tail call i32 @fseek(i32* %0, i32 0, i32 %3)
%5 = tail call i32 @ftell(i32* %0)
%6 = add nsw i32 %5, 1
%7 = tail call i8* @calloc(i32 %6, i32 1)
%8 = tail call i32 @rewind(i32* %0)
%9 = tail call signext i8 @fgetc(i32* %0)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %20, label %12
12: ; preds = %1, %12
%13 = phi i64 [ %15, %12 ], [ 0, %1 ]
%14 = phi i8 [ %17, %12 ], [ %9, %1 ]
%15 = add nuw i64 %13, 1
%16 = getelementptr inbounds i8, i8* %7, i64 %13
store i8 %14, i8* %16
%17 = tail call signext i8 @fgetc(i32* %0)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %20, label %12
20: ; preds = %12, %1
%21 = tail call i32 @rewind(i32* %0)
ret i8* %7
}