#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*/ assert(char *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ fread(char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
scalar_t__ realloc(char *, size_t);
char *readFile(FILE *f) {
  size_t a_ret = 1;
  size_t n_ret = 0;
  char *ret = (char *)malloc(a_ret);
  assert(ret);
  while (1) {
    n_ret += fread(ret, 1, a_ret - n_ret, f);
    if (feof(f))
      break;
    a_ret *= 2;
    ret = (char *)realloc(ret, a_ret);
    assert(ret);
  }
  ret[n_ret] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
sub    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11bc <readFile+0x6c>
jmp    11e7 <readFile+0x97>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <assert@plt>
jmp    1182 <readFile+0x32>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x1,%r12d
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <assert@plt>
mov    $0x1,%edx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
nop
mov    %r14,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11d7 <readFile+0x87>
mov    %rbx,%r13
add    %r12,%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <realloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <assert@plt>
mov    %r12,%rdx
sub    %rbx,%rdx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
add    %r13,%rbx
jmp    1190 <readFile+0x40>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @readFile(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i32* %0, i32** %2
store i64 1, i64* %3
store i64 0, i64* %4
%6 = load i64, i64* %3
%7 = call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @assert(i8* %9)
br label %11
11: ; preds = %1, %24
%12 = load i8*, i8** %5
%13 = load i64, i64* %3
%14 = load i64, i64* %4
%15 = sub i64 %13, %14
%16 = load i32*, i32** %2
%17 = call i64 @fread(i8* %12, i32 1, i64 %15, i32* %16)
%18 = load i64, i64* %4
%19 = add i64 %18, %17
store i64 %19, i64* %4
%20 = load i32*, i32** %2
%21 = call i64 @feof(i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %11
br label %33
24: ; preds = %11
%25 = load i64, i64* %3
%26 = mul i64 %25, 2
store i64 %26, i64* %3
%27 = load i8*, i8** %5
%28 = load i64, i64* %3
%29 = call i64 @realloc(i8* %27, i64 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = call i32 @assert(i8* %31)
br label %11
33: ; preds = %23
%34 = load i8*, i8** %5
%35 = load i64, i64* %4
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %5
ret i8* %37
}

LLVM IR (-O2):
define i8* @readFile(i32* nocapture %0) {
%2 = tail call i64 @malloc(i64 1)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @assert(i8* %3)
%5 = tail call i64 @fread(i8* %3, i32 1, i64 1, i32* %0)
%6 = tail call i64 @feof(i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %1, %8
%9 = phi i64 [ %18, %8 ], [ %5, %1 ]
%10 = phi i8* [ %14, %8 ], [ %3, %1 ]
%11 = phi i64 [ %12, %8 ], [ 1, %1 ]
%12 = shl i64 %11, 1
%13 = tail call i64 @realloc(i8* %10, i64 %12)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @assert(i8* %14)
%16 = sub i64 %12, %9
%17 = tail call i64 @fread(i8* %14, i32 1, i64 %16, i32* %0)
%18 = add i64 %17, %9
%19 = tail call i64 @feof(i32* %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %8, label %21
21: ; preds = %8
%22 = inttoptr i64 %13 to i8*
br label %23
23: ; preds = %21, %1
%24 = phi i8* [ %3, %1 ], [ %22, %21 ]
%25 = phi i64 [ %5, %1 ], [ %18, %21 ]
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 0, i8* %26
ret i8* %24
}