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


x86 assembly (clang, -O0):
<matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    -0x4(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <matrix+0x4b>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1211 <matrix+0xf1>
mov    -0x10(%rbp),%edi
sub    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11e1 <matrix+0xc1>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x14(%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    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <matrix+0x6b>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%r13d
mov    %edi,%r12d
mov    %esi,%r15d
sub    %edi,%r15d
add    $0x1,%r15d
mov    %r15d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    116a <matrix+0x4a>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
call   1040 <fprintf@plt>
movslq %r12d,%rax
shl    $0x3,%rax
mov    %rbp,%rcx
sub    %rax,%rcx
mov    %rcx,(%rsp)
cmp    %r13d,%r12d
jle    1193 <matrix+0x73>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
sub    %ebx,%r14d
add    $0x1,%r14d
movslq %ebx,%r13
neg    %r13
xor    %ebx,%ebx
lea    0xe78(%rip),%r12
jmp    11c2 <matrix+0xa2>
nopl   0x0(%rax,%rax,1)
lea    (%rax,%r13,8),%rax
mov    %rax,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
cmp    %ebx,%r15d
je     1180 <matrix+0x60>
mov    %r14d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,0x0(%rbp,%rbx,8)
test   %rax,%rax
jne    11b0 <matrix+0x90>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
call   1040 <fprintf@plt>
mov    0x0(%rbp,%rbx,8),%rax
jmp    11b0 <matrix+0x90>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"allocation failure 1 in matrix()\00"
@.str.1 = [33 x i8] c"allocation failure 2 in matrix()\00"
define double** @matrix(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = sub i32 1, %0
%6 = add i32 %5, %1
%7 = tail call i64 @calloc(i32 %6, i32 8)
%8 = inttoptr i64 %7 to double**
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %4
%14 = sext i32 %0 to i64
%15 = sub nsw i64 0, %14
%16 = getelementptr inbounds double*, double** %8, i64 %15
%17 = icmp sgt i32 %0, %1
br i1 %17, label %40, label %18
18: ; preds = %13
%19 = sub i32 1, %2
%20 = add i32 %19, %3
%21 = sext i32 %2 to i64
%22 = sub nsw i64 0, %21
%23 = add i32 %1, 1
br label %24
24: ; preds = %18, %34
%25 = phi i64 [ %14, %18 ], [ %37, %34 ]
%26 = tail call i64 @calloc(i32 %20, i32 8)
%27 = inttoptr i64 %26 to double*
%28 = getelementptr inbounds double*, double** %16, i64 %25
store double* %27, double** %28
%29 = icmp eq i64 %26, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%33 = load double*, double** %28
br label %34
34: ; preds = %30, %24
%35 = phi double* [ %33, %30 ], [ %27, %24 ]
%36 = getelementptr inbounds double, double* %35, i64 %22
store double* %36, double** %28
%37 = add nsw i64 %25, 1
%38 = trunc i64 %37 to i32
%39 = icmp eq i32 %23, %38
br i1 %39, label %40, label %24
40: ; preds = %34, %13
ret double** %16
}