#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);
double **dmatrix_2d(size_t m, size_t n) {
  double **mat = malloc(sizeof(double *) * m);
  for (int i = 0; i < m; i++) {
    mat[i] = malloc(sizeof(double) * n);
  }
  return mat;
}


x86 assembly (clang, -O0):
<dmatrix_2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1174 <dmatrix_2d+0x64>
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113a <dmatrix_2d+0x2a>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmatrix_2d>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rdi,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r12
test   %r15,%r15
je     1155 <dmatrix_2d+0x45>
shl    $0x3,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
call   1030 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <dmatrix_2d+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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