#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__ malloc(int);
int allocateArray3(double ****x, unsigned long firstDim,
                   unsigned long secondDim, unsigned long thirdDim) {
  double ***xinternal;
  unsigned long i, j;
  xinternal = (double ***)malloc(sizeof(double **) * firstDim);
  if (xinternal == NULL)
    return -1;
  for (i = 0; i < firstDim; i++) {
    xinternal[i] = (double **)malloc(sizeof(double *) * secondDim);
    if (xinternal[i] == NULL)
      return -1;
    for (j = 0; j < secondDim; j++) {
      xinternal[i][j] = (double *)malloc(sizeof(double) * thirdDim);
      if (xinternal[i][j] == NULL)
        return -1;
    }
  }
  *x = xinternal;
  return 0;
}


x86 assembly (clang, -O0):
<allocateArray3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1152 <allocateArray3+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <allocateArray3+0x136>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1234 <allocateArray3+0x124>
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11a5 <allocateArray3+0x95>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <allocateArray3+0x136>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    121e <allocateArray3+0x10e>
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x40(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x40(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1208 <allocateArray3+0xf8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <allocateArray3+0x136>
jmp    120d <allocateArray3+0xfd>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11ad <allocateArray3+0x9d>
jmp    1223 <allocateArray3+0x113>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    115a <allocateArray3+0x4a>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocateArray3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r13
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x0(,%rsi,8),%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
mov    $0xffffffff,%eax
test   %rbx,%rbx
je     11d7 <allocateArray3+0xc7>
mov    %r14,0x10(%rsp)
test   %r12,%r12
je     11cd <allocateArray3+0xbd>
lea    0x0(,%rbp,8),%r14d
shl    $0x3,%r13d
xor    %r15d,%r15d
mov    %r14d,0xc(%rsp)
jmp    117e <allocateArray3+0x6e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r12,%r15
mov    0xc(%rsp),%r14d
je     11cd <allocateArray3+0xbd>
mov    %r14d,%edi
call   1030 <malloc@plt>
mov    %rax,(%rbx,%r15,8)
test   %rax,%rax
je     11c6 <allocateArray3+0xb6>
test   %rbp,%rbp
je     1170 <allocateArray3+0x60>
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
call   1030 <malloc@plt>
mov    (%rbx,%r15,8),%rcx
mov    %rax,(%rcx,%r14,8)
mov    (%rbx,%r15,8),%rax
cmpq   $0x0,(%rax,%r14,8)
je     11c6 <allocateArray3+0xb6>
add    $0x1,%r14
cmp    %r14,%rbp
jne    11a0 <allocateArray3+0x90>
jmp    1170 <allocateArray3+0x60>
mov    $0xffffffff,%eax
jmp    11d7 <allocateArray3+0xc7>
mov    0x10(%rsp),%rax
mov    %rbx,(%rax)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @allocateArray3(double**** nocapture writeonly %0, i64 %1, i64 %2, i64 %3) {
%5 = trunc i64 %1 to i32
%6 = shl i32 %5, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to double***
%9 = icmp eq i64 %7, 0
br i1 %9, label %42, label %10
10: ; preds = %4
%11 = icmp eq i64 %1, 0
br i1 %11, label %41, label %12
12: ; preds = %10
%13 = trunc i64 %2 to i32
%14 = shl i32 %13, 3
%15 = icmp eq i64 %2, 0
%16 = trunc i64 %3 to i32
%17 = shl i32 %16, 3
br label %18
18: ; preds = %12, %38
%19 = phi i64 [ 0, %12 ], [ %39, %38 ]
%20 = tail call i64 @malloc(i32 %14)
%21 = inttoptr i64 %20 to double**
%22 = getelementptr inbounds double**, double*** %8, i64 %19
store double** %21, double*** %22
%23 = icmp eq i64 %20, 0
br i1 %23, label %42, label %24
24: ; preds = %18
br i1 %15, label %38, label %27
25: ; preds = %27
%26 = icmp eq i64 %37, %2
br i1 %26, label %38, label %27
27: ; preds = %24, %25
%28 = phi i64 [ %37, %25 ], [ 0, %24 ]
%29 = tail call i64 @malloc(i32 %17)
%30 = inttoptr i64 %29 to double*
%31 = load double**, double*** %22
%32 = getelementptr inbounds double*, double** %31, i64 %28
store double* %30, double** %32
%33 = load double**, double*** %22
%34 = getelementptr inbounds double*, double** %33, i64 %28
%35 = load double*, double** %34
%36 = icmp eq double* %35, null
%37 = add nuw i64 %28, 1
br i1 %36, label %42, label %25
38: ; preds = %25, %24
%39 = add nuw i64 %19, 1
%40 = icmp eq i64 %39, %1
br i1 %40, label %41, label %18
41: ; preds = %38, %10
store double*** %8, double**** %0
br label %42
42: ; preds = %18, %27, %4, %41
%43 = phi i32 [ 0, %41 ], [ -1, %4 ], [ -1, %27 ], [ -1, %18 ]
ret i32 %43
}