#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 *calloc(int, int);
double **mat_cria(int m, int n) {
  double **mat = calloc(sizeof(double *), m);
  for (m -= 1; m + 1; m--) {
    mat[m] = calloc(sizeof(double), n);
  }
  return mat;
}


x86 assembly (clang, -O0):
<mat_cria>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x8,%edi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cmp    $0x0,%eax
je     1171 <mat_cria+0x61>
mov    -0x8(%rbp),%esi
mov    $0x8,%edi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1138 <mat_cria+0x28>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat_cria>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r12d
mov    $0x8,%edi
mov    %r12d,%esi
call   1030 <calloc@plt>
mov    %rax,%r14
test   %r12d,%r12d
je     116b <mat_cria+0x5b>
movslq %r12d,%rax
lea    (%r14,%rax,8),%rbp
add    $0xfffffffffffffff8,%rbp
neg    %r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x8,%edi
mov    %r15d,%esi
call   1030 <calloc@plt>
mov    %rax,0x0(%rbp,%rbx,8)
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r12d
jne    1150 <mat_cria+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @mat_cria(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double**
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i8* @calloc(i32 8, i32 %6)
%8 = bitcast i8* %7 to double**
store double** %8, double*** %5
%9 = load i32, i32* %3
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %3
br label %11
11: ; preds = %23, %2
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i32, i32* %4
%17 = call i8* @calloc(i32 8, i32 %16)
%18 = bitcast i8* %17 to double*
%19 = load double**, double*** %5
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double*, double** %19, i64 %21
store double* %18, double** %22
br label %23
23: ; preds = %15
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
br label %11
26: ; preds = %11
%27 = load double**, double*** %5
ret double** %27
}

LLVM IR (-O2):
define noalias double** @mat_cria(i32 %0, i32 %1) {
%3 = tail call i8* @calloc(i32 8, i32 %0)
%4 = bitcast i8* %3 to double**
%5 = icmp eq i32 %0, 0
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = sext i32 %0 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %7, %6 ], [ %10, %8 ]
%10 = add nsw i64 %9, -1
%11 = tail call i8* @calloc(i32 8, i32 %1)
%12 = getelementptr inbounds double*, double** %4, i64 %10
%13 = bitcast double** %12 to i8**
store i8* %11, i8** %13
%14 = trunc i64 %10 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %2
ret double** %4
}