#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 fread(char *, int, int const, int /*<<< orphan*/ *);
char *malloc(int);
char *realloc(char *, int);
char *filesuck(FILE *in) {
  const int inc = 1024 * 100;
  int len = 0, cnt;
  char *file = malloc(1);
  do {
    file = realloc(file, len + inc + 1);
    cnt = fread(&file[len], 1, inc, in);
    len += cnt;
  } while (cnt == inc);
  file[len] = '\0';
  return file;
}


x86 assembly (clang, -O0):
<filesuck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x19000,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
add    $0x19000,%esi
add    $0x1,%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x19000,%edx
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x19000,-0x14(%rbp)
je     1158 <filesuck+0x28>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filesuck>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    0x19001(%rbx),%esi
mov    %r15,%rdi
call   1050 <realloc@plt>
mov    %rax,%r15
movslq %ebx,%rbx
lea    (%rax,%rbx,1),%rdi
mov    $0x1,%esi
mov    $0x19000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
add    %eax,%ebx
cmp    $0x19000,%eax
je     1150 <filesuck+0x20>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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