#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
void read_matrix_file1(int ***A, int *length) {
  FILE *fisier;
  int m, n, i, j;
  if (!(fisier = fopen("matrice1.txt", "r")))
    printf("eroare la deschidere");
  else {
    fscanf(fisier, "%d", &m);
    n = m;
    *length = m;
    (*A) = (int **)malloc(m * sizeof(int *));
    for (i = 0; i < m; i++) {
      (*A)[i] = (int *)malloc(n * sizeof(int));
      for (j = 0; j < n; j++)
        fscanf(fisier, "%d", &(*A)[i][j]);
    }
  }
  printf("\n");
  fclose(fisier);
}


x86 assembly (clang, -O0):
<read_matrix_file1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe99(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1192 <read_matrix_file1+0x42>
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
jmp    1265 <read_matrix_file1+0x115>
mov    -0x18(%rbp),%rdi
lea    0xe87(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1260 <read_matrix_file1+0x110>
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    124d <read_matrix_file1+0xfd>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdea(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1209 <read_matrix_file1+0xb9>
jmp    1252 <read_matrix_file1+0x102>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d5 <read_matrix_file1+0x85>
jmp    1265 <read_matrix_file1+0x115>
lea    0xdbb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_matrix_file1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe85(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     1250 <read_matrix_file1+0xf0>
lea    0xe8a(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1060 <fscanf@plt>
mov    0x8(%rsp),%eax
mov    %eax,0x0(%rbp)
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,8),%edi
call   1070 <malloc@plt>
mov    %rax,(%rbx)
cmpl   $0x0,0x8(%rsp)
jle    125c <read_matrix_file1+0xfc>
mov    0x10(%rsp),%rax
lea    0x0(,%rax,4),%ecx
mov    %ecx,0xc(%rsp)
lea    0x0(,%rax,4),%rbp
xor    %r12d,%r12d
lea    0xe35(%rip),%r13
jmp    120e <read_matrix_file1+0xae>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
movslq 0x8(%rsp),%rax
cmp    %rax,%r12
jge    125c <read_matrix_file1+0xfc>
mov    0xc(%rsp),%edi
call   1070 <malloc@plt>
mov    (%rbx),%rcx
mov    %rax,(%rcx,%r12,8)
cmpl   $0x0,0x10(%rsp)
jle    1200 <read_matrix_file1+0xa0>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rax
mov    (%rax,%r12,8),%rdx
add    %r15,%rdx
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <fscanf@plt>
add    $0x4,%r15
cmp    %r15,%rbp
jne    1230 <read_matrix_file1+0xd0>
jmp    1200 <read_matrix_file1+0xa0>
lea    0xdb8(%rip),%rdi
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"matrice1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"eroare la deschidere\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @read_matrix_file1(i32*** %0, i32* %1) {
%3 = alloca i32***
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32*** %0, i32**** %3
store i32* %1, i32** %4
%10 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %67
14: ; preds = %2
%15 = load i32*, i32** %5
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%17 = load i32, i32* %6
store i32 %17, i32* %7
%18 = load i32, i32* %6
%19 = load i32*, i32** %4
store i32 %18, i32* %19
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 8
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i32**
%26 = load i32***, i32**** %3
store i32** %25, i32*** %26
store i32 0, i32* %8
br label %27
27: ; preds = %63, %14
%28 = load i32, i32* %8
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %66
31: ; preds = %27
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 4
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i32*
%38 = load i32***, i32**** %3
%39 = load i32**, i32*** %38
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32*, i32** %39, i64 %41
store i32* %37, i32** %42
store i32 0, i32* %9
br label %43
43: ; preds = %59, %31
%44 = load i32, i32* %9
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %62
47: ; preds = %43
%48 = load i32*, i32** %5
%49 = load i32***, i32**** %3
%50 = load i32**, i32*** %49
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32*, i32** %50, i64 %52
%54 = load i32*, i32** %53
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
%58 = call i32 @fscanf(i32* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %57)
br label %59
59: ; preds = %47
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %43
62: ; preds = %43
br label %63
63: ; preds = %62
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %27
66: ; preds = %27
br label %67
67: ; preds = %66, %12
%68 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%69 = load i32*, i32** %5
%70 = call i32 @fclose(i32* %69)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"matrice1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"eroare la deschidere\00"
@.str.3 = [3 x i8] c"%d\00"
define void @read_matrix_file1(i32*** nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %41
9: ; preds = %2
%10 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
store i32 %11, i32* %1
%12 = shl i32 %11, 3
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32**
store i32** %14, i32*** %0
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %41
17: ; preds = %9
%18 = shl i32 %11, 2
%19 = icmp sgt i32 %11, 0
%20 = zext i32 %11 to i64
br label %21
21: ; preds = %17, %36
%22 = phi i64 [ 0, %17 ], [ %37, %36 ]
%23 = call i64 @malloc(i32 %18)
%24 = inttoptr i64 %23 to i32*
%25 = load i32**, i32*** %0
%26 = getelementptr inbounds i32*, i32** %25, i64 %22
store i32* %24, i32** %26
br i1 %19, label %27, label %36
27: ; preds = %21, %27
%28 = phi i64 [ %34, %27 ], [ 0, %21 ]
%29 = load i32**, i32*** %0
%30 = getelementptr inbounds i32*, i32** %29, i64 %22
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 %28
%33 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %32)
%34 = add nuw nsw i64 %28, 1
%35 = icmp eq i64 %34, %20
br i1 %35, label %36, label %27
36: ; preds = %27, %21
%37 = add nuw nsw i64 %22, 1
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %37, %39
br i1 %40, label %21, label %41
41: ; preds = %36, %9, %7
%42 = call i32 @putchar(i32 10)
%43 = call i32 @fclose(i32* %5)
ret void
}