#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(long, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ivector(long);
int /*<<< orphan*/ stderr;
int **imatrix(long n, long m) {
  int **M;
  int i;
  if (n < 1 || m < 1) {
    fprintf(stderr, "imatrix: parameters n and m must be > 0\n");
    return NULL;
  }
  if (!(M = (int **)calloc(n, sizeof(int *)))) {
    fprintf(stderr, "imatrix: out of memory\n");
    return NULL;
  }
  for (i = 0; i < n; i++)
    if (!(M[i] = (int *)ivector(m))) {
      fprintf(stderr, "imatrix: error allocating memory for M[%d]\n", i);
      return NULL;
    }
  if (!M)
    fprintf(stderr, "imatrix: out of memory\n");
  return M;
}


x86 assembly (clang, -O0):
<imatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x1,-0x10(%rbp)
jl     1156 <imatrix+0x26>
cmpq   $0x1,-0x18(%rbp)
jge    117a <imatrix+0x4a>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1252 <imatrix+0x122>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ba <imatrix+0x8a>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1252 <imatrix+0x122>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1228 <imatrix+0xf8>
mov    -0x18(%rbp),%rdi
call   1050 <ivector@plt>
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    1215 <imatrix+0xe5>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1252 <imatrix+0x122>
jmp    121a <imatrix+0xea>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c1 <imatrix+0x91>
cmpq   $0x0,-0x20(%rbp)
jne    124a <imatrix+0x11a>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imatrix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
jle    117c <imatrix+0x4c>
mov    %rsi,%r15
test   %rsi,%rsi
jle    117c <imatrix+0x4c>
mov    %rdi,%r12
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     118e <imatrix+0x5e>
mov    %rax,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r15,%rdi
call   1050 <ivector@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     11aa <imatrix+0x7a>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <imatrix+0x30>
jmp    11c6 <imatrix+0x96>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
jmp    119e <imatrix+0x6e>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11c6 <imatrix+0x96>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
xor    %r14d,%r14d
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"imatrix: parameters n and m must be > 0\0A\00"
@.str.1 = [24 x i8] c"imatrix: out of memory\0A\00"
@.str.2 = [44 x i8] c"imatrix: error allocating memory for M[%d]\0A\00"
define i32** @imatrix(i64 %0, i64 %1) {
%3 = alloca i32**
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32**
%7 = alloca i32
store i64 %0, i64* %4
store i64 %1, i64* %5
%8 = load i64, i64* %4
%9 = icmp slt i64 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i64, i64* %5
%12 = icmp slt i64 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10, %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32** null, i32*** %3
br label %55
16: ; preds = %10
%17 = load i64, i64* %4
%18 = call i64 @calloc(i64 %17, i32 8)
%19 = inttoptr i64 %18 to i32**
store i32** %19, i32*** %6
%20 = icmp ne i32** %19, null
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32** null, i32*** %3
br label %55
24: ; preds = %16
store i32 0, i32* %7
br label %25
25: ; preds = %44, %24
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = load i64, i64* %4
%29 = icmp slt i64 %27, %28
br i1 %29, label %30, label %47
30: ; preds = %25
%31 = load i64, i64* %5
%32 = call i64 @ivector(i64 %31)
%33 = inttoptr i64 %32 to i32*
%34 = load i32**, i32*** %6
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32*, i32** %34, i64 %36
store i32* %33, i32** %37
%38 = icmp ne i32* %33, null
br i1 %38, label %43, label %39
39: ; preds = %30
%40 = load i32, i32* @stderr
%41 = load i32, i32* %7
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %41)
store i32** null, i32*** %3
br label %55
43: ; preds = %30
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %25
47: ; preds = %25
%48 = load i32**, i32*** %6
%49 = icmp ne i32** %48, null
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %50, %47
%54 = load i32**, i32*** %6
store i32** %54, i32*** %3
br label %55
55: ; preds = %53, %39, %21, %13
%56 = load i32**, i32*** %3
ret i32** %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"imatrix: parameters n and m must be > 0\0A\00"
@.str.1 = [24 x i8] c"imatrix: out of memory\0A\00"
@.str.2 = [44 x i8] c"imatrix: error allocating memory for M[%d]\0A\00"
define i32** @imatrix(i64 %0, i64 %1) {
%3 = icmp slt i64 %0, 1
%4 = icmp slt i64 %1, 1
%5 = or i1 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %29
9: ; preds = %2
%10 = tail call i64 @calloc(i64 %0, i32 8)
%11 = inttoptr i64 %10 to i32**
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %29
16: ; preds = %9, %26
%17 = phi i64 [ %27, %26 ], [ 0, %9 ]
%18 = tail call i64 @ivector(i64 %1)
%19 = inttoptr i64 %18 to i32*
%20 = getelementptr inbounds i32*, i32** %11, i64 %17
store i32* %19, i32** %20
%21 = icmp eq i64 %18, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = trunc i64 %17 to i32
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %29
26: ; preds = %16
%27 = add nuw nsw i64 %17, 1
%28 = icmp eq i64 %27, %0
br i1 %28, label %29, label %16
29: ; preds = %26, %22, %13, %6
%30 = phi i32** [ null, %6 ], [ null, %22 ], [ null, %13 ], [ %11, %26 ]
ret i32** %30
}