#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double **allocate2d(int dimX, int dimY) {
  double **array, *tmp;
  int i;
  tmp = (double *)calloc(dimX * dimY, sizeof(double));
  array = (double **)calloc(dimX, sizeof(double *));
  for (i = 0; i < dimX; i++)
    array[i] = tmp + i * dimY;
  if (array == NULL || tmp == NULL) {
    fprintf(stderr, "Error in allocation\n");
    exit(-1);
  }
  return array;
}


x86 assembly (clang, -O0):
<allocate2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
imul   -0x8(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a5 <allocate2d+0x75>
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116b <allocate2d+0x3b>
cmpq   $0x0,-0x10(%rbp)
je     11bb <allocate2d+0x8b>
cmpq   $0x0,-0x18(%rbp)
jne    11da <allocate2d+0xaa>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate2d>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%ebx
mov    %esi,%edi
imul   %ebx,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %ebx,%ebx
jle    1210 <allocate2d+0xe0>
movslq %ebp,%r8
mov    %ebx,%r10d
lea    -0x1(%r10),%rcx
mov    %r10d,%r9d
and    $0x3,%r9d
cmp    $0x3,%rcx
jae    1179 <allocate2d+0x49>
xor    %edi,%edi
jmp    11db <allocate2d+0xab>
and    $0xfffffffc,%r10d
mov    %r8,%r11
shl    $0x4,%r11
mov    %r8,%rbx
shl    $0x5,%rbx
lea    0x0(,%r8,8),%rbp
lea    0x0(,%rbp,2),%rdx
add    %rbp,%rdx
xor    %edi,%edi
mov    %r14,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rsi,(%rax,%rdi,8)
lea    (%rsi,%rbp,1),%rcx
mov    %rcx,0x8(%rax,%rdi,8)
lea    (%rsi,%r11,1),%rcx
mov    %rcx,0x10(%rax,%rdi,8)
lea    (%rsi,%rdx,1),%rcx
mov    %rcx,0x18(%rax,%rdi,8)
add    $0x4,%rdi
add    %rbx,%rsi
cmp    %rdi,%r10
jne    11b0 <allocate2d+0x80>
test   %r9,%r9
je     1210 <allocate2d+0xe0>
lea    (%rax,%rdi,8),%rcx
imul   %r8,%rdi
lea    (%r14,%rdi,8),%rdx
shl    $0x3,%r8
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rdx,(%rcx,%rsi,8)
add    $0x1,%rsi
add    %r8,%rdx
cmp    %rsi,%r9
jne    1200 <allocate2d+0xd0>
test   %rax,%rax
je     121f <allocate2d+0xef>
test   %r14,%r14
je     121f <allocate2d+0xef>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Error in allocation\0A\00"
define double** @allocate2d(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double**
%6 = alloca double*
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = mul nsw i32 %8, %9
%11 = call i64 @calloc(i32 %10, i32 8)
%12 = inttoptr i64 %11 to double*
store double* %12, double** %6
%13 = load i32, i32* %3
%14 = call i64 @calloc(i32 %13, i32 8)
%15 = inttoptr i64 %14 to double**
store double** %15, double*** %5
store i32 0, i32* %7
br label %16
16: ; preds = %31, %2
%17 = load i32, i32* %7
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = load double*, double** %6
%22 = load i32, i32* %7
%23 = load i32, i32* %4
%24 = mul nsw i32 %22, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %21, i64 %25
%27 = load double**, double*** %5
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double*, double** %27, i64 %29
store double* %26, double** %30
br label %31
31: ; preds = %20
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %16
34: ; preds = %16
%35 = load double**, double*** %5
%36 = icmp eq double** %35, null
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load double*, double** %6
%39 = icmp eq double* %38, null
br i1 %39, label %40, label %44
40: ; preds = %37, %34
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %37
%45 = load double**, double*** %5
ret double** %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Error in allocation\0A\00"
define double** @allocate2d(i32 %0, i32 %1) {
%3 = mul nsw i32 %1, %0
%4 = tail call i64 @calloc(i32 %3, i32 8)
%5 = inttoptr i64 %4 to double*
%6 = tail call i64 @calloc(i32 %0, i32 8)
%7 = inttoptr i64 %6 to double**
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %50
9: ; preds = %2
%10 = sext i32 %1 to i64
%11 = zext i32 %0 to i64
%12 = add nsw i64 %11, -1
%13 = and i64 %11, 3
%14 = icmp ult i64 %12, 3
br i1 %14, label %38, label %15
15: ; preds = %9
%16 = and i64 %11, 4294967292
br label %17
17: ; preds = %17, %15
%18 = phi i64 [ 0, %15 ], [ %35, %17 ]
%19 = phi i64 [ 0, %15 ], [ %36, %17 ]
%20 = mul nsw i64 %18, %10
%21 = getelementptr inbounds double, double* %5, i64 %20
%22 = getelementptr inbounds double*, double** %7, i64 %18
store double* %21, double** %22
%23 = or i64 %18, 1
%24 = mul nsw i64 %23, %10
%25 = getelementptr inbounds double, double* %5, i64 %24
%26 = getelementptr inbounds double*, double** %7, i64 %23
store double* %25, double** %26
%27 = or i64 %18, 2
%28 = mul nsw i64 %27, %10
%29 = getelementptr inbounds double, double* %5, i64 %28
%30 = getelementptr inbounds double*, double** %7, i64 %27
store double* %29, double** %30
%31 = or i64 %18, 3
%32 = mul nsw i64 %31, %10
%33 = getelementptr inbounds double, double* %5, i64 %32
%34 = getelementptr inbounds double*, double** %7, i64 %31
store double* %33, double** %34
%35 = add nuw nsw i64 %18, 4
%36 = add i64 %19, 4
%37 = icmp eq i64 %36, %16
br i1 %37, label %38, label %17
38: ; preds = %17, %9
%39 = phi i64 [ 0, %9 ], [ %35, %17 ]
%40 = icmp eq i64 %13, 0
br i1 %40, label %50, label %41
41: ; preds = %38, %41
%42 = phi i64 [ %47, %41 ], [ %39, %38 ]
%43 = phi i64 [ %48, %41 ], [ 0, %38 ]
%44 = mul nsw i64 %42, %10
%45 = getelementptr inbounds double, double* %5, i64 %44
%46 = getelementptr inbounds double*, double** %7, i64 %42
store double* %45, double** %46
%47 = add nuw nsw i64 %42, 1
%48 = add i64 %43, 1
%49 = icmp eq i64 %48, %13
br i1 %49, label %50, label %41
50: ; preds = %38, %41, %2
%51 = icmp eq i64 %6, 0
%52 = icmp eq i64 %4, 0
%53 = select i1 %51, i1 true, i1 %52
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = tail call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%57 = tail call i32 @exit(i32 -1)
unreachable
58: ; preds = %50
ret double** %7
}