#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(long);
int /*<<< orphan*/ nrerror(char *);
int **imatrix(long nrl, long nrh, long ncl, long nch) {
  long i;
  int **m;
  m = (int **)malloc((nrh - nrl + 1) * sizeof(int *));
  if (!m)
    nrerror("allocation failure 1 in imatrix()");
  m -= nrl;
  for (i = nrl; i <= nrh; i++) {
    m[i] = (int *)malloc((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    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
sub    -0x8(%rbp),%rdi
add    $0x1,%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1168 <imatrix+0x48>
lea    0xe9d(%rip),%rdi
call   1030 <nrerror@plt>
mov    -0x8(%rbp),%rdx
mov    -0x30(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     120a <imatrix+0xea>
mov    -0x20(%rbp),%rdi
sub    -0x18(%rbp),%rdi
add    $0x1,%rdi
shl    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11d9 <imatrix+0xb9>
lea    0xe4e(%rip),%rdi
call   1030 <nrerror@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
xor    %esi,%esi
sub    %rdi,%rsi
shl    $0x2,%rsi
add    %rsi,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1188 <imatrix+0x68>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %rsi,%rax
sub    %rdi,%rax
lea    0x8(,%rax,8),%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115e <imatrix+0x3e>
lea    0xea7(%rip),%rdi
call   1030 <nrerror@plt>
lea    0x0(,%rbp,8),%rax
mov    %rbx,%rcx
sub    %rax,%rcx
mov    %rcx,(%rsp)
sub    %rbp,%r15
jge    1188 <imatrix+0x68>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
sub    %r14,%r13
lea    0x4(,%r13,4),%r13
neg    %r14
add    $0x1,%r15
xor    %r12d,%r12d
lea    0xe7e(%rip),%rbp
jmp    11c1 <imatrix+0xa1>
cs nopw 0x0(%rax,%rax,1)
lea    (%rax,%r14,4),%rax
mov    %rax,(%rbx,%r12,8)
add    $0x1,%r12
cmp    %r12,%r15
je     1175 <imatrix+0x55>
mov    %r13,%rdi
call   1040 <malloc@plt>
mov    %rax,(%rbx,%r12,8)
test   %rax,%rax
jne    11b0 <imatrix+0x90>
mov    %rbp,%rdi
call   1030 <nrerror@plt>
mov    (%rbx,%r12,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(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 i32**
store i64 %0, i64* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i64, i64* %6
%12 = load i64, i64* %5
%13 = sub nsw i64 %11, %12
%14 = add nsw i64 %13, 1
%15 = mul i64 %14, 8
%16 = call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i32**
store i32** %17, i32*** %10
%18 = load i32**, i32*** %10
%19 = icmp ne i32** %18, null
br i1 %19, label %22, label %20
20: ; preds = %4
%21 = call i32 @nrerror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %4
%23 = load i64, i64* %5
%24 = load i32**, i32*** %10
%25 = sub i64 0, %23
%26 = getelementptr inbounds i32*, i32** %24, i64 %25
store i32** %26, i32*** %10
%27 = load i64, i64* %5
store i64 %27, i64* %9
br label %28
28: ; preds = %58, %22
%29 = load i64, i64* %9
%30 = load i64, i64* %6
%31 = icmp sle i64 %29, %30
br i1 %31, label %32, label %61
32: ; preds = %28
%33 = load i64, i64* %8
%34 = load i64, i64* %7
%35 = sub nsw i64 %33, %34
%36 = add nsw i64 %35, 1
%37 = mul i64 %36, 4
%38 = call i64 @malloc(i64 %37)
%39 = inttoptr i64 %38 to i32*
%40 = load i32**, i32*** %10
%41 = load i64, i64* %9
%42 = getelementptr inbounds i32*, i32** %40, i64 %41
store i32* %39, i32** %42
%43 = load i32**, i32*** %10
%44 = load i64, i64* %9
%45 = getelementptr inbounds i32*, i32** %43, i64 %44
%46 = load i32*, i32** %45
%47 = icmp ne i32* %46, null
br i1 %47, label %50, label %48
48: ; preds = %32
%49 = call i32 @nrerror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %48, %32
%51 = load i64, i64* %7
%52 = load i32**, i32*** %10
%53 = load i64, i64* %9
%54 = getelementptr inbounds i32*, i32** %52, i64 %53
%55 = load i32*, i32** %54
%56 = sub i64 0, %51
%57 = getelementptr inbounds i32, i32* %55, i64 %56
store i32* %57, i32** %54
br label %58
58: ; preds = %50
%59 = load i64, i64* %9
%60 = add nsw i64 %59, 1
store i64 %60, i64* %9
br label %28
61: ; preds = %28
%62 = load i32**, i32*** %10
ret i32** %62
}

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(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = sub nsw i64 %1, %0
%6 = shl i64 %5, 3
%7 = add i64 %6, 8
%8 = tail call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i32**
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 @nrerror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %4
%14 = sub i64 0, %0
%15 = getelementptr inbounds i32*, i32** %9, i64 %14
%16 = icmp slt i64 %1, %0
br i1 %16, label %36, label %17
17: ; preds = %13
%18 = sub nsw i64 %3, %2
%19 = shl i64 %18, 2
%20 = add i64 %19, 4
%21 = sub i64 0, %2
br label %22
22: ; preds = %17, %31
%23 = phi i64 [ %0, %17 ], [ %34, %31 ]
%24 = tail call i64 @malloc(i64 %20)
%25 = inttoptr i64 %24 to i32*
%26 = getelementptr inbounds i32*, i32** %15, i64 %23
store i32* %25, i32** %26
%27 = icmp eq i64 %24, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = tail call i32 @nrerror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32*, i32** %26
br label %31
31: ; preds = %28, %22
%32 = phi i32* [ %30, %28 ], [ %25, %22 ]
%33 = getelementptr inbounds i32, i32* %32, i64 %21
store i32* %33, i32** %26
%34 = add i64 %23, 1
%35 = icmp eq i64 %23, %1
br i1 %35, label %36, label %22
36: ; preds = %31, %13
ret i32** %15
}