#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);
scalar_t__ malloc(int);
double **alloc_data_matrix(int rows, int cols) {
  double **dm = (double **)malloc(rows * sizeof(double *));
  if (dm == NULL)
    return NULL;
  int i;
  for (i = 0; i < rows; ++i) {
    dm[i] = (double *)calloc(cols, sizeof(double));
    if (dm[i] == NULL)
      return NULL;
  }
  return dm;
}


x86 assembly (clang, -O0):
<alloc_data_matrix>:
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   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1159 <alloc_data_matrix+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11c3 <alloc_data_matrix+0xa3>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bb <alloc_data_matrix+0x9b>
mov    -0x10(%rbp),%edi
mov    $0x8,%esi
call   1030 <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    11a8 <alloc_data_matrix+0x88>
movq   $0x0,-0x8(%rbp)
jmp    11c3 <alloc_data_matrix+0xa3>
jmp    11ad <alloc_data_matrix+0x8d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <alloc_data_matrix+0x40>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_data_matrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1171 <alloc_data_matrix+0x51>
mov    %rax,%rbx
test   %r14d,%r14d
jle    1173 <alloc_data_matrix+0x53>
mov    %r14d,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r15d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%rbx,%rbp,8)
test   %rax,%rax
je     1171 <alloc_data_matrix+0x51>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1150 <alloc_data_matrix+0x30>
jmp    1173 <alloc_data_matrix+0x53>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @alloc_data_matrix(i32 %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca i32
%6 = alloca double**
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double**
store double** %13, double*** %6
%14 = load double**, double*** %6
%15 = icmp eq double** %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store double** null, double*** %3
br label %43
17: ; preds = %2
store i32 0, i32* %7
br label %18
18: ; preds = %38, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %41
22: ; preds = %18
%23 = load i32, i32* %5
%24 = call i64 @calloc(i32 %23, i32 8)
%25 = inttoptr i64 %24 to double*
%26 = load double**, double*** %6
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double*, double** %26, i64 %28
store double* %25, double** %29
%30 = load double**, double*** %6
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double*, double** %30, i64 %32
%34 = load double*, double** %33
%35 = icmp eq double* %34, null
br i1 %35, label %36, label %37
36: ; preds = %22
store double** null, double*** %3
br label %43
37: ; preds = %22
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %18
41: ; preds = %18
%42 = load double**, double*** %6
store double** %42, double*** %3
br label %43
43: ; preds = %41, %36, %16
%44 = load double**, double*** %3
ret double** %44
}

LLVM IR (-O2):
define double** @alloc_data_matrix(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 %20, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %20
9: ; preds = %7
%10 = zext i32 %0 to i64
br label %13
11: ; preds = %13
%12 = icmp eq i64 %19, %10
br i1 %12, label %20, label %13
13: ; preds = %9, %11
%14 = phi i64 [ 0, %9 ], [ %19, %11 ]
%15 = tail call i64 @calloc(i32 %1, i32 8)
%16 = inttoptr i64 %15 to double*
%17 = getelementptr inbounds double*, double** %5, i64 %14
store double* %16, double** %17
%18 = icmp eq i64 %15, 0
%19 = add nuw nsw i64 %14, 1
br i1 %18, label %20, label %11
20: ; preds = %11, %13, %7, %2
%21 = phi double** [ null, %2 ], [ %5, %7 ], [ %5, %11 ], [ null, %13 ]
ret double** %21
}