#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 **ShareMallocM2d(int, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
double ***ShareMallocM3d(int size1, int size2, int size3) {
  int i;
  double ***s = NULL;
  if ((s = (double ***)calloc(size1, sizeof(double **))) == NULL) {
    printf("double *** malloc error!\n");
    exit(1);
  }
  if (size2 > 0) {
    for (i = 0; i < size1; i++)
      s[i] = ShareMallocM2d(size2, size3);
  }
  return s;
}


x86 assembly (clang, -O0):
<ShareMallocM3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    118a <ShareMallocM3d+0x4a>
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11d4 <ShareMallocM3d+0x94>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11cf <ShareMallocM3d+0x8f>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <ShareMallocM2d@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119b <ShareMallocM3d+0x5b>
jmp    11d4 <ShareMallocM3d+0x94>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ShareMallocM3d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r12d
mov    %edi,%r15d
mov    $0x8,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11ab <ShareMallocM3d+0x6b>
mov    %rax,%r13
test   %r12d,%r12d
jle    1199 <ShareMallocM3d+0x59>
test   %r15d,%r15d
jle    1199 <ShareMallocM3d+0x59>
mov    %r15d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,%edi
mov    %r14d,%esi
call   1040 <ShareMallocM2d@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <ShareMallocM3d+0x40>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"double *** malloc error!\0A\00"
define double*** @ShareMallocM3d(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double***
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store double*** null, double**** %8
%9 = load i32, i32* %4
%10 = call i64 @calloc(i32 %9, i32 8)
%11 = inttoptr i64 %10 to double***
store double*** %11, double**** %8
%12 = icmp eq double*** %11, null
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %16
store i32 0, i32* %7
br label %20
20: ; preds = %32, %19
%21 = load i32, i32* %7
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = call double** @ShareMallocM2d(i32 %25, i32 %26)
%28 = load double***, double**** %8
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double**, double*** %28, i64 %30
store double** %27, double*** %31
br label %32
32: ; preds = %24
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %20
35: ; preds = %20
br label %36
36: ; preds = %35, %16
%37 = load double***, double**** %8
ret double*** %37
}

LLVM IR (-O2):
@str = [25 x i8] c"double *** malloc error!\00"
define double*** @ShareMallocM3d(i32 %0, i32 %1, i32 %2) {
%4 = tail call i64 @calloc(i32 %0, i32 8)
%5 = inttoptr i64 %4 to double***
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = icmp sgt i32 %1, 0
%12 = icmp sgt i32 %0, 0
%13 = and i1 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = zext i32 %0 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %20, %16 ]
%18 = tail call double** @ShareMallocM2d(i32 %1, i32 %2)
%19 = getelementptr inbounds double**, double*** %5, i64 %17
store double** %18, double*** %19
%20 = add nuw nsw i64 %17, 1
%21 = icmp eq i64 %20, %15
br i1 %21, label %22, label %16
22: ; preds = %16, %10
ret double*** %5
}