#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ printf(char *);
double **matrixAlocation(int dimension) {
  double **m;
  int i;
  if (dimension < 1) {
    printf("Error : Invalid dimensionension of the matrix.\n");
    return (NULL);
  }
  m = (double **)calloc(dimension, sizeof(double));
  if (m == NULL) {
    printf("Error : Insuficient memory to allocate the matrix.\n");
    return (NULL);
  }
  for (i = 0; i < dimension; i++) {
    m[i] = (double *)calloc(dimension, sizeof(double));
    if (m[i] == NULL) {
      printf("Error : Insuficient memory to allocate the matrix.\n");
      return (NULL);
    }
  }
  return (m);
}


x86 assembly (clang, -O0):
<matrixAlocation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    114e <matrixAlocation+0x2e>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f9 <matrixAlocation+0xd9>
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1183 <matrixAlocation+0x63>
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f9 <matrixAlocation+0xd9>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f1 <matrixAlocation+0xd1>
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11de <matrixAlocation+0xbe>
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f9 <matrixAlocation+0xd9>
jmp    11e3 <matrixAlocation+0xc3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118a <matrixAlocation+0x6a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixAlocation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    1171 <matrixAlocation+0x51>
mov    %edi,%r12d
mov    $0x8,%esi
call   1040 <calloc@plt>
lea    0xec0(%rip),%r14
test   %rax,%rax
je     1178 <matrixAlocation+0x58>
mov    %rax,%rbx
mov    %r12d,%r15d
xor    %ebp,%ebp
nopl   (%rax)
mov    %r12d,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,(%rbx,%rbp,8)
test   %rax,%rax
je     1178 <matrixAlocation+0x58>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1150 <matrixAlocation+0x30>
jmp    1182 <matrixAlocation+0x62>
lea    0xebb(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Error : Invalid dimensionension of the matrix.\0A\00"
@.str.1 = [52 x i8] c"Error : Insuficient memory to allocate the matrix.\0A\00"
define double** @matrixAlocation(i32 %0) {
%2 = alloca double**
%3 = alloca i32
%4 = alloca double**
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
store double** null, double*** %2
br label %45
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i64 @calloc(i32 %11, i32 8)
%13 = inttoptr i64 %12 to double**
store double** %13, double*** %4
%14 = load double**, double*** %4
%15 = icmp eq double** %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
store double** null, double*** %2
br label %45
18: ; preds = %10
store i32 0, i32* %5
br label %19
19: ; preds = %40, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %43
23: ; preds = %19
%24 = load i32, i32* %3
%25 = call i64 @calloc(i32 %24, i32 8)
%26 = inttoptr i64 %25 to double*
%27 = load double**, double*** %4
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double*, double** %27, i64 %29
store double* %26, double** %30
%31 = load double**, double*** %4
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double*, double** %31, i64 %33
%35 = load double*, double** %34
%36 = icmp eq double* %35, null
br i1 %36, label %37, label %39
37: ; preds = %23
%38 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
store double** null, double*** %2
br label %45
39: ; preds = %23
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %19
43: ; preds = %19
%44 = load double**, double*** %4
store double** %44, double*** %2
br label %45
45: ; preds = %43, %37, %16, %8
%46 = load double**, double*** %2
ret double** %46
}

LLVM IR (-O2):
@str.2 = [51 x i8] c"Error : Insuficient memory to allocate the matrix.\00"
@str.3 = [47 x i8] c"Error : Invalid dimensionension of the matrix.\00"
define double** @matrixAlocation(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = tail call i64 @calloc(i32 %0, i32 8)
%5 = inttoptr i64 %4 to double**
%6 = icmp eq i64 %4, 0
br i1 %6, label %18, label %7
7: ; preds = %3
%8 = zext i32 %0 to i64
br label %11
9: ; preds = %11
%10 = icmp eq i64 %17, %8
br i1 %10, label %21, label %11
11: ; preds = %7, %9
%12 = phi i64 [ 0, %7 ], [ %17, %9 ]
%13 = tail call i64 @calloc(i32 %0, i32 8)
%14 = inttoptr i64 %13 to double*
%15 = getelementptr inbounds double*, double** %5, i64 %12
store double* %14, double** %15
%16 = icmp eq i64 %13, 0
%17 = add nuw nsw i64 %12, 1
br i1 %16, label %18, label %9
18: ; preds = %11, %3, %1
%19 = phi i8* [ getelementptr inbounds ([47 x i8], [47 x i8]* @str.3, i64 0, i64 0), %1 ], [ getelementptr inbounds ([51 x i8], [51 x i8]* @str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([51 x i8], [51 x i8]* @str.2, i64 0, i64 0), %11 ]
%20 = tail call i32 @puts(i8* dereferenceable(1) %19)
br label %21
21: ; preds = %9, %18
%22 = phi double** [ null, %18 ], [ %5, %9 ]
ret double** %22
}