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

/* Variables and functions */
double atof(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int readMatrixDouble(double *mat, const char *fileName) {
  long i = 0;
  FILE *fp;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  fp = fopen(fileName, "r");
  if (fp == NULL)
    return -1;
  while ((read = getline(&line, &len, fp)) != -1) {
    mat[i] = atof(line);
    i++;
  }
  free(line);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<readMatrixDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a3 <readMatrixDouble+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <readMatrixDouble+0xb5>
jmp    11a8 <readMatrixDouble+0x58>
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     11ec <readMatrixDouble+0x9c>
mov    -0x30(%rbp),%rdi
call   1040 <atof@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a8 <readMatrixDouble+0x58>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readMatrixDouble>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe86(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11eb <readMatrixDouble+0x9b>
mov    %rax,%r14
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     11d5 <readMatrixDouble+0x85>
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,(%rbx)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1070 <getline@plt>
add    $0x8,%rbx
cmp    $0xffffffff,%eax
jne    11b0 <readMatrixDouble+0x60>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    11f0 <readMatrixDouble+0xa0>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @readMatrixDouble(double* %0, i8* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store double* %0, double** %4
store i8* %1, i8** %5
store i64 0, i64* %6
store i8* null, i8** %8
store i64 0, i64* %9
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %34
16: ; preds = %2
br label %17
17: ; preds = %21, %16
%18 = load i32*, i32** %7
%19 = call i32 @getline(i8** %8, i64* %9, i32* %18)
store i32 %19, i32* %10
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i8*, i8** %8
%23 = call double @atof(i8* %22)
%24 = load double*, double** %4
%25 = load i64, i64* %6
%26 = getelementptr inbounds double, double* %24, i64 %25
store double %23, double* %26
%27 = load i64, i64* %6
%28 = add nsw i64 %27, 1
store i64 %28, i64* %6
br label %17
29: ; preds = %17
%30 = load i8*, i8** %8
%31 = call i32 @free(i8* %30)
%32 = load i32*, i32** %7
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %3
br label %34
34: ; preds = %29, %15
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @readMatrixDouble(double* nocapture writeonly %0, i8* nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = tail call i32* @fopen(i8* %1, 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 = %2
%10 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%11 = icmp eq i32 %10, -1
br i1 %11, label %20, label %12
12: ; preds = %9, %12
%13 = phi i64 [ %17, %12 ], [ 0, %9 ]
%14 = load i8*, i8** %3
%15 = call double @atof(i8* %14)
%16 = getelementptr inbounds double, double* %0, i64 %13
store double %15, double* %16
%17 = add nuw nsw i64 %13, 1
%18 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %12
20: ; preds = %12, %9
%21 = load i8*, i8** %3
%22 = call i32 @free(i8* %21)
%23 = call i32 @fclose(i32* %7)
br label %24
24: ; preds = %2, %20
%25 = phi i32 [ 0, %20 ], [ -1, %2 ]
ret i32 %25
}