#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 */
double *allocate_double_1D(int);
double **allocate_double_2D_AP(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double **allocate_double_SQ(int n_X) {
  int i, j;
  double **pointerarray = allocate_double_2D_AP(n_X);
  if (pointerarray == NULL) {
    fprintf(stderr, "PE: Memory allocation fails!\n");
    exit(1);
  }
  for (i = 0; i < n_X; i++) {
    pointerarray[i] = allocate_double_1D(n_X);
    if (pointerarray[i] == NULL) {
      fprintf(stderr, "PE: Memory allocation fails!\n");
      exit(1);
    }
    for (j = 0; j < n_X; j++) {
      pointerarray[i][j] = 0.0;
    }
  }
  return (pointerarray);
}


x86 assembly (clang, -O0):
<allocate_double_SQ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <allocate_double_2D_AP@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1181 <allocate_double_SQ+0x41>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1229 <allocate_double_SQ+0xe9>
mov    -0x4(%rbp),%edi
call   1040 <allocate_double_1D@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11dd <allocate_double_SQ+0x9d>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1216 <allocate_double_SQ+0xd6>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0xc(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e4 <allocate_double_SQ+0xa4>
jmp    121b <allocate_double_SQ+0xdb>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1188 <allocate_double_SQ+0x48>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_double_SQ>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
call   1070 <allocate_double_2D_AP@plt>
test   %rax,%rax
je     11b3 <allocate_double_SQ+0x63>
mov    %rax,%r15
test   %r14d,%r14d
jle    11a7 <allocate_double_SQ+0x57>
mov    %r14d,%r12d
lea    0x0(,%r12,8),%rbp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
call   1050 <allocate_double_1D@plt>
mov    %rax,(%r15,%rbx,8)
test   %rax,%rax
je     11b3 <allocate_double_SQ+0x63>
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1030 <memset@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <allocate_double_SQ+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

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