#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(unsigned int, int);
int /*<<< orphan*/ errorHandler(char *);
scalar_t__ malloc(unsigned int);
double **doublePointer(unsigned int LENGTH, unsigned int INIT) {
  double **P;
  if (!INIT) {
    if ((P = (double **)malloc(LENGTH * sizeof(double *))) == NULL)
      errorHandler("Error - In doublePointer(): Can't allocate memory");
  } else {
    if ((P = (double **)calloc(LENGTH, sizeof(double *))) == NULL)
      errorHandler("Error - In doublePointer(): Can't allocate memory");
  }
  return P;
}


x86 assembly (clang, -O0):
<doublePointer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1175 <doublePointer+0x45>
mov    -0x4(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1170 <doublePointer+0x40>
lea    0xe95(%rip),%rdi
call   1050 <errorHandler@plt>
jmp    11a1 <doublePointer+0x71>
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    119c <doublePointer+0x6c>
lea    0xe69(%rip),%rdi
call   1050 <errorHandler@plt>
jmp    11a1 <doublePointer+0x71>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doublePointer>:
push   %rax
test   %esi,%esi
je     1146 <doublePointer+0x16>
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     1153 <doublePointer+0x23>
pop    %rcx
ret
shl    $0x3,%edi
call   1040 <malloc@plt>
test   %rax,%rax
jne    1144 <doublePointer+0x14>
lea    0xea6(%rip),%rdi
call   1050 <errorHandler@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Error - In doublePointer(): Can't allocate memory\00"
define double** @doublePointer(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double**
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %2
%9 = load i32, i32* %3
%10 = zext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double**
store double** %14, double*** %5
%15 = icmp eq double** %14, null
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @errorHandler(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %8
br label %27
19: ; preds = %2
%20 = load i32, i32* %3
%21 = call i64 @calloc(i32 %20, i32 8)
%22 = inttoptr i64 %21 to double**
store double** %22, double*** %5
%23 = icmp eq double** %22, null
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @errorHandler(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
br label %27
27: ; preds = %26, %18
%28 = load double**, double*** %5
ret double** %28
}

LLVM IR (-O2):
@.str = [50 x i8] c"Error - In doublePointer(): Can't allocate memory\00"
define double** @doublePointer(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = shl i32 %0, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double**
%8 = icmp eq i64 %6, 0
br i1 %8, label %13, label %15
9: ; preds = %2
%10 = tail call i64 @calloc(i32 %0, i32 8)
%11 = inttoptr i64 %10 to double**
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %9, %4
%14 = tail call i32 @errorHandler(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %9, %4
%16 = phi double** [ %11, %9 ], [ %7, %4 ], [ null, %13 ]
ret double** %16
}