#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 */
int /*<<< orphan*/ fatalerr(char *, int, int);
scalar_t__ malloc(int);
extern double *mat(int n, int m) {
  double *p;
  if (n <= 0 || m <= 0) {
    return NULL;
  }
  if (!(p = (double *)malloc(sizeof(double) * n * m))) {
    fatalerr("matrix memory allocation error: n=%d,m=%d\n", n, m);
  }
  return p;
}


x86 assembly (clang, -O0):
<mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1142 <mat+0x22>
cmpl   $0x0,-0x10(%rbp)
jg     114f <mat+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    118e <mat+0x6e>
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
movslq -0x10(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1186 <mat+0x66>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe7f(%rip),%rdi
call   1030 <fatalerr@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %edi,%edi
jle    1158 <mat+0x38>
mov    %esi,%r14d
test   %esi,%esi
jle    1158 <mat+0x38>
mov    %edi,%ebp
imul   %r14d,%edi
shl    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1158 <mat+0x38>
lea    0xeb2(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <fatalerr@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"matrix memory allocation error: n=%d,m=%d\0A\00"
define double* @mat(i32 %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca double*
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store double* null, double** %3
br label %30
13: ; preds = %9
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = mul i64 8, %15
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = mul i64 %16, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to double*
store double* %22, double** %6
%23 = icmp ne double* %22, null
br i1 %23, label %28, label %24
24: ; preds = %13
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = call i32 @fatalerr(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %24, %13
%29 = load double*, double** %6
store double* %29, double** %3
br label %30
30: ; preds = %28, %12
%31 = load double*, double** %3
ret double* %31
}

LLVM IR (-O2):
@.str = [43 x i8] c"matrix memory allocation error: n=%d,m=%d\0A\00"
define double* @mat(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 1
%4 = icmp slt i32 %1, 1
%5 = or i1 %3, %4
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = shl i32 %0, 3
%8 = mul i32 %7, %1
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to double*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @fatalerr(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
br label %14
14: ; preds = %6, %12, %2
%15 = phi double* [ null, %2 ], [ %10, %12 ], [ %10, %6 ]
ret double* %15
}