#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);
int /*<<< orphan*/ no_mem_exit(char *);
int get_mem2Ddouble(double ***array2D, int rows, int columns) {
  int i;
  if ((*array2D = (double **)calloc(rows, sizeof(double *))) == NULL)
    no_mem_exit("get_mem2Ddouble: array2D");
  if (((*array2D)[0] = (double *)calloc(rows * columns, sizeof(double))) ==
      NULL)
    no_mem_exit("get_mem2Ddouble: array2D");
  for (i = 1; i < rows; i++)
    (*array2D)[i] = (*array2D)[i - 1] + columns;
  return rows * columns * sizeof(double);
}


x86 assembly (clang, -O0):
<get_mem2Ddouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    -0x8(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    115c <get_mem2Ddouble+0x3c>
lea    0xea9(%rip),%rdi
call   1040 <no_mem_exit@plt>
mov    -0xc(%rbp),%edi
imul   -0x10(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    118d <get_mem2Ddouble+0x6d>
lea    0xe78(%rip),%rdi
call   1040 <no_mem_exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dc <get_mem2Ddouble+0xbc>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1194 <get_mem2Ddouble+0x74>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mem2Ddouble>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
jne    114f <get_mem2Ddouble+0x2f>
lea    0xeb6(%rip),%rdi
call   1040 <no_mem_exit@plt>
mov    %r15d,%r14d
imul   %ebp,%r14d
mov    %r14d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    (%rbx),%rcx
mov    %rax,(%rcx)
test   %rax,%rax
je     1178 <get_mem2Ddouble+0x58>
cmp    $0x2,%ebp
jge    118d <get_mem2Ddouble+0x6d>
jmp    1239 <get_mem2Ddouble+0x119>
lea    0xe81(%rip),%rdi
call   1040 <no_mem_exit@plt>
cmp    $0x2,%ebp
jl     1239 <get_mem2Ddouble+0x119>
movslq %r15d,%r8
mov    %ebp,%edi
lea    -0x1(%rdi),%rsi
add    $0xfffffffffffffffe,%rdi
mov    %esi,%ecx
and    $0x3,%ecx
mov    $0x1,%edx
cmp    $0x3,%rdi
jb     120d <get_mem2Ddouble+0xed>
and    $0xfffffffffffffffc,%rsi
xor    %edx,%edx
lea    0x0(,%r8,8),%rdi
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rbp
mov    0x0(%rbp,%rdx,8),%rax
add    %rdi,%rax
mov    %rax,0x8(%rbp,%rdx,8)
mov    (%rbx),%rax
mov    0x8(%rax,%rdx,8),%rbp
add    %rdi,%rbp
mov    %rbp,0x10(%rax,%rdx,8)
mov    (%rbx),%rax
mov    0x10(%rax,%rdx,8),%rbp
add    %rdi,%rbp
mov    %rbp,0x18(%rax,%rdx,8)
mov    (%rbx),%rax
mov    0x18(%rax,%rdx,8),%rbp
add    %rdi,%rbp
mov    %rbp,0x20(%rax,%rdx,8)
add    $0x4,%rdx
cmp    %rdx,%rsi
jne    11c0 <get_mem2Ddouble+0xa0>
add    $0x1,%rdx
test   %rcx,%rcx
je     1239 <get_mem2Ddouble+0x119>
shl    $0x3,%r8
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx),%rax
mov    -0x8(%rax,%rdx,8),%rsi
add    %r8,%rsi
mov    %rsi,(%rax,%rdx,8)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rcx
jne    1220 <get_mem2Ddouble+0x100>
shl    $0x3,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"get_mem2Ddouble: array2D\00"
define i32 @get_mem2Ddouble(double*** %0, i32 %1, i32 %2) {
%4 = alloca double***
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store double*** %0, double**** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = call i64 @calloc(i32 %8, i32 8)
%10 = inttoptr i64 %9 to double**
%11 = load double***, double**** %4
store double** %10, double*** %11
%12 = icmp eq double** %10, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @no_mem_exit(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = mul nsw i32 %16, %17
%19 = call i64 @calloc(i32 %18, i32 8)
%20 = inttoptr i64 %19 to double*
%21 = load double***, double**** %4
%22 = load double**, double*** %21
%23 = getelementptr inbounds double*, double** %22, i64 0
store double* %20, double** %23
%24 = icmp eq double* %20, null
br i1 %24, label %25, label %27
25: ; preds = %15
%26 = call i32 @no_mem_exit(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %15
store i32 1, i32* %7
br label %28
28: ; preds = %48, %27
%29 = load i32, i32* %7
%30 = load i32, i32* %5
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %51
32: ; preds = %28
%33 = load double***, double**** %4
%34 = load double**, double*** %33
%35 = load i32, i32* %7
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double*, double** %34, i64 %37
%39 = load double*, double** %38
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double***, double**** %4
%44 = load double**, double*** %43
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double*, double** %44, i64 %46
store double* %42, double** %47
br label %48
48: ; preds = %32
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %28
51: ; preds = %28
%52 = load i32, i32* %5
%53 = load i32, i32* %6
%54 = mul nsw i32 %52, %53
%55 = sext i32 %54 to i64
%56 = mul i64 %55, 8
%57 = trunc i64 %56 to i32
ret i32 %57
}

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