#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
void leggi(char *file, float **m, int *n) {
  FILE *fp;
  int i, j;
  if ((fp = fopen(file, "r")) == NULL) {
    fprintf(stderr, "Impossibile aprire il file %s\n", file);
    exit(-2);
  }
  fscanf(fp, "%d", n);
  m = (float **)malloc((*n) * sizeof(float *));
  for (i = 0; i < *n; i++)
    m[i] = (float *)malloc((*n) * sizeof(float));
  for (i = 0; i < *n; i++)
    for (j = 0; j < *n; j++)
      fscanf(fp, "%f", &m[i][j]);
  fclose(fp);
}


x86 assembly (clang, -O0):
<leggi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b5 <leggi+0x55>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1226 <leggi+0xc6>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e8 <leggi+0x88>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    129c <leggi+0x13c>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1289 <leggi+0x129>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1243 <leggi+0xe3>
jmp    128e <leggi+0x12e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    122d <leggi+0xcd>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leggi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %rdi,%rbx
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1271 <leggi+0x111>
lea    0xe91(%rip),%rsi
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    0x0(%rbp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,(%rsp)
mov    %rbp,0x8(%rsp)
mov    0x0(%rbp),%edi
test   %edi,%edi
jle    1259 <leggi+0xf9>
xor    %ebx,%ebx
mov    0x8(%rsp),%r14
mov    (%rsp),%rbp
nopl   0x0(%rax)
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
movslq (%r14),%rdi
cmp    %rdi,%rbx
jl     11d0 <leggi+0x70>
test   %edi,%edi
jle    1259 <leggi+0xf9>
lea    0xe30(%rip),%r14
xor    %r15d,%r15d
mov    0x8(%rsp),%r13
mov    (%rsp),%rbx
jmp    121c <leggi+0xbc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %edi,%rax
add    $0x1,%r15
cmp    %rax,%r15
jge    1259 <leggi+0xf9>
test   %edi,%edi
jle    1210 <leggi+0xb0>
xor    %ebp,%ebp
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx,%r15,8),%rdx
add    %rbp,%rdx
mov    0x10(%rsp),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0x1,%r12
movslq 0x0(%r13),%rdi
add    $0x4,%rbp
cmp    %rdi,%r12
jl     1230 <leggi+0xd0>
jmp    1210 <leggi+0xb0>
mov    0x10(%rsp),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Impossibile aprire il file %s\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c"%f\00"
define void @leggi(i8* %0, float** nocapture readnone %1, i32* %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 -2)
unreachable
10: ; preds = %3
%11 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = shl i32 %12, 3
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to float**
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 0
br i1 %17, label %20, label %51
18: ; preds = %20
%19 = icmp sgt i32 %28, 0
br i1 %19, label %31, label %51
20: ; preds = %10, %20
%21 = phi i64 [ %27, %20 ], [ 0, %10 ]
%22 = phi i32 [ %28, %20 ], [ %16, %10 ]
%23 = shl i32 %22, 2
%24 = tail call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to float*
%26 = getelementptr inbounds float*, float** %15, i64 %21
store float* %25, float** %26
%27 = add nuw nsw i64 %21, 1
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %20, label %18
31: ; preds = %18, %46
%32 = phi i32 [ %47, %46 ], [ %28, %18 ]
%33 = phi i64 [ %49, %46 ], [ 0, %18 ]
%34 = icmp sgt i32 %32, 0
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = getelementptr inbounds float*, float** %15, i64 %33
br label %37
37: ; preds = %35, %37
%38 = phi i64 [ 0, %35 ], [ %42, %37 ]
%39 = load float*, float** %36
%40 = getelementptr inbounds float, float* %39, i64 %38
%41 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %40)
%42 = add nuw nsw i64 %38, 1
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %42, %44
br i1 %45, label %37, label %46
46: ; preds = %37, %31
%47 = phi i32 [ %32, %31 ], [ %43, %37 ]
%48 = sext i32 %47 to i64
%49 = add nuw nsw i64 %33, 1
%50 = icmp slt i64 %49, %48
br i1 %50, label %31, label %51
51: ; preds = %46, %10, %18
%52 = tail call i32 @fclose(i32* %4)
ret void
}