#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 */
void *calloc(size_t, int);
int /*<<< orphan*/ *get_fp(char *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
double *realloc(double *, size_t);
int /*<<< orphan*/ sscanf(char *, char *, double *);
double *get_b(char *filename, int *dim) {
  int n = 0;
  size_t size;
  size = *dim;
  double *b = calloc(size, sizeof(double));
  FILE *fp = get_fp(filename, "r");
  size_t m = 4096;
  char *line_buf = calloc(m, sizeof(char));
  double result;
  while (getline(&line_buf, &m, fp) != -1) {
    sscanf(line_buf, "%lf\n", &result);
    if (n >= size) {
      size++;
      b = realloc(b, size * sizeof(double));
    }
    b[n] = result;
    n++;
  }
  *dim = n;
  return (b);
}


x86 assembly (clang, -O0):
<get_b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1070 <get_fp@plt>
mov    %rax,-0x30(%rbp)
movq   $0x1000,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdx
lea    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     122f <get_b+0xdf>
mov    -0x40(%rbp),%rdi
lea    0xe2b(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1040 <sscanf@plt>
movslq -0x14(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     120f <get_b+0xbf>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
shl    $0x3,%rsi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <get_b+0x62>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_b>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
movslq (%rsi),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
lea    0xe82(%rip),%rsi
mov    %rbp,%rdi
call   1070 <get_fp@plt>
mov    %rax,%r12
movq   $0x1000,0x10(%rsp)
mov    $0x1000,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r12,%rdx
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     122e <get_b+0xde>
mov    %r14,0x18(%rsp)
xor    %ebp,%ebp
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r13
jmp    11f3 <get_b+0xa3>
movsd  0x20(%rsp),%xmm0
movsd  %xmm0,(%r15,%rbp,8)
add    $0x1,%rbp
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     1227 <get_b+0xd7>
mov    0x8(%rsp),%rdi
lea    0xe03(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1040 <sscanf@plt>
cmp    %rbp,%rbx
ja     11d0 <get_b+0x80>
lea    0x8(,%rbx,8),%rsi
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <realloc@plt>
mov    %rax,%r15
jmp    11d0 <get_b+0x80>
mov    0x18(%rsp),%r14
jmp    1230 <get_b+0xe0>
xor    %ebp,%ebp
mov    %ebp,(%r14)
mov    %r15,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%lf\0A\00"
define double* @get_b(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i64
%7 = alloca double*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca double
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
%12 = load i32*, i32** %4
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = call i8* @calloc(i64 %15, i32 8)
%17 = bitcast i8* %16 to double*
store double* %17, double** %7
%18 = load i8*, i8** %3
%19 = call i32* @get_fp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %8
store i64 4096, i64* %9
%20 = load i64, i64* %9
%21 = call i8* @calloc(i64 %20, i32 1)
store i8* %21, i8** %10
br label %22
22: ; preds = %40, %2
%23 = load i32*, i32** %8
%24 = call i32 @getline(i8** %10, i64* %9, i32* %23)
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %48
26: ; preds = %22
%27 = load i8*, i8** %10
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double* %11)
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = load i64, i64* %6
%32 = icmp uge i64 %30, %31
br i1 %32, label %33, label %40
33: ; preds = %26
%34 = load i64, i64* %6
%35 = add i64 %34, 1
store i64 %35, i64* %6
%36 = load double*, double** %7
%37 = load i64, i64* %6
%38 = mul i64 %37, 8
%39 = call double* @realloc(double* %36, i64 %38)
store double* %39, double** %7
br label %40
40: ; preds = %33, %26
%41 = load double, double* %11
%42 = load double*, double** %7
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
store double %41, double* %45
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %22
48: ; preds = %22
%49 = load i32, i32* %5
%50 = load i32*, i32** %4
store i32 %49, i32* %50
%51 = load double*, double** %7
ret double* %51
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%lf\0A\00"
define double* @get_b(i8* %0, i32* nocapture %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca double
%6 = load i32, i32* %1
%7 = sext i32 %6 to i64
%8 = tail call i8* @calloc(i64 %7, i32 8)
%9 = bitcast i8* %8 to double*
%10 = tail call i32* @get_fp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = bitcast i64* %3 to i8*
store i64 4096, i64* %3
%12 = bitcast i8** %4 to i8*
%13 = tail call i8* @calloc(i64 4096, i32 1)
store i8* %13, i8** %4
%14 = bitcast double* %5 to i8*
%15 = call i32 @getline(i8** %4, i64* %3, i32* %10)
%16 = icmp eq i32 %15, -1
br i1 %16, label %38, label %17
17: ; preds = %2, %28
%18 = phi i64 [ %33, %28 ], [ 0, %2 ]
%19 = phi double* [ %30, %28 ], [ %9, %2 ]
%20 = phi i64 [ %29, %28 ], [ %7, %2 ]
%21 = load i8*, i8** %4
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double* %5)
%23 = icmp ugt i64 %20, %18
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = add i64 %20, 1
%26 = shl i64 %25, 3
%27 = call double* @realloc(double* %19, i64 %26)
br label %28
28: ; preds = %24, %17
%29 = phi i64 [ %25, %24 ], [ %20, %17 ]
%30 = phi double* [ %27, %24 ], [ %19, %17 ]
%31 = load double, double* %5
%32 = getelementptr inbounds double, double* %30, i64 %18
store double %31, double* %32
%33 = add nuw i64 %18, 1
%34 = call i32 @getline(i8** %4, i64* %3, i32* %10)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %17
36: ; preds = %28
%37 = trunc i64 %33 to i32
br label %38
38: ; preds = %36, %2
%39 = phi double* [ %9, %2 ], [ %30, %36 ]
%40 = phi i32 [ 0, %2 ], [ %37, %36 ]
store i32 %40, i32* %1
ret double* %39
}