#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_UT(int n_X) {
  int i, total = n_X * (n_X + 1) / 2;
  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;
  }
  total = n_X + 1;
  for (i = 1; i < n_X; i++) {
    pointerarray[i] = pointerarray[i - 1] + (total - i);
  }
  return (pointerarray);
}


x86 assembly (clang, -O0):
<allocate_s_double_UT>:
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
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <allocate_double_2D_AP@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1198 <allocate_s_double_UT+0x58>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%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    11d7 <allocate_s_double_UT+0x97>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%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    120b <allocate_s_double_UT+0xcb>
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    11de <allocate_s_double_UT+0x9e>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1261 <allocate_s_double_UT+0x121>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
cltq
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    121b <allocate_s_double_UT+0xdb>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_s_double_UT>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
call   1070 <allocate_double_2D_AP@plt>
test   %rax,%rax
je     1277 <allocate_s_double_UT+0x127>
mov    %rax,%r14
lea    0x1(%r15),%r13d
mov    %r13d,%ebp
imul   %r15d,%ebp
mov    %ebp,%r12d
shr    $0x1f,%r12d
add    %ebp,%r12d
sar    %r12d
mov    %r12d,%edi
call   1050 <allocate_double_1D@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1277 <allocate_s_double_UT+0x127>
mov    %rax,%rbx
cmp    $0x2,%ebp
jl     11b9 <allocate_s_double_UT+0x69>
add    $0xffffffff,%r12d
lea    0x8(,%r12,8),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
cmp    $0x2,%r15d
jl     1265 <allocate_s_double_UT+0x115>
mov    %r13d,%eax
mov    %r15d,%edi
lea    -0x1(%rdi),%rdx
add    $0xfffffffffffffffe,%rdi
mov    %edx,%r8d
and    $0x3,%r8d
mov    $0x1,%esi
cmp    $0x3,%rdi
jb     1240 <allocate_s_double_UT+0xf0>
lea    0x20(%r14),%rsi
and    $0xfffffffffffffffc,%rdx
neg    %rdx
xor    %edi,%edi
lea    (%rax,%rdi,1),%rbp
lea    (%rbx,%rbp,8),%rcx
lea    (%rbx,%rbp,8),%rbx
add    $0xfffffffffffffff8,%rbx
mov    %rbx,-0x18(%rsi)
lea    -0x8(%rcx,%rbp,8),%rbx
lea    -0x18(%rcx,%rbp,8),%rcx
mov    %rcx,-0x10(%rsi)
lea    -0x10(%rbx,%rbp,8),%rcx
lea    -0x28(%rbx,%rbp,8),%rbx
mov    %rbx,-0x8(%rsi)
lea    (%rcx,%rbp,8),%rbx
add    $0xffffffffffffffc8,%rbx
mov    %rbx,(%rsi)
add    $0xfffffffffffffffc,%rdi
add    $0x20,%rsi
cmp    %rdi,%rdx
jne    11f0 <allocate_s_double_UT+0xa0>
mov    $0x1,%esi
sub    %rdi,%rsi
test   %r8,%r8
je     1265 <allocate_s_double_UT+0x115>
lea    (%r14,%rsi,8),%rdx
sub    %rsi,%rax
xor    %esi,%esi
xchg   %ax,%ax
lea    (%rbx,%rax,8),%rbx
mov    %rbx,(%rdx,%rsi,8)
add    $0x1,%rsi
add    $0xffffffffffffffff,%rax
cmp    %rsi,%r8
jne    1250 <allocate_s_double_UT+0x100>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xd79(%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_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 = load i32, i32* %2
%8 = add nsw i32 %7, 1
%9 = mul nsw i32 %6, %8
%10 = sdiv i32 %9, 2
store i32 %10, i32* %4
%11 = load i32, i32* %2
%12 = call double** @allocate_double_2D_AP(i32 %11)
store double** %12, double*** %5
%13 = load double**, double*** %5
%14 = icmp eq double** %13, null
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %1
%20 = load i32, i32* %4
%21 = call double* @allocate_double_1D(i32 %20)
%22 = load double**, double*** %5
%23 = getelementptr inbounds double*, double** %22, i64 0
store double* %21, double** %23
%24 = load double**, double*** %5
%25 = getelementptr inbounds double*, double** %24, i64 0
%26 = load double*, double** %25
%27 = icmp eq double* %26, null
br i1 %27, label %28, label %32
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %19
store i32 0, i32* %3
br label %33
33: ; preds = %44, %32
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %47
37: ; preds = %33
%38 = load double**, double*** %5
%39 = getelementptr inbounds double*, double** %38, i64 0
%40 = load double*, double** %39
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
store double 0.000000e+00, double* %43
br label %44
44: ; preds = %37
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %33
47: ; preds = %33
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
store i32 1, i32* %3
br label %50
50: ; preds = %70, %47
%51 = load i32, i32* %3
%52 = load i32, i32* %2
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %73
54: ; preds = %50
%55 = load double**, double*** %5
%56 = load i32, i32* %3
%57 = sub nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double*, double** %55, i64 %58
%60 = load double*, double** %59
%61 = load i32, i32* %4
%62 = load i32, i32* %3
%63 = sub nsw i32 %61, %62
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %60, i64 %64
%66 = load double**, double*** %5
%67 = load i32, i32* %3
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double*, double** %66, i64 %68
store double* %65, double** %69
br label %70
70: ; preds = %54
%71 = load i32, i32* %3
%72 = add nsw i32 %71, 1
store i32 %72, i32* %3
br label %50
73: ; preds = %50
%74 = load double**, double*** %5
ret double** %74
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"PE: Memory allocation fails!\0A\00"
define double** @allocate_s_double_UT(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 = tail call double* @allocate_double_1D(i32 %4)
%13 = bitcast double* %12 to i8*
store double* %12, double** %5
%14 = icmp eq double* %12, null
br i1 %14, label %22, label %15
15: ; preds = %11
%16 = icmp sgt i32 %3, 1
br i1 %16, label %17, label %26
17: ; preds = %15
%18 = add nsw i32 %4, -1
%19 = zext i32 %18 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 = %17, %15
%27 = icmp sgt i32 %0, 1
br i1 %27, label %28, label %73
28: ; preds = %26
%29 = zext i32 %2 to i64
%30 = zext i32 %0 to i64
%31 = add nsw i64 %30, -1
%32 = add nsw i64 %30, -2
%33 = and i64 %31, 3
%34 = icmp ult i64 %32, 3
br i1 %34, label %59, label %35
35: ; preds = %28
%36 = and i64 %31, -4
br label %37
37: ; preds = %37, %35
%38 = phi double* [ %12, %35 ], [ %54, %37 ]
%39 = phi i64 [ 1, %35 ], [ %56, %37 ]
%40 = phi i64 [ 0, %35 ], [ %57, %37 ]
%41 = sub nsw i64 %29, %39
%42 = getelementptr inbounds double, double* %38, i64 %41
%43 = getelementptr inbounds double*, double** %5, i64 %39
store double* %42, double** %43
%44 = add nuw nsw i64 %39, 1
%45 = sub nsw i64 %29, %44
%46 = getelementptr inbounds double, double* %42, i64 %45
%47 = getelementptr inbounds double*, double** %5, i64 %44
store double* %46, double** %47
%48 = add nuw nsw i64 %39, 2
%49 = sub nsw i64 %29, %48
%50 = getelementptr inbounds double, double* %46, i64 %49
%51 = getelementptr inbounds double*, double** %5, i64 %48
store double* %50, double** %51
%52 = add nuw nsw i64 %39, 3
%53 = sub nsw i64 %29, %52
%54 = getelementptr inbounds double, double* %50, i64 %53
%55 = getelementptr inbounds double*, double** %5, i64 %52
store double* %54, double** %55
%56 = add nuw nsw i64 %39, 4
%57 = add i64 %40, 4
%58 = icmp eq i64 %57, %36
br i1 %58, label %59, label %37
59: ; preds = %37, %28
%60 = phi double* [ %12, %28 ], [ %54, %37 ]
%61 = phi i64 [ 1, %28 ], [ %56, %37 ]
%62 = icmp eq i64 %33, 0
br i1 %62, label %73, label %63
63: ; preds = %59, %63
%64 = phi double* [ %68, %63 ], [ %60, %59 ]
%65 = phi i64 [ %70, %63 ], [ %61, %59 ]
%66 = phi i64 [ %71, %63 ], [ 0, %59 ]
%67 = sub nsw i64 %29, %65
%68 = getelementptr inbounds double, double* %64, i64 %67
%69 = getelementptr inbounds double*, double** %5, i64 %65
store double* %68, double** %69
%70 = add nuw nsw i64 %65, 1
%71 = add i64 %66, 1
%72 = icmp eq i64 %71, %33
br i1 %72, label %73, label %63
73: ; preds = %59, %63, %26
ret double** %5
}