#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 */

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/, char *, long *);
scalar_t__ malloc(int);
scalar_t__ realloc(long *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
long *read_input() {
  int alloc = 1024, len = 1;
  long elem, *elems = (long *)malloc(sizeof(long) * alloc);
  while (!feof(stdin)) {
    int symbols_read = fscanf(stdin, "%ld", &elem);
    if (symbols_read < 1)
      continue;
    if (len >= alloc) {
      alloc *= 2;
      elems = (long *)realloc(elems, sizeof(long) * alloc);
      if (elems == NULL) {
        fprintf(stderr, "Not enough memory\n");
        break;
      }
    }
    elems[len++] = elem;
  }
  elems[0] = len - 1;
  return elems;
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x400,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119c <read_input+0x4c>
jmp    123c <read_input+0xec>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    11c7 <read_input+0x77>
jmp    1179 <read_input+0x29>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jl     121d <read_input+0xcd>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <read_input+0xc8>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
call   1040 <fprintf@plt>
jmp    123c <read_input+0xec>
jmp    121d <read_input+0xcd>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x8(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1179 <read_input+0x29>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x2000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x2e79(%rip),%r12
mov    (%r12),%edi
call   1050 <feof@plt>
mov    $0x1,%ebp
test   %eax,%eax
je     119c <read_input+0x4c>
add    $0xffffffff,%ebp
movslq %ebp,%rax
mov    %rax,(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x400,%r13d
lea    0xe57(%rip),%r14
mov    %rsp,%r15
jmp    11cb <read_input+0x7b>
xchg   %ax,%ax
mov    (%rsp),%rax
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %rax,(%rbx,%rcx,8)
mov    (%r12),%edi
call   1050 <feof@plt>
test   %eax,%eax
jne    1181 <read_input+0x31>
mov    (%r12),%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <fscanf@plt>
test   %eax,%eax
jle    11be <read_input+0x6e>
cmp    %r13d,%ebp
jl     11b0 <read_input+0x60>
mov    %r13d,%esi
shl    $0x4,%esi
mov    %rbx,%rdi
call   1070 <realloc@plt>
test   %rax,%rax
je     11fe <read_input+0xae>
mov    %rax,%rbx
add    %r13d,%r13d
jmp    11b0 <read_input+0x60>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
call   1040 <fprintf@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%ld\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Not enough memory\0A\00"
define i64* @read_input() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64*
%5 = alloca i32
store i32 1024, i32* %1
store i32 1, i32* %2
%6 = load i32, i32* %1
%7 = sext i32 %6 to i64
%8 = mul i64 8, %7
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i64*
store i64* %11, i64** %4
br label %12
12: ; preds = %43, %22, %0
%13 = load i32, i32* @stdin
%14 = call i32 @feof(i32 %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %50
17: ; preds = %12
%18 = load i32, i32* @stdin
%19 = call i32 @fscanf(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %3)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %17
br label %12
23: ; preds = %17
%24 = load i32, i32* %2
%25 = load i32, i32* %1
%26 = icmp sge i32 %24, %25
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = load i32, i32* %1
%29 = mul nsw i32 %28, 2
store i32 %29, i32* %1
%30 = load i64*, i64** %4
%31 = load i32, i32* %1
%32 = sext i32 %31 to i64
%33 = mul i64 8, %32
%34 = trunc i64 %33 to i32
%35 = call i64 @realloc(i64* %30, i32 %34)
%36 = inttoptr i64 %35 to i64*
store i64* %36, i64** %4
%37 = load i64*, i64** %4
%38 = icmp eq i64* %37, null
br i1 %38, label %39, label %42
39: ; preds = %27
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %50
42: ; preds = %27
br label %43
43: ; preds = %42, %23
%44 = load i64, i64* %3
%45 = load i64*, i64** %4
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i64, i64* %45, i64 %48
store i64 %44, i64* %49
br label %12
50: ; preds = %39, %12
%51 = load i32, i32* %2
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = load i64*, i64** %4
%55 = getelementptr inbounds i64, i64* %54, i64 0
store i64 %53, i64* %55
%56 = load i64*, i64** %4
ret i64* %56
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%ld\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Not enough memory\0A\00"
define i64* @read_input() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i64 @malloc(i32 8192)
%4 = inttoptr i64 %3 to i64*
%5 = load i32, i32* @stdin
%6 = call i32 @feof(i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %40
8: ; preds = %0, %33
%9 = phi i32 [ %36, %33 ], [ 1024, %0 ]
%10 = phi i64* [ %35, %33 ], [ %4, %0 ]
%11 = phi i32 [ %34, %33 ], [ 1, %0 ]
%12 = load i32, i32* @stdin
%13 = call i32 @fscanf(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%14 = icmp slt i32 %13, 1
br i1 %14, label %33, label %15
15: ; preds = %8
%16 = icmp slt i32 %11, %9
br i1 %16, label %26, label %17
17: ; preds = %15
%18 = shl nsw i32 %9, 1
%19 = shl i32 %9, 4
%20 = call i64 @realloc(i64* %10, i32 %19)
%21 = inttoptr i64 %20 to i64*
%22 = icmp eq i64 %20, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
unreachable
26: ; preds = %17, %15
%27 = phi i64* [ %21, %17 ], [ %10, %15 ]
%28 = phi i32 [ %18, %17 ], [ %9, %15 ]
%29 = load i64, i64* %1
%30 = add nsw i32 %11, 1
%31 = sext i32 %11 to i64
%32 = getelementptr inbounds i64, i64* %27, i64 %31
store i64 %29, i64* %32
br label %33
33: ; preds = %8, %26
%34 = phi i32 [ %30, %26 ], [ %11, %8 ]
%35 = phi i64* [ %27, %26 ], [ %10, %8 ]
%36 = phi i32 [ %28, %26 ], [ %9, %8 ]
%37 = load i32, i32* @stdin
%38 = call i32 @feof(i32 %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %8, label %40
40: ; preds = %33, %0
%41 = phi i32 [ 1, %0 ], [ %34, %33 ]
%42 = phi i64* [ %4, %0 ], [ %35, %33 ]
%43 = add nsw i32 %41, -1
%44 = sext i32 %43 to i64
store i64 %44, i64* %42
ret i64* %42
}