#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 */
float atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *strtok(char *, char *);
int readmatrix(const char *filename, float *matrix) {
  FILE *input;
  char *line = NULL;
  size_t size;
  char *token;
  int count = 0;
  input = fopen(filename, "r");
  if (input == NULL) {
    return (-1);
  }
  while (getline(&line, &size, input) != -1) {
    token = strtok(line, "\t");
    matrix[count] = atoi(token);
    count++;
    while ((token = strtok(NULL, "\t")) != NULL) {
      matrix[count] = atoi(token);
      count++;
    }
  }
  fclose(input);
  free(line);
  return (0);
}


x86 assembly (clang, -O0):
<readmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11aa <readmatrix+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    125c <readmatrix+0xfc>
jmp    11af <readmatrix+0x4f>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1243 <readmatrix+0xe3>
mov    -0x28(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <atoi@plt>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdfb(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     123e <readmatrix+0xde>
mov    -0x38(%rbp),%rdi
call   1070 <atoi@plt>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11fc <readmatrix+0x9c>
jmp    11af <readmatrix+0x4f>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readmatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
movq   $0x0,0x8(%rsp)
lea    0xe7f(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     124c <readmatrix+0xec>
mov    %rax,%r14
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1236 <readmatrix+0xd6>
xor    %ebp,%ebp
lea    0xe4c(%rip),%rbx
lea    0x10(%rsp),%r13
jmp    11d5 <readmatrix+0x75>
nopl   (%rax)
lea    0x8(%rsp),%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1236 <readmatrix+0xd6>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
movslq %ebp,%rbp
movss  %xmm0,(%r15,%rbp,4)
add    $0x1,%ebp
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11c0 <readmatrix+0x60>
movslq %ebp,%rcx
lea    (%r15,%rcx,4),%r12
nopl   0x0(%rax)
mov    %rax,%rdi
call   1070 <atoi@plt>
movss  %xmm0,(%r12)
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
add    $0x4,%r12
add    $0x1,%ebp
test   %rax,%rax
jne    1210 <readmatrix+0xb0>
jmp    11c0 <readmatrix+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1251 <readmatrix+0xf1>
mov    $0xffffffff,%eax
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"
@.str.1 = [2 x i8] c"\09\00"
define i32 @readmatrix(i8* %0, float* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca float*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store float* %1, float** %5
store i8* null, i8** %7
store i32 0, i32* %10
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %50
16: ; preds = %2
br label %17
17: ; preds = %44, %16
%18 = load i32*, i32** %6
%19 = call i32 @getline(i8** %7, i64* %8, i32* %18)
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %45
21: ; preds = %17
%22 = load i8*, i8** %7
%23 = call i8* @strtok(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = call float @atoi(i8* %24)
%26 = load float*, float** %5
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds float, float* %26, i64 %28
store float %25, float* %29
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %32
32: ; preds = %35, %21
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %33, i8** %9
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %44
35: ; preds = %32
%36 = load i8*, i8** %9
%37 = call float @atoi(i8* %36)
%38 = load float*, float** %5
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %38, i64 %40
store float %37, float* %41
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %32
44: ; preds = %32
br label %17
45: ; preds = %17
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = load i8*, i8** %7
%49 = call i32 @free(i8* %48)
store i32 0, i32* %3
br label %50
50: ; preds = %45, %15
%51 = load i32, i32* %3
ret i32 %51
}

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