#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 */
scalar_t__ calloc(int, int);
scalar_t__ malloc(int);
double ***alloc3d_dble(int nrows, int ncols, int nz) {
  int i, j;
  double ***array3 = (double ***)malloc(nrows * sizeof(double **));
  for (i = 0; i < nrows; i++) {
    array3[i] = (double **)malloc(ncols * sizeof(double *));
    for (j = 0; j < ncols; j++) {
      array3[i][j] = (double *)calloc(nz, sizeof(double));
    }
  }
  return array3;
}


x86 assembly (clang, -O0):
<alloc3d_dble>:
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)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11cd <alloc3d_dble+0xad>
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)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ba <alloc3d_dble+0x9a>
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@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    117c <alloc3d_dble+0x5c>
jmp    11bf <alloc3d_dble+0x9f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114b <alloc3d_dble+0x2b>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc3d_dble>:
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>
mov    %rax,%rbx
test   %r12d,%r12d
jle    11b0 <alloc3d_dble+0x90>
mov    0x10(%rsp),%rax
lea    0x0(,%rax,8),%ecx
mov    %ecx,0xc(%rsp)
mov    %r12d,%r12d
mov    %eax,%ebp
xor    %r14d,%r14d
jmp    1179 <alloc3d_dble+0x59>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r12,%r14
je     11b0 <alloc3d_dble+0x90>
mov    0xc(%rsp),%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx,%r14,8)
cmpl   $0x0,0x10(%rsp)
jle    1170 <alloc3d_dble+0x50>
xor    %r15d,%r15d
mov    %r13d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    (%rbx,%r14,8),%rcx
mov    %rax,(%rcx,%r15,8)
add    $0x1,%r15
cmp    %r15,%rbp
jne    1190 <alloc3d_dble+0x70>
jmp    1170 <alloc3d_dble+0x50>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double*** @alloc3d_dble(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
store i32 0, i32* %7
br label %16
16: ; preds = %51, %3
%17 = load i32, i32* %7
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %54
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to double**
%27 = load double***, double**** %9
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double**, double*** %27, i64 %29
store double** %26, double*** %30
store i32 0, i32* %8
br label %31
31: ; preds = %47, %20
%32 = load i32, i32* %8
%33 = load i32, i32* %5
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32, i32* %6
%37 = call i64 @calloc(i32 %36, i32 8)
%38 = inttoptr i64 %37 to double*
%39 = load double***, double**** %9
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double**, double*** %39, i64 %41
%43 = load double**, double*** %42
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double*, double** %43, i64 %45
store double* %38, double** %46
br label %47
47: ; preds = %35
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %31
50: ; preds = %31
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %16
54: ; preds = %16
%55 = load double***, double**** %9
ret double*** %55
}

LLVM IR (-O2):
define double*** @alloc3d_dble(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 sgt i32 %0, 0
br i1 %7, label %8, label %29
8: ; preds = %3
%9 = shl i32 %1, 3
%10 = icmp sgt i32 %1, 0
%11 = zext i32 %0 to i64
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %8, %26
%14 = phi i64 [ 0, %8 ], [ %27, %26 ]
%15 = tail call i64 @malloc(i32 %9)
%16 = inttoptr i64 %15 to double**
%17 = getelementptr inbounds double**, double*** %6, i64 %14
store double** %16, double*** %17
br i1 %10, label %18, label %26
18: ; preds = %13, %18
%19 = phi i64 [ %24, %18 ], [ 0, %13 ]
%20 = tail call i64 @calloc(i32 %2, i32 8)
%21 = inttoptr i64 %20 to double*
%22 = load double**, double*** %17
%23 = getelementptr inbounds double*, double** %22, i64 %19
store double* %21, double** %23
%24 = add nuw nsw i64 %19, 1
%25 = icmp eq i64 %24, %12
br i1 %25, label %26, label %18
26: ; preds = %18, %13
%27 = add nuw nsw i64 %14, 1
%28 = icmp eq i64 %27, %11
br i1 %28, label %29, label %13
29: ; preds = %26, %3
ret double*** %6
}