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

/* Variables and functions */
scalar_t__ calloc(long, int);
long fscanf(int /*<<< orphan*/, char *, double *);
scalar_t__ realloc(double *, int);
int /*<<< orphan*/ stdin;
double *read_file(long *array_length) {
  double *x;
  long i, n, size;
  size = 10;
  x = (double *)calloc(size, sizeof(x[0]));
  i = 0;
  n = fscanf(stdin, "%lf", &x[0]);
  while (n == 1) {
    i++;
    if (i >= size) {
      size = 2 * size + 10;
      x = (double *)realloc(x, sizeof(double) * size);
    }
    n = fscanf(stdin, "%lf", &x[i]);
  }
  *array_length = i;
  return x;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0xa,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8e(%rip),%rsi
call   1030 <fscanf@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x1,-0x20(%rbp)
jne    11f4 <read_file+0xc4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jl     11c7 <read_file+0x97>
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
add    $0xa,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe1a(%rip),%rsi
call   1030 <fscanf@plt>
mov    %rax,-0x20(%rbp)
jmp    117b <read_file+0x4b>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,(%rsp)
mov    $0xa,%ebx
mov    $0xa,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r12
mov    0x2e8b(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe98(%rip),%rsi
mov    %rax,%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%rax
jne    11ce <read_file+0x9e>
mov    $0x8,%r14d
xor    %ebp,%ebp
lea    0xe7b(%rip),%r15
jmp    11aa <read_file+0x7a>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
lea    (%r12,%r14,1),%rdx
mov    %r15,%rsi
call   1030 <fscanf@plt>
add    $0x8,%r14
cmp    $0x1,%rax
jne    11d0 <read_file+0xa0>
add    $0x1,%rbp
cmp    %rbx,%rbp
jl     1190 <read_file+0x60>
add    %rbx,%rbx
add    $0xa,%rbx
lea    0x0(,%rbx,8),%esi
mov    %r12,%rdi
call   1050 <realloc@plt>
mov    %rax,%r12
jmp    1190 <read_file+0x60>
xor    %ebp,%ebp
mov    (%rsp),%rax
mov    %rbp,(%rax)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%lf\00"
define double* @read_file(i64* %0) {
%2 = alloca i64*
%3 = alloca double*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64* %0, i64** %2
store i64 10, i64* %6
%7 = load i64, i64* %6
%8 = call i64 @calloc(i64 %7, i32 8)
%9 = inttoptr i64 %8 to double*
store double* %9, double** %3
store i64 0, i64* %4
%10 = load i32, i32* @stdin
%11 = load double*, double** %3
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = call i64 @fscanf(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %12)
store i64 %13, i64* %5
br label %14
14: ; preds = %33, %1
%15 = load i64, i64* %5
%16 = icmp eq i64 %15, 1
br i1 %16, label %17, label %39
17: ; preds = %14
%18 = load i64, i64* %4
%19 = add nsw i64 %18, 1
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = load i64, i64* %6
%22 = icmp sge i64 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %17
%24 = load i64, i64* %6
%25 = mul nsw i64 2, %24
%26 = add nsw i64 %25, 10
store i64 %26, i64* %6
%27 = load double*, double** %3
%28 = load i64, i64* %6
%29 = mul i64 8, %28
%30 = trunc i64 %29 to i32
%31 = call i64 @realloc(double* %27, i32 %30)
%32 = inttoptr i64 %31 to double*
store double* %32, double** %3
br label %33
33: ; preds = %23, %17
%34 = load i32, i32* @stdin
%35 = load double*, double** %3
%36 = load i64, i64* %4
%37 = getelementptr inbounds double, double* %35, i64 %36
%38 = call i64 @fscanf(i32 %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %37)
store i64 %38, i64* %5
br label %14
39: ; preds = %14
%40 = load i64, i64* %4
%41 = load i64*, i64** %2
store i64 %40, i64* %41
%42 = load double*, double** %3
ret double* %42
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%lf\00"
define double* @read_file(i64* nocapture writeonly %0) {
%2 = tail call i64 @calloc(i64 10, i32 8)
%3 = inttoptr i64 %2 to double*
%4 = load i32, i32* @stdin
%5 = tail call i64 @fscanf(i32 %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %3)
%6 = icmp eq i64 %5, 1
br i1 %6, label %7, label %27
7: ; preds = %1, %20
%8 = phi i64 [ %22, %20 ], [ 10, %1 ]
%9 = phi i64 [ %11, %20 ], [ 0, %1 ]
%10 = phi double* [ %21, %20 ], [ %3, %1 ]
%11 = add nuw nsw i64 %9, 1
%12 = icmp slt i64 %11, %8
br i1 %12, label %20, label %13
13: ; preds = %7
%14 = shl nsw i64 %8, 1
%15 = add nsw i64 %14, 10
%16 = trunc i64 %15 to i32
%17 = shl i32 %16, 3
%18 = tail call i64 @realloc(double* %10, i32 %17)
%19 = inttoptr i64 %18 to double*
br label %20
20: ; preds = %13, %7
%21 = phi double* [ %19, %13 ], [ %10, %7 ]
%22 = phi i64 [ %15, %13 ], [ %8, %7 ]
%23 = load i32, i32* @stdin
%24 = getelementptr inbounds double, double* %21, i64 %11
%25 = tail call i64 @fscanf(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %24)
%26 = icmp eq i64 %25, 1
br i1 %26, label %7, label %27
27: ; preds = %20, %1
%28 = phi double* [ %3, %1 ], [ %21, %20 ]
%29 = phi i64 [ 0, %1 ], [ %11, %20 ]
store i64 %29, i64* %0
ret double* %28
}