#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
double *realloc(double *, int);
int sscanf(char *, char *, double *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int read_column(double **delivery_array, FILE *input) {
  double current;
  char line[50];
  int index = 0;
  int size = 50;
  double *build_array;
  double *temp;
  if (!input) {
    input = stdin;
  }
  build_array = (double *)malloc(size * sizeof(double));
  if (build_array == NULL) {
    fputs("Error allocating memory", stderr);
    exit(EXIT_FAILURE);
  }
  while (fgets(line, sizeof(line), input) != NULL) {
    int ret_val;
    if (!strcmp(line, "\n")) {
      continue;
    }
    ret_val = sscanf(line, "%lf", &current);
    if (ret_val == 0) {
      fprintf(stderr, "Error parsing numerics on line %d: %s", index + 1, line);
      exit(EXIT_FAILURE);
    }
    build_array[index] = current;
    index++;
    if (index == size) {
      double *temp;
      size += 300;
      temp = realloc(build_array, size * sizeof(double));
      if (temp == NULL) {
        free(build_array);
        fputs("Error allocating memory", stderr);
        exit(EXIT_FAILURE);
      }
      build_array = temp;
    }
  }
  size = index;
  temp = realloc(build_array, size * sizeof(double));
  if (temp == NULL) {
    free(build_array);
    fputs("Error allocating memory", stderr);
    exit(EXIT_FAILURE);
  }
  build_array = temp;
  *delivery_array = build_array;
  return (size);
}


x86 assembly (clang, -O0):
<read_column>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x32,-0x58(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ca <read_column+0x3a>
mov    0x2e25(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
movslq -0x58(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    120b <read_column+0x7b>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    0xe08(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    1210 <read_column+0x80>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x32,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1325 <read_column+0x195>
lea    -0x50(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    124a <read_column+0xba>
jmp    1210 <read_column+0x80>
lea    -0x50(%rbp),%rdi
lea    0xdc5(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1090 <sscanf@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jne    1298 <read_column+0x108>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
add    $0x1,%edx
lea    -0x50(%rbp),%rcx
lea    0xd99(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
movsd  -0x18(%rbp),%xmm0
mov    -0x60(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
jne    1320 <read_column+0x190>
mov    -0x58(%rbp),%eax
add    $0x12c,%eax
mov    %eax,-0x58(%rbp)
mov    -0x60(%rbp),%rdi
movslq -0x58(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    1318 <read_column+0x188>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
lea    0xcfb(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x78(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    1210 <read_column+0x80>
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x60(%rbp),%rdi
movslq -0x58(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1379 <read_column+0x1e9>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%esi
lea    0xc9a(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x68(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_column>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r13
mov    %rdi,%rbx
test   %rsi,%rsi
jne    11a3 <read_column+0x23>
mov    0x2e48(%rip),%rax
mov    (%rax),%r13
mov    $0x190,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12cf <read_column+0x14f>
mov    %rax,%r15
mov    %rbx,(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x32,%ebx
mov    $0x32,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     127a <read_column+0xfa>
lea    0x10(%rsp),%r12
jmp    120f <read_column+0x8f>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%r14d
mov    %ebp,%ebx
mov    %ebx,%ebp
mov    %r12,%rdi
mov    $0x32,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
mov    %r14d,%ebx
test   %rax,%rax
je     127a <read_column+0xfa>
cmpw   $0xa,0x10(%rsp)
je     11f0 <read_column+0x70>
mov    %r12,%rdi
lea    0xdf7(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1080 <sscanf@plt>
test   %eax,%eax
je     12a6 <read_column+0x126>
movsd  0x8(%rsp),%xmm0
movslq %ebp,%rax
movsd  %xmm0,(%r15,%rax,8)
add    $0x1,%eax
cmp    %ebx,%eax
jne    1270 <read_column+0xf0>
lea    0x960(,%rbx,8),%esi
mov    %r15,%rdi
call   1090 <realloc@plt>
test   %rax,%rax
je     12c7 <read_column+0x147>
lea    0x12c(%rbx),%r14d
mov    %rax,%r15
jmp    11f5 <read_column+0x75>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%r14d
mov    %eax,%ebx
jmp    11f5 <read_column+0x75>
lea    0x0(,%rbp,8),%esi
mov    %r15,%rdi
call   1090 <realloc@plt>
test   %rax,%rax
je     12c7 <read_column+0x147>
mov    (%rsp),%rcx
mov    %rax,(%rcx)
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
add    $0x1,%ebp
lea    0xd63(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    %ebp,%edx
call   1060 <fprintf@plt>
jmp    12e4 <read_column+0x164>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
lea    0xd21(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [24 x i8] c"Error allocating memory\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [38 x i8] c"Error parsing numerics on line %d: %s\00"
define i32 @read_column(double** %0, i32* %1) {
%3 = alloca double**
%4 = alloca i32*
%5 = alloca double
%6 = alloca [50 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca double*
store double** %0, double*** %3
store i32* %1, i32** %4
store i32 0, i32* %7
store i32 50, i32* %8
%13 = load i32*, i32** %4
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = load i32*, i32** @stdin
store i32* %16, i32** %4
br label %17
17: ; preds = %15, %2
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to double*
store double* %23, double** %9
%24 = load double*, double** %9
%25 = icmp eq double* %24, null
br i1 %25, label %26, label %31
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %17
br label %32
32: ; preds = %86, %41, %31
%33 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%34 = load i32*, i32** %4
%35 = call i32* @fgets(i8* %33, i32 50, i32* %34)
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %87
37: ; preds = %32
%38 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %37
br label %32
42: ; preds = %37
%43 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%44 = call i32 @sscanf(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %5)
store i32 %44, i32* %11
%45 = load i32, i32* %11
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
%51 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%52 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %50, i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %42
%56 = load double, double* %5
%57 = load double*, double** %9
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
store double %56, double* %60
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
%63 = load i32, i32* %7
%64 = load i32, i32* %8
%65 = icmp eq i32 %63, %64
br i1 %65, label %66, label %86
66: ; preds = %55
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 300
store i32 %68, i32* %8
%69 = load double*, double** %9
%70 = load i32, i32* %8
%71 = sext i32 %70 to i64
%72 = mul i64 %71, 8
%73 = trunc i64 %72 to i32
%74 = call double* @realloc(double* %69, i32 %73)
store double* %74, double** %12
%75 = load double*, double** %12
%76 = icmp eq double* %75, null
br i1 %76, label %77, label %84
77: ; preds = %66
%78 = load double*, double** %9
%79 = call i32 @free(double* %78)
%80 = load i32, i32* @stderr
%81 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %80)
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %66
%85 = load double*, double** %12
store double* %85, double** %9
br label %86
86: ; preds = %84, %55
br label %32
87: ; preds = %32
%88 = load i32, i32* %7
store i32 %88, i32* %8
%89 = load double*, double** %9
%90 = load i32, i32* %8
%91 = sext i32 %90 to i64
%92 = mul i64 %91, 8
%93 = trunc i64 %92 to i32
%94 = call double* @realloc(double* %89, i32 %93)
store double* %94, double** %10
%95 = load double*, double** %10
%96 = icmp eq double* %95, null
br i1 %96, label %97, label %104
97: ; preds = %87
%98 = load double*, double** %9
%99 = call i32 @free(double* %98)
%100 = load i32, i32* @stderr
%101 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %100)
%102 = load i32, i32* @EXIT_FAILURE
%103 = call i32 @exit(i32 %102)
unreachable
104: ; preds = %87
%105 = load double*, double** %10
store double* %105, double** %9
%106 = load double*, double** %9
%107 = load double**, double*** %3
store double* %106, double** %107
%108 = load i32, i32* %8
ret i32 %108
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [24 x i8] c"Error allocating memory\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [38 x i8] c"Error parsing numerics on line %d: %s\00"
define i32 @read_column(double** nocapture writeonly %0, i32* %1) {
%3 = alloca double
%4 = alloca [50 x i8]
%5 = bitcast double* %3 to i8*
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32* %1, null
%8 = load i32*, i32** @stdin
%9 = select i1 %7, i32* %8, i32* %1
%10 = tail call i64 @malloc(i32 400)
%11 = inttoptr i64 %10 to double*
%12 = icmp eq i64 %10, 0
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = call i32* @fgets(i8* %6, i32 50, i32* %9)
%15 = icmp eq i32* %14, null
br i1 %15, label %61, label %16
16: ; preds = %13
%17 = bitcast [50 x i8]* %4 to i16*
br label %23
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = tail call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %16, %55
%24 = phi i32 [ 0, %16 ], [ %58, %55 ]
%25 = phi i32 [ 50, %16 ], [ %57, %55 ]
%26 = phi double* [ %11, %16 ], [ %56, %55 ]
%27 = load i16, i16* %17
%28 = icmp eq i16 %27, 10
br i1 %28, label %55, label %29
29: ; preds = %23
%30 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %3)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = add nsw i32 %24, 1
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %34, i8* %6)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %29
%39 = load double, double* %3
%40 = sext i32 %24 to i64
%41 = getelementptr inbounds double, double* %26, i64 %40
store double %39, double* %41
%42 = add nsw i32 %24, 1
%43 = icmp eq i32 %42, %25
br i1 %43, label %44, label %55
44: ; preds = %38
%45 = add nsw i32 %25, 300
%46 = shl i32 %45, 3
%47 = call double* @realloc(double* %26, i32 %46)
%48 = icmp eq double* %47, null
br i1 %48, label %49, label %55
49: ; preds = %44
%50 = call i32 @free(double* %26)
%51 = load i32, i32* @stderr
%52 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %38, %44, %23
%56 = phi double* [ %26, %23 ], [ %26, %38 ], [ %47, %44 ]
%57 = phi i32 [ %25, %23 ], [ %25, %38 ], [ %45, %44 ]
%58 = phi i32 [ %24, %23 ], [ %42, %38 ], [ %25, %44 ]
%59 = call i32* @fgets(i8* %6, i32 50, i32* %9)
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %23
61: ; preds = %55, %13
%62 = phi double* [ %11, %13 ], [ %56, %55 ]
%63 = phi i32 [ 0, %13 ], [ %58, %55 ]
%64 = shl i32 %63, 3
%65 = call double* @realloc(double* %62, i32 %64)
%66 = icmp eq double* %65, null
br i1 %66, label %67, label %73
67: ; preds = %61
%68 = call i32 @free(double* %62)
%69 = load i32, i32* @stderr
%70 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %61
store double* %65, double** %0
ret i32 %63
}