#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);
double ***make3Darray_continuousMem(int a1, int a2, int a3) {
  double *tmp_vec = (double *)malloc(a1 * a2 * a3 * sizeof(double));
  double ***tmp;
  tmp = (double ***)malloc(a1 * sizeof(double **));
  for (int i = 0; i < a1; i++) {
    tmp[i] = (double **)malloc(a2 * sizeof(double *));
    for (int j = 0; j < a2; j++) {
      tmp[i][j] = &(tmp_vec[i * a2 * a3 + j * a3]);
    }
  }
  return tmp;
}


x86 assembly (clang, -O0):
<make3Darray_continuousMem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ea <make3Darray_continuousMem+0xda>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d7 <make3Darray_continuousMem+0xc7>
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%eax
imul   -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    -0x28(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    %ecx,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1188 <make3Darray_continuousMem+0x78>
jmp    11dc <make3Darray_continuousMem+0xcc>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1157 <make3Darray_continuousMem+0x47>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make3Darray_continuousMem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,8),%ebx
mov    %esi,%eax
mov    %rdx,0x8(%rsp)
imul   %edx,%eax
mov    %ebx,%edi
mov    %eax,0x18(%rsp)
imul   %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    126f <make3Darray_continuousMem+0x15f>
lea    0x0(,%r15,8),%eax
mov    %eax,0x14(%rsp)
mov    %r14d,%eax
mov    %rax,0x30(%rsp)
mov    %r15d,%ebp
add    $0xffffffffffffffff,%rbp
mov    0x8(%rsp),%rax
lea    (%rax,%rax,1),%r14d
mov    %rbp,0x20(%rsp)
mov    %rbp,%r10
and    $0xfffffffffffffffe,%r10
neg    %r10
xor    %r13d,%r13d
mov    %eax,%ebp
mov    %r14d,%r11d
mov    %r10,0x28(%rsp)
jmp    11b8 <make3Darray_continuousMem+0xa8>
nopl   0x0(%rax)
add    $0x1,%r13
mov    0x18(%rsp),%eax
add    %eax,%r11d
add    %eax,%ebp
cmp    0x30(%rsp),%r13
je     126f <make3Darray_continuousMem+0x15f>
mov    %r11d,0x1c(%rsp)
mov    0x14(%rsp),%edi
call   1030 <malloc@plt>
mov    0x1c(%rsp),%r11d
mov    0x28(%rsp),%r10
mov    %rax,(%rbx,%r13,8)
test   %r15d,%r15d
jle    11a0 <make3Darray_continuousMem+0x90>
mov    %r13d,%r8d
imul   %r15d,%r8d
mov    %r8d,%edx
imul   0x8(%rsp),%edx
movslq %edx,%rdx
lea    (%r12,%rdx,8),%rdx
mov    %rdx,(%rax)
cmp    $0x1,%r15d
je     11a0 <make3Darray_continuousMem+0x90>
mov    $0x1,%eax
cmp    $0x2,%r15d
je     1247 <make3Darray_continuousMem+0x137>
mov    $0x1,%eax
mov    %ebp,%edx
mov    %r11d,%esi
nopl   (%rax)
mov    (%rbx,%r13,8),%rdi
movslq %edx,%rdx
lea    (%r12,%rdx,8),%rcx
mov    %rcx,(%rdi,%rax,8)
mov    (%rbx,%r13,8),%rcx
movslq %esi,%rsi
lea    (%r12,%rsi,8),%rdi
mov    %rdi,0x8(%rcx,%rax,8)
add    %r14d,%esi
add    %r14d,%edx
lea    (%r10,%rax,1),%rcx
add    $0x2,%rcx
add    $0x2,%rax
cmp    $0x1,%rcx
jne    1210 <make3Darray_continuousMem+0x100>
testb  $0x1,0x20(%rsp)
je     11a0 <make3Darray_continuousMem+0x90>
mov    (%rbx,%r13,8),%rdx
add    %eax,%r8d
imul   0x8(%rsp),%r8d
movslq %r8d,%rcx
lea    (%r12,%rcx,8),%rcx
mov    %rcx,(%rdx,%rax,8)
jmp    11a0 <make3Darray_continuousMem+0x90>
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double*** @make3Darray_continuousMem(i32 %0, i32 %1, i32 %2) {
%4 = shl i32 %0, 3
%5 = mul i32 %4, %1
%6 = mul i32 %5, %2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to double*
%9 = tail call i64 @malloc(i32 %4)
%10 = inttoptr i64 %9 to double***
%11 = icmp sgt i32 %0, 0
br i1 %11, label %12, label %22
12: ; preds = %3
%13 = shl i32 %1, 3
%14 = icmp sgt i32 %1, 0
%15 = zext i32 %0 to i64
%16 = zext i32 %1 to i64
%17 = add nsw i64 %16, -1
%18 = and i64 %17, 1
%19 = icmp eq i32 %1, 2
%20 = and i64 %17, -2
%21 = icmp eq i64 %18, 0
br label %23
22: ; preds = %44, %3
ret double*** %10
23: ; preds = %12, %44
%24 = phi i64 [ 0, %12 ], [ %45, %44 ]
%25 = tail call i64 @malloc(i32 %13)
%26 = inttoptr i64 %25 to double**
%27 = getelementptr inbounds double**, double*** %10, i64 %24
store double** %26, double*** %27
br i1 %14, label %28, label %44
28: ; preds = %23
%29 = trunc i64 %24 to i32
%30 = mul nsw i32 %29, %1
%31 = mul i32 %30, %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %8, i64 %32
store double* %33, double** %26
switch i32 %1, label %47 [
i32 1, label %44
i32 2, label %34
]
34: ; preds = %47, %28
%35 = phi i64 [ 1, %28 ], [ %65, %47 ]
br i1 %21, label %44, label %36
36: ; preds = %34
%37 = load double**, double*** %27
%38 = trunc i64 %35 to i32
%39 = add i32 %30, %38
%40 = mul i32 %39, %2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %8, i64 %41
%43 = getelementptr inbounds double*, double** %37, i64 %35
store double* %42, double** %43
br label %44
44: ; preds = %36, %34, %28, %23
%45 = add nuw nsw i64 %24, 1
%46 = icmp eq i64 %45, %15
br i1 %46, label %22, label %23
47: ; preds = %28, %47
%48 = phi i64 [ %65, %47 ], [ 1, %28 ]
%49 = phi i64 [ %66, %47 ], [ 0, %28 ]
%50 = load double**, double*** %27
%51 = trunc i64 %48 to i32
%52 = add i32 %30, %51
%53 = mul i32 %52, %2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %8, i64 %54
%56 = getelementptr inbounds double*, double** %50, i64 %48
store double* %55, double** %56
%57 = add nuw nsw i64 %48, 1
%58 = load double**, double*** %27
%59 = trunc i64 %57 to i32
%60 = add i32 %30, %59
%61 = mul i32 %60, %2
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %8, i64 %62
%64 = getelementptr inbounds double*, double** %58, i64 %57
store double* %63, double** %64
%65 = add nuw nsw i64 %48, 2
%66 = add i64 %49, 2
%67 = icmp eq i64 %66, %20
br i1 %67, label %34, label %47
}