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


x86 assembly (clang, -O0):
<allocate_s_double_LT_pam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <allocate_double_2D_AP@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119b <allocate_s_double_LT_pam+0x5b>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%edi
call   1040 <allocate_double_1D@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11da <allocate_s_double_LT_pam+0x9a>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120e <allocate_s_double_LT_pam+0xce>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x8(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e1 <allocate_s_double_LT_pam+0xa1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x8,%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1265 <allocate_s_double_LT_pam+0x125>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1223 <allocate_s_double_LT_pam+0xe3>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_s_double_LT_pam>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
call   1070 <allocate_double_2D_AP@plt>
test   %rax,%rax
je     12ae <allocate_s_double_LT_pam+0x15e>
mov    %rax,%r14
lea    0x1(%r15),%ebp
imul   %r15d,%ebp
mov    %ebp,%r12d
shr    $0x1f,%r12d
add    %ebp,%r12d
sar    %r12d
lea    0x1(%r12),%edi
call   1050 <allocate_double_1D@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     12ae <allocate_s_double_LT_pam+0x15e>
mov    %rax,%rbx
cmp    $0xffffffff,%ebp
jl     11b4 <allocate_s_double_LT_pam+0x64>
mov    %r12d,%eax
lea    0x8(,%rax,8),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
add    $0x8,%rbx
mov    %rbx,(%r14)
cmp    $0x2,%r15d
jl     12a2 <allocate_s_double_LT_pam+0x152>
mov    %r15d,%esi
lea    -0x1(%rsi),%rdx
add    $0xfffffffffffffffe,%rsi
mov    %edx,%eax
and    $0x7,%eax
mov    $0x1,%ecx
cmp    $0x7,%rsi
jb     1281 <allocate_s_double_LT_pam+0x131>
and    $0xfffffffffffffff8,%rdx
neg    %rdx
mov    $0x8,%ecx
lea    (%rbx,%rcx,8),%rsi
lea    (%rbx,%rcx,8),%rdi
add    $0xffffffffffffffc8,%rdi
mov    %rdi,-0x38(%r14,%rcx,8)
lea    -0x38(%rsi,%rcx,8),%rdi
lea    -0x68(%rsi,%rcx,8),%rsi
mov    %rsi,-0x30(%r14,%rcx,8)
lea    -0x30(%rdi,%rcx,8),%rsi
lea    -0x58(%rdi,%rcx,8),%rdi
mov    %rdi,-0x28(%r14,%rcx,8)
lea    -0x28(%rsi,%rcx,8),%rdi
lea    -0x48(%rsi,%rcx,8),%rsi
mov    %rsi,-0x20(%r14,%rcx,8)
lea    -0x20(%rdi,%rcx,8),%rsi
lea    -0x38(%rdi,%rcx,8),%rdi
mov    %rdi,-0x18(%r14,%rcx,8)
lea    -0x18(%rsi,%rcx,8),%rdi
lea    -0x28(%rsi,%rcx,8),%rsi
mov    %rsi,-0x10(%r14,%rcx,8)
lea    -0x10(%rdi,%rcx,8),%rsi
lea    -0x18(%rdi,%rcx,8),%rdi
mov    %rdi,-0x8(%r14,%rcx,8)
lea    (%rsi,%rcx,8),%rbx
add    $0xfffffffffffffff8,%rbx
mov    %rbx,(%r14,%rcx,8)
lea    (%rdx,%rcx,1),%rsi
add    $0x8,%rsi
add    $0x8,%rcx
cmp    $0x8,%rsi
jne    11f0 <allocate_s_double_LT_pam+0xa0>
add    $0xfffffffffffffff9,%rcx
test   %rax,%rax
je     12a2 <allocate_s_double_LT_pam+0x152>
cs nopw 0x0(%rax,%rax,1)
lea    (%rbx,%rcx,8),%rbx
mov    %rbx,(%r14,%rcx,8)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rax
jne    1290 <allocate_s_double_LT_pam+0x140>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%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_s_double_LT_pam(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 = load i32, i32* %2
%8 = add nsw i32 %7, 1
%9 = mul nsw i32 %6, %8
%10 = sdiv i32 %9, 2
%11 = add nsw i32 %10, 1
store i32 %11, i32* %4
%12 = load i32, i32* %2
%13 = call double** @allocate_double_2D_AP(i32 %12)
store double** %13, double*** %5
%14 = load double**, double*** %5
%15 = icmp eq double** %14, null
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %1
%21 = load i32, i32* %4
%22 = call double* @allocate_double_1D(i32 %21)
%23 = load double**, double*** %5
%24 = getelementptr inbounds double*, double** %23, i64 0
store double* %22, double** %24
%25 = load double**, double*** %5
%26 = getelementptr inbounds double*, double** %25, i64 0
%27 = load double*, double** %26
%28 = icmp eq double* %27, null
br i1 %28, label %29, label %33
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %20
store i32 0, i32* %3
br label %34
34: ; preds = %45, %33
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = load double**, double*** %5
%40 = getelementptr inbounds double*, double** %39, i64 0
%41 = load double*, double** %40
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
store double 0.000000e+00, double* %44
br label %45
45: ; preds = %38
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %34
48: ; preds = %34
%49 = load double**, double*** %5
%50 = getelementptr inbounds double*, double** %49, i64 0
%51 = load double*, double** %50
%52 = getelementptr inbounds double, double* %51, i32 1
store double* %52, double** %50
store i32 1, i32* %3
br label %53
53: ; preds = %71, %48
%54 = load i32, i32* %3
%55 = load i32, i32* %2
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %74
57: ; preds = %53
%58 = load double**, double*** %5
%59 = load i32, i32* %3
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double*, double** %58, i64 %61
%63 = load double*, double** %62
%64 = load i32, i32* %3
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double**, double*** %5
%68 = load i32, i32* %3
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double*, double** %67, i64 %69
store double* %66, double** %70
br label %71
71: ; preds = %57
%72 = load i32, i32* %3
%73 = add nsw i32 %72, 1
store i32 %73, i32* %3
br label %53
74: ; preds = %53
%75 = load double**, double*** %5
ret double** %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"PE: Memory allocation fails!\0A\00"
define double** @allocate_s_double_LT_pam(i32 %0) {
%2 = add nsw i32 %0, 1
%3 = mul nsw i32 %2, %0
%4 = sdiv i32 %3, 2
%5 = tail call double** @allocate_double_2D_AP(i32 %0)
%6 = icmp eq double** %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = add nsw i32 %4, 1
%13 = tail call double* @allocate_double_1D(i32 %12)
%14 = bitcast double* %13 to i8*
store double* %13, double** %5
%15 = icmp eq double* %13, null
br i1 %15, label %22, label %16
16: ; preds = %11
%17 = icmp slt i32 %3, -1
br i1 %17, label %26, label %18
18: ; preds = %16
%19 = zext i32 %4 to i64
%20 = shl nuw nsw i64 %19, 3
%21 = add nuw nsw i64 %20, 8
br label %26
22: ; preds = %11
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %18, %16
%27 = getelementptr inbounds double, double* %13, i64 1
store double* %27, double** %5
%28 = icmp sgt i32 %0, 1
br i1 %28, label %29, label %80
29: ; preds = %26
%30 = zext i32 %0 to i64
%31 = add nsw i64 %30, -1
%32 = add nsw i64 %30, -2
%33 = and i64 %31, 7
%34 = icmp ult i64 %32, 7
br i1 %34, label %67, label %35
35: ; preds = %29
%36 = and i64 %31, -8
br label %37
37: ; preds = %37, %35
%38 = phi double* [ %27, %35 ], [ %62, %37 ]
%39 = phi i64 [ 1, %35 ], [ %64, %37 ]
%40 = phi i64 [ 0, %35 ], [ %65, %37 ]
%41 = getelementptr inbounds double, double* %38, i64 %39
%42 = getelementptr inbounds double*, double** %5, i64 %39
store double* %41, double** %42
%43 = add nuw nsw i64 %39, 1
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = getelementptr inbounds double*, double** %5, i64 %43
store double* %44, double** %45
%46 = add nuw nsw i64 %39, 2
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = getelementptr inbounds double*, double** %5, i64 %46
store double* %47, double** %48
%49 = add nuw nsw i64 %39, 3
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = getelementptr inbounds double*, double** %5, i64 %49
store double* %50, double** %51
%52 = add nuw nsw i64 %39, 4
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = getelementptr inbounds double*, double** %5, i64 %52
store double* %53, double** %54
%55 = add nuw nsw i64 %39, 5
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = getelementptr inbounds double*, double** %5, i64 %55
store double* %56, double** %57
%58 = add nuw nsw i64 %39, 6
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = getelementptr inbounds double*, double** %5, i64 %58
store double* %59, double** %60
%61 = add nuw nsw i64 %39, 7
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = getelementptr inbounds double*, double** %5, i64 %61
store double* %62, double** %63
%64 = add nuw nsw i64 %39, 8
%65 = add i64 %40, 8
%66 = icmp eq i64 %65, %36
br i1 %66, label %67, label %37
67: ; preds = %37, %29
%68 = phi double* [ %27, %29 ], [ %62, %37 ]
%69 = phi i64 [ 1, %29 ], [ %64, %37 ]
%70 = icmp eq i64 %33, 0
br i1 %70, label %80, label %71
71: ; preds = %67, %71
%72 = phi double* [ %75, %71 ], [ %68, %67 ]
%73 = phi i64 [ %77, %71 ], [ %69, %67 ]
%74 = phi i64 [ %78, %71 ], [ 0, %67 ]
%75 = getelementptr inbounds double, double* %72, i64 %73
%76 = getelementptr inbounds double*, double** %5, i64 %73
store double* %75, double** %76
%77 = add nuw nsw i64 %73, 1
%78 = add i64 %74, 1
%79 = icmp eq i64 %78, %33
br i1 %79, label %80, label %71
80: ; preds = %67, %71, %26
ret double** %5
}