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


x86 assembly (clang, -O0):
<imatrix>:
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   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1162 <imatrix+0x42>
lea    0xea3(%rip),%rdi
call   1030 <nrerror@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     11ff <imatrix+0xdf>
mov    -0x10(%rbp),%edi
sub    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x4,%esi
call   1040 <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    11cf <imatrix+0xaf>
lea    0xe58(%rip),%rdi
call   1030 <nrerror@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    $0x2,%rsi
add    %rsi,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <imatrix+0x62>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imatrix>:
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   1040 <calloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1161 <imatrix+0x41>
lea    0xea4(%rip),%rdi
call   1030 <nrerror@plt>
movslq %r12d,%rax
shl    $0x3,%rax
mov    %rbp,%rcx
sub    %rax,%rcx
mov    %rcx,(%rsp)
cmp    %r13d,%r12d
jle    118a <imatrix+0x6a>
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    0xe82(%rip),%r12
jmp    11c2 <imatrix+0xa2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rax,%r13,4),%rax
mov    %rax,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
cmp    %ebx,%r15d
je     1177 <imatrix+0x57>
mov    %r14d,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,0x0(%rbp,%rbx,8)
test   %rax,%rax
jne    11b0 <imatrix+0x90>
mov    %r12,%rdi
call   1030 <nrerror@plt>
mov    0x0(%rbp,%rbx,8),%rax
jmp    11b0 <imatrix+0x90>

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

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