#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 */
double atof(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
double *realloc(double *, int);
double *read_source(FILE *fp, int *num) {
  int n = 0;
  char line[1024];
  double *values = NULL;
  while (fgets(line, 1023, fp) != NULL) {
    values = realloc(values, sizeof(double) * (n + 1));
    values[n++] = atof(line);
  }
  *num = n;
  return values;
}


x86 assembly (clang, -O0):
<read_source>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3ff,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11c0 <read_source+0x90>
mov    -0x428(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x428(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1155 <read_source+0x25>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x428(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_source>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0x10(%rsp),%rdi
mov    $0x3ff,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c1 <read_source+0x91>
mov    %rbp,0x8(%rsp)
mov    $0x8,%ebp
xor    %r14d,%r14d
lea    0x10(%rsp),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%r13
add    $0x1,%r14
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <realloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <atof@plt>
movsd  %xmm0,(%rbx,%r13,8)
mov    %r12,%rdi
mov    $0x3ff,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
add    $0x8,%ebp
test   %rax,%rax
jne    1180 <read_source+0x50>
mov    0x8(%rsp),%rbp
jmp    11c6 <read_source+0x96>
xor    %r14d,%r14d
xor    %ebx,%ebx
mov    %r14d,0x0(%rbp)
mov    %rbx,%rax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double* @read_source(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32* @fgets(i8* %4, i32 1023, i32* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %20, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %10, %7 ], [ 0, %2 ]
%9 = phi double* [ %13, %7 ], [ null, %2 ]
%10 = add nuw i64 %8, 1
%11 = trunc i64 %10 to i32
%12 = shl i32 %11, 3
%13 = call double* @realloc(double* %9, i32 %12)
%14 = call double @atof(i8* %4)
%15 = getelementptr inbounds double, double* %13, i64 %8
store double %14, double* %15
%16 = call i32* @fgets(i8* %4, i32 1023, i32* %0)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %7
18: ; preds = %7
%19 = trunc i64 %10 to i32
br label %20
20: ; preds = %18, %2
%21 = phi i32 [ 0, %2 ], [ %19, %18 ]
%22 = phi double* [ null, %2 ], [ %13, %18 ]
store i32 %21, i32* %1
ret double* %22
}