#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*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fisCreateMatrix(int, int, int);
int /*<<< orphan*/ fisError(char *);
int /*<<< orphan*/ *fisOpenFile(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, ...);
double **returnDataMatrix(char *filename, int *row_n_p, int *col_n_p) {
  double **datamatrix;
  int element_n = 0, row_n = 0, col_n = 0, i, j;
  FILE *fp;
  char str1[500];
  double num1;
  fp = fisOpenFile(filename, "r");
  row_n = 0;
  while (fscanf(fp, " %[^\n] ", str1) != EOF)
    row_n++;
  fclose(fp);
  fp = fisOpenFile(filename, "r");
  while (fscanf(fp, "%lf", &num1) != EOF)
    element_n++;
  fclose(fp);
  col_n = element_n / row_n;
  datamatrix = (double **)fisCreateMatrix(row_n, col_n, sizeof(double));
  fp = fisOpenFile(filename, "r");
  for (i = 0; i < row_n; i++) {
    for (j = 0; j < col_n; j++) {
      if (fscanf(fp, "%lf", &num1) != EOF)
        datamatrix[i][j] = num1;
      else
        fisError("Not enough data in data file!");
    }
  }
  fclose(fp);
  *row_n_p = row_n;
  *col_n_p = col_n;
  return (datamatrix);
}


x86 assembly (clang, -O0):
<returnDataMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fisOpenFile@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x240(%rbp),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
je     11ce <returnDataMatrix+0x7e>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1197 <returnDataMatrix+0x47>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1060 <fisOpenFile@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe14(%rip),%rsi
lea    -0x248(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%rax
je     1222 <returnDataMatrix+0xd2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11eb <returnDataMatrix+0x9b>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    $0x8,%edx
call   1050 <fisCreateMatrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdac(%rip),%rsi
call   1060 <fisOpenFile@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1300 <returnDataMatrix+0x1b0>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12ed <returnDataMatrix+0x19d>
mov    -0x40(%rbp),%rdi
lea    0xd7c(%rip),%rsi
lea    -0x248(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    0x2d45(%rip),%rcx
cmp    (%rcx),%rax
je     12ce <returnDataMatrix+0x17e>
movsd  -0x248(%rbp),%xmm0
ff
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    12da <returnDataMatrix+0x18a>
lea    0xd39(%rip),%rdi
call   1030 <fisError@plt>
jmp    12df <returnDataMatrix+0x18f>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1277 <returnDataMatrix+0x127>
jmp    12f2 <returnDataMatrix+0x1a2>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1264 <returnDataMatrix+0x114>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<returnDataMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
mov    %rdx,0x30(%rsp)
mov    %rsi,0x28(%rsp)
mov    %rdi,%r13
lea    0xe8b(%rip),%rsi
call   1060 <fisOpenFile@plt>
mov    %rax,%rbx
mov    $0xffffffffffffffff,%rbp
lea    0xe77(%rip),%r14
lea    0x40(%rsp),%r15
mov    0x2e51(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
add    $0x1,%rbp
cmp    (%r12),%rax
jne    11a0 <returnDataMatrix+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe37(%rip),%rsi
mov    %r13,0x20(%rsp)
mov    %r13,%rdi
call   1060 <fisOpenFile@plt>
mov    %rax,%rbx
mov    $0xffffffff,%r13d
lea    0xe24(%rip),%r14
lea    0x18(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
add    $0x1,%r13d
cmp    (%r12),%rax
jne    11f0 <returnDataMatrix+0xa0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r13d,%eax
xor    %edx,%edx
div    %ebp
mov    %ebp,%edi
mov    %eax,0x8(%rsp)
mov    %eax,%esi
mov    $0x8,%edx
call   1050 <fisCreateMatrix@plt>
mov    %rax,0x10(%rsp)
lea    0xdc9(%rip),%rsi
mov    0x20(%rsp),%rdi
call   1060 <fisOpenFile@plt>
mov    %rax,%rbx
test   %ebp,%ebp
je     12f6 <returnDataMatrix+0x1a6>
mov    %r13d,%eax
mov    0x8(%rsp),%ecx
cmp    $0x2,%ecx
mov    $0x1,%r15d
cmovae %ecx,%r15d
lea    0x18(%rsp),%r13
xor    %r12d,%r12d
mov    %rbp,0x38(%rsp)
mov    %eax,0xc(%rsp)
jmp    1292 <returnDataMatrix+0x142>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r12
mov    0x38(%rsp),%rbp
cmp    %r12,%rbp
mov    0xc(%rsp),%eax
je     12f6 <returnDataMatrix+0x1a6>
cmp    %eax,%ebp
mov    0x2d4d(%rip),%rbp
ja     1280 <returnDataMatrix+0x130>
xor    %r14d,%r14d
jmp    12c5 <returnDataMatrix+0x175>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd57(%rip),%rdi
call   1030 <fisError@plt>
add    $0x1,%r14
cmp    %r15,%r14
je     1280 <returnDataMatrix+0x130>
mov    %rbx,%rdi
lea    0xd3b(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
cmp    0x0(%rbp),%rax
je     12b0 <returnDataMatrix+0x160>
movsd  0x18(%rsp),%xmm0
mov    0x10(%rsp),%rax
mov    (%rax,%r12,8),%rax
movsd  %xmm0,(%rax,%r14,8)
jmp    12bc <returnDataMatrix+0x16c>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x28(%rsp),%rax
mov    %ebp,(%rax)
mov    0x30(%rsp),%rax
mov    0x8(%rsp),%ecx
mov    %ecx,(%rax)
mov    0x10(%rsp),%rax
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c" %[^\0A] \00"
@EOF = global i64 0
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [30 x i8] c"Not enough data in data file!\00"
define double** @returnDataMatrix(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca double**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca [500 x i8]
%15 = alloca double
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%16 = load i8*, i8** %4
%17 = call i32* @fisOpenFile(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %13
store i32 0, i32* %9
br label %18
18: ; preds = %24, %3
%19 = load i32*, i32** %13
%20 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%21 = call i64 (i32*, i8*, ...) @fscanf(i32* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i64, i64* @EOF
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
br label %18
27: ; preds = %18
%28 = load i32*, i32** %13
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %4
%31 = call i32* @fisOpenFile(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %31, i32** %13
br label %32
32: ; preds = %37, %27
%33 = load i32*, i32** %13
%34 = call i64 (i32*, i8*, ...) @fscanf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %15)
%35 = load i64, i64* @EOF
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %32
40: ; preds = %32
%41 = load i32*, i32** %13
%42 = call i32 @fclose(i32* %41)
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = sdiv i32 %43, %44
store i32 %45, i32* %10
%46 = load i32, i32* %9
%47 = load i32, i32* %10
%48 = call i64 @fisCreateMatrix(i32 %46, i32 %47, i32 8)
%49 = inttoptr i64 %48 to double**
store double** %49, double*** %7
%50 = load i8*, i8** %4
%51 = call i32* @fisOpenFile(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %51, i32** %13
store i32 0, i32* %11
br label %52
52: ; preds = %83, %40
%53 = load i32, i32* %11
%54 = load i32, i32* %9
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %86
56: ; preds = %52
store i32 0, i32* %12
br label %57
57: ; preds = %79, %56
%58 = load i32, i32* %12
%59 = load i32, i32* %10
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %82
61: ; preds = %57
%62 = load i32*, i32** %13
%63 = call i64 (i32*, i8*, ...) @fscanf(i32* %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %15)
%64 = load i64, i64* @EOF
%65 = icmp ne i64 %63, %64
br i1 %65, label %66, label %76
66: ; preds = %61
%67 = load double, double* %15
%68 = load double**, double*** %7
%69 = load i32, i32* %11
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double*, double** %68, i64 %70
%72 = load double*, double** %71
%73 = load i32, i32* %12
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
store double %67, double* %75
br label %78
76: ; preds = %61
%77 = call i32 @fisError(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %78
78: ; preds = %76, %66
br label %79
79: ; preds = %78
%80 = load i32, i32* %12
%81 = add nsw i32 %80, 1
store i32 %81, i32* %12
br label %57
82: ; preds = %57
br label %83
83: ; preds = %82
%84 = load i32, i32* %11
%85 = add nsw i32 %84, 1
store i32 %85, i32* %11
br label %52
86: ; preds = %52
%87 = load i32*, i32** %13
%88 = call i32 @fclose(i32* %87)
%89 = load i32, i32* %9
%90 = load i32*, i32** %5
store i32 %89, i32* %90
%91 = load i32, i32* %10
%92 = load i32*, i32** %6
store i32 %91, i32* %92
%93 = load double**, double*** %7
ret double** %93
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c" %[^\0A] \00"
@EOF = global i64 0
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [30 x i8] c"Not enough data in data file!\00"
define double** @returnDataMatrix(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [500 x i8]
%5 = alloca double
%6 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%7 = bitcast double* %5 to i8*
%8 = tail call i32* @fisOpenFile(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %9, %3
%10 = phi i32 [ 0, %3 ], [ %14, %9 ]
%11 = call i64 (i32*, i8*, ...) @fscanf(i32* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
%14 = add nuw nsw i32 %10, 1
br i1 %13, label %15, label %9
15: ; preds = %9
%16 = call i32 @fclose(i32* %8)
%17 = call i32* @fisOpenFile(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %18, %15
%19 = phi i32 [ 0, %15 ], [ %23, %18 ]
%20 = call i64 (i32*, i8*, ...) @fscanf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %5)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
%23 = add nuw nsw i32 %19, 1
br i1 %22, label %24, label %18
24: ; preds = %18
%25 = call i32 @fclose(i32* %17)
%26 = udiv i32 %19, %10
%27 = call i64 @fisCreateMatrix(i32 %10, i32 %26, i32 8)
%28 = inttoptr i64 %27 to double**
%29 = call i32* @fisOpenFile(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i32 %10, 0
br i1 %30, label %57, label %31
31: ; preds = %24
%32 = icmp ugt i32 %10, %19
%33 = zext i32 %10 to i64
%34 = call i32 @llvm.umax.i32(i32 %26, i32 1)
%35 = zext i32 %34 to i64
br label %36
36: ; preds = %31, %54
%37 = phi i64 [ 0, %31 ], [ %55, %54 ]
br i1 %32, label %54, label %38
38: ; preds = %36
%39 = getelementptr inbounds double*, double** %28, i64 %37
br label %40
40: ; preds = %38, %51
%41 = phi i64 [ 0, %38 ], [ %52, %51 ]
%42 = call i64 (i32*, i8*, ...) @fscanf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %5)
%43 = load i64, i64* @EOF
%44 = icmp eq i64 %42, %43
br i1 %44, label %49, label %45
45: ; preds = %40
%46 = load double, double* %5
%47 = load double*, double** %39
%48 = getelementptr inbounds double, double* %47, i64 %41
store double %46, double* %48
br label %51
49: ; preds = %40
%50 = call i32 @fisError(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %45, %49
%52 = add nuw nsw i64 %41, 1
%53 = icmp eq i64 %52, %35
br i1 %53, label %54, label %40
54: ; preds = %51, %36
%55 = add nuw nsw i64 %37, 1
%56 = icmp eq i64 %55, %33
br i1 %56, label %57, label %36
57: ; preds = %54, %24
%58 = call i32 @fclose(i32* %29)
store i32 %10, i32* %1
store i32 %26, i32* %2
ret double** %28
}