#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
void *malloc(int);
int /*<<< orphan*/ printf(char *);
size_t strcspn(char *, char *);
char *strtok(char *, char *);
scalar_t__ strtol(char *, char **, int);
void fetch_matrix(long long ***m, int *n) {
  FILE *reader = fopen("matrix.txt", "r");
  char *buff = malloc(100 * sizeof(char));
  if (reader == NULL) {
    printf("File couldn't open");
    exit(-1);
  }
  char *cell, *end;
  int i;
  for (i = -1; fgets(buff, 100, reader) != NULL; i++) {
    buff[strcspn(buff, "\r\n")] = 0;
    cell = strtok(buff, ",");
    if (i == -1) {
      *n = (int)strtol(cell, &end, 10);
      *m = malloc((*n) * sizeof(long long *));
      int k;
      for (k = 0; k < *n; k++)
        (*m)[k] = malloc((*n) * sizeof(long long *));
      continue;
    }
    int j = 0;
    while (cell != NULL) {
      (*m)[i][j] = (long long)strtol(cell, &end, 10);
      cell = strtok(NULL, ",");
      j++;
    }
  }
  free(buff);
  fclose(reader);
}


x86 assembly (clang, -O0):
<fetch_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe49(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f6 <fetch_matrix+0x56>
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
movl   $0xffffffff,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1350 <fetch_matrix+0x1b0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    12dd <fetch_matrix+0x13d>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    12d8 <fetch_matrix+0x138>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x38(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1297 <fetch_matrix+0xf7>
jmp    1342 <fetch_matrix+0x1a2>
movl   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     133d <fetch_matrix+0x19d>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcfd(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12e4 <fetch_matrix+0x144>
jmp    1342 <fetch_matrix+0x1a2>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11fd <fetch_matrix+0x5d>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fetch_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,(%rsp)
mov    %rdi,%r14
lea    0xe44(%rip),%rdi
lea    0xe48(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbp
mov    $0x64,%edi
call   1090 <malloc@plt>
test   %rbp,%rbp
je     1363 <fetch_matrix+0x1c3>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x64,%esi
mov    %rbp,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1345 <fetch_matrix+0x1a5>
mov    $0xffffffffffffffff,%rbx
lea    0xe1b(%rip),%r12
mov    %rbp,0x10(%rsp)
mov    %r15,0x8(%rsp)
jmp    1248 <fetch_matrix+0xa8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0x64,%esi
mov    0x10(%rsp),%rbp
mov    %rbp,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
mov    0x18(%rsp),%rbx
je     1345 <fetch_matrix+0x1a5>
mov    %rbx,%rbp
mov    %r15,%rdi
lea    0xdcb(%rip),%rsi
call   1060 <strcspn@plt>
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   10b0 <strtok@plt>
inc    %rbx
mov    %rbx,0x18(%rsp)
jne    1300 <fetch_matrix+0x160>
mov    %rax,%rdi
lea    0x20(%rsp),%rsi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%r15
mov    (%rsp),%rax
mov    %r15d,(%rax)
lea    0x0(,%r15,8),%r13d
mov    %r13d,%edi
call   1090 <malloc@plt>
mov    %rax,(%r14)
test   %r15d,%r15d
jle    1220 <fetch_matrix+0x80>
mov    %rax,%rbp
mov    %r15d,%r15d
mov    %r13d,%edi
call   1090 <malloc@plt>
mov    %rax,0x0(%rbp)
cmp    $0x1,%r15
je     1220 <fetch_matrix+0x80>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%rbx
mov    %r13d,%edi
call   1090 <malloc@plt>
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    12e0 <fetch_matrix+0x140>
jmp    1220 <fetch_matrix+0x80>
nopl   (%rax)
test   %rax,%rax
je     1220 <fetch_matrix+0x80>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
lea    0x20(%rsp),%rsi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    (%r14),%rcx
mov    (%rcx,%rbp,8),%rcx
mov    %rax,(%rcx,%rbx,1)
xor    %edi,%edi
mov    %r12,%rsi
call   10b0 <strtok@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    1310 <fetch_matrix+0x170>
jmp    1220 <fetch_matrix+0x80>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xca3(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"matrix.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"File couldn't open\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [2 x i8] c",\00"
define void @fetch_matrix(i64*** %0, i32* %1) {
%3 = alloca i64***
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i64*** %0, i64**** %3
store i32* %1, i32** %4
%12 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %5
%13 = call i8* @malloc(i32 100)
store i8* %13, i8** %6
%14 = load i32*, i32** %5
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
store i32 -1, i32* %9
br label %20
20: ; preds = %89, %19
%21 = load i8*, i8** %6
%22 = load i32*, i32** %5
%23 = call i32* @fgets(i8* %21, i32 100, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %92
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = load i8*, i8** %6
%28 = call i64 @strcspn(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %6
%31 = call i8* @strtok(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %31, i8** %7
%32 = load i32, i32* %9
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %69
34: ; preds = %25
%35 = load i8*, i8** %7
%36 = call i64 @strtol(i8* %35, i8** %8, i32 10)
%37 = trunc i64 %36 to i32
%38 = load i32*, i32** %4
store i32 %37, i32* %38
%39 = load i32*, i32** %4
%40 = load i32, i32* %39
%41 = sext i32 %40 to i64
%42 = mul i64 %41, 8
%43 = trunc i64 %42 to i32
%44 = call i8* @malloc(i32 %43)
%45 = bitcast i8* %44 to i64**
%46 = load i64***, i64**** %3
store i64** %45, i64*** %46
store i32 0, i32* %10
br label %47
47: ; preds = %65, %34
%48 = load i32, i32* %10
%49 = load i32*, i32** %4
%50 = load i32, i32* %49
%51 = icmp slt i32 %48, %50
br i1 %51, label %52, label %68
52: ; preds = %47
%53 = load i32*, i32** %4
%54 = load i32, i32* %53
%55 = sext i32 %54 to i64
%56 = mul i64 %55, 8
%57 = trunc i64 %56 to i32
%58 = call i8* @malloc(i32 %57)
%59 = bitcast i8* %58 to i64*
%60 = load i64***, i64**** %3
%61 = load i64**, i64*** %60
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i64*, i64** %61, i64 %63
store i64* %59, i64** %64
br label %65
65: ; preds = %52
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %47
68: ; preds = %47
br label %89
69: ; preds = %25
store i32 0, i32* %11
br label %70
70: ; preds = %73, %69
%71 = load i8*, i8** %7
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %88
73: ; preds = %70
%74 = load i8*, i8** %7
%75 = call i64 @strtol(i8* %74, i8** %8, i32 10)
%76 = load i64***, i64**** %3
%77 = load i64**, i64*** %76
%78 = load i32, i32* %9
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i64*, i64** %77, i64 %79
%81 = load i64*, i64** %80
%82 = load i32, i32* %11
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i64, i64* %81, i64 %83
store i64 %75, i64* %84
%85 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %85, i8** %7
%86 = load i32, i32* %11
%87 = add nsw i32 %86, 1
store i32 %87, i32* %11
br label %70
88: ; preds = %70
br label %89
89: ; preds = %88, %68
%90 = load i32, i32* %9
%91 = add nsw i32 %90, 1
store i32 %91, i32* %9
br label %20
92: ; preds = %20
%93 = load i8*, i8** %6
%94 = call i32 @free(i8* %93)
%95 = load i32*, i32** %5
%96 = call i32 @fclose(i32* %95)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"matrix.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"File couldn't open\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [2 x i8] c",\00"
define void @fetch_matrix(i64*** nocapture %0, i32* nocapture %1) {
%3 = alloca i8*
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%6 = icmp eq i32* %4, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = bitcast i8** %3 to i8*
%12 = tail call i32* @fgets(i8* %5, i32 100, i32* %4)
%13 = icmp eq i32* %12, null
br i1 %13, label %58, label %14
14: ; preds = %10
%15 = bitcast i64*** %0 to i8**
br label %16
16: ; preds = %14, %54
%17 = phi i64 [ -1, %14 ], [ %55, %54 ]
%18 = tail call i64 @strcspn(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds i8, i8* %5, i64 %18
store i8 0, i8* %19
%20 = tail call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %17, -1
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = icmp eq i8* %20, null
br i1 %23, label %54, label %43
24: ; preds = %16
%25 = call i64 @strtol(i8* %20, i8** %3, i32 10)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %1
%27 = shl i32 %26, 3
%28 = tail call i8* @malloc(i32 %27)
store i8* %28, i8** %15
%29 = icmp sgt i32 %26, 0
br i1 %29, label %30, label %54
30: ; preds = %24
%31 = and i64 %25, 4294967295
%32 = tail call i8* @malloc(i32 %27)
%33 = bitcast i8* %28 to i8**
store i8* %32, i8** %33
%34 = icmp eq i64 %31, 1
br i1 %34, label %54, label %35
35: ; preds = %30, %35
%36 = phi i64 [ %41, %35 ], [ 1, %30 ]
%37 = load i64**, i64*** %0
%38 = tail call i8* @malloc(i32 %27)
%39 = getelementptr inbounds i64*, i64** %37, i64 %36
%40 = bitcast i64** %39 to i8**
store i8* %38, i8** %40
%41 = add nuw nsw i64 %36, 1
%42 = icmp eq i64 %41, %31
br i1 %42, label %54, label %35
43: ; preds = %22, %43
%44 = phi i64 [ %52, %43 ], [ 0, %22 ]
%45 = phi i8* [ %51, %43 ], [ %20, %22 ]
%46 = call i64 @strtol(i8* %45, i8** %3, i32 10)
%47 = load i64**, i64*** %0
%48 = getelementptr inbounds i64*, i64** %47, i64 %17
%49 = load i64*, i64** %48
%50 = getelementptr inbounds i64, i64* %49, i64 %44
store i64 %46, i64* %50
%51 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%52 = add nuw i64 %44, 1
%53 = icmp eq i8* %51, null
br i1 %53, label %54, label %43
54: ; preds = %43, %35, %30, %22, %24
%55 = add i64 %17, 1
%56 = tail call i32* @fgets(i8* %5, i32 100, i32* %4)
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %16
58: ; preds = %54, %10
%59 = tail call i32 @free(i8* %5)
%60 = tail call i32 @fclose(i32* %4)
ret void
}