#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__ malloc(long);
double **matrix(long nr, long nc) {
  long i;
  double **m;
  m = (double **)malloc(nr * sizeof(double *));
  for (i = 0; i < nr; i++)
    m[i] = (double *)malloc(nc * sizeof(double));
  return m;
}


x86 assembly (clang, -O0):
<matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    1174 <matrix+0x64>
mov    -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1139 <matrix+0x29>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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