#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);
double **alloc_2D_double(int nrows, int ncolumns) {
  int i;
  double **array = (double **)calloc(nrows, sizeof(double *));
  if (array == NULL)
    return NULL;
  array[0] = (double *)calloc(nrows * ncolumns, sizeof(double));
  if (array[0] == NULL)
    return NULL;
  for (i = 1; i < nrows; ++i)
    array[i] = array[0] + i * ncolumns;
  return array;
}


x86 assembly (clang, -O0):
<alloc_2D_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1147 <alloc_2D_double+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11c9 <alloc_2D_double+0xb9>
mov    -0xc(%rbp),%edi
imul   -0x10(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    117d <alloc_2D_double+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    11c9 <alloc_2D_double+0xb9>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c1 <alloc_2D_double+0xb1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    -0x14(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <alloc_2D_double+0x74>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_2D_double>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     1202 <alloc_2D_double+0xf2>
mov    %rax,%r15
mov    %r14d,%edi
imul   %ebp,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1202 <alloc_2D_double+0xf2>
cmp    $0x2,%ebp
jl     1205 <alloc_2D_double+0xf5>
movslq %r14d,%r8
mov    %ebp,%ecx
lea    -0x1(%rcx),%r10
add    $0xfffffffffffffffe,%rcx
mov    %r10d,%r9d
and    $0x3,%r9d
mov    $0x1,%edi
cmp    $0x3,%rcx
jb     11cd <alloc_2D_double+0xbd>
and    $0xfffffffffffffffc,%r10
mov    %r8,%rcx
shl    $0x5,%rcx
lea    (%rax,%rcx,1),%rbp
lea    (%r8,%r8,2),%rdx
lea    (%rax,%rdx,8),%rdx
lea    (%rax,%r8,8),%rsi
mov    %r8,%rbx
shl    $0x4,%rbx
add    %rax,%rbx
xor    %edi,%edi
nopl   (%rax)
mov    %rsi,0x8(%r15,%rdi,8)
mov    %rbx,0x10(%r15,%rdi,8)
mov    %rdx,0x18(%r15,%rdi,8)
mov    %rbp,0x20(%r15,%rdi,8)
add    $0x4,%rdi
add    %rcx,%rbp
add    %rcx,%rdx
add    %rcx,%rsi
add    %rcx,%rbx
cmp    %rdi,%r10
jne    11a0 <alloc_2D_double+0x90>
add    $0x1,%rdi
test   %r9,%r9
je     1205 <alloc_2D_double+0xf5>
lea    (%r15,%rdi,8),%rcx
imul   %r8,%rdi
lea    (%rax,%rdi,8),%rax
shl    $0x3,%r8
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,(%rcx,%rdx,8)
add    $0x1,%rdx
add    %r8,%rax
cmp    %rdx,%r9
jne    11f0 <alloc_2D_double+0xe0>
jmp    1205 <alloc_2D_double+0xf5>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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