#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__ malloc(size_t);
int /*<<< orphan*/ nrerror(char *);
int /*<<< orphan*/ printf(char *);
double **dmatrix(long nrl, long nrh, long ncl, long nch) {
  long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
  double **m;
  m = (double **)malloc((size_t)((nrow + 1) * sizeof(double *)));
  if (!m)
    nrerror("allocation failure 1 in matrix()");
  m += 1;
  m -= nrl;
  printf("dmatrix\n");
  m[nrl] = (double *)malloc((size_t)((nrow * ncol + 1) * sizeof(double)));
  if (!m[nrl])
    nrerror("allocation failure 2 in matrix()");
  m[nrl] += 1;
  m[nrl] -= ncl;
  for (i = nrl + 1; i <= nrh; i++)
    m[i] = m[i - 1] + ncol;
  return m;
}


x86 assembly (clang, -O0):
<dmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
sub    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1194 <dmatrix+0x64>
lea    0xe71(%rip),%rdi
call   1030 <nrerror@plt>
mov    -0x40(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x40(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
imul   -0x38(%rbp),%rdi
add    $0x1,%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1208 <dmatrix+0xd8>
lea    0xe27(%rip),%rdi
call   1030 <nrerror@plt>
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x8,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
xor    %esi,%esi
sub    %rdi,%rsi
shl    $0x3,%rsi
add    %rsi,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     128e <dmatrix+0x15e>
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x38(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1248 <dmatrix+0x118>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,0x10(%rsp)
sub    %rdi,%r14
mov    %rcx,%r15
mov    %rdx,0x20(%rsp)
sub    %rdx,%r15
add    $0x1,%r15
lea    0x10(,%r14,8),%rdi
shl    $0x3,%r14
call   1050 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1183 <dmatrix+0x53>
lea    0xe82(%rip),%rdi
call   1040 <nrerror@plt>
lea    0x0(,%rbx,8),%rax
mov    %r13,%rbp
sub    %rax,%rbp
lea    0x8(%rbp),%rax
mov    %rax,0x8(%rsp)
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%r14
mov    %r15,0x18(%rsp)
imul   %r15,%r14
add    $0x8,%r14
mov    %r14,%rdi
call   1050 <malloc@plt>
mov    %rax,0x8(%rbp,%rbx,8)
test   %rax,%rax
mov    %rbx,%r15
mov    0x8(%rsp),%rbx
jne    11e1 <dmatrix+0xb1>
lea    0xe49(%rip),%rdi
call   1040 <nrerror@plt>
mov    (%rbx,%r15,8),%rax
mov    0x20(%rsp),%r11
lea    0x0(,%r11,8),%r8
mov    %rax,%rdx
sub    %r8,%rdx
add    $0x8,%rdx
mov    %rdx,(%rbx,%r15,8)
mov    0x10(%rsp),%rbp
cmp    %r15,%rbp
mov    0x18(%rsp),%r14
jle    1309 <dmatrix+0x1d9>
mov    %ebp,%edi
sub    %r15d,%edi
mov    %r15,%r9
not    %r9
add    %rbp,%r9
and    $0x7,%rdi
je     1275 <dmatrix+0x145>
mov    %rbx,%r10
lea    0x0(,%r12,8),%rcx
sub    %r8,%rcx
add    $0x8,%rcx
mov    %r12,%rbx
sub    %r11,%rbx
sub    %r11,%rbx
lea    (%rax,%rbx,8),%rsi
add    $0x10,%rsi
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
mov    %rsi,0x10(%r13,%rax,8)
add    $0x1,%rax
add    %rcx,%rdx
add    %rcx,%rsi
cmp    %rax,%rdi
jne    1250 <dmatrix+0x120>
add    %r15,%rax
mov    %r10,%rbx
cmp    $0x7,%r9
jae    1282 <dmatrix+0x152>
jmp    1309 <dmatrix+0x1d9>
mov    %r15,%rax
cmp    $0x7,%r9
jb     1309 <dmatrix+0x1d9>
lea    (%rdx,%r14,8),%rdx
mov    %r12,%rsi
shl    $0x6,%rsi
shl    $0x6,%r11
sub    %r11,%rsi
add    $0x40,%rsi
mov    $0x9,%ecx
sub    %r15,%rcx
lea    0x0(,%rcx,8),%rdi
add    %r13,%rdi
shl    $0x3,%r12
sub    %r8,%r12
add    $0x8,%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rdx,-0x38(%rdi,%rax,8)
lea    (%rdx,%r12,1),%rcx
mov    %rcx,-0x30(%rdi,%rax,8)
add    %r12,%rcx
mov    %rcx,-0x28(%rdi,%rax,8)
add    %r12,%rcx
mov    %rcx,-0x20(%rdi,%rax,8)
add    %r12,%rcx
mov    %rcx,-0x18(%rdi,%rax,8)
add    %r12,%rcx
mov    %rcx,-0x10(%rdi,%rax,8)
add    %r12,%rcx
mov    %rcx,-0x8(%rdi,%rax,8)
add    %r12,%rcx
mov    %rcx,(%rdi,%rax,8)
add    $0x8,%rax
add    %rsi,%rdx
cmp    %rax,%rbp
jne    12c0 <dmatrix+0x190>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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