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


x86 assembly (clang, -O0):
<dmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x1,-0x10(%rbp)
jl     1156 <dmatrix+0x26>
cmpq   $0x1,-0x18(%rbp)
jge    117a <dmatrix+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 <dmatrix+0x122>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ba <dmatrix+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 <dmatrix+0x122>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1228 <dmatrix+0xf8>
mov    -0x18(%rbp),%rdi
call   1050 <dvector@plt>
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    1215 <dmatrix+0xe5>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1252 <dmatrix+0x122>
jmp    121a <dmatrix+0xea>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c1 <dmatrix+0x91>
cmpq   $0x0,-0x20(%rbp)
jne    124a <dmatrix+0x11a>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%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):
<dmatrix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
jle    117c <dmatrix+0x4c>
mov    %rsi,%r15
test   %rsi,%rsi
jle    117c <dmatrix+0x4c>
mov    %rdi,%r12
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     118e <dmatrix+0x5e>
mov    %rax,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r15,%rdi
call   1050 <dvector@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     11aa <dmatrix+0x7a>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <dmatrix+0x30>
jmp    11c6 <dmatrix+0x96>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
jmp    119e <dmatrix+0x6e>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11c6 <dmatrix+0x96>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%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"dmatrix: parameters n and m must be > 0\0A\00"
@.str.1 = [23 x i8] c"dmatrix: out of memory\00"
@.str.2 = [44 x i8] c"dmatrix: error allocating memory for M[%d]\0A\00"
@.str.3 = [24 x i8] c"dmatrix: out of memory\0A\00"
define double** @dmatrix(i64 %0, i64 %1) {
%3 = alloca double**
%4 = alloca i64
%5 = alloca i64
%6 = alloca double**
%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 double** null, double*** %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 double**
store double** %19, double*** %6
%20 = icmp ne double** %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 ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store double** null, double*** %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 @dvector(i64 %31)
%33 = inttoptr i64 %32 to double*
%34 = load double**, double*** %6
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double*, double** %34, i64 %36
store double* %33, double** %37
%38 = icmp ne double* %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 double** null, double*** %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 double**, double*** %6
%49 = icmp ne double** %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.3, i64 0, i64 0))
br label %53
53: ; preds = %50, %47
%54 = load double**, double*** %6
store double** %54, double*** %3
br label %55
55: ; preds = %53, %39, %21, %13
%56 = load double**, double*** %3
ret double** %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"dmatrix: parameters n and m must be > 0\0A\00"
@.str.1 = [23 x i8] c"dmatrix: out of memory\00"
@.str.2 = [44 x i8] c"dmatrix: error allocating memory for M[%d]\0A\00"
define double** @dmatrix(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 double**
%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 ([23 x i8], [23 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 @dvector(i64 %1)
%19 = inttoptr i64 %18 to double*
%20 = getelementptr inbounds double*, double** %11, i64 %17
store double* %19, double** %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 double** [ null, %6 ], [ null, %22 ], [ null, %13 ], [ %11, %26 ]
ret double** %30
}