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

/* Variables and functions */
double atof(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
void readFileAsVector(char **path, int *maxVals, double *vals, int *readVals) {
  FILE *fp = fopen(*path, "r");
  if (fp == NULL) {
    return;
  }
  char buf[256];
  *readVals = 0;
  while (fgets(buf, sizeof(buf), fp)) {
    vals[*readVals] = atof(buf);
    *readVals = *readVals + 1;
    if (*readVals >= *maxVals) {
      fclose(fp);
      return;
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<readFileAsVector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1182 <readFileAsVector+0x42>
jmp    1204 <readFileAsVector+0xc4>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11fb <readFileAsVector+0xbb>
lea    -0x130(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jl     11f6 <readFileAsVector+0xb6>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1204 <readFileAsVector+0xc4>
jmp    118c <readFileAsVector+0x4c>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFileAsVector>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    (%rdi),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b8 <readFileAsVector+0x78>
mov    %rax,%r12
movl   $0x0,(%rbx)
mov    %rsp,%r13
nopl   0x0(%rax)
mov    %r13,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11b0 <readFileAsVector+0x70>
mov    %r13,%rdi
call   1030 <atof@plt>
movslq (%rbx),%rax
movsd  %xmm0,(%r14,%rax,8)
add    $0x1,%eax
mov    %eax,(%rbx)
cmp    (%r15),%eax
jl     1180 <readFileAsVector+0x40>
mov    %r12,%rdi
call   1040 <fclose@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define void @readFileAsVector(i8** %0, i32* %1, double* %2, i32* %3) {
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca double*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [256 x i8]
store i8** %0, i8*** %5
store i32* %1, i32** %6
store double* %2, double** %7
store i32* %3, i32** %8
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %9
%14 = load i32*, i32** %9
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
br label %48
17: ; preds = %4
%18 = load i32*, i32** %8
store i32 0, i32* %18
br label %19
19: ; preds = %44, %17
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%21 = load i32*, i32** %9
%22 = call i64 @fgets(i8* %20, i32 256, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %45
24: ; preds = %19
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%26 = call double @atof(i8* %25)
%27 = load double*, double** %7
%28 = load i32*, i32** %8
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %27, i64 %30
store double %26, double* %31
%32 = load i32*, i32** %8
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1
%35 = load i32*, i32** %8
store i32 %34, i32* %35
%36 = load i32*, i32** %8
%37 = load i32, i32* %36
%38 = load i32*, i32** %6
%39 = load i32, i32* %38
%40 = icmp sge i32 %37, %39
br i1 %40, label %41, label %44
41: ; preds = %24
%42 = load i32*, i32** %9
%43 = call i32 @fclose(i32* %42)
br label %48
44: ; preds = %24
br label %19
45: ; preds = %19
%46 = load i32*, i32** %9
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %45, %41, %16
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @readFileAsVector(i8** nocapture %0, i32* nocapture %1, double* nocapture writeonly %2, i32* nocapture %3) {
%5 = alloca [256 x i8]
%6 = load i8*, i8** %0
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %24, label %9
9: ; preds = %4
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
store i32 0, i32* %3
br label %11
11: ; preds = %14, %9
%12 = call i64 @fgets(i8* %10, i32 256, i32* %7)
%13 = icmp eq i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = call double @atof(i8* %10)
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %2, i64 %17
store double %15, double* %18
%19 = add nsw i32 %16, 1
store i32 %19, i32* %3
%20 = load i32, i32* %1
%21 = icmp slt i32 %19, %20
br i1 %21, label %11, label %22
22: ; preds = %11, %14
%23 = call i32 @fclose(i32* %7)
br label %24
24: ; preds = %4, %22
ret void
}