#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 **doubleMatrix(unsigned int ROWS, unsigned int COLS, unsigned int INIT) {
  unsigned int i;
  double **M;
  if (!INIT) {
    if ((M = (double **)malloc(ROWS * sizeof(double *))) == NULL)
      errorHandler("Error - In doubleMatrix(): Can't allocate memory");
    for (i = 0; i < ROWS; i++)
      if ((M[i] = (double *)malloc(COLS * sizeof(double))) == NULL)
        errorHandler("Error - In doubleMatrix(): Can't allocate memory");
  } else {
    if ((M = (double **)calloc(ROWS, sizeof(double *))) == NULL)
      errorHandler("Error - In doubleMatrix(): Can't allocate memory");
    for (i = 0; i < ROWS; i++)
      if ((M[i] = (double *)calloc(COLS, sizeof(double))) == NULL)
        errorHandler("Error - In doubleMatrix(): Can't allocate memory");
  }
  return M;
}


x86 assembly (clang, -O0):
<doubleMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11cd <doubleMatrix+0x9d>
mov    -0x4(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1173 <doubleMatrix+0x43>
lea    0xe92(%rip),%rdi
call   1050 <errorHandler@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11c8 <doubleMatrix+0x98>
mov    -0x8(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%edx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11b5 <doubleMatrix+0x85>
lea    0xe50(%rip),%rdi
call   1050 <errorHandler@plt>
jmp    11ba <doubleMatrix+0x8a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117a <doubleMatrix+0x4a>
jmp    124d <doubleMatrix+0x11d>
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f4 <doubleMatrix+0xc4>
lea    0xe11(%rip),%rdi
call   1050 <errorHandler@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    1248 <doubleMatrix+0x118>
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%edx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    1235 <doubleMatrix+0x105>
lea    0xdd0(%rip),%rdi
call   1050 <errorHandler@plt>
jmp    123a <doubleMatrix+0x10a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11fb <doubleMatrix+0xcb>
jmp    124d <doubleMatrix+0x11d>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubleMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
test   %edx,%edx
je     11ad <doubleMatrix+0x7d>
mov    %r14d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1163 <doubleMatrix+0x33>
lea    0xea2(%rip),%rdi
call   1050 <errorHandler@plt>
test   %r14d,%r14d
je     1214 <doubleMatrix+0xe4>
mov    %r14d,%ebp
xor    %ebx,%ebx
lea    0xe88(%rip),%r14
jmp    118d <doubleMatrix+0x5d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1214 <doubleMatrix+0xe4>
mov    %r15d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
jne    1180 <doubleMatrix+0x50>
mov    %r14,%rdi
call   1050 <errorHandler@plt>
jmp    1180 <doubleMatrix+0x50>
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11ce <doubleMatrix+0x9e>
lea    0xe37(%rip),%rdi
call   1050 <errorHandler@plt>
test   %r14d,%r14d
je     1214 <doubleMatrix+0xe4>
shl    $0x3,%r15d
mov    %r14d,%ebp
xor    %ebx,%ebx
lea    0xe1d(%rip),%r14
jmp    11f9 <doubleMatrix+0xc9>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1214 <doubleMatrix+0xe4>
mov    %r15d,%edi
call   1040 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
jne    11f0 <doubleMatrix+0xc0>
mov    %r14,%rdi
call   1050 <errorHandler@plt>
jmp    11f0 <doubleMatrix+0xc0>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [49 x i8] c"Error - In doubleMatrix(): Can't allocate memory\00"
define double** @doubleMatrix(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %5, label %28
5: ; preds = %3
%6 = shl i32 %0, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to double**
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @errorHandler(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %5
%13 = icmp eq i32 %0, 0
br i1 %13, label %49, label %14
14: ; preds = %12
%15 = shl i32 %1, 3
%16 = zext i32 %0 to i64
br label %17
17: ; preds = %14, %25
%18 = phi i64 [ 0, %14 ], [ %26, %25 ]
%19 = tail call i64 @malloc(i32 %15)
%20 = inttoptr i64 %19 to double*
%21 = getelementptr inbounds double*, double** %8, i64 %18
store double* %20, double** %21
%22 = icmp eq i64 %19, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @errorHandler(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %17, %23
%26 = add nuw nsw i64 %18, 1
%27 = icmp eq i64 %26, %16
br i1 %27, label %49, label %17
28: ; preds = %3
%29 = tail call i64 @calloc(i32 %0, i32 8)
%30 = inttoptr i64 %29 to double**
%31 = icmp eq i64 %29, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @errorHandler(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = icmp eq i32 %0, 0
br i1 %35, label %49, label %36
36: ; preds = %34
%37 = zext i32 %0 to i64
br label %38
38: ; preds = %36, %46
%39 = phi i64 [ 0, %36 ], [ %47, %46 ]
%40 = tail call i64 @calloc(i32 %1, i32 8)
%41 = inttoptr i64 %40 to double*
%42 = getelementptr inbounds double*, double** %30, i64 %39
store double* %41, double** %42
%43 = icmp eq i64 %40, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = tail call i32 @errorHandler(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %46
46: ; preds = %38, %44
%47 = add nuw nsw i64 %39, 1
%48 = icmp eq i64 %47, %37
br i1 %48, label %49, label %38
49: ; preds = %46, %25, %34, %12
%50 = phi double** [ %8, %12 ], [ %30, %34 ], [ %8, %25 ], [ %30, %46 ]
ret double** %50
}