#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 scalar_t__ *nlns;
typedef size_t i;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double atof(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
char *strtok(char *, char *);
double *read_file_double(char *fname, int nlns, int ncol, char *delim) {
  FILE *datei;
  char *txt;
  char *tok;
  int i;
  int j = 0;
  size_t nbytes = 0;
  int ndatpt = ncol * nlns;
  double *data = (double *)malloc(ndatpt * sizeof(double));
  datei = fopen(fname, "r");
  if (datei != NULL) {
    while (getline(&txt, &nbytes, datei) != -1) {
      tok = strtok(txt, delim);
      i = 0;
      while (tok != NULL) {
        (data[(i) * (nlns) + (j)]) = atof(tok);
        tok = strtok(NULL, delim);
        ++i;
      }
      ++j;
    }
    fclose(datei);
    free(txt);
  }
  return data;
}


x86 assembly (clang, -O0):
<read_file_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1271 <read_file_double+0x101>
jmp    11d6 <read_file_double+0x66>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     125f <read_file_double+0xef>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1251 <read_file_double+0xe1>
mov    -0x30(%rbp),%rdi
call   1040 <atof@plt>
mov    -0x50(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1208 <read_file_double+0x98>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11d6 <read_file_double+0x66>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %esi,%r12d
mov    %rdi,%r14
movq   $0x0,0x10(%rsp)
imul   %esi,%edx
lea    0x0(,%rdx,8),%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0xe57(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1257 <read_file_double+0xe7>
mov    %rax,%r15
mov    %rbp,0x8(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     1241 <read_file_double+0xd1>
movslq %r12d,%rbp
shl    $0x3,%rbp
lea    0x10(%rsp),%r13
mov    0x8(%rsp),%r12
jmp    1207 <read_file_double+0x97>
nopw   0x0(%rax,%rax,1)
mov    %rsp,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1090 <getline@plt>
add    $0x8,%r12
cmp    $0xffffffff,%eax
je     1241 <read_file_double+0xd1>
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11f0 <read_file_double+0x80>
mov    %r12,%r14
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1040 <atof@plt>
movsd  %xmm0,(%r14)
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <strtok@plt>
add    %rbp,%r14
test   %rax,%rax
jne    1220 <read_file_double+0xb0>
jmp    11f0 <read_file_double+0x80>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rbp
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define double* @read_file_double(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i32
%16 = alloca double*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32 0, i32* %13
store i64 0, i64* %14
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = mul nsw i32 %17, %18
store i32 %19, i32* %15
%20 = load i32, i32* %15
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 8
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to double*
store double* %25, double** %16
%26 = load i8*, i8** %5
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %9
%28 = load i32*, i32** %9
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %65
30: ; preds = %4
br label %31
31: ; preds = %57, %30
%32 = load i32*, i32** %9
%33 = call i32 @getline(i8** %10, i64* %14, i32* %32)
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %60
35: ; preds = %31
%36 = load i8*, i8** %10
%37 = load i8*, i8** %8
%38 = call i8* @strtok(i8* %36, i8* %37)
store i8* %38, i8** %11
store i32 0, i32* %12
br label %39
39: ; preds = %42, %35
%40 = load i8*, i8** %11
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %57
42: ; preds = %39
%43 = load i8*, i8** %11
%44 = call double @atof(i8* %43)
%45 = load double*, double** %16
%46 = load i32, i32* %12
%47 = load i32, i32* %6
%48 = mul nsw i32 %46, %47
%49 = load i32, i32* %13
%50 = add nsw i32 %48, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %45, i64 %51
store double %44, double* %52
%53 = load i8*, i8** %8
%54 = call i8* @strtok(i8* null, i8* %53)
store i8* %54, i8** %11
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %12
br label %39
57: ; preds = %39
%58 = load i32, i32* %13
%59 = add nsw i32 %58, 1
store i32 %59, i32* %13
br label %31
60: ; preds = %31
%61 = load i32*, i32** %9
%62 = call i32 @fclose(i32* %61)
%63 = load i8*, i8** %10
%64 = call i32 @free(i8* %63)
br label %65
65: ; preds = %60, %4
%66 = load double*, double** %16
ret double* %66
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define double* @read_file_double(i8* nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = bitcast i8** %5 to i8*
%8 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%9 = shl i32 %1, 3
%10 = mul i32 %9, %2
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to double*
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %43, label %15
15: ; preds = %4
%16 = call i32 @getline(i8** %5, i64* %6, i32* %13)
%17 = icmp eq i32 %16, -1
br i1 %17, label %39, label %18
18: ; preds = %15
%19 = sext i32 %1 to i64
br label %20
20: ; preds = %18, %35
%21 = phi i64 [ 0, %18 ], [ %36, %35 ]
%22 = load i8*, i8** %5
%23 = call i8* @strtok(i8* %22, i8* %3)
%24 = icmp eq i8* %23, null
br i1 %24, label %35, label %25
25: ; preds = %20, %25
%26 = phi i64 [ %33, %25 ], [ 0, %20 ]
%27 = phi i8* [ %32, %25 ], [ %23, %20 ]
%28 = call double @atof(i8* %27)
%29 = mul nsw i64 %26, %19
%30 = add nsw i64 %29, %21
%31 = getelementptr inbounds double, double* %12, i64 %30
store double %28, double* %31
%32 = call i8* @strtok(i8* null, i8* %3)
%33 = add nuw i64 %26, 1
%34 = icmp eq i8* %32, null
br i1 %34, label %35, label %25
35: ; preds = %25, %20
%36 = add nuw i64 %21, 1
%37 = call i32 @getline(i8** %5, i64* %6, i32* %13)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %20
39: ; preds = %35, %15
%40 = call i32 @fclose(i32* %13)
%41 = load i8*, i8** %5
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %39, %4
ret double* %12
}