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


x86 assembly (clang, -O0):
<get_mem2Ddb_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    -0x8(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    115f <get_mem2Ddb_offset+0x3f>
lea    0xea6(%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    1190 <get_mem2Ddb_offset+0x70>
lea    0xe75(%rip),%rdi
call   1040 <no_mem_exit@plt>
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
shl    $0x3,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f9 <get_mem2Ddb_offset+0xd9>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%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 -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b1 <get_mem2Ddb_offset+0x91>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mem2Ddb_offset>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
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    1153 <get_mem2Ddb_offset+0x33>
lea    0xeb2(%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
jne    117e <get_mem2Ddb_offset+0x5e>
lea    0xe87(%rip),%rdi
call   1040 <no_mem_exit@plt>
mov    (%rbx),%rax
movslq %r12d,%rcx
shl    $0x3,%rcx
add    %rcx,(%rax)
cmp    $0x2,%ebp
jl     1239 <get_mem2Ddb_offset+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_mem2Ddb_offset+0xed>
and    $0xfffffffffffffffc,%rsi
xor    %edx,%edx
lea    0x0(,%r8,8),%rdi
nop
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_mem2Ddb_offset+0xa0>
add    $0x1,%rdx
test   %rcx,%rcx
je     1239 <get_mem2Ddb_offset+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_mem2Ddb_offset+0x100>
shl    $0x3,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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