#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);
double **mm_alloc(int size) {
  double **matrix;
  int i;
  matrix = (double **)calloc(size, sizeof(double *));
  for (i = 0; i < size; i++) {
    matrix[i] = (double *)calloc(size, sizeof(double));
  }
  return (matrix);
}


x86 assembly (clang, -O0):
<mm_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1169 <mm_alloc+0x59>
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <mm_alloc+0x23>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mm_alloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    115a <mm_alloc+0x4a>
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <mm_alloc+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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