#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 */
int arrayAlloc2D(int, int, double ****);
int /*<<< orphan*/ free(double **);
int /*<<< orphan*/ printf(char *, double);
int main() {
  int dim1 = 5;
  int dim2 = 5;
  int i, j;
  double(*array)[dim1][dim2] = NULL;
  int ret = arrayAlloc2D(dim1, dim2, &array);
  if (ret == -1) {
    return -1;
  }
  for (i = 0; i < dim1; i++) {
    for (j = 0; j < dim2; j++) {
      (*array)[i][j] = i + j;
    }
  }
  for (i = 0; i < dim1; i++) {
    for (j = 0; j < dim2; j++) {
      printf("%f \n", (*array)[i][j]);
    }
  }
  free(*array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x5,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1050 <arrayAlloc2D@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1184 <main+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1278 <main+0x148>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f5 <main+0xc5>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e2 <main+0xb2>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119e <main+0x6e>
jmp    11e7 <main+0xb7>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118b <main+0x5b>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1268 <main+0x138>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1255 <main+0x125>
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdbe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    120f <main+0xdf>
jmp    125a <main+0x12a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11fc <main+0xcc>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdx
mov    $0x5,%edi
mov    $0x5,%esi
call   1050 <arrayAlloc2D@plt>
cmp    $0xffffffff,%eax
je     13c4 <main+0x294>
xorps  %xmm0,%xmm0
movhps 0xe9b(%rip),%xmm0
mov    0x8(%rsp),%rax
movups %xmm0,(%rax)
movaps 0xe9c(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xea1(%rip),%xmm1
movups %xmm1,0x20(%rax)
movups %xmm0,0x30(%rax)
movaps 0xea2(%rip),%xmm1
movups %xmm1,0x40(%rax)
movups %xmm0,0x50(%rax)
movups %xmm1,0x60(%rax)
movaps 0xe9f(%rip),%xmm0
movups %xmm0,0x70(%rax)
movups %xmm1,0x80(%rax)
movaps 0xe9d(%rip),%xmm0
movups %xmm0,0x90(%rax)
movups %xmm1,0xa0(%rax)
movups %xmm0,0xb0(%rax)
movabs $0x4020000000000000,%rcx
mov    %rcx,0xc0(%rax)
lea    0xe80(%rip),%rbx
xorps  %xmm0,%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x8(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x10(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x18(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x20(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x28(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x30(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x38(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x40(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x48(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x50(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x58(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x60(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x68(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x70(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x78(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x80(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x88(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x90(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0x98(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0xa0(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0xa8(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0xb0(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0xb8(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
movsd  0xc0(%rax),%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    13c9 <main+0x299>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%f \0A\00"
define i32 @main() {
%1 = alloca double*
%2 = bitcast double** %1 to i8*
store double* null, double** %1
%3 = bitcast double** %1 to double****
%4 = call i32 @arrayAlloc2D(i32 5, i32 5, double**** %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %132, label %6
6: ; preds = %0
%7 = load double*, double** %1
%8 = bitcast double* %7 to <2 x double>*
store <2 x double> <double 0.000000e+00, double 1.000000e+00>, <2 x double>* %8
%9 = getelementptr inbounds double, double* %7, i64 2
%10 = bitcast double* %9 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 3.000000e+00>, <2 x double>* %10
%11 = getelementptr inbounds double, double* %7, i64 4
%12 = bitcast double* %11 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 1.000000e+00>, <2 x double>* %12
%13 = getelementptr inbounds double, double* %7, i64 6
%14 = bitcast double* %13 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 3.000000e+00>, <2 x double>* %14
%15 = getelementptr inbounds double, double* %7, i64 8
%16 = bitcast double* %15 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 5.000000e+00>, <2 x double>* %16
%17 = getelementptr inbounds double, double* %7, i64 10
%18 = bitcast double* %17 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 3.000000e+00>, <2 x double>* %18
%19 = getelementptr inbounds double, double* %7, i64 12
%20 = bitcast double* %19 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 5.000000e+00>, <2 x double>* %20
%21 = getelementptr inbounds double, double* %7, i64 14
%22 = bitcast double* %21 to <2 x double>*
store <2 x double> <double 6.000000e+00, double 3.000000e+00>, <2 x double>* %22
%23 = getelementptr inbounds double, double* %7, i64 16
%24 = bitcast double* %23 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 5.000000e+00>, <2 x double>* %24
%25 = getelementptr inbounds double, double* %7, i64 18
%26 = bitcast double* %25 to <2 x double>*
store <2 x double> <double 6.000000e+00, double 7.000000e+00>, <2 x double>* %26
%27 = getelementptr inbounds double, double* %7, i64 20
%28 = bitcast double* %27 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 5.000000e+00>, <2 x double>* %28
%29 = getelementptr inbounds double, double* %7, i64 22
%30 = bitcast double* %29 to <2 x double>*
store <2 x double> <double 6.000000e+00, double 7.000000e+00>, <2 x double>* %30
%31 = getelementptr inbounds double, double* %7, i64 24
store double 8.000000e+00, double* %31
%32 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double 0.000000e+00)
%33 = load double*, double** %1
%34 = getelementptr inbounds double, double* %33, i64 1
%35 = load double, double* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %35)
%37 = load double*, double** %1
%38 = getelementptr inbounds double, double* %37, i64 2
%39 = load double, double* %38
%40 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %39)
%41 = load double*, double** %1
%42 = getelementptr inbounds double, double* %41, i64 3
%43 = load double, double* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %43)
%45 = load double*, double** %1
%46 = getelementptr inbounds double, double* %45, i64 4
%47 = load double, double* %46
%48 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %47)
%49 = load double*, double** %1
%50 = getelementptr inbounds double, double* %49, i64 5
%51 = load double, double* %50
%52 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %51)
%53 = load double*, double** %1
%54 = getelementptr inbounds double, double* %53, i64 6
%55 = load double, double* %54
%56 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %55)
%57 = load double*, double** %1
%58 = getelementptr inbounds double, double* %57, i64 7
%59 = load double, double* %58
%60 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %59)
%61 = load double*, double** %1
%62 = getelementptr inbounds double, double* %61, i64 8
%63 = load double, double* %62
%64 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %63)
%65 = load double*, double** %1
%66 = getelementptr inbounds double, double* %65, i64 9
%67 = load double, double* %66
%68 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %67)
%69 = load double*, double** %1
%70 = getelementptr inbounds double, double* %69, i64 10
%71 = load double, double* %70
%72 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %71)
%73 = load double*, double** %1
%74 = getelementptr inbounds double, double* %73, i64 11
%75 = load double, double* %74
%76 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %75)
%77 = load double*, double** %1
%78 = getelementptr inbounds double, double* %77, i64 12
%79 = load double, double* %78
%80 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %79)
%81 = load double*, double** %1
%82 = getelementptr inbounds double, double* %81, i64 13
%83 = load double, double* %82
%84 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %83)
%85 = load double*, double** %1
%86 = getelementptr inbounds double, double* %85, i64 14
%87 = load double, double* %86
%88 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %87)
%89 = load double*, double** %1
%90 = getelementptr inbounds double, double* %89, i64 15
%91 = load double, double* %90
%92 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %91)
%93 = load double*, double** %1
%94 = getelementptr inbounds double, double* %93, i64 16
%95 = load double, double* %94
%96 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %95)
%97 = load double*, double** %1
%98 = getelementptr inbounds double, double* %97, i64 17
%99 = load double, double* %98
%100 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %99)
%101 = load double*, double** %1
%102 = getelementptr inbounds double, double* %101, i64 18
%103 = load double, double* %102
%104 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %103)
%105 = load double*, double** %1
%106 = getelementptr inbounds double, double* %105, i64 19
%107 = load double, double* %106
%108 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %107)
%109 = load double*, double** %1
%110 = getelementptr inbounds double, double* %109, i64 20
%111 = load double, double* %110
%112 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %111)
%113 = load double*, double** %1
%114 = getelementptr inbounds double, double* %113, i64 21
%115 = load double, double* %114
%116 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %115)
%117 = load double*, double** %1
%118 = getelementptr inbounds double, double* %117, i64 22
%119 = load double, double* %118
%120 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %119)
%121 = load double*, double** %1
%122 = getelementptr inbounds double, double* %121, i64 23
%123 = load double, double* %122
%124 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %123)
%125 = load double*, double** %1
%126 = getelementptr inbounds double, double* %125, i64 24
%127 = load double, double* %126
%128 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %127)
%129 = bitcast double** %1 to double***
%130 = load double**, double*** %129
%131 = call i32 @free(double** %130)
br label %132
132: ; preds = %0, %6
%133 = phi i32 [ 0, %6 ], [ -1, %0 ]
ret i32 %133
}