#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 */
int /*<<< orphan*/ deallocateSpace(double **, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
double **allocateSpace(int size) {
  double **data = (double **)malloc(size * sizeof(double *));
  if (data == 0) {
    fprintf(stderr, "ERROR: Memory allocation unsuccessful.\n");
    deallocateSpace(data, 0);
    return NULL;
  }
  int row;
  for (row = 0; row < size; row++) {
    data[row] = (double *)malloc(size * sizeof(double));
    if (data[row] == 0) {
      fprintf(stderr, "ERROR: Memory allocation unsuccessful.\n");
      deallocateSpace(data, size);
      return NULL;
    }
  }
  return data;
}


x86 assembly (clang, -O0):
<allocateSpace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <allocateSpace+0x56>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <deallocateSpace@plt>
movq   $0x0,-0x8(%rbp)
jmp    1213 <allocateSpace+0xe3>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120b <allocateSpace+0xdb>
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@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    11f8 <allocateSpace+0xc8>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <deallocateSpace@plt>
movq   $0x0,-0x8(%rbp)
jmp    1213 <allocateSpace+0xe3>
jmp    11fd <allocateSpace+0xcd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <allocateSpace+0x5d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocateSpace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
lea    0x0(,%r14,8),%r12d
mov    %r12d,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     117c <allocateSpace+0x4c>
mov    %rax,%r15
test   %r14d,%r14d
jle    11c2 <allocateSpace+0x92>
mov    %r14d,%ebx
xor    %ebp,%ebp
nopl   (%rax)
mov    %r12d,%edi
call   1050 <malloc@plt>
mov    %rax,(%r15,%rbp,8)
test   %rax,%rax
je     119f <allocateSpace+0x6f>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <allocateSpace+0x30>
jmp    11c2 <allocateSpace+0x92>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
xor    %r15d,%r15d
xor    %edi,%edi
xor    %esi,%esi
call   1030 <deallocateSpace@plt>
jmp    11c2 <allocateSpace+0x92>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1040 <fprintf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <deallocateSpace@plt>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"ERROR: Memory allocation unsuccessful.\0A\00"
define double** @allocateSpace(i32 %0) {
%2 = alloca double**
%3 = alloca i32
%4 = alloca double**
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 8
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to double**
store double** %11, double*** %4
%12 = load double**, double*** %4
%13 = icmp eq double** %12, null
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%17 = load double**, double*** %4
%18 = call i32 @deallocateSpace(double** %17, i32 0)
store double** null, double*** %2
br label %53
19: ; preds = %1
store i32 0, i32* %5
br label %20
20: ; preds = %48, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %51
24: ; preds = %20
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 8
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to double*
%31 = load double**, double*** %4
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double*, double** %31, i64 %33
store double* %30, double** %34
%35 = load double**, double*** %4
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double*, double** %35, i64 %37
%39 = load double*, double** %38
%40 = icmp eq double* %39, null
br i1 %40, label %41, label %47
41: ; preds = %24
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%44 = load double**, double*** %4
%45 = load i32, i32* %3
%46 = call i32 @deallocateSpace(double** %44, i32 %45)
store double** null, double*** %2
br label %53
47: ; preds = %24
br label %48
48: ; preds = %47
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %20
51: ; preds = %20
%52 = load double**, double*** %4
store double** %52, double*** %2
br label %53
53: ; preds = %51, %41, %14
%54 = load double**, double*** %2
ret double** %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"ERROR: Memory allocation unsuccessful.\0A\00"
define double** @allocateSpace(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to double**
%5 = icmp eq i64 %3, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %27
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %16
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @deallocateSpace(double** null, i32 0)
br label %27
14: ; preds = %16
%15 = icmp eq i64 %22, %9
br i1 %15, label %27, label %16
16: ; preds = %8, %14
%17 = phi i64 [ 0, %8 ], [ %22, %14 ]
%18 = tail call i64 @malloc(i32 %2)
%19 = inttoptr i64 %18 to double*
%20 = getelementptr inbounds double*, double** %4, i64 %17
store double* %19, double** %20
%21 = icmp eq i64 %18, 0
%22 = add nuw nsw i64 %17, 1
br i1 %21, label %23, label %14
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%26 = tail call i32 @deallocateSpace(double** %4, i32 %0)
br label %27
27: ; preds = %14, %6, %23, %10
%28 = phi double** [ null, %10 ], [ null, %23 ], [ %4, %6 ], [ %4, %14 ]
ret double** %28
}