#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 EOF;
int getc(int /*<<< orphan*/ *);
char *realloc(char *, int);
char *load_input(FILE *stream) {
  int c;
  int n = 0;
  char *input = NULL;
  while ((c = getc(stream)) != EOF) {
    input = realloc(input, ++n);
    input[n - 1] = c;
  }
  input = realloc(input, n + 1);
  input[n] = 0;
  return input;
}


x86 assembly (clang, -O0):
<load_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%eax
je     1186 <load_input+0x66>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
call   1030 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    113b <load_input+0x1b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
add    $0x1,%esi
call   1030 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <getc@plt>
mov    0x2eae(%rip),%r12
cmp    (%r12),%eax
jne    1147 <load_input+0x27>
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1179 <load_input+0x59>
mov    %eax,%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r15,%r13
add    $0x1,%r15
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <realloc@plt>
mov    %rax,%rbx
mov    %bpl,(%rax,%r13,1)
mov    %r14,%rdi
call   1040 <getc@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
jne    1150 <load_input+0x30>
lea    0x1(%r15),%esi
mov    %rbx,%rdi
call   1030 <realloc@plt>
mov    %r15d,%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i8* @load_input(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %19, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %9, %5 ], [ 0, %1 ]
%7 = phi i32 [ %14, %5 ], [ %2, %1 ]
%8 = phi i8* [ %11, %5 ], [ null, %1 ]
%9 = add nuw i64 %6, 1
%10 = trunc i64 %9 to i32
%11 = tail call i8* @realloc(i8* %8, i32 %10)
%12 = trunc i32 %7 to i8
%13 = getelementptr inbounds i8, i8* %11, i64 %6
store i8 %12, i8* %13
%14 = tail call i32 @getc(i32* %0)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %5
17: ; preds = %5
%18 = trunc i64 %9 to i32
br label %19
19: ; preds = %17, %1
%20 = phi i32 [ 0, %1 ], [ %18, %17 ]
%21 = phi i8* [ null, %1 ], [ %11, %17 ]
%22 = add nuw nsw i32 %20, 1
%23 = tail call i8* @realloc(i8* %21, i32 %22)
%24 = zext i32 %20 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 0, i8* %25
ret i8* %23
}