#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 */
void *calloc(int, int);
int /*<<< orphan*/ error_and_exit();
double ***calloc_double_array(int dim1, int dim2, int dim3) {
  int i, j;
  double ***array;
  array = calloc(sizeof(double **), dim1);
  if (array == NULL)
    error_and_exit();
  for (i = 0; i < dim1; i++) {
    array[i] = calloc(sizeof(double *), dim2);
    if (array[i] == NULL)
      error_and_exit();
    for (j = 0; j < dim2; j++) {
      array[i][j] = calloc(sizeof(double), dim3);
      if (array[i][j] == NULL)
        error_and_exit();
    }
  }
  return array;
}


x86 assembly (clang, -O0):
<calloc_double_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x8,%edi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1154 <calloc_double_array+0x34>
mov    $0x0,%al
call   1040 <error_and_exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121c <calloc_double_array+0xfc>
mov    -0x8(%rbp),%esi
mov    $0x8,%edi
call   1030 <calloc@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    119d <calloc_double_array+0x7d>
mov    $0x0,%al
call   1040 <error_and_exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1209 <calloc_double_array+0xe9>
mov    -0xc(%rbp),%esi
mov    $0x8,%edi
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    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11f6 <calloc_double_array+0xd6>
mov    $0x0,%al
call   1040 <error_and_exit@plt>
jmp    11fb <calloc_double_array+0xdb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <calloc_double_array+0x84>
jmp    120e <calloc_double_array+0xee>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115b <calloc_double_array+0x3b>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calloc_double_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r13d
mov    %esi,%r15d
mov    %edi,%ebp
mov    $0x8,%edi
mov    %ebp,%esi
call   1030 <calloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1155 <calloc_double_array+0x35>
test   %ebp,%ebp
jg     1164 <calloc_double_array+0x44>
jmp    11f9 <calloc_double_array+0xd9>
xor    %eax,%eax
call   1040 <error_and_exit@plt>
test   %ebp,%ebp
jle    11f9 <calloc_double_array+0xd9>
mov    %ebp,%eax
mov    %rax,0x10(%rsp)
mov    %r15d,%ebx
xor    %r14d,%r14d
jmp    118b <calloc_double_array+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     11f9 <calloc_double_array+0xd9>
mov    $0x8,%edi
mov    %r15d,%esi
call   1030 <calloc@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%rax
mov    %rbp,(%rax,%r14,8)
test   %rbp,%rbp
je     11b0 <calloc_double_array+0x90>
test   %r15d,%r15d
jg     11bc <calloc_double_array+0x9c>
jmp    1180 <calloc_double_array+0x60>
xor    %eax,%eax
call   1040 <error_and_exit@plt>
test   %r15d,%r15d
jle    1180 <calloc_double_array+0x60>
xor    %r12d,%r12d
jmp    11d9 <calloc_double_array+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%rbx
je     1180 <calloc_double_array+0x60>
mov    $0x8,%edi
mov    %r13d,%esi
call   1030 <calloc@plt>
mov    %rax,0x0(%rbp,%r12,8)
test   %rax,%rax
jne    11d0 <calloc_double_array+0xb0>
xor    %eax,%eax
call   1040 <error_and_exit@plt>
jmp    11d0 <calloc_double_array+0xb0>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double*** @calloc_double_array(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 = call i8* @calloc(i32 8, i32 %10)
%12 = bitcast i8* %11 to double***
store double*** %12, double**** %9
%13 = load double***, double**** %9
%14 = icmp eq double*** %13, null
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 (...) @error_and_exit()
br label %17
17: ; preds = %15, %3
store i32 0, i32* %7
br label %18
18: ; preds = %72, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %75
22: ; preds = %18
%23 = load i32, i32* %5
%24 = call i8* @calloc(i32 8, i32 %23)
%25 = bitcast i8* %24 to double**
%26 = load double***, double**** %9
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double**, double*** %26, i64 %28
store double** %25, double*** %29
%30 = load double***, double**** %9
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double**, double*** %30, i64 %32
%34 = load double**, double*** %33
%35 = icmp eq double** %34, null
br i1 %35, label %36, label %38
36: ; preds = %22
%37 = call i32 (...) @error_and_exit()
br label %38
38: ; preds = %36, %22
store i32 0, i32* %8
br label %39
39: ; preds = %68, %38
%40 = load i32, i32* %8
%41 = load i32, i32* %5
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %71
43: ; preds = %39
%44 = load i32, i32* %6
%45 = call i8* @calloc(i32 8, i32 %44)
%46 = bitcast i8* %45 to double*
%47 = load double***, double**** %9
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double**, double*** %47, i64 %49
%51 = load double**, double*** %50
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double*, double** %51, i64 %53
store double* %46, double** %54
%55 = load double***, double**** %9
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double**, double*** %55, i64 %57
%59 = load double**, double*** %58
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double*, double** %59, i64 %61
%63 = load double*, double** %62
%64 = icmp eq double* %63, null
br i1 %64, label %65, label %67
65: ; preds = %43
%66 = call i32 (...) @error_and_exit()
br label %67
67: ; preds = %65, %43
br label %68
68: ; preds = %67
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
br label %39
71: ; preds = %39
br label %72
72: ; preds = %71
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
br label %18
75: ; preds = %18
%76 = load double***, double**** %9
ret double*** %76
}

LLVM IR (-O2):
define noalias double*** @calloc_double_array(i32 %0, i32 %1, i32 %2) {
%4 = tail call i8* @calloc(i32 8, i32 %0)
%5 = bitcast i8* %4 to double***
%6 = icmp eq i8* %4, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (...) @error_and_exit()
br label %9
9: ; preds = %7, %3
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %39
11: ; preds = %9
%12 = icmp sgt i32 %1, 0
%13 = zext i32 %0 to i64
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %11, %36
%16 = phi i64 [ 0, %11 ], [ %37, %36 ]
%17 = tail call i8* @calloc(i32 8, i32 %1)
%18 = getelementptr inbounds double**, double*** %5, i64 %16
%19 = bitcast double*** %18 to i8**
store i8* %17, i8** %19
%20 = icmp eq i8* %17, null
%21 = bitcast i8* %17 to double**
br i1 %20, label %22, label %24
22: ; preds = %15
%23 = tail call i32 (...) @error_and_exit()
br label %24
24: ; preds = %22, %15
br i1 %12, label %25, label %36
25: ; preds = %24, %33
%26 = phi i64 [ %34, %33 ], [ 0, %24 ]
%27 = tail call i8* @calloc(i32 8, i32 %2)
%28 = getelementptr inbounds double*, double** %21, i64 %26
%29 = bitcast double** %28 to i8**
store i8* %27, i8** %29
%30 = icmp eq i8* %27, null
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = tail call i32 (...) @error_and_exit()
br label %33
33: ; preds = %25, %31
%34 = add nuw nsw i64 %26, 1
%35 = icmp eq i64 %34, %14
br i1 %35, label %36, label %25
36: ; preds = %33, %24
%37 = add nuw nsw i64 %16, 1
%38 = icmp eq i64 %37, %13
br i1 %38, label %39, label %15
39: ; preds = %36, %9
ret double*** %5
}