#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 /*<<< orphan*/ free_dmatrix(double **, int, int, int);
scalar_t__ malloc(size_t);
double **dmatrix(int nrl, int nrh, int ncl, int nch) {
  int i;
  double **m;
  m = (double **)malloc((size_t)((nrh - nrl + 1) * sizeof(double *)));
  if (!m)
    return NULL;
  m -= nrl;
  for (i = nrl; i <= nrh; i++) {
    m[i] = (double *)malloc((size_t)((nch - ncl + 1) * sizeof(double)));
    if (!(m[i])) {
      free_dmatrix(m, nrl, i - 1, ncl);
      return NULL;
    }
    m[i] -= ncl;
  }
  return m;
}


x86 assembly (clang, -O0):
<dmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1165 <dmatrix+0x45>
movq   $0x0,-0x8(%rbp)
jmp    1222 <dmatrix+0x102>
mov    -0xc(%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    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     121a <dmatrix+0xfa>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11ea <dmatrix+0xca>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%ecx
call   1040 <free_dmatrix@plt>
movq   $0x0,-0x8(%rbp)
jmp    1222 <dmatrix+0x102>
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%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    1185 <dmatrix+0x65>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r13d
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%ebp
mov    %esi,%eax
sub    %edi,%eax
add    $0x1,%eax
movslq %eax,%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
je     11c8 <dmatrix+0xa8>
mov    %rax,%rbx
movslq %ebp,%rax
shl    $0x3,%rax
mov    %rbx,%r12
sub    %rax,%r12
cmp    %r14d,%ebp
jg     11cb <dmatrix+0xab>
sub    %r15d,%r13d
add    $0x1,%r13d
movslq %r13d,%r13
shl    $0x3,%r13
mov    %r15d,0xc(%rsp)
movslq %r15d,%r15
neg    %r15
mov    %rbp,0x10(%rsp)
add    $0xffffffff,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1030 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11b5 <dmatrix+0x95>
lea    (%rax,%r15,8),%rax
mov    %rax,(%rbx)
add    $0x1,%ebp
add    $0x8,%rbx
cmp    %ebp,%r14d
jne    1190 <dmatrix+0x70>
jmp    11cb <dmatrix+0xab>
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
mov    %ebp,%edx
mov    0xc(%rsp),%ecx
call   1040 <free_dmatrix@plt>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @dmatrix(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double**
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = sub nsw i32 %12, %13
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 8
%18 = call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to double**
store double** %19, double*** %11
%20 = load double**, double*** %11
%21 = icmp ne double** %20, null
br i1 %21, label %23, label %22
22: ; preds = %4
store double** null, double*** %5
br label %75
23: ; preds = %4
%24 = load i32, i32* %6
%25 = load double**, double*** %11
%26 = sext i32 %24 to i64
%27 = sub i64 0, %26
%28 = getelementptr inbounds double*, double** %25, i64 %27
store double** %28, double*** %11
%29 = load i32, i32* %6
store i32 %29, i32* %10
br label %30
30: ; preds = %70, %23
%31 = load i32, i32* %10
%32 = load i32, i32* %7
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %73
34: ; preds = %30
%35 = load i32, i32* %9
%36 = load i32, i32* %8
%37 = sub nsw i32 %35, %36
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 8
%41 = call i64 @malloc(i64 %40)
%42 = inttoptr i64 %41 to double*
%43 = load double**, double*** %11
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double*, double** %43, i64 %45
store double* %42, double** %46
%47 = load double**, double*** %11
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double*, double** %47, i64 %49
%51 = load double*, double** %50
%52 = icmp ne double* %51, null
br i1 %52, label %60, label %53
53: ; preds = %34
%54 = load double**, double*** %11
%55 = load i32, i32* %6
%56 = load i32, i32* %10
%57 = sub nsw i32 %56, 1
%58 = load i32, i32* %8
%59 = call i32 @free_dmatrix(double** %54, i32 %55, i32 %57, i32 %58)
store double** null, double*** %5
br label %75
60: ; preds = %34
%61 = load i32, i32* %8
%62 = load double**, double*** %11
%63 = load i32, i32* %10
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double*, double** %62, i64 %64
%66 = load double*, double** %65
%67 = sext i32 %61 to i64
%68 = sub i64 0, %67
%69 = getelementptr inbounds double, double* %66, i64 %68
store double* %69, double** %65
br label %70
70: ; preds = %60
%71 = load i32, i32* %10
%72 = add nsw i32 %71, 1
store i32 %72, i32* %10
br label %30
73: ; preds = %30
%74 = load double**, double*** %11
store double** %74, double*** %5
br label %75
75: ; preds = %73, %53, %22
%76 = load double**, double*** %5
ret double** %76
}

LLVM IR (-O2):
define double** @dmatrix(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = sub i32 1, %0
%6 = add i32 %5, %1
%7 = sext i32 %6 to i64
%8 = shl nsw i64 %7, 3
%9 = tail call i64 @malloc(i64 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %40, label %11
11: ; preds = %4
%12 = inttoptr i64 %9 to double**
%13 = sext i32 %0 to i64
%14 = sub nsw i64 0, %13
%15 = getelementptr inbounds double*, double** %12, i64 %14
%16 = icmp sgt i32 %0, %1
br i1 %16, label %40, label %17
17: ; preds = %11
%18 = sub i32 1, %2
%19 = add i32 %18, %3
%20 = sext i32 %19 to i64
%21 = shl nsw i64 %20, 3
%22 = sext i32 %2 to i64
%23 = sub nsw i64 0, %22
%24 = add i32 %1, 1
br label %25
25: ; preds = %17, %35
%26 = phi i64 [ %13, %17 ], [ %37, %35 ]
%27 = tail call i64 @malloc(i64 %21)
%28 = inttoptr i64 %27 to double*
%29 = getelementptr inbounds double*, double** %15, i64 %26
store double* %28, double** %29
%30 = icmp eq i64 %27, 0
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = trunc i64 %26 to i32
%33 = add nsw i32 %32, -1
%34 = tail call i32 @free_dmatrix(double** %15, i32 %0, i32 %33, i32 %2)
br label %40
35: ; preds = %25
%36 = getelementptr inbounds double, double* %28, i64 %23
store double* %36, double** %29
%37 = add nsw i64 %26, 1
%38 = trunc i64 %37 to i32
%39 = icmp eq i32 %24, %38
br i1 %39, label %40, label %25
40: ; preds = %35, %11, %4, %31
%41 = phi double** [ null, %31 ], [ null, %4 ], [ %15, %11 ], [ %15, %35 ]
ret double** %41
}