#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(size_t);
char *realloc(char *, size_t);
char *slurp(FILE *f) {
  const int increment = 8192;
  size_t 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)
movq   $0x2000,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x2000,-0x28(%rbp)
jae    11af <slurp+0x7f>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x18(%rbp),%rax
add    $0x2000,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
jmp    1160 <slurp+0x30>

x86 assembly (clang, -O2):
<slurp>:
push   %r15
push   %r14
push   %r12
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,%r12
cmp    $0x2000,%rax
jb     11a6 <slurp+0x76>
mov    $0x4000,%ebx
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <realloc@plt>
mov    %rax,%r15
lea    (%rax,%r12,1),%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
add    %rax,%r12
add    $0x2000,%rbx
cmp    $0x2000,%rax
jae    1170 <slurp+0x40>
movb   $0x0,(%r15,%r12,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @slurp(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32* %0, i32** %2
store i32 8192, i32* %3
store i64 8192, i64* %4
%8 = load i64, i64* %4
%9 = call i8* @malloc(i64 %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 i64, i64* %4
%28 = add i64 %27, 8192
store i64 %28, i64* %4
%29 = load i8*, i8** %5
%30 = load i64, i64* %4
%31 = call i8* @realloc(i8* %29, i64 %30)
store i8* %31, i8** %5
br label %10
}

LLVM IR (-O2):
define noalias i8* @slurp(i32* nocapture %0) {
%2 = tail call dereferenceable_or_null(8192) i8* @malloc(i64 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 i64 [ %13, %9 ], [ 8192, %1 ]
%12 = phi i8* [ %14, %9 ], [ %2, %1 ]
%13 = add i64 %11, 8192
%14 = tail call i8* @realloc(i8* %12, i64 %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
}