#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);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
double ***allocate_double_RT_3D(int K, int L, int ncode) {
  int k, l;
  double ***pointerarray = (double ***)malloc(K * sizeof(double **));
  if (pointerarray == NULL) {
    fprintf(stderr, "PE: Memory allocation fails!\n");
    exit(1);
  }
  for (k = 0; k < K; k++) {
    pointerarray[k] = (double **)malloc(L * sizeof(double *));
    if (pointerarray[k] == NULL) {
      fprintf(stderr, "PE: Memory allocation fails!\n");
      exit(1);
    }
    for (l = 0; l < L; l++) {
      pointerarray[k][l] = allocate_double_1D(ncode);
    }
  }
  return (pointerarray);
}


x86 assembly (clang, -O0):
<allocate_double_RT_3D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <allocate_double_RT_3D+0x4e>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1244 <allocate_double_RT_3D+0x104>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11f1 <allocate_double_RT_3D+0xb1>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1231 <allocate_double_RT_3D+0xf1>
mov    -0xc(%rbp),%edi
call   1050 <allocate_double_1D@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f8 <allocate_double_RT_3D+0xb8>
jmp    1236 <allocate_double_RT_3D+0xf6>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1195 <allocate_double_RT_3D+0x55>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_double_RT_3D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r13d
mov    %rsi,0x10(%rsp)
mov    %edi,%r12d
lea    0x0(,%r12,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11fd <allocate_double_RT_3D+0xbd>
mov    %rax,%rbx
test   %r12d,%r12d
jle    11eb <allocate_double_RT_3D+0xab>
mov    0x10(%rsp),%rax
lea    0x0(,%rax,8),%ecx
mov    %ecx,0xc(%rsp)
mov    %r12d,%r12d
mov    %eax,%ebp
xor    %r14d,%r14d
jmp    11a9 <allocate_double_RT_3D+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r12,%r14
je     11eb <allocate_double_RT_3D+0xab>
mov    0xc(%rsp),%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx,%r14,8)
test   %rax,%rax
je     11fd <allocate_double_RT_3D+0xbd>
cmpl   $0x0,0x10(%rsp)
jle    11a0 <allocate_double_RT_3D+0x60>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%edi
call   1050 <allocate_double_1D@plt>
mov    (%rbx,%r14,8),%rcx
mov    %rax,(%rcx,%r15,8)
add    $0x1,%r15
cmp    %r15,%rbp
jne    11d0 <allocate_double_RT_3D+0x90>
jmp    11a0 <allocate_double_RT_3D+0x60>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   1030 <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_RT_3D(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double***
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to double***
store double*** %15, double**** %9
%16 = load double***, double**** %9
%17 = icmp eq double*** %16, null
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %3
store i32 0, i32* %7
br label %23
23: ; preds = %68, %22
%24 = load i32, i32* %7
%25 = load i32, i32* %4
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %71
27: ; preds = %23
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to double**
%34 = load double***, double**** %9
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double**, double*** %34, i64 %36
store double** %33, double*** %37
%38 = load double***, double**** %9
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double**, double*** %38, i64 %40
%42 = load double**, double*** %41
%43 = icmp eq double** %42, null
br i1 %43, label %44, label %48
44: ; preds = %27
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %27
store i32 0, i32* %8
br label %49
49: ; preds = %64, %48
%50 = load i32, i32* %8
%51 = load i32, i32* %5
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %67
53: ; preds = %49
%54 = load i32, i32* %6
%55 = call double* @allocate_double_1D(i32 %54)
%56 = load double***, double**** %9
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double**, double*** %56, i64 %58
%60 = load double**, double*** %59
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double*, double** %60, i64 %62
store double* %55, double** %63
br label %64
64: ; preds = %53
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %49
67: ; preds = %49
br label %68
68: ; preds = %67
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %23
71: ; preds = %23
%72 = load double***, double**** %9
ret double*** %72
}

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