#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*/ feof(int /*<<< orphan*/ *);
scalar_t__ fread(char *, int, size_t, int /*<<< orphan*/ *);
char *malloc(size_t);
char *realloc(char *, size_t);
char *slurp(FILE *in) {
  size_t size = 256, count = 0;
  char *buffer = malloc(size);
  while (!feof(in)) {
    count += fread(buffer + count, 1, size - count, in);
    if (count == size) {
      size *= 2;
      buffer = realloc(buffer, size);
    }
  }
  buffer[count] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<slurp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x100,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1187 <slurp+0x47>
jmp    11dd <slurp+0x9d>
mov    -0x20(%rbp),%rdi
add    -0x18(%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    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11d8 <slurp+0x98>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
jmp    1169 <slurp+0x29>
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):
<slurp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x100,%r12d
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <feof@plt>
xor    %r13d,%r13d
jmp    1178 <slurp+0x38>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <feof@plt>
test   %eax,%eax
jne    11b4 <slurp+0x74>
mov    %r13,%rbx
lea    (%r15,%r13,1),%rdi
mov    %r12,%rdx
sub    %r13,%rdx
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %rax,%r13
add    %rbx,%r13
cmp    %r12,%r13
jne    1170 <slurp+0x30>
add    %r12,%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <realloc@plt>
mov    %rax,%r15
jmp    1170 <slurp+0x30>
movb   $0x0,(%r15,%r13,1)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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