#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);
int allocateMatrix2(double ***x, unsigned long rows, unsigned long columns) {
  double **xinternal;
  unsigned long i;
  xinternal = (double **)malloc(sizeof(double *) * rows);
  if (xinternal == NULL)
    return -1;
  for (i = 0; i < rows; i++) {
    xinternal[i] = (double *)malloc(sizeof(double) * columns);
    if (xinternal[i] == NULL)
      return -2;
  }
  *x = xinternal;
  return 0;
}


x86 assembly (clang, -O0):
<allocateMatrix2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    114e <allocateMatrix2+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <allocateMatrix2+0xb9>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11b7 <allocateMatrix2+0xa7>
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11a1 <allocateMatrix2+0x91>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11c9 <allocateMatrix2+0xb9>
jmp    11a6 <allocateMatrix2+0x96>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1156 <allocateMatrix2+0x46>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocateMatrix2>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x0(,%rsi,8),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1172 <allocateMatrix2+0x62>
mov    %rax,%r13
test   %r12,%r12
je     116b <allocateMatrix2+0x5b>
shl    $0x3,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
call   1030 <malloc@plt>
mov    %rax,0x0(%r13,%rbx,8)
test   %rax,%rax
je     1179 <allocateMatrix2+0x69>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <allocateMatrix2+0x40>
mov    %r13,(%r14)
xor    %eax,%eax
jmp    117e <allocateMatrix2+0x6e>
mov    $0xffffffff,%eax
jmp    117e <allocateMatrix2+0x6e>
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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