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

/* Variables and functions */
double atof(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strtok(char *, char *);
double *readMatrixFile(FILE *file, int rows, int columns) {
  int j = 0, i = 0;
  char string[100];
  rewind(file);
  double *matrix = (double *)malloc(rows * columns * sizeof(double));
  while (fgets(string, sizeof(string), file) != NULL) {
    for (j = 0; j < columns; j++) {
      *(matrix + i * columns + j) = atof(strtok(j == 0 ? string : NULL, ","));
    }
    i++;
  }
  return matrix;
}


x86 assembly (clang, -O0):
<readMatrixFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1245 <readMatrixFile+0xf5>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1237 <readMatrixFile+0xe7>
cmpl   $0x0,-0x14(%rbp)
jne    11e0 <readMatrixFile+0x90>
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
jmp    11ee <readMatrixFile+0x9e>
xor    %eax,%eax
mov    %rax,-0x90(%rbp)
jmp    11ee <readMatrixFile+0x9e>
mov    -0x90(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1070 <strtok@plt>
mov    %eax,%edi
call   1030 <atof@plt>
mov    -0x88(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0x10(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ba <readMatrixFile+0x6a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1197 <readMatrixFile+0x47>
mov    -0x88(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readMatrixFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
call   1040 <rewind@plt>
mov    %ebp,0xc(%rsp)
imul   %ebp,%ebx
shl    $0x3,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %r14,0x18(%rsp)
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     121c <readMatrixFile+0xcc>
movslq 0xc(%rsp),%r13
mov    %r13d,%r14d
shl    $0x3,%r13
lea    0xe4b(%rip),%rbx
mov    0x10(%rsp),%r15
jmp    11da <readMatrixFile+0x8a>
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x64,%esi
mov    0x18(%rsp),%rdx
call   1050 <fgets@plt>
add    %r13,%r15
test   %rax,%rax
je     121c <readMatrixFile+0xcc>
cmpl   $0x0,0xc(%rsp)
jle    11c0 <readMatrixFile+0x70>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r12,%r12
mov    $0x0,%edi
cmove  %rbp,%rdi
mov    %rbx,%rsi
call   1070 <strtok@plt>
mov    %eax,%edi
call   1030 <atof@plt>
movsd  %xmm0,(%r15,%r12,8)
add    $0x1,%r12
cmp    %r12,%r14
jne    11f0 <readMatrixFile+0xa0>
jmp    11c0 <readMatrixFile+0x70>
mov    0x10(%rsp),%rax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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