#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 */

/* Variables and functions */
void *malloc(int);
int /*<<< orphan*/ scanf(char *, int *);
int **leggiMatrice(int h, int w) {
  int **mat = malloc(sizeof(int *) * h);
  for (int i = 0; i < h; i++) {
    mat[i] = malloc(sizeof(int) * w);
    for (int j = 0; j < w; j++) {
      scanf("%d", &mat[i][j]);
    }
  }
  return mat;
}


x86 assembly (clang, -O0):
<leggiMatrice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c9 <leggiMatrice+0xa9>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b6 <leggiMatrice+0x96>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe5d(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1179 <leggiMatrice+0x59>
jmp    11bb <leggiMatrice+0x9b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <leggiMatrice+0x28>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leggiMatrice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,%ebx
lea    0x0(,%rbx,8),%edi
call   1030 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %ebx,%ebx
jle    11b7 <leggiMatrice+0x97>
mov    0x8(%rsp),%rax
lea    0x0(,%rax,4),%ecx
mov    %ecx,0x4(%rsp)
mov    %ebx,%r13d
mov    %eax,%r12d
xor    %r15d,%r15d
lea    0xe96(%rip),%rbx
jmp    1179 <leggiMatrice+0x59>
nopl   0x0(%rax)
add    $0x1,%r15
cmp    %r13,%r15
je     11b7 <leggiMatrice+0x97>
mov    0x4(%rsp),%edi
call   1030 <malloc@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rax
mov    %rbp,(%rax,%r15,8)
mov    %r12,%r14
cmpl   $0x0,0x8(%rsp)
jle    1170 <leggiMatrice+0x50>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <scanf@plt>
add    $0x4,%rbp
add    $0xffffffffffffffff,%r14
jne    11a0 <leggiMatrice+0x80>
jmp    1170 <leggiMatrice+0x50>
mov    0x10(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32** @leggiMatrice(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 8, %9
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
%13 = bitcast i8* %12 to i32**
store i32** %13, i32*** %5
store i32 0, i32* %6
br label %14
14: ; preds = %47, %2
%15 = load i32, i32* %6
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %50
18: ; preds = %14
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = mul i64 4, %20
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
%24 = bitcast i8* %23 to i32*
%25 = load i32**, i32*** %5
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32*, i32** %25, i64 %27
store i32* %24, i32** %28
store i32 0, i32* %7
br label %29
29: ; preds = %43, %18
%30 = load i32, i32* %7
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %46
33: ; preds = %29
%34 = load i32**, i32*** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32*, i32** %34, i64 %36
%38 = load i32*, i32** %37
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %41)
br label %43
43: ; preds = %33
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %29
46: ; preds = %29
br label %47
47: ; preds = %46
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %14
50: ; preds = %14
%51 = load i32**, i32*** %5
ret i32** %51
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define noalias i32** @leggiMatrice(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i8* @malloc(i32 %3)
%5 = bitcast i8* %4 to i32**
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = shl i32 %1, 2
%9 = icmp sgt i32 %1, 0
%10 = zext i32 %0 to i64
%11 = zext i32 %1 to i64
br label %13
12: ; preds = %19, %2
ret i32** %5
13: ; preds = %7, %19
%14 = phi i64 [ 0, %7 ], [ %20, %19 ]
%15 = tail call i8* @malloc(i32 %8)
%16 = getelementptr inbounds i32*, i32** %5, i64 %14
%17 = bitcast i32** %16 to i8**
store i8* %15, i8** %17
%18 = bitcast i8* %15 to i32*
br i1 %9, label %22, label %19
19: ; preds = %22, %13
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %12, label %13
22: ; preds = %13, %22
%23 = phi i64 [ %26, %22 ], [ 0, %13 ]
%24 = getelementptr inbounds i32, i32* %18, i64 %23
%25 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %24)
%26 = add nuw nsw i64 %23, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %19, label %22
}