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


x86 assembly (clang, -O0):
<allocate_double_UT>:
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_UT+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    1231 <allocate_double_UT+0xf1>
mov    -0x4(%rbp),%edi
sub    -0x8(%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    11e0 <allocate_double_UT+0xa0>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    121e <allocate_double_UT+0xde>
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    11e7 <allocate_double_UT+0xa7>
jmp    1223 <allocate_double_UT+0xe3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1188 <allocate_double_UT+0x48>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_double_UT>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
call   1070 <allocate_double_2D_AP@plt>
test   %rax,%rax
je     11a8 <allocate_double_UT+0x58>
mov    %rax,%r14
test   %ebx,%ebx
jle    119f <allocate_double_UT+0x4f>
mov    %ebx,%ebx
mov    %r14,%r15
jmp    117a <allocate_double_UT+0x2a>
nop
add    $0x8,%r15
add    $0xffffffffffffffff,%rbx
je     119f <allocate_double_UT+0x4f>
mov    %ebx,%edi
call   1050 <allocate_double_1D@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11a8 <allocate_double_UT+0x58>
test   %ebx,%ebx
jle    1170 <allocate_double_UT+0x20>
mov    %ebx,%edx
shl    $0x3,%rdx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
jmp    1170 <allocate_double_UT+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%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_UT(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 = %58, %14
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %61
19: ; preds = %15
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = sub nsw i32 %20, %21
%23 = call double* @allocate_double_1D(i32 %22)
%24 = load double**, double*** %5
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double*, double** %24, i64 %26
store double* %23, double** %27
%28 = load double**, double*** %5
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
%32 = load double*, double** %31
%33 = icmp eq double* %32, null
br i1 %33, label %34, label %38
34: ; preds = %19
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %19
store i32 0, i32* %4
br label %39
39: ; preds = %54, %38
%40 = load i32, i32* %4
%41 = load i32, i32* %2
%42 = load i32, i32* %3
%43 = sub nsw i32 %41, %42
%44 = icmp slt i32 %40, %43
br i1 %44, label %45, label %57
45: ; preds = %39
%46 = load double**, double*** %5
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double*, double** %46, i64 %48
%50 = load double*, double** %49
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
store double 0.000000e+00, double* %53
br label %54
54: ; preds = %45
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %39
57: ; preds = %39
br label %58
58: ; preds = %57
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 1
store i32 %60, i32* %3
br label %15
61: ; preds = %15
%62 = load double**, double*** %5
ret double** %62
}

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