#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*/ SEEK_SET;
int /*<<< orphan*/ fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(long);
char *readFromFile(FILE *fp) {
  fseek(fp, 0, SEEK_END);
  long sz = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  if (sz == 0)
    return NULL;
  char *str = (char *)malloc((sz + 1) * sizeof(char));
  fread(str, sizeof(char), sz, fp);
  str[sz] = 0;
  return str;
}


x86 assembly (clang, -O0):
<readFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1199 <readFromFile+0x59>
movq   $0x0,-0x8(%rbp)
jmp    11d8 <readFromFile+0x98>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFromFile>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %r15,%rdi
call   1040 <ftell@plt>
mov    %rax,%rbx
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
test   %rbx,%rbx
je     11a5 <readFromFile+0x65>
mov    %rbx,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <fread@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @readFromFile(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = load i32, i32* @SEEK_END
%8 = call i32 @fseek(i32* %6, i32 0, i32 %7)
%9 = load i32*, i32** %3
%10 = call i64 @ftell(i32* %9)
store i64 %10, i64* %4
%11 = load i32*, i32** %3
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @fseek(i32* %11, i32 0, i32 %12)
%14 = load i64, i64* %4
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i8* null, i8** %2
br label %31
17: ; preds = %1
%18 = load i64, i64* %4
%19 = add nsw i64 %18, 1
%20 = mul i64 %19, 1
%21 = call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = load i64, i64* %4
%25 = load i32*, i32** %3
%26 = call i32 @fread(i8* %23, i32 1, i64 %24, i32* %25)
%27 = load i8*, i8** %5
%28 = load i64, i64* %4
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %5
store i8* %30, i8** %2
br label %31
31: ; preds = %17, %16
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @readFromFile(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 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i32 0, i32 %5)
%7 = icmp eq i64 %4, 0
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = add nsw i64 %4, 1
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @fread(i8* %11, i32 1, i64 %4, i32* %0)
%13 = getelementptr inbounds i8, i8* %11, i64 %4
store i8 0, i8* %13
br label %14
14: ; preds = %1, %8
%15 = phi i8* [ %11, %8 ], [ null, %1 ]
ret i8* %15
}