#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*/ printf(char *);
double ***dmatrix3d(int nsl, int nsh, int nrl, int nrh, int ncl, int nch) {
  int i, j;
  double ***m;
  m = (double ***)calloc((unsigned)(nsh - nsl + 1), sizeof(double **));
  if (!m)
    printf("allocation failure 1 in dmatrix3d()");
  m -= nsl;
  for (j = nsl; j <= nsh; j++) {
    m[j] = (double **)calloc((unsigned)(nrh - nrl + 1), sizeof(double *));
    if (!m[j])
      printf("allocation failure 2 in dmatrix3d()");
    m[j] -= nrl;
    for (i = nrl; i <= nrh; i++) {
      m[j][i] = (double *)calloc((unsigned)(nch - ncl + 1), sizeof(double));
      if (!m[j][i])
        printf("allocation failure 3 in dmatrix3d()");
      m[j][i] -= ncl;
    }
  }
  return m;
}


x86 assembly (clang, -O0):
<dmatrix3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
mov    -0x8(%rbp),%edi
sub    -0x4(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116a <dmatrix3d+0x4a>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12a7 <dmatrix3d+0x187>
mov    -0x10(%rbp),%edi
sub    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11d7 <dmatrix3d+0xb7>
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq %esi,%rdi
xor    %esi,%esi
sub    %rdi,%rsi
shl    $0x3,%rsi
add    %rsi,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1294 <dmatrix3d+0x174>
mov    -0x18(%rbp),%edi
sub    -0x14(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    125c <dmatrix3d+0x13c>
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq %esi,%rdi
xor    %esi,%esi
sub    %rdi,%rsi
shl    $0x3,%rsi
add    %rsi,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ff <dmatrix3d+0xdf>
jmp    1299 <dmatrix3d+0x179>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118a <dmatrix3d+0x6a>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmatrix3d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%ebx
mov    %r8d,%r14d
mov    %ecx,0x10(%rsp)
mov    %edx,0xc(%rsp)
mov    %esi,%r12d
mov    %edi,%r13d
mov    %esi,%edi
sub    %r13d,%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1168 <dmatrix3d+0x48>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
movslq %r13d,%r15
lea    0x0(,%r15,8),%rax
sub    %rax,%rbp
mov    %r12d,0x8(%rsp)
cmp    %r12d,%r13d
jle    1192 <dmatrix3d+0x72>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%ecx
mov    0xc(%rsp),%eax
sub    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x14(%rsp)
cltq
mov    %rax,0x18(%rsp)
neg    %rax
mov    %rax,0x20(%rsp)
sub    %r14d,%ebx
add    $0x1,%ebx
movslq %r14d,%r12
neg    %r12
addl   $0x1,0x8(%rsp)
jmp    11db <dmatrix3d+0xbb>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r15
cmp    %r15d,0x8(%rsp)
je     1180 <dmatrix3d+0x60>
mov    0x14(%rsp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,0x0(%rbp,%r15,8)
test   %rax,%rax
jne    1204 <dmatrix3d+0xe4>
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
mov    0x0(%rbp,%r15,8),%rax
mov    0x20(%rsp),%rcx
lea    (%rax,%rcx,8),%rax
mov    %rax,0x0(%rbp,%r15,8)
mov    0xc(%rsp),%eax
cmp    0x10(%rsp),%eax
jg     11d0 <dmatrix3d+0xb0>
mov    0x14(%rsp),%r13d
mov    0x18(%rsp),%r14
jmp    1242 <dmatrix3d+0x122>
nopl   0x0(%rax,%rax,1)
lea    (%rcx,%r12,8),%rcx
mov    %rcx,(%rax,%r14,8)
add    $0x1,%r14
add    $0xffffffff,%r13d
je     11d0 <dmatrix3d+0xb0>
mov    %ebx,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    0x0(%rbp,%r15,8),%rcx
mov    %rax,(%rcx,%r14,8)
mov    0x0(%rbp,%r15,8),%rax
mov    (%rax,%r14,8),%rcx
test   %rcx,%rcx
jne    1230 <dmatrix3d+0x110>
lea    0xddc(%rip),%rdi
call   1030 <printf@plt>
mov    0x0(%rbp,%r15,8),%rax
mov    (%rax,%r14,8),%rcx
jmp    1230 <dmatrix3d+0x110>

LLVM IR (-O0):
@.str = [36 x i8] c"allocation failure 1 in dmatrix3d()\00"
@.str.1 = [36 x i8] c"allocation failure 2 in dmatrix3d()\00"
@.str.2 = [36 x i8] c"allocation failure 3 in dmatrix3d()\00"
define double*** @dmatrix3d(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double***
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = sub nsw i32 %16, %17
%19 = add nsw i32 %18, 1
%20 = call i64 @calloc(i32 %19, i32 8)
%21 = inttoptr i64 %20 to double***
store double*** %21, double**** %15
%22 = load double***, double**** %15
%23 = icmp ne double*** %22, null
br i1 %23, label %26, label %24
24: ; preds = %6
%25 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %6
%27 = load i32, i32* %7
%28 = load double***, double**** %15
%29 = sext i32 %27 to i64
%30 = sub i64 0, %29
%31 = getelementptr inbounds double**, double*** %28, i64 %30
store double*** %31, double**** %15
%32 = load i32, i32* %7
store i32 %32, i32* %14
br label %33
33: ; preds = %116, %26
%34 = load i32, i32* %14
%35 = load i32, i32* %8
%36 = icmp sle i32 %34, %35
br i1 %36, label %37, label %119
37: ; preds = %33
%38 = load i32, i32* %10
%39 = load i32, i32* %9
%40 = sub nsw i32 %38, %39
%41 = add nsw i32 %40, 1
%42 = call i64 @calloc(i32 %41, i32 8)
%43 = inttoptr i64 %42 to double**
%44 = load double***, double**** %15
%45 = load i32, i32* %14
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double**, double*** %44, i64 %46
store double** %43, double*** %47
%48 = load double***, double**** %15
%49 = load i32, i32* %14
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double**, double*** %48, i64 %50
%52 = load double**, double*** %51
%53 = icmp ne double** %52, null
br i1 %53, label %56, label %54
54: ; preds = %37
%55 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %56
56: ; preds = %54, %37
%57 = load i32, i32* %9
%58 = load double***, double**** %15
%59 = load i32, i32* %14
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double**, double*** %58, i64 %60
%62 = load double**, double*** %61
%63 = sext i32 %57 to i64
%64 = sub i64 0, %63
%65 = getelementptr inbounds double*, double** %62, i64 %64
store double** %65, double*** %61
%66 = load i32, i32* %9
store i32 %66, i32* %13
br label %67
67: ; preds = %112, %56
%68 = load i32, i32* %13
%69 = load i32, i32* %10
%70 = icmp sle i32 %68, %69
br i1 %70, label %71, label %115
71: ; preds = %67
%72 = load i32, i32* %12
%73 = load i32, i32* %11
%74 = sub nsw i32 %72, %73
%75 = add nsw i32 %74, 1
%76 = call i64 @calloc(i32 %75, i32 8)
%77 = inttoptr i64 %76 to double*
%78 = load double***, double**** %15
%79 = load i32, i32* %14
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double**, double*** %78, i64 %80
%82 = load double**, double*** %81
%83 = load i32, i32* %13
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double*, double** %82, i64 %84
store double* %77, double** %85
%86 = load double***, double**** %15
%87 = load i32, i32* %14
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double**, double*** %86, i64 %88
%90 = load double**, double*** %89
%91 = load i32, i32* %13
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double*, double** %90, i64 %92
%94 = load double*, double** %93
%95 = icmp ne double* %94, null
br i1 %95, label %98, label %96
96: ; preds = %71
%97 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %98
98: ; preds = %96, %71
%99 = load i32, i32* %11
%100 = load double***, double**** %15
%101 = load i32, i32* %14
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double**, double*** %100, i64 %102
%104 = load double**, double*** %103
%105 = load i32, i32* %13
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds double*, double** %104, i64 %106
%108 = load double*, double** %107
%109 = sext i32 %99 to i64
%110 = sub i64 0, %109
%111 = getelementptr inbounds double, double* %108, i64 %110
store double* %111, double** %107
br label %112
112: ; preds = %98
%113 = load i32, i32* %13
%114 = add nsw i32 %113, 1
store i32 %114, i32* %13
br label %67
115: ; preds = %67
br label %116
116: ; preds = %115
%117 = load i32, i32* %14
%118 = add nsw i32 %117, 1
store i32 %118, i32* %14
br label %33
119: ; preds = %33
%120 = load double***, double**** %15
ret double*** %120
}

LLVM IR (-O2):
@.str = [36 x i8] c"allocation failure 1 in dmatrix3d()\00"
@.str.1 = [36 x i8] c"allocation failure 2 in dmatrix3d()\00"
@.str.2 = [36 x i8] c"allocation failure 3 in dmatrix3d()\00"
define double*** @dmatrix3d(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = sub i32 1, %0
%8 = add i32 %7, %1
%9 = tail call i64 @calloc(i32 %8, i32 8)
%10 = inttoptr i64 %9 to double***
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %6
%15 = sext i32 %0 to i64
%16 = sub nsw i64 0, %15
%17 = getelementptr inbounds double**, double*** %10, i64 %16
%18 = icmp sgt i32 %0, %1
br i1 %18, label %70, label %19
19: ; preds = %14
%20 = sub i32 1, %2
%21 = add i32 %20, %3
%22 = sext i32 %2 to i64
%23 = sub nsw i64 0, %22
%24 = icmp sgt i32 %2, %3
%25 = sub i32 1, %4
%26 = add i32 %25, %5
%27 = sext i32 %4 to i64
%28 = sub nsw i64 0, %27
%29 = add i32 %3, 1
%30 = add i32 %1, 1
br label %31
31: ; preds = %19, %66
%32 = phi i64 [ %15, %19 ], [ %67, %66 ]
%33 = tail call i64 @calloc(i32 %21, i32 8)
%34 = inttoptr i64 %33 to double**
%35 = getelementptr inbounds double**, double*** %17, i64 %32
store double** %34, double*** %35
%36 = icmp eq i64 %33, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%39 = load double**, double*** %35
br label %40
40: ; preds = %37, %31
%41 = phi double** [ %39, %37 ], [ %34, %31 ]
%42 = getelementptr inbounds double*, double** %41, i64 %23
store double** %42, double*** %35
br i1 %24, label %66, label %43
43: ; preds = %40, %58
%44 = phi i64 [ %63, %58 ], [ %22, %40 ]
%45 = tail call i64 @calloc(i32 %26, i32 8)
%46 = inttoptr i64 %45 to double*
%47 = load double**, double*** %35
%48 = getelementptr inbounds double*, double** %47, i64 %44
store double* %46, double** %48
%49 = load double**, double*** %35
%50 = getelementptr inbounds double*, double** %49, i64 %44
%51 = load double*, double** %50
%52 = icmp eq double* %51, null
br i1 %52, label %53, label %58
53: ; preds = %43
%54 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%55 = load double**, double*** %35
%56 = getelementptr inbounds double*, double** %55, i64 %44
%57 = load double*, double** %56
br label %58
58: ; preds = %53, %43
%59 = phi double* [ %57, %53 ], [ %51, %43 ]
%60 = phi double** [ %55, %53 ], [ %49, %43 ]
%61 = getelementptr inbounds double*, double** %60, i64 %44
%62 = getelementptr inbounds double, double* %59, i64 %28
store double* %62, double** %61
%63 = add nsw i64 %44, 1
%64 = trunc i64 %63 to i32
%65 = icmp eq i32 %29, %64
br i1 %65, label %66, label %43
66: ; preds = %58, %40
%67 = add nsw i64 %32, 1
%68 = trunc i64 %67 to i32
%69 = icmp eq i32 %30, %68
br i1 %69, label %70, label %31
70: ; preds = %66, %14
ret double*** %17
}