#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 */
size_t fread(char *, int, int const, int /*<<< orphan*/ *);
char *malloc(int);
char *realloc(char *, int);
char *slurp(FILE *f) {
  const int increment = 8192;
  int capa = increment;
  char *buf = malloc(capa);
  size_t res, offs = 0;
  for (;;) {
    res = fread(buf + offs, 1, increment, f);
    offs += res;
    if (res < increment) {
      buf[offs] = '\0';
      return buf;
    }
    capa += increment;
    buf = realloc(buf, capa);
  }
}


x86 assembly (clang, -O0):
<slurp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x2000,-0xc(%rbp)
movl   $0x2000,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x2000,-0x20(%rbp)
jae    11ad <slurp+0x7d>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%eax
add    $0x2000,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
jmp    115e <slurp+0x2e>

x86 assembly (clang, -O2):
<slurp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2000,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
cmp    $0x2000,%rax
jb     11a4 <slurp+0x74>
mov    $0x4000,%ebp
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <realloc@plt>
mov    %rax,%r15
lea    (%rax,%rbx,1),%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
add    %rax,%rbx
add    $0x2000,%ebp
cmp    $0x2000,%rax
jae    1170 <slurp+0x40>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @slurp(i32* nocapture %0) {
%2 = tail call dereferenceable_or_null(8192) i8* @malloc(i32 8192)
%3 = tail call i64 @fread(i8* %2, i32 1, i32 8192, i32* %0)
%4 = icmp ult i64 %3, 8192
br i1 %4, label %5, label %9
5: ; preds = %9, %1
%6 = phi i8* [ %2, %1 ], [ %14, %9 ]
%7 = phi i64 [ %3, %1 ], [ %17, %9 ]
%8 = getelementptr inbounds i8, i8* %6, i64 %7
store i8 0, i8* %8
ret i8* %6
9: ; preds = %1, %9
%10 = phi i64 [ %17, %9 ], [ %3, %1 ]
%11 = phi i32 [ %13, %9 ], [ 8192, %1 ]
%12 = phi i8* [ %14, %9 ], [ %2, %1 ]
%13 = add nuw nsw i32 %11, 8192
%14 = tail call i8* @realloc(i8* %12, i32 %13)
%15 = getelementptr inbounds i8, i8* %14, i64 %10
%16 = tail call i64 @fread(i8* %15, i32 1, i32 8192, i32* %0)
%17 = add i64 %16, %10
%18 = icmp ult i64 %16, 8192
br i1 %18, label %5, label %9
}