#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 */
int /*<<< orphan*/ EXIT_FAILURE;
float *calloc(int, int);
int countSpaces(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fgetline_123(char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
float **malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
float **parseFloats(char *filename) {
  FILE *myfile;
  int i, j, h, w;
  float myvariable;
  float **floats;
  char *line;
  myfile = fopen(filename, "r");
  if (!myfile) {
    printf("No filename detected, exiting!\n");
    exit(EXIT_FAILURE);
  }
  h = 0;
  w = 0;
  while (fgetline_123(&line, myfile)) {
    h++;
    i = countSpaces(line) + 1;
    if (i > w)
      w = i;
  }
  floats = malloc(h * sizeof(float *));
  for (i = 0; i < h; i++)
    floats[i] = calloc(w, sizeof(float));
  rewind(myfile);
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      fscanf(myfile, "%f", &myvariable);
      floats[i][j] = myvariable;
    }
  }
  return floats;
}


x86 assembly (clang, -O0):
<parseFloats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d5 <parseFloats+0x45>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x38(%rbp),%rdi
call   1090 <fgetline_123@plt>
cmp    $0x0,%rax
je     1229 <parseFloats+0x99>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <countSpaces@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1224 <parseFloats+0x94>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11e3 <parseFloats+0x53>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1279 <parseFloats+0xe9>
mov    -0x20(%rbp),%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1243 <parseFloats+0xb3>
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12f7 <parseFloats+0x167>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12e4 <parseFloats+0x154>
mov    -0x10(%rbp),%rdi
lea    0xd6f(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1060 <fscanf@plt>
movss  -0x24(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    129c <parseFloats+0x10c>
jmp    12e9 <parseFloats+0x159>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1289 <parseFloats+0xf9>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseFloats>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe5b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12f9 <parseFloats+0x169>
mov    %rax,%r12
lea    0x18(%rsp),%rdi
mov    %rax,%rsi
call   1090 <fgetline_123@plt>
test   %rax,%rax
je     12d5 <parseFloats+0x145>
xor    %ebp,%ebp
lea    0x18(%rsp),%r15
xor    %r14d,%r14d
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    %r13d,%ebx
mov    0x18(%rsp),%rdi
call   1040 <countSpaces@plt>
lea    0x1(%rax),%r13d
cmp    %ebx,%eax
cmovl  %ebx,%r13d
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <fgetline_123@plt>
add    $0x1,%r14
add    $0x8,%ebp
test   %rax,%rax
jne    11e0 <parseFloats+0x50>
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %r14,0x20(%rsp)
mov    %rax,0x10(%rsp)
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,(%rbx)
add    $0x8,%rbx
add    $0xffffffffffffffff,%r14
jne    1230 <parseFloats+0xa0>
mov    %r12,0x28(%rsp)
mov    %r12,%rdi
call   1050 <rewind@plt>
mov    %r13d,0x8(%rsp)
mov    %r13d,%eax
xor    %r15d,%r15d
lea    0xd99(%rip),%rbx
lea    0xc(%rsp),%rbp
mov    %rax,0x30(%rsp)
mov    0x28(%rsp),%r13
mov    0x10(%rsp),%r14
jmp    128b <parseFloats+0xfb>
nop
add    $0x1,%r15
cmp    %r15,0x20(%rsp)
je     12ce <parseFloats+0x13e>
cmpl   $0x0,0x8(%rsp)
jle    1280 <parseFloats+0xf0>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1060 <fscanf@plt>
movss  0xc(%rsp),%xmm0
mov    (%r14,%r15,8),%rax
movss  %xmm0,(%rax,%r12,4)
mov    0x30(%rsp),%rax
add    $0x1,%r12
cmp    %r12,%rax
jne    12a0 <parseFloats+0x110>
jmp    1280 <parseFloats+0xf0>
mov    0x10(%rsp),%rbx
jmp    12e7 <parseFloats+0x157>
xor    %edi,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <rewind@plt>
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd05(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"No filename detected, exiting!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%f\00"
define float** @parseFloats(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca float**
%10 = alloca i8*
store i8* %0, i8** %2
%11 = load i8*, i8** %2
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = icmp ne i32* %13, null
br i1 %14, label %19, label %15
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %1
store i32 0, i32* %6
store i32 0, i32* %7
br label %20
20: ; preds = %35, %19
%21 = load i32*, i32** %3
%22 = call i64 @fgetline_123(i8** %10, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
%27 = load i8*, i8** %10
%28 = call i32 @countSpaces(i8* %27)
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = load i32, i32* %7
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = load i32, i32* %4
store i32 %34, i32* %7
br label %35
35: ; preds = %33, %24
br label %20
36: ; preds = %20
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 8
%40 = trunc i64 %39 to i32
%41 = call float** @malloc(i32 %40)
store float** %41, float*** %9
store i32 0, i32* %4
br label %42
42: ; preds = %53, %36
%43 = load i32, i32* %4
%44 = load i32, i32* %6
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %56
46: ; preds = %42
%47 = load i32, i32* %7
%48 = call float* @calloc(i32 %47, i32 4)
%49 = load float**, float*** %9
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds float*, float** %49, i64 %51
store float* %48, float** %52
br label %53
53: ; preds = %46
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %42
56: ; preds = %42
%57 = load i32*, i32** %3
%58 = call i32 @rewind(i32* %57)
store i32 0, i32* %4
br label %59
59: ; preds = %84, %56
%60 = load i32, i32* %4
%61 = load i32, i32* %6
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %87
63: ; preds = %59
store i32 0, i32* %5
br label %64
64: ; preds = %80, %63
%65 = load i32, i32* %5
%66 = load i32, i32* %7
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %83
68: ; preds = %64
%69 = load i32*, i32** %3
%70 = call i32 @fscanf(i32* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %8)
%71 = load float, float* %8
%72 = load float**, float*** %9
%73 = load i32, i32* %4
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds float*, float** %72, i64 %74
%76 = load float*, float** %75
%77 = load i32, i32* %5
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds float, float* %76, i64 %78
store float %71, float* %79
br label %80
80: ; preds = %68
%81 = load i32, i32* %5
%82 = add nsw i32 %81, 1
store i32 %82, i32* %5
br label %64
83: ; preds = %64
br label %84
84: ; preds = %83
%85 = load i32, i32* %4
%86 = add nsw i32 %85, 1
store i32 %86, i32* %4
br label %59
87: ; preds = %59
%88 = load float**, float*** %9
ret float** %88
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%f\00"
@str = [31 x i8] c"No filename detected, exiting!\00"
define noalias float** @parseFloats(i8* nocapture %0) {
%2 = alloca float
%3 = alloca i8*
%4 = bitcast float* %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = call i64 @fgetline_123(i8** %3, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = call float** @malloc(i32 0)
%13 = call i32 @rewind(i32* %6)
br label %59
14: ; preds = %1
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %8, %18
%19 = phi i32 [ %26, %18 ], [ 0, %8 ]
%20 = phi i32 [ %21, %18 ], [ 0, %8 ]
%21 = add nuw nsw i32 %20, 1
%22 = load i8*, i8** %3
%23 = call i32 @countSpaces(i8* %22)
%24 = icmp slt i32 %23, %19
%25 = add nsw i32 %23, 1
%26 = select i1 %24, i32 %19, i32 %25
%27 = call i64 @fgetline_123(i8** %3, i32* %6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %18
29: ; preds = %18
%30 = shl i32 %21, 3
%31 = call float** @malloc(i32 %30)
%32 = zext i32 %21 to i64
br label %33
33: ; preds = %29, %33
%34 = phi i64 [ 0, %29 ], [ %37, %33 ]
%35 = call float* @calloc(i32 %26, i32 4)
%36 = getelementptr inbounds float*, float** %31, i64 %34
store float* %35, float** %36
%37 = add nuw nsw i64 %34, 1
%38 = icmp eq i64 %37, %32
br i1 %38, label %39, label %33
39: ; preds = %33
%40 = call i32 @rewind(i32* %6)
%41 = icmp sgt i32 %26, 0
%42 = zext i32 %21 to i64
%43 = zext i32 %26 to i64
br label %44
44: ; preds = %39, %56
%45 = phi i64 [ 0, %39 ], [ %57, %56 ]
br i1 %41, label %46, label %56
46: ; preds = %44
%47 = getelementptr inbounds float*, float** %31, i64 %45
br label %48
48: ; preds = %46, %48
%49 = phi i64 [ 0, %46 ], [ %54, %48 ]
%50 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %2)
%51 = load float, float* %2
%52 = load float*, float** %47
%53 = getelementptr inbounds float, float* %52, i64 %49
store float %51, float* %53
%54 = add nuw nsw i64 %49, 1
%55 = icmp eq i64 %54, %43
br i1 %55, label %56, label %48
56: ; preds = %48, %44
%57 = add nuw nsw i64 %45, 1
%58 = icmp eq i64 %57, %42
br i1 %58, label %59, label %44
59: ; preds = %56, %11
%60 = phi float** [ %12, %11 ], [ %31, %56 ]
ret float** %60
}