#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(int);
double **dmatrix(int nr, int nc) {
  int i, j;
  double **m;
  m = (double **)malloc(nr * sizeof(double *));
  if (!m)
    return NULL;
  for (i = 0; i < nr; i++) {
    m[i] = (double *)malloc(nc * sizeof(double));
    if (!m[i])
      return NULL;
    for (j = 0; j < nc; j++)
      m[i][j] = 0;
  }
  return m;
}


x86 assembly (clang, -O0):
<dmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1149 <dmatrix+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11ee <dmatrix+0xde>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <dmatrix+0xd6>
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    119a <dmatrix+0x8a>
movq   $0x0,-0x8(%rbp)
jmp    11ee <dmatrix+0xde>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d3 <dmatrix+0xc3>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a1 <dmatrix+0x91>
jmp    11d8 <dmatrix+0xc8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1150 <dmatrix+0x40>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r12d
lea    0x0(,%r12,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     119e <dmatrix+0x7e>
mov    %rax,%rbx
test   %r12d,%r12d
jle    11a0 <dmatrix+0x80>
lea    0x0(,%r14,8),%r13d
mov    %r14d,%r15d
shl    $0x3,%r15
mov    %r12d,%r12d
xor    %ebp,%ebp
jmp    1179 <dmatrix+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     11a0 <dmatrix+0x80>
mov    %r13d,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx,%rbp,8)
test   %rax,%rax
je     119e <dmatrix+0x7e>
test   %r14d,%r14d
jle    1170 <dmatrix+0x50>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <memset@plt>
jmp    1170 <dmatrix+0x50>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @dmatrix(i32 %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double**
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double**
store double** %14, double*** %8
%15 = load double**, double*** %8
%16 = icmp ne double** %15, null
br i1 %16, label %18, label %17
17: ; preds = %2
store double** null, double*** %3
br label %64
18: ; preds = %2
store i32 0, i32* %6
br label %19
19: ; preds = %59, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %62
23: ; preds = %19
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 8
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to double*
%30 = load double**, double*** %8
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double*, double** %30, i64 %32
store double* %29, double** %33
%34 = load double**, double*** %8
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double*, double** %34, i64 %36
%38 = load double*, double** %37
%39 = icmp ne double* %38, null
br i1 %39, label %41, label %40
40: ; preds = %23
store double** null, double*** %3
br label %64
41: ; preds = %23
store i32 0, i32* %7
br label %42
42: ; preds = %55, %41
%43 = load i32, i32* %7
%44 = load i32, i32* %5
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %58
46: ; preds = %42
%47 = load double**, double*** %8
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double*, double** %47, i64 %49
%51 = load double*, double** %50
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
store double 0.000000e+00, double* %54
br label %55
55: ; preds = %46
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %42
58: ; preds = %42
br label %59
59: ; preds = %58
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %19
62: ; preds = %19
%63 = load double**, double*** %8
store double** %63, double*** %3
br label %64
64: ; preds = %62, %40, %17
%65 = load double**, double*** %3
ret double** %65
}

LLVM IR (-O2):
define double** @dmatrix(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double**
%6 = icmp eq i64 %4, 0
br i1 %6, label %27, label %7
7: ; preds = %2
%8 = shl i32 %1, 3
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = icmp sgt i32 %1, 0
%12 = zext i32 %1 to i64
%13 = shl nuw nsw i64 %12, 3
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %10, %24
%16 = phi i64 [ 0, %10 ], [ %25, %24 ]
%17 = tail call i64 @malloc(i32 %8)
%18 = inttoptr i64 %17 to double*
%19 = inttoptr i64 %17 to i8*
%20 = getelementptr inbounds double*, double** %5, i64 %16
store double* %18, double** %20
%21 = icmp eq i64 %17, 0
br i1 %21, label %27, label %22
22: ; preds = %15
br i1 %11, label %23, label %24
23: ; preds = %22
br label %24
24: ; preds = %23, %22
%25 = add nuw nsw i64 %16, 1
%26 = icmp eq i64 %25, %14
br i1 %26, label %27, label %15
27: ; preds = %15, %24, %7, %2
%28 = phi double** [ null, %2 ], [ %5, %7 ], [ null, %15 ], [ %5, %24 ]
ret double** %28
}