#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 */
typedef uintptr_t uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fatal(char *);
double **malloc(uintptr_t);
double *mallocDouble(uintptr_t);
double **mallocDouble2D(uintptr_t numRows, uintptr_t numCols) {
  uint32_t i;
  double **array = NULL;
  array = malloc(numRows * sizeof(uintptr_t *));
  if (array == NULL)
    fatal("Memory allocation error.\n");
  for (i = 0; i < numRows; i++) {
    array[i] = mallocDouble(numCols);
  }
  return array;
}


x86 assembly (clang, -O0):
<mallocDouble2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1170 <mallocDouble2D+0x40>
lea    0xe95(%rip),%rdi
call   1050 <fatal@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11af <mallocDouble2D+0x7f>
mov    -0x10(%rbp),%rdi
call   1030 <mallocDouble@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    1178 <mallocDouble2D+0x48>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mallocDouble2D>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rdi,8),%rdi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     115a <mallocDouble2D+0x2a>
test   %r15,%r15
jne    116b <mallocDouble2D+0x3b>
jmp    1185 <mallocDouble2D+0x55>
lea    0xe9f(%rip),%rdi
call   1050 <fatal@plt>
test   %r15,%r15
je     1185 <mallocDouble2D+0x55>
xor    %ebx,%ebx
nopl   (%rax)
mov    %r14,%rdi
call   1030 <mallocDouble@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <mallocDouble2D+0x40>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Memory allocation error.\0A\00"
define double** @mallocDouble2D(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
store double** null, double*** %6
%7 = load i64, i64* %3
%8 = mul i64 %7, 8
%9 = call double** @malloc(i64 %8)
store double** %9, double*** %6
%10 = load double**, double*** %6
%11 = icmp eq double** %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
store i64 0, i64* %5
br label %15
15: ; preds = %25, %14
%16 = load i64, i64* %5
%17 = load i64, i64* %3
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i64, i64* %4
%21 = call double* @mallocDouble(i64 %20)
%22 = load double**, double*** %6
%23 = load i64, i64* %5
%24 = getelementptr inbounds double*, double** %22, i64 %23
store double* %21, double** %24
br label %25
25: ; preds = %19
%26 = load i64, i64* %5
%27 = add i64 %26, 1
store i64 %27, i64* %5
br label %15
28: ; preds = %15
%29 = load double**, double*** %6
ret double** %29
}

LLVM IR (-O2):
@.str = [26 x i8] c"Memory allocation error.\0A\00"
define noalias double** @mallocDouble2D(i64 %0, i64 %1) {
%3 = shl i64 %0, 3
%4 = tail call double** @malloc(i64 %3)
%5 = icmp eq double** %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = icmp eq i64 %0, 0
br i1 %9, label %16, label %10
10: ; preds = %8, %10
%11 = phi i64 [ %14, %10 ], [ 0, %8 ]
%12 = tail call double* @mallocDouble(i64 %1)
%13 = getelementptr inbounds double*, double** %4, i64 %11
store double* %12, double** %13
%14 = add nuw i64 %11, 1
%15 = icmp eq i64 %14, %0
br i1 %15, label %16, label %10
16: ; preds = %10, %8
ret double** %4
}